DOC: Can I perform operations on the geocube pixels during rasterization? Count, Mean, etc.
See original GitHub issueHi this is my first foray into geocube. Thanks for your work here, clearly a good idea.
I’d like to add an example usage that I believe should be possible, but not just quite getting right.
Is it possible to count the number of polygons in a cell, or perform operations on the geocube pixels during rasterization? Imagine a geopandas dataframe with many polygons. For each cell, perform some numpy operation (like rasterstats does) on the incoming polygons. I can perform pandas like operation after creating a geocube, but it doesn’t preserve the spatial object. I feel like the group_by argument is in this direction, but could not succeed.
Something like
#Turn each set of predictions into a raster
import geopandas as gpd
from shapely.geometry import Polygon
from geocube.api.core import make_geocube
#a numeric column to count
g["mask"] = 1
cube = make_geocube(vector_data=g, resolution=(-50, 50), function=mask.count())
To create a heatmap of number of polygons in each cell.
Here is a notebook to help illustrate use case (sorry the geocube svg doesn’t play well with ipython on github).
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top GitHub Comments
Fixed by passing
all_touched=True
:yup. that did it. I’m away for the weekend, but i’ll try to fork and submit a notebook PR to add as a resource on monday. Thanks.
On Thu, Jun 18, 2020 at 8:12 PM Alan D. Snow notifications@github.com wrote:
– Ben Weinstein, Ph.D. Postdoctoral Fellow University of Florida http://benweinstein.weebly.com/