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

Add __geo_interface__ for items #885

Merged
merged 3 commits into from
Jan 23, 2023
Merged

Add __geo_interface__ for items #885

merged 3 commits into from
Jan 23, 2023

Conversation

gadomski
Copy link
Member

@gadomski gadomski commented Aug 27, 2022

Related Issue(s):

Description:
Adds __geo_interface__ for items, collections, and spatial extent. Includes a pystac.utils.box function that cribs from shapely, with a couple of tweaks. Collection and spatial extent geo interfaces are impelemented per @duckontheweb's suggestion (if len(bboxes) == 1, use that as a Polygon; if len(bboxes) > 1, use bboxes[1:] as a MultiPolygon).

I can see @philvarner's point that we're making an opinionated decision w.r.t. the Collection geointerface that may not be correct. It'd be good to get other's opinions on the correct Collection approach, and if there's disagreement it may make sense to remove it from this PR and put that decision off until later. I've pulled in a couple of reviewers for that reason.

PR Checklist:

  • Code is formatted (run pre-commit run --all-files)
  • Tests pass (run scripts/test)
  • Documentation has been updated to reflect changes, if applicable
  • This PR maintains or improves overall codebase code coverage.
  • Changes are added to the CHANGELOG. See the docs for information about adding to the changelog.

@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2022

Codecov Report

Base: 94.29% // Head: 94.31% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (0f28b9f) compared to base (8b2a540).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #885      +/-   ##
==========================================
+ Coverage   94.29%   94.31%   +0.01%     
==========================================
  Files          80       80              
  Lines       11909    11941      +32     
  Branches     1130     1132       +2     
==========================================
+ Hits        11230    11262      +32     
  Misses        496      496              
  Partials      183      183              
Impacted Files Coverage Δ
pystac/collection.py 92.69% <100.00%> (+0.26%) ⬆️
pystac/item.py 88.88% <100.00%> (+0.17%) ⬆️
pystac/utils.py 95.48% <100.00%> (+0.10%) ⬆️
tests/test_collection.py 99.59% <100.00%> (+0.02%) ⬆️
tests/test_item.py 99.55% <100.00%> (+<0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TomAugspurger
Copy link
Collaborator

TomAugspurger commented Aug 27, 2022

Collection and spatial extent geo interfaces are impelemented per @duckontheweb's suggestion (if len(bboxes) == 1, use that as a Polygon; if len(bboxes) > 1, use bboxes[1:] as a MultiPolygon)

This is a tough one, but worries me a bit. In pandas, I think we've regretted "values-dependent" behavior, where the output type or structure depends on the values of the input, rather than just the type, every single time we've done it (on purpose or accidentally).

What's the downside to always returning a MultiPolygon for a Collection (even if it has just a single member)? Will they be fundamentally harder for downstream consumers to use than a single Polygon?

@gadomski
Copy link
Member Author

What's the downside to always returning a MultiPolygon for a Collection (even if it has just a single member)? Will they be fundamentally harder for downstream consumers to use than a single Polygon?

I don't know -- I don't have a great sense of the downstream tooling. It felt weird to make a thing Multi when I knew it wasn't but I don't have any fundamental problem with always doing a MultiPolygon.

IMO bigger issue is whether we include the first bounding box (full envelope) in that MultiPolygon

@gadomski gadomski changed the title Add _geo_interface__ for items, collections, and spatial extent Add __geo_interface__ for items, collections, and spatial extent Nov 7, 2022
@gadomski gadomski added this to the 1.7 milestone Nov 15, 2022
@gadomski gadomski self-assigned this Jan 18, 2023
@gadomski
Copy link
Member Author

I've removed __geo_interface__ for Collections and SpatialExtents, keeping it only for Items. This seems like the best way forward, since there isn't an obvious implementation for SpatialExtents.

@gadomski gadomski changed the title Add __geo_interface__ for items, collections, and spatial extent Add __geo_interface__ for items Jan 23, 2023
@gadomski gadomski requested review from philvarner and removed request for matthewhanson and duckontheweb January 23, 2023 17:57
@gadomski gadomski requested a review from philvarner January 23, 2023 18:04
@gadomski gadomski merged commit 62e25cd into stac-utils:main Jan 23, 2023
@gadomski gadomski deleted the issues/786-geo-interface branch January 23, 2023 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement __geo_interface__
4 participants