You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently trying to use pyflwdir to obtain subbasins for any arbitrary points using the Hydrosheds FlowDirection GeoTiff file. I wanted to check if it may be possible with the package. I have tried a few ways, but I end up in errors so far.
Sharing my (rough) code below:
importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltimportrasteriofromrasterio.maskimportmaskfromrasterio.plotimportshowimportshapelyimportxarrayasxrimportrioxarrayasrxrimportgeopandasasgpdimportfionaimportpyflwdirfrompyflwdirimportFlwdirRaster# Read Vector geometrybasins_fn="basins.gpkg"#read Rhine basin vector from Geopackageflowdir_fn="eu_dir_3s.tif"#flowdirection file from Hydroshedslayer_name=layers[0] #select Rhine basin layergdf=gpd.read_file(basins_fn, layer=layer_name)
# Read flow direction raster and clip itrhine_shapes=gdf.geometry.valueswithrasterio.open(flowdir_fn) assrc:
#Clip flowdirout_image, out_transform=mask(src, rhine_shapes, crop=True)
out_meta=src.meta.copy()
# Update metadata for the output fileout_meta.update({
"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform
})
# Use PyFlwDir workflow to get sub-basinsrc=rasterio.open(output_path) # Rhine flowdir file from Hydroshedsflwdir=src.read(1)
transform=src.transformcrs=src.crslatlon=crs.to_epsg() ==4326flw=pyflwdir.from_array(flwdir, ftype="d8", transform=transform, latlon=latlon, cache=True)
x, y=np.array([6, 7, 8, 10]), np.array([52, 49, 50, 50]) #random points for basin outletsubbasins=flw.basins(xy=(x, y))
feats=flw.stream_order(type="strahler", mask=stream_mask)
gdf=gpd.GeoDataFrame.from_features(feats, crs=src.crs)
Currently, the last line shows the following error, while the earlier lines give some result. Not sure if my current approach is relevant..
Kind of request
Adding new functionality
Enhancement Description
Dear team,
I am currently trying to use
pyflwdir
to obtain subbasins for any arbitrary points using the Hydrosheds FlowDirection GeoTiff file. I wanted to check if it may be possible with the package. I have tried a few ways, but I end up in errors so far.Sharing my (rough) code below:
Currently, the last line shows the following error, while the earlier lines give some result. Not sure if my current approach is relevant..
Sharing the error message below:
Use case
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: