Skip to content

Fix inside-out polygon artifact in ObliqueMercator projection#2651

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

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

Conversation

@jackbenn
Copy link

@jackbenn jackbenn commented Mar 25, 2026

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
Copy link

CLAassistant commented Mar 25, 2026

CLA assistant check
All committers have signed the CLA.

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.

2 participants