Skip to content

Fix inside-out polygon artifact in ObliqueMercator projection#2651

Open
jackbenn wants to merge 1 commit into
SciTools:mainfrom
jackbenn:fix/oblique-mercator-inverted-polygon
Open

Fix inside-out polygon artifact in ObliqueMercator projection#2651
jackbenn wants to merge 1 commit into
SciTools:mainfrom
jackbenn:fix/oblique-mercator-inverted-polygon

Conversation

@jackbenn

@jackbenn jackbenn commented Mar 25, 2026

Copy link
Copy Markdown

Rationale

When a polygon crosses the projection cut line (the antipodal great circle), _attach_lines_to_boundary can produce an exterior ring that traces the complement of the intended shape while still carrying the correct CCW/CW winding flag. The ring is therefore classified as exterior by _rings_to_multi_polygon, and sgeom.Polygon(exterior_ring) produces a polygon covering ~80-95% of the projection domain — causing ocean areas to render as land colour.

The fix: before processing each exterior ring in the normal holes-slurping loop, check whether the ring's polygon area exceeds half the projection domain area. If it does, the ring is inverted; replace it with boundary_poly.difference(ring_polygon) to recover the correct shape and continue to the next ring.

Regression test added in TestMisc.test_oblique_mercator_no_inverted_land using 50m Natural Earth land data (the bug only manifests at 50m or finer; AdaptiveScaler picks 50m when the map extent is small enough to require more detail).

Fixes rendering of land/ocean features in ObliqueMercator projections over the North Pacific (e.g. a Seattle–Tokyo strip map), where several large land masses (Alaska, Chukotka, Kamchatka) cross the cut line.

This is a fix for #2650

Implications

This should have no effect beyond fixing the immediate bug.

When a polygon crosses the projection cut line (the antipodal great
circle), _attach_lines_to_boundary can produce an exterior ring that
traces the *complement* of the intended shape while still carrying the
correct CCW/CW winding flag.  The ring is therefore classified as
exterior by _rings_to_multi_polygon, and sgeom.Polygon(exterior_ring)
produces a polygon covering ~80-95% of the projection domain — causing
ocean areas to render as land colour.

The fix: before processing each exterior ring in the normal
holes-slurping loop, check whether the ring's polygon area exceeds half
the projection domain area.  If it does, the ring is inverted; replace
it with boundary_poly.difference(ring_polygon) to recover the correct
shape and continue to the next ring.

Regression test added in TestMisc.test_oblique_mercator_no_inverted_land
using 50m Natural Earth land data (the bug only manifests at 50m or
finer; AdaptiveScaler picks 50m when the map extent is small enough to
require more detail).

Fixes rendering of land/ocean features in ObliqueMercator projections
over the North Pacific (e.g. a Seattle–Tokyo strip map), where several
large land masses (Alaska, Chukotka, Kamchatka) cross the cut line.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Mar 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@QuLogic QuLogic closed this Jul 14, 2026
@QuLogic QuLogic reopened this Jul 14, 2026
Comment thread lib/cartopy/crs.py
Comment on lines +1207 to +1209
# ring rather than an interior one). The tell-tale sign is an
# area that exceeds half the projection domain: a genuine land or
# ocean polygon can never be that large. Invert such rings back

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As noted in #2650, I don't know why this assertion holds. Surely if you zoom in enough, any land or ocean polygon can fill up to the entire domain.

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.

3 participants