-
Notifications
You must be signed in to change notification settings - Fork 0
Update module to handle both geodetic and cartesian coordinate systems #18
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9e4c449
Refactor transformations module to split out cartesian
reweeden c87fa6a
Add function to densify polygon along geodetic lines
reweeden c596762
Remove default_transformer
reweeden 3b0237f
Update documentation
reweeden b25b1a5
Bump version number
reweeden 4fbc34a
Densify using crossTrackDistanceTo to determine error from cartesian
reweeden 7e9482b
Update `drop_z_coordinate` to work with holey polygons too
reweeden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """Geospatial helpers to prepare spatial extents for submission to CMR. | ||
|
|
||
| CMR can interpret polygons as being in one of two coordinate systems, Cartesian | ||
| or Geodetic. Transformation helpers that must assume they are working in one of | ||
| these two coordinate systems all found in their own submodules `cartesian` and | ||
| `geodetic`. | ||
|
|
||
| Each coordinate system also has its own set of constraints that polygons must | ||
| follow. These constraints are documented in the corresponding module for the | ||
| coordinate system. | ||
|
|
||
| There are some additional constraints that depend on the data format being used. | ||
| For UMM-G, polygons must | ||
| - Be counter clockwise ordered | ||
| - Include closure points | ||
|
|
||
| In this module, polygons are expected to follow the UMM-G constraints. | ||
|
|
||
| A table describing the differences between data format requirements can be found | ||
| here: | ||
| https://wiki.earthdata.nasa.gov/display/CMR/Polygon+Support+in+CMR+Search+and+Ingest+Interfaces | ||
|
|
||
| There are several challenges with representing polygons on a spherical surface, | ||
| the primary being that since all straight lines will 'wrap around' the surface, | ||
| it becomes impossible to unabmiguously define a polygon using only an ordered | ||
| set of points. This is the primary reason for the CMR requirements, as those | ||
| additional constraints make it possible to determine exactly which area is | ||
| meant by a set of points. Unfortunately, the polygons that we get from the data | ||
| provider won't necessarily meet those same requirements and we must use mission | ||
| specific knowledge to convert them to an unambiguous set of polygons to be used | ||
| by CMR. | ||
|
|
||
| This module aims to assist in that conversion to unambiguous polygons using the | ||
| CMR additional requirements. | ||
| """ | ||
|
|
||
| from geo_extensions.transformations.cartesian import ( | ||
| simplify_polygon, | ||
| split_polygon_on_antimeridian_ccw, | ||
| split_polygon_on_antimeridian_fixed_size, | ||
| ) | ||
| from geo_extensions.transformations.general import drop_z_coordinate, reverse_polygon | ||
| from geo_extensions.transformations.geodetic import densify_polygon | ||
|
|
||
| __all__ = ( | ||
| "densify_polygon", | ||
| "drop_z_coordinate", | ||
| "reverse_polygon", | ||
| "simplify_polygon", | ||
| "split_polygon_on_antimeridian_ccw", | ||
| "split_polygon_on_antimeridian_fixed_size", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """Geospatial helpers that work the same regardless of which coordinate system | ||
| the polygons are using. | ||
| """ | ||
|
|
||
| from shapely.geometry import Polygon | ||
|
|
||
| from geo_extensions.types import TransformationResult | ||
|
|
||
|
|
||
| def reverse_polygon(polygon: Polygon) -> TransformationResult: | ||
| """Perform a shapely reverse operation on the polygon.""" | ||
| yield polygon.reverse() | ||
|
|
||
|
|
||
| def drop_z_coordinate(polygon: Polygon) -> TransformationResult: | ||
| """Drop the third element from each coordinate in the polygon.""" | ||
| yield Polygon( | ||
| shell=((x, y) for x, y, *_ in polygon.exterior.coords), | ||
| holes=[ | ||
| ((x, y) for x, y, *_ in interior.coords) | ||
| for interior in polygon.interiors | ||
| ], | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This feels more like readme info. I think as a user of the module. Id rather just have a bit of info on the constraints, the key bits about umm-g formatted polygon. The rest feels a bit noisy. I think linking to a readme for more info would make more sense. its just a huge text block when you hover the transformations.
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.
Interesting take. I find it quite useful to have all the info I need show up when I hover over something in my editor rather than have to exit to another application (web browser), find the correct third party link and look stuff up there. I quite like using doc strings to document the code and I also think it makes the docs less likely to go out of date as the code churns.
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 am inclined to lean towards what Matt is saying. It does kind of feel like a readme. That being said, I also see the case for having it here and am more than happy with its current location.
Uh oh!
There was an error while loading. Please reload this page.
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 like having the doc string but this is TLDR situation imo.
Im not sure this is valuable in my editor when im trying to use the transformations. but this isnt a show stopper.