-
Notifications
You must be signed in to change notification settings - Fork 27
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
DOC: Can I perform operations on the geocube pixels during rasterization? Count, Mean, etc. #28
Comments
I think it would go right here geocube/geocube/vector_to_cube.py Line 156 in 2b42f47
|
Should probably add better documentation around this, but you can pass in a custom rasterization function (examle in docs): from functools import partial
from rasterio.enums import MergeAlg
from geocube.rasterize import rasterize_image
from geocube.api.core import make_geocube
cube = make_geocube(
...
rasterize_function=partial(rasterize_image, merge_alg=MergeAlg.add),
fill=0,
) With this method, each cell should contain the count of the number of times a polygon overlapped the cell. |
Awesome, i'll try to mock something up and submit a PR with a notebook to
docs.
…On Thu, Jun 18, 2020 at 2:20 PM Alan D. Snow ***@***.***> wrote:
Should probably add better documentation around this, but you can pass in
a custom rasterization function (examle in docs
<https://corteva.github.io/geocube/stable/examples/timestamp_missing_data.html>
):
from functools import partial
from rasterio.enums import MergeAlgfrom geocube.rasterize import rasterize_imagefrom geocube.api.core import make_geocube
cube = make_geocube(
...
rasterize_function=partial(rasterize_image, merge_alg=MergeAlg.add)
)
With this method, each cell should contain the count of the number of
times a polygon overlapped the cell.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#28 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJHBLBHZIVSM7XR55M6FSLRXKAJHANCNFSM4OCEMGIA>
.
--
Ben Weinstein, Ph.D.
Postdoctoral Fellow
University of Florida
http://benweinstein.weebly.com/
|
I'm still debugging, i'll update when I fix.
isn't quite right, the cube is blank
or specifying measurements=['mask']
|
Try using |
I wasn't sure where to place, but tried both, no change.
here is the data link if its useful. I also tried removing the measurements arg. No change. Not 100%, but just using the plot error as an indicator of success. https://www.dropbox.com/s/jwxlldua58n82du/2018_BART_4_320000_4881000_image.shp?dl=0 |
The second one is correct. I suggest doing |
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 ***@***.***> wrote:
The second one is correct. I suggest doing cube.mask.plot()
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#28 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJHBLB6QF7EZKAYMWMTV5DRXLJSNANCNFSM4OCEMGIA>
.
--
Ben Weinstein, Ph.D.
Postdoctoral Fellow
University of Florida
http://benweinstein.weebly.com/
|
I was trying to do something similar, with the polygons of all cities in the world, and I would expect to get a count of cities in each cell, but it looks like I only get 0/1 values. Here is an example notebook: |
Fixed by passing rasterize_function=partial(rasterize_image, merge_alg=MergeAlg.add, all_touched=True) |
Thanks @snowman2 for your work here and others for asking questions. This helped me this evening. Not to myself to make a PR tomorrow to add "Examples - count points in grid cells" to https://corteva.github.io/geocube/stable/examples/examples.html |
Hi 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
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).
https://github.com/weecology/NEON_crown_maps/blob/master/notebooks/Create%20a%20raster%20of%20polygon%20counts.ipynb
The text was updated successfully, but these errors were encountered: