Skip to content
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

Introduce LatLngPoly and LatLngMultiPoly #364

Merged
merged 19 commits into from
May 18, 2024
Merged

Introduce LatLngPoly and LatLngMultiPoly #364

merged 19 commits into from
May 18, 2024

Conversation

ajfriend
Copy link
Contributor

@ajfriend ajfriend commented May 4, 2024

Following from #332.

I'm leaving H3Shape instead of changing to just Shape because that seems too generic. And I think functions like geo_to_shape would be more confusing than geo_to_h3shape. Thoughts?

I'm also open to suggestions for a better name than H3Shape.

@ajfriend ajfriend marked this pull request as draft May 4, 2024 22:07
Copy link

codecov bot commented May 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (26285ef) to head (eec4c0f).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #364   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines          319       319           
=========================================
  Hits           319       319           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ajfriend
Copy link
Contributor Author

ajfriend commented May 4, 2024

Gotta drops builds like #363

@ajfriend ajfriend marked this pull request as ready for review May 5, 2024 16:16
docs/polygon_tutorial.ipynb Outdated Show resolved Hide resolved
src/h3/api/basic_int/__init__.py Outdated Show resolved Hide resolved
tests/polyfill/test_polyfill_ordering.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@nrabinowitz nrabinowitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -395,14 +395,14 @@ def uncompact_cells(cells, res):
return _out_collection(hu)


def h3shape_to_cells(h3shape, res):
def h3shape_to_cells(shape, res):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW - I don't want to second-guess this, but I'm not sure how much this approach offers over just offering polygon_to_cells and making the caller break multi-polygons into polygons. The caller still has to handle this, by choosing LatLngPoly or LatLngMultiPoly when they convert their input data, but in this context you have to handle the both shapes in separate clauses and lose the clarity of sticking to the core library API. I'm not sure that trade-off is worthwhile for a slight ergonomic improvement when prepping input.

That said, I'm sure you've thought through this, so I'm okay with this API if you think it's worthwhile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was imagining this being helpful in the API because everything is symmetric and there are no special cases. We have three classes of objects: "geo objects", H3Shapes, and cells. For any two types, there's a function that translates between them, and every function has an obvious inverse. To me, that's a nice complete set of functionality, and there are no gotchas like "oh, right... for that case, I need to give it a list of polygons".

And I don't think it is true that the caller has to handle it by choosing either LatLngPoly or LatLngMultiPoly. I think the typical use case is actually that they call geo_to_h3shape() on a GeoPandas column (which are often a mix of Shapely Polygons and MultiPolygons). So think this aligns more with what Python folks expect from working with geopandas.

Also, we have a MultiPolygon class in the core API (its just kind of hard to use), so I think this actually still matches the C code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I do generally take your point. I agree we should try to align with the C library as close as possible unless there's a good reason otherwise.

src/h3/api/basic_int/__init__.py Outdated Show resolved Hide resolved
src/h3/api/basic_int/__init__.py Outdated Show resolved Hide resolved
@ajfriend ajfriend merged commit f0fc6df into master May 18, 2024
43 checks passed
@ajfriend ajfriend deleted the aj/latlngpoly branch May 18, 2024 16:46
@ajfriend ajfriend mentioned this pull request May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants