New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add groupby arg to gen_zonal_stats #134
Add groupby arg to gen_zonal_stats #134
Conversation
@perrygeo hey any thoughts on this one? |
I think this might be better left for the user to handle before running rasterstats. maybe add a demo / sample code to the wiki that covers a preprocessing step with similar functionality? |
@sgoodm I like this feature because it allows for data exploration without duplicating source data on disk or opening a desktop GIS package. Consider how useful this |
@brendancol Sorry for the delay on my end, haven't had the time to dig into code outside of work lately! I think this functionality is useful no doubt. I've done a similar type of analysis but it seems like something that could be decoupled from There are big benefits to decoupling any feature/geometry manipulation from zonal stats:
More concretely, I'd be more in favor of something like
where |
@brendancol The more I think about it, it could easily be a separate project when you consider some of the complexities that arise with aggregate functions (http://postgis.net/docs/manual-1.4/ch08.html#PostGIS_Aggregate_Functions). But I'm happy to start it out in this repo and spin it off later if we need to. How about |
This PR adds a
groupby
argument togen_zonal_stats
inspired by the ArcGIS gp.ZonalStatisticszone_field
argument. The effect is that stats are computed by group, instead of by each individual feature.The
groupby
arg takes a string or a function. If the value is a string, it is assumed to be a field present in each feature properties. If the value is a function, the function's return value will be the groupby key.Caveats:
Also included in this PR is an example shapefile for use with testing.