Skip to content

Update module to handle both geodetic and cartesian coordinate systems#18

Merged
reweeden merged 7 commits intomainfrom
rew/geographic-systems
Dec 22, 2025
Merged

Update module to handle both geodetic and cartesian coordinate systems#18
reweeden merged 7 commits intomainfrom
rew/geographic-systems

Conversation

@reweeden
Copy link
Contributor

@reweeden reweeden commented Oct 3, 2025

This PR refactors the module structure, docstrings and readme to reflect what I've learned about the different CMR coordinate systems to make it more clear what coordinate system each function will work correctly in.

Near the poles the geodetic and cartesian systems become very different from eachother. Luckily we can still achieve approximately the right polygons using cartesian operations (shapely) if we have a sufficiently dense polygon. This PR adds a 'densify' operation that uses pygeodesy to densify a polygon along great circle arcs. This should allow us to continue using cartesian coordinates in CMR, but produce more accurately split polygons by simply adding a densify operation to the start of our tranformation pipelines.

Old densify implementation by maximum line segment length

Here's an example of how a cartesian rectangle looks after being densified and rendered in webmercator projection:

image

And a cartesian rectangle with a hole in the middle:
image

New implementation based on cross track error

4 point diagonal box in cartesian space
image

Densified with an error tolerance of 50km:
image

Densified with an error tolerance of 20km:
image

Densified with an error tolerance of 5km:
image

With this implementation edges are only densified when they need to be in order to reduce error. For instance edges that run due north/south will not be densified at all since they are the same in both cartesian coordinates and the geodetic great circle model. Similarly, edges that run along the equator will also not be densified, but edges that run parrallel to the equator at a high latitude will be densified quite a lot.

For instance this polygon:
image

Densified with an error tolerance of 5km:
image

Only results in a small number of points being added along a single edge.

Pull Request Checklist

I have:

  • performed a self review of my code I&A code style
    • Resources and Data Structures are sorted by ABC or a defined sorting pattern
  • updated the documentation accordingly
  • verified required action checks are passing
  • bumped the version number as appropriate

@reweeden reweeden force-pushed the rew/geographic-systems branch 4 times, most recently from 38bf05d to 928c734 Compare October 6, 2025 22:24
@reweeden reweeden marked this pull request as ready for review October 6, 2025 22:35
Comment on lines +1 to +35
"""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.
"""
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@mattp0 mattp0 Dec 19, 2025

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.

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.

Im not sure this is valuable in my editor when im trying to use the transformations. but this isnt a show stopper.

@reweeden reweeden marked this pull request as draft October 10, 2025 17:16
@reweeden reweeden force-pushed the rew/geographic-systems branch from 1974060 to 4f73710 Compare December 11, 2025 20:09
@reweeden reweeden force-pushed the rew/geographic-systems branch 2 times, most recently from cec5933 to 4d5385f Compare December 11, 2025 20:22
@reweeden reweeden marked this pull request as ready for review December 19, 2025 00:27
@reweeden reweeden force-pushed the rew/geographic-systems branch from 084e93c to e44ce7e Compare December 19, 2025 00:57
@reweeden reweeden force-pushed the rew/geographic-systems branch from e44ce7e to 7e9482b Compare December 19, 2025 01:04
@reweeden reweeden requested review from gjclark and mattp0 December 19, 2025 01:08
@reweeden reweeden merged commit bcb9164 into main Dec 22, 2025
10 checks passed
@reweeden reweeden deleted the rew/geographic-systems branch December 22, 2025 18:14
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