Closed sunt05 closed 4 years ago
This might be the utility we should use: http://xarray.pydata.org/en/stable/groupby.html
Here the code we can use to rasterize a geopanda shapefile before re-gridding. It does not need a raster templates. I am using this in Sri Lanka case:
import rasterio
from rasterio.features import rasterize
from rasterio.transform import from_bounds
df=sub_df_bldg #It is a shapefile dataframe with two columns of geometry and levels
dimns = 1000, 1000
dtype=rasterio.float64
transform=rasterio.transform.from_bounds(*df.total_bounds, *dimns)
rasterize_rivernet = rasterize(
[(shape, level) for shape,level in zip(df['geometry'],df['levels'])],
out_shape=dimns,
transform=transform,
fill=0,
all_touched=True,
dtype=dtype)
with rasterio.open(
'rasterized.tif', 'w',
driver='GTiff',
dtype=dtype,
count=1,
width=dimns[0],
height=dimns[1],
transform=transform
) as dst:
dst.write(rasterize_rivernet, indexes=1)
as this has been implemented, this can be closed.
https://github.com/Urban-Meteorology-Reading/WRF-SUEWS/blob/e84a333579f0a399803e2348015b3bfaabe2a003/input-processor/pre-processor-UK/utility/modify_London.py#L10-L28
we need a more performant one while keep the accuracy.