Skip to content

feat: draw imagery across the antimeridian in output mode - #714

Closed
kylebarron wants to merge 13 commits into
mainfrom
kyle/antimeridian-unwrap
Closed

kylebarron wants to merge 13 commits into
mainfrom
kyle/antimeridian-unwrap

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code) on behalf of @kylebarron, not by @kylebarron.

An image that crosses the antimeridian now renders in Web Mercator as one mesh, straight across 180°, when mesh error is measured in output pixels (_errorSpace: "output"). Today its mesh never converges and is drawn the long way around the world.

Why it broke. proj4 returns x inside one copy of the world. So a tile that crosses 180° has its west corners near +180° and its east corners near −180°, and its triangles span the whole world. The GPU then draws points near the seam in the middle of the world, and refinement piles up along the seam until it hits the iteration cap.

An image that stops just short of 180° can cross it too, when its edge tiles are fetched as full blocks, as MultiCOGLayer does. The blocks' padding runs on past 180° even though the image doesn't. #366's Digital Earth Pacific COG, in EPSG:3832, ends at 179.97°E, and its 512 px edge blocks reach 180.07°E. COGLayer cuts edge tiles to the image, so it doesn't hit this.

What changes. Each tile stays one mesh, in "unwrapped" x that may run past the world's edge, and is then cut at the edge.

  • @developmentseed/raster-reproject gets a wrapX option: the period of the output x axis, one world. With it, each vertex goes on the copy next to its neighbors:

    • A test point is measured against the copy nearest where the GPU draws it, and keeps that copy if it becomes a vertex.
    • Each corner of the initial triangulation is unwrapped by walking to it from the triangulation's center. The walk is unwrapAlong, which is exported as @internal. This keeps a 360°-wide image a world wide. Starting from the center, not a corner, means a corner at a pole can't throw the walk off.
    • The pixel size is measured the short way around the wrap.

    wrapX requires _errorSpace: "output". Output mode never calls the inverse projection, which is what made this hard in input mode (feat: antimeridian support #673).

  • @developmentseed/deck.gl-raster

    • RasterLayer gets an @internal _wrapX prop. It passes it to the reprojector and cuts the finished mesh at the world's edge, moving each part back into the world. The cut uses Sutherland–Hodgman clipping and interpolates UVs along cut edges. The debug overlay draws the cut mesh.
    • RasterTileLayer passes _wrapX: 512 to Web Mercator tiles in output mode. Input mode and the globe are unchanged.
    • Tile selection: a crossing tile's bounding volume is unwrapped around the tile's center, instead of spanning the world. Its part past the world's edge is also tested one world over. Either part alone in view selects the tile, with or without repeat, and the tile is no longer selected from the far side of the world. A tile that contains a pole has no continuous unwrap, so it is bounded across the whole world. This part applies in input mode too.
    • The debug tile outline goes the short way across the antimeridian.
  • cog-basic lists the five antimeridian fixtures from fixtures/geotiff-test-data as sources in development. Picking one switches to output pixels and draws the antimeridian for reference.

  • Spec: dev-docs/specs/2026-10-14-antimeridian-unwrap-design.md replaces the 2026-05-27 cut-in-two spec, which is now marked superseded. It explains why output-pixel error makes one mesh the better design.

Tests. The main requirement is that a crossing image is never drawn the long way around. The tests check that:

  • the unwrapped mesh spans the image's real width, never a world minus it;
  • no triangle spans more than half a world;
  • the drawn mesh lies inside the world, with a part at each edge.

They run on synthetic images, and on every tile of every level of the five fixtures through the projections COGLayer builds. A polar stereographic grid (NSIDC's EPSG:3413 extent) must be selected at every longitude, and a polar tile with the pole at a corner must mesh exactly as it does without wrapX. An EPSG:3832 edge block whose padding crosses 180°, though its image doesn't, must mesh the short way. The fixtures are EPSG:4326, rotated, UTM 60N (where the seam is curved), EPSG:3832, and 180°W to 180°E. Each fixture is also selected with the view centered on the seam and on either side of it, with and without repeat. A crossing tile meshes exactly like the same tile moved off the seam, and a tile that doesn't cross is unchanged.

Not changed here:

  • Input mode, the default, still can't draw a crossing image. A follow-up PR makes output pixels the only mode in the layers.
  • MultiCOGLayer meshes the full block of an edge tile, including the zero-filled padding past the image. In output mode, padding that crosses 180° is drawn just east of −180°, unless the render pipeline hides zeros. A follow-up could mesh only the image part of edge blocks.
  • COGLayer's geographic bounds for a projected image that crosses 180° span the whole world. So cog-basic's fitBounds zooms out to the world for the UTM and EPSG:3832 fixtures.
  • These tiny fixtures show two existing bugs, which feat: antimeridian support #673 fixed alongside its main change:
    • The Web Mercator clamp seed takes the nominal tile's latitudes, not the data's, so the 180°W–180°E strip is cut off at about 3°N.
    • The debug outline draws the nominal 64×64 tile, not the data.
  • Reprojection mesh never converges for EPSG:4326 tiles centered on the equator #713: tiles centered on the equator never converge. That is unrelated to the seam.
  • MosaicLayer and MultiCOGLayer source bounds across 180° (fix(deck.gl-geotiff): Select MosaicLayer sources across the antimeridian #639).
  • Tiles that contain a pole have no continuous unwrap.

Closes #171
Closes #366
Closes #269
Closes #374
Closes #576
Closes #673

🤖 Written by Claude Code

kylebarron and others added 12 commits October 14, 2026 17:13
The 2026-05-27 spec cut each crossing tile in two because keeping it as one
mesh needed crossing detection, vertices outside [0, 512], and an inverse
projection that agrees on every world copy. Output-pixel error (#711) removes
the inverse, walking from the first corner needs no detection, and clipping at
the world edge brings vertices back into [0, 512]. This spec replaces the old
one, which is marked superseded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A projection returns x in one copy of the world, so an image that crosses
the antimeridian has corners on both sides of it, its triangles span the
whole world, and refinement never converges. With wrapX (one world width),
each vertex goes on the copy next to its neighbors:

- a test point is measured against the copy nearest where the GPU draws it,
  and keeps that copy when it becomes a vertex;
- each corner of the initial triangulation is unwrapped by walking to it from
  the first corner (unwrapAlong), so a 360°-wide image keeps its width;
- the pixel size is measured the short way around the wrap.

wrapX requires output mode, which never calls the inverse functions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the reprojector's wrapX, the mesh of an image that crosses the
antimeridian stays in one piece, so part of it runs past the world's edge.
RasterLayer's new @internal _wrapX prop passes the period to the reprojector
and cuts the finished mesh at every multiple of it, moving each part back
into the world. Each crossing triangle is clipped (Sutherland–Hodgman) and
fan-triangulated, with texture coordinates interpolated along the cut edges.
A mesh that lies inside one world is unchanged. The debug overlay draws the
cut mesh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- RasterTileLayer passes `_wrapX` (one world) to Web Mercator tiles when
  `_errorSpace` is "output". Input mode and the globe are unchanged.
- Tile selection: each reference point of a tile's bounding volume is
  unwrapped from the tile's center, so a crossing tile's box hugs it instead
  of spanning the world. A box that runs past the world's edge is also tested
  one world over, where its other part is drawn, so either part alone in view
  selects the tile, with or without `repeat`. The dataset-bounds check allows
  a one-world shift.
- The debug tile outline unwraps each corner by walking the tile's edge, and
  PathLayer cuts it at ±180°.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every tile of every level of the five antimeridian fixtures (EPSG:4326,
rotated, UTM 60N, EPSG:3832 and edge to edge), through the projections
COGLayer builds and RasterLayer in output mode, converges, never goes the long
way across the world, and is drawn inside the world. Each is selected with
the view on the seam and on either side of it, with and without `repeat`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The five antimeridian fixtures from the geotiff-test-data submodule are
selectable in development, served with range requests by a Vite middleware
(ported from the cut-in-two prototype). Picking one switches the mesh to
output pixels, which is what can draw across 180°, and draws the antimeridian
for reference. Switching back to input pixels shows today's broken mesh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Walking to each corner from the first corner breaks when that corner is a
pole, where longitude is undefined: a corner of a polar grid's quadrant tile
landed a world away, and refinement ended in a stack overflow in _legalize.
Walk from the center of the seed's UV bounds instead, which is inside the
image and is where the pixel size is measured. That tile now meshes exactly
as it does without wrapX.

unwrapAlong's docs now state when its answer is right, and it's marked
@internal: it's exported for deck.gl-raster, not as public API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A tile that contains a pole winds through every longitude, so unwrapping its
reference points spread them over more than a world, and its box plus the
copy one world over left a gap. Views in that gap, such as 20°W, 55°N on
NSIDC's EPSG:3413 grid, selected no tiles, in every error mode. A box half a
world wide or more now covers the whole world.

Also keep proj4's x for a reference point the walk can't place, build the
clamped projection once per box, and fix a comment the other-part test made
stale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ipping

A triangle with an infinite x made clipMeshToWorld loop forever over world
copies. Leave such a triangle where it is, and find each triangle's copies
without allocating arrays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A request for the fixtures directory itself threw EISDIR from an unhandled
stream error, which stopped the dev server. Pass directories and read errors
on to the next handler. The flag for the antimeridian test images is renamed,
since the edge-to-edge image touches 180° without crossing it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Seed corners are walked from the center, tiles around a pole get a box across
the whole world, polar grids aren't clamped short of the pole, tile selection
changes in input mode too, and the dataset's bounds aren't unwrapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An image that stops just short of 180° still crosses it when its edge tiles
are fetched as full blocks, as MultiCOGLayer does: the padding runs on past
180° (#366's Digital Earth Pacific COG in EPSG:3832 ends at 179.97°E, and its
512 px edge blocks reach 180.07°E). Pin that such a block meshes the short way
with wrapX, and note the case in the spec.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 Support images spanning the antimeridian

1 participant