-
Notifications
You must be signed in to change notification settings - Fork 116
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 gdf_zonal_stat to main.py #293
base: master
Are you sure you want to change the base?
Conversation
here is a function to get the result of the zonal stat directly as a Geodataframe to keep all the properties and the geometry together with the initial vectors CRS. I you think there's a more efficient way to do this I would be happy to ear it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea for a user experience improvement. I'd like to see a test but we can add that later.
src/rasterstats/main.py
Outdated
""" | ||
|
||
gdf = gpd.GeoDataFrame.from_features( | ||
list(gen_zonal_stats(vectors, geojson_out=True, *args, **kwargs)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from_features
should be able to take an iterable sequence - we could remove the intermediate list
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, I have just tried without the list
and it works !
function `list` was not necessary
Are you talking about unit test or just an example ? |
A unit test would be ideal. Geopandas is included in the CI test runner so it should work. |
I am not sure I did it the right way but I added a unit test and updated the function to fit to a file path input |
@@ -4,13 +4,14 @@ | |||
import sys | |||
|
|||
import numpy as np | |||
import geopandas as gpd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see in the test you runned that there are problems with geopandas import. I don't know what to do to solve this. Maybe I was not supposed to add this line to the test file ?
Hello,
I am not sure it's the best way to do this but I would like to propose a function to get the result of the zonal stat directly as a Geodataframe to keep all the properties and the geometry together with the initial vectors CRS. I you think there's a more efficient way to do this I would be happy to ear it.