-
Notifications
You must be signed in to change notification settings - Fork 132
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
v4 Python Bindings: h3.Polygon has no "len()" #284
Comments
Thanks for the report! It is definitely an experimental object, so I'm happy to hear any and all feedback you have about your experience using it! What version of Python are you using? Is this a runtime error or a type-checking error? |
@KcTheMapper Are you trying to pass in a shapely polygon? I assume h3 only supports geojson-like coordinates |
Hey @ajfriend, I appreciate your attention to this! I am using Python Version 3.9.6, h3 version 4 @kylebarron I am trying to pass in an h3 polygon, which appears to be the only acceptable poly to pass into in v4. |
Apologies; I haven't followed the API changes in v4 and didn't know there was a new Polygon class |
@kylebarron no worries! |
Can you share a code snippet that gives you this error? The following works for me: import h3
poly = h3.Polygon(
[(37.68, -122.54), (37.68, -122.34), (37.82, -122.34), (37.82, -122.54)],
[(37.76, -122.51), (37.76, -122.44), (37.81, -122.51)],
)
h3.polygon_to_cells(poly, 6) I can reproduce your error if I call I'm curious what bit of your code might be trying to call And it is true that Polygon is currently the only acceptable input for Also, the |
I'm encountering the same issue on import geopandas as gpd
import h3
path = gpd.datasets.get_path('nybb')
df = gpd.read_file(path).to_crs(epsg=4326)
# finding largest polygon in multipolygon
polygon = max(df.loc[0, "geometry"].geoms, key=lambda a: a.area)
assert isinstance(polygon, shapely.geometry.polygon.Polygon)
h3_poly = h3.Polygon(polygon)
assert isinstance(h3_poly, h3.Polygon)
# raises "TypeError: object of type 'Polygon' has no len()"
h3.polygon_to_cells(h3_poly, 9) Stack Trace:
I was able to fix it by changing # h3_poly = h3.Polygon(polygon)
h3_poly = h3.Polygon(polygon.exterior.coords) My first thought is maybe this has something do with holes? When I print the working code I see >>> h3_poly
<h3.Polygon |outer|=8877, |holes|=()> Attempting to print the non working one returns an error (although it initializes with no issues).
I don't totally understand this behavior but it seems like a foot gun. |
it is quite the opposite. the whole difference is @ajfriend may i ask you to speed up that "geojson" support? i started with |
Ah, thanks for the info @spawn-guy! Indeed the old xy vs yx order seems to be at the root of my trouble. I'm really not liking working with the h3.Polygon (with inners and outters) class. Thanks @Filimoa! That's getting me in a closer direction so it seems. |
@spawn-guy @KcTheMapper Thanks for the feedback on this! Apologies that I've let this languish in beta for so long. I'm hoping to get back into active development. That being said, please do keep the feedback coming around the |
@ajfriend well, you asked for it 😅 Why not just implement the I think, most of the current py geo tools support this. What do you think? |
@spawn-guy, I'm glad I did ask for it! This is great! 😄 I wasn't aware of the interface, but the fact that it seems pretty much standard makes things easier. |
h3.polygon_to_cells requires an h3 polygon input.
I get the following error when running h3.polygon_to_cells on an polygon, however:
TypeError: object of type 'Polygon' has no len()
I see that there is a no length variable tied to the h3.Polygon object, but there is a value for lengh under Polygon.outer.length
This prevents me from doing any type of polyfill-ing (er, i mean polygon_to_cells-ifying)
The text was updated successfully, but these errors were encountered: