Comments (2)
hi @MauKruisheer,
You can pass multiple locations to the basins method as a tuple of x and y coordinates at once, instead of looping over your geodataframe as shown in this example. The streams argument is optional and used to snap outlet points the nearest downstream stream. You can also rasterize your own stream network using e.g. rasterio to get a stream network mask instead of using the a stream order based mask (or create the stream order mask outside the loop).
Note however, that if some points are within the basins of other points you would have to sum the contributing areas of each subbasin to get the total contributing area. You could use the snap method but provide a mask of the outlet points instead of the streams to snap points to the next downstream point and use this info to determine which areas you have to sum.
from pyflwdir.
hi @DirkEilander ,
Thanks for your answer. The first part of your answer seems to work for me: many basins are being created. The second part of your answer I tried to do, but seem to fail.. Can you explain/show how this snap method works? I am now doing this:
`
with rasterio.open(flwdir_fn, "r") as src:
flwdir, _ = mask(src, watershed_lvl0.geometry, invert=False)
flwdir = flwdir.reshape(flwdir.shape[0] * flwdir.shape[1], flwdir.shape[2])
crs = src.crs
flw = pyflwdir.from_array(
flwdir,
ftype="d8",
transform=src.transform,
latlon=crs.is_geographic,
cache=True,
)
streams = readFile(intermediate_dir / 'RiverBinary_R.tif')
subbasins = flw.basins(xy=(x, y))
gdf_bas = vectorize(subbasins.astype(np.int32), 0, flw.transform, src.crs, name="basin")
gdf_bas.to_file(intermediate_dir / 'test_basins.shp')
points = pd.merge(left=geo_df, right = gdf_bas, how='inner', left_index= True, right_on= "basin")
points.rename({'geometry_x': 'geometry'}, axis=1, inplace=True)
exampleR = rioxarray.open_rasterio(flwdir_fn, masked=True).squeeze()
points_R = shpToRaster(points, exampleR, "basin").to_array().squeeze()
points_Binary = points_R.values > 0
idxs1, dists = flw.snap(xy= (x, y), mask= points_Binary*1, unit="m")
`
from pyflwdir.
Related Issues (20)
- Distance to river network HOT 3
- User guide instructions for plotting import error HOT 2
- Failed read MERIT flowdir HOT 4
- Subcatchment routing hierarchy by landuse HOT 8
- unexpected results adjust_dem
- prioritize non-boundary cells with same elevation over boundary cells in dem.fill_depressions
- fix version number in docs
- use pyflwdir package to parse nextxy data of CaMa-Flood! HOT 8
- error in plotting the river mouths using the nextxy.bin dataset HOT 7
- increase short river lengths
- subgrid floodplain schematization
- river branch map
- check compatibility with latest numpy and py3.11
- No implementation of function Function(<built-in function heappush>) found for signature HOT 5
- method to get all upstream nodes for vector based flow directions
- working with circular grids HOT 1
- deal with missing nodata values in from_dem method HOT 1
- check minimal required numba version
- Helper function to get coordinates from linear indices HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyflwdir.