aggregate raster data to polygons with area-weighting #671
-
|
A very common use case for USGS (and others in hydrology) is to aggregate raster data over some polygon (e.g. total precipitation over a watershed). xagg is a package to aggregate gridded data in xarray to polygons in geopandas using area-weighting from the relative area overlaps between pixels and polygons. A raster of weights is generated for each polygon, then the weight raster is multiplied by the data raster and summed to get the value for the polygon. Could xarray-spatial do this kind of calculation? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
|
For this sort of problem I would use |
Beta Was this translation helpful? Give feedback.
-
|
That is what I meant, yes, but I realise now that doesn't give you the area weighting that you want. |
Beta Was this translation helpful? Give feedback.
-
|
Hello, I wanted to hop onto this discussion and ask if xarray-spatial had implemented any area weighted methods since this post? |
Beta Was this translation helpful? Give feedback.
@rsignell-usgs @alaws-USGS just wanted to chime in here, hope all are well. Like @ianthomas23 mentioned, xarray-spatial doesn't handle the rasterization step (yet...), but it does have zonal.apply() which takes an arbitrary callable on irregular zonals defined by contiguous values / labels.
Assuming you rasterized using datashader or another method...the xarray-spatial steps would look like: