Skip to content

fix: handle antimeridian-crossing tiles in Web Mercator reprojection#374

Open
james-willis wants to merge 1 commit intodevelopmentseed:mainfrom
james-willis:fix/antimeridian-mesh-divergence
Open

fix: handle antimeridian-crossing tiles in Web Mercator reprojection#374
james-willis wants to merge 1 commit intodevelopmentseed:mainfrom
james-willis:fix/antimeridian-mesh-divergence

Conversation

@james-willis
Copy link

Summary

Fixes #366 — COG tiles near ±180° longitude cause RasterReprojector mesh refinement to diverge in Web Mercator mode.

Problem

When rendering an EPSG:4326 COG that spans the antimeridian, forwardTo3857 maps nearby source coordinates on opposite sides of ±180° to EPSG:3857 x-values ~40 million meters apart (+20M vs -20M). The mesh triangles connecting these vertices span the entire map, and the reprojection error never converges (currentError=43200 after 10001 iterations).

Solution

In COGLayer._renderSubLayers, for the Web Mercator code path:

  1. Detect antimeridian-crossing tiles — project the four tile corners to EPSG:3857 and check whether their x-values span more than half the world circumference (~20M meters)
  2. Wrap the projection functions — shift negative EPSG:3857 x-values by +circumference so the tile's coordinate space is continuous (all positive), and unwrap in the inverse direction

This makes the mesh subdivision see a smooth, continuous coordinate space instead of a discontinuity, allowing RasterReprojector to converge normally.

Changes

  • packages/deck.gl-geotiff/src/cog-layer.ts:
    • Added HALF_CIRCUMFERENCE constant
    • Added antimeridian detection + projection wrapping logic in the Web Mercator branch of _renderSubLayers

Testing

  • Build passes (pnpm build)
  • Lint passes (pnpm lint)
  • Existing tests are unaffected (pre-existing Node.js version issue prevents test runner from starting on this machine)

@github-actions github-actions bot added the fix label Mar 25, 2026
Tiles near ±180° longitude cause RasterReprojector mesh refinement to
diverge because forwardTo3857 maps nearby source coordinates on opposite
sides of the antimeridian to EPSG:3857 x-values ~40M meters apart.

Detect these tiles by checking if corner x-values in EPSG:3857 span
more than half the world circumference, then wrap the projection
functions to make the coordinate space continuous.

Extract the wrapping logic into wrapAntimeridianProjections() in proj.ts
with unit tests covering no-op passthrough, wrapping detection,
coordinate continuity, and forward/inverse round-tripping.

Closes developmentseed#366
@james-willis james-willis force-pushed the fix/antimeridian-mesh-divergence branch from 39cf0d5 to 7280242 Compare March 25, 2026 21:39
@james-willis james-willis marked this pull request as ready for review March 25, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COG tiles near ±180° longitude cause RasterReprojector mesh divergence in Web Mercator mode

1 participant