Skip to content

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

Merged
kylebarron merged 13 commits into
mainfrom
kyle/antimeridian-wrap-x
Oct 15, 2026
Merged

kylebarron merged 13 commits into
mainfrom
kyle/antimeridian-wrap-x

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Antimeridian handling has been a requested feature for a long time. It took a little while but I'm happy with where we're ending up, architecturally.

For one, we no longer split the mesh in two, like one of my previous attempts did.

And our switch to using an error metric in output space rather than in input space (#711) makes it a lot simpler to compute the reprojection mesh.

Here's an example of rendering across the antimeridian of a Sentinel 2 TCI image in Fiji:

image image image

Note

This PR was written by Claude (Claude Code), 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"). Before, its mesh never converged and was 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. The same wrap made a crossing tile's bounding box span the world, so the tile was selected everywhere. It also sent the tile's debug outline the long way around, and made getGeographicBounds span the world, so the examples' fly-to zoomed out to the far side of it.

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 past 180° 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.

The approach. The forward projection is made continuous across the wrap before the mesh is built, and the finished mesh is cut at the world's edge. The reprojector stays planar: it knows nothing about world copies, Web Mercator or longitudes. RasterLayer is told only that its output x wraps with some period, and RasterTileLayer, which knows it draws in Web Mercator's common space, passes the period. This replaces #714, which unwrapped inside the reprojector and gave the same meshes.

What changes.

  • @developmentseed/proj gets nearestCopy, which moves a value by whole periods next to a reference, and unwrapAlong, which unwraps a value at the end of a path by walking along it.
  • @developmentseed/deck.gl-raster
    • RasterLayer gets an @internal _wrapX prop: the period of the output's x axis. With it, RasterLayer lifts the image's forward projection. It unwraps the image's corners by walking to each from the image's center, then moves each projected x to the copy nearest the bilinear blend of the corners at that pixel. The unchanged reprojector meshes the result, and RasterLayer cuts the mesh at the world's edge, moving each part back into the world (Sutherland-Hodgman, with UVs interpolated along cut edges). _wrapX requires _errorSpace: "output", which never calls the inverse projection; that is what made this hard in input mode (feat: antimeridian support #673). The debug overlay outlines the mesh as drawn.
    • RasterTileLayer sets the period, 512, in its Web Mercator branch, and passes it as _wrapX in output mode. Input mode and the globe are unchanged.
    • Tile selection: a tile's reference points are unwrapped from its center, so a crossing tile's box hugs it. The part past the world's edge is also tested one world over, so either part alone in view selects the tile, with or without repeat, and it is no longer selected from across the world. A box half a world wide or more covers the whole world, which handles tiles around a pole. This also fixes a bug where a polar grid's root tile was culled near the antimeridian and no tile was selected. Tile selection changes in input mode too.
    • The debug tile outline goes the short way across the antimeridian, and its label sits in the world copy nearest 0°.
  • @developmentseed/deck.gl-geotiff: getGeographicBounds bounds an image across the antimeridian the short way. West is in [-180°, 180°), and east may run past 180°, as MapLibre's fitBounds accepts.
  • cog-basic, in development, serves the five antimeridian fixtures from fixtures/geotiff-test-data and lists them as sources. Picking one switches to output pixels and draws the antimeridian.
  • Spec: dev-docs/specs/2026-10-14-antimeridian-unwrap-design.md replaces the 2026-05-27 cut-in-two spec, now marked superseded.

Tests. The main requirement is that a crossing image is never drawn the long way around. The tests check that the unwrapped mesh is under half a world wide and crosses exactly one world edge, that no drawn triangle is wider than half a world, and that 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 antimeridian fixtures, through the tileset and RasterLayer that COGLayer builds. The fixtures are EPSG:4326, rotated, UTM 60N (where the seam is curved), EPSG:3832, and 180°W to 180°E, and each is selected with the view on the seam and on either side of it, with and without repeat. A crossing image meshes exactly like the same image moved off the seam, and an image that doesn't cross is unchanged. An EPSG:3832 edge block whose padding crosses 180° meshes the short way, a polar grid (NSIDC's EPSG:3413 extent) is selected at every longitude, and an EPSG:3031 tile with the pole at a corner is drawn as it would be without wrapping.

Not changed here:

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

🤖 Written by Claude Code

kylebarron and others added 12 commits October 15, 2026 12:28
A longitude repeats every 360°, and x in Web Mercator every world width, so
a projection returns them in one copy and they jump across the wrap.
nearestCopy moves a value by whole periods next to a reference. unwrapAlong
walks a path and moves each step next to the one before, so it finds the
right copy at the end even when the two ends are a whole period apart, like
the two edges of a 360°-wide image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s edge

RasterTileLayer renders every view but the globe in Web Mercator's common
space, whose x repeats every world (512 units). That branch now sets the
period, and each tile's RasterLayer gets it as `_wrapX` in output mode, so a
tile that crosses the antimeridian is meshed in one piece and cut at the
world's edge. Input mode and the globe don't wrap.

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

proj4 returns x inside one world, so the reference points of a tile that
crosses the antimeridian landed at both edges of it, and its bounding box
spanned the whole world: the tile was selected everywhere, even with the
view across the world from it.

Each reference point's x is now unwrapped by walking to it from the tile's
center, so the box hugs the tile and may run past the world's edge. The
frustum test also checks the part past the edge one world over, where
RasterLayer draws it, and the bounds check allows a one-world shift.

A box half a world wide or more becomes a whole-world box. That covers tiles
around a pole, where longitude has no continuous unwrap. It also fixes a bug
on main: the root tile of a polar grid contains the pole, but its nine
reference points left a gap in its box around the antimeridian, so at 160°W,
55°N no tile was selected at all.

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

The debug outline joined a tile's four corners as proj4 returned them, inside
one world, so a tile across the antimeridian was outlined the long way around
the world, and its label sat on the far side of it.

Each corner's longitude is now unwrapped by walking the tile's edge to it, and
the PathLayer wraps longitudes, cutting the path at the antimeridian. Steps of
more than 90° are split, since wrapLongitude takes each step the short way, so
a whole-world tile keeps its width. The label goes in the world copy nearest
0°.

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

getGeographicBounds took the extremes of the corners' longitudes as proj4
returned them, inside one world, so an image across the antimeridian was
bounded the long way around the world, and the fly-to in the examples zoomed
out to the far side of it.

Each corner's longitude is now unwrapped by walking the image's outline to it.
West is moved into [-180°, 180°) and east with it, so east may run past 180°,
as MapLibre's fitBounds accepts. An image that goes all the way around gets
-180° to 180°.

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

The five antimeridian fixtures in geotiff-test-data now go through the same
tileset and RasterLayer that COGLayer builds. Each is selected on and beside
the seam, with and without repeat, and every tile at every level converges.
An image that crosses is meshed less than half a world wide, across exactly
one world edge, and drawn as two parts inside the world.

Two cases from #714's reprojector tests now go through RasterLayer with
proj4: a Digital Earth Pacific edge block whose zero-filled padding crosses
180° though its image doesn't (#366), and an Antarctic tile with the pole at a
corner, drawn as it would be without wrapping.

A unit test pins the lift's guard against walking onto a corner that's a
pole: with a projection that gives no longitude there, reaching the pole
would make every x NaN.

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

In development only, cog-basic's Vite server serves the geotiff-test-data
fixtures at /__fixtures/, with HTTP range requests, so COGLayer reads them the
way it reads a COG from a bucket. The five antimeridian fixtures appear in
the image picker. Picking one switches to output mode, which can mesh across
180°, and draws the antimeridian over it, at both 180° and -180°, since only
one is in the world copy the map is centered in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The antimeridian spec now describes the design as implemented: the
reprojector stays planar; RasterLayer, told its x wraps, lifts the image's
forward projection so that it's continuous across the wrap, meshes it, and
cuts the mesh at the world's edge; RasterTileLayer passes the period for Web
Mercator; and tile selection, the debug outlines and the fly-to bounds unwrap
longitudes the same way. The cut-in-two spec is marked superseded, and
world-copies.md notes the one-world shift in the bounds check and the test of
a tile's part past the world's edge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the feat label Oct 15, 2026
…-basic

cog-basic's antimeridian test images are synthetic and all but black. This
adds a real one: Sentinel-2 tile 1KAB, in UTM zone 1, from 2025-04-27. It
spans 179.24°E to 179.72°W, and the 180° meridian runs through Taveuni, Fiji.
It comes from Earth Search's Collection 1, whose COGs are public; the older
sentinel-cogs bucket has no COG for this tile.

The test images are now `DEV_FIXTURES`, served from geotiff-test-data in
development only, and the option flag is `renderAntimeridian`: it draws the
antimeridian, and for now also switches to output mode, until output mode is
the only mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kylebarron
kylebarron merged commit c7db345 into main Oct 15, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/antimeridian-wrap-x branch October 15, 2026 19:06
@willjnz

willjnz commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Awesome work @kylebarron! 🚀

kylebarron added a commit that referenced this pull request Oct 16, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Every layer now measures mesh error in output pixels. `RasterLayer`
always builds its mesh with `RasterReprojector`'s output mode (#711),
and so do the layers built on `RasterTileLayer`: `COGLayer`, `ZarrLayer`
and `MultiCOGLayer`. The experimental `_errorSpace` prop is removed from
`RasterLayer` and `RasterTileLayer`. `@developmentseed/raster-reproject`
keeps both modes, and its own default stays `"input"`.

**What changes for users**

- **`maxError` is in output pixels.** The default is still 0.125. It now
bounds how far the mesh may draw a point from where it belongs on the
map, in units of one input pixel's size on the map, normally measured at
the center of the meshed area. Before, it bounded a distance in the
source image, found through the inverse projection.
- **Imagery across the antimeridian draws by default.** Every Web
Mercator tile now gets #716's unwrap, which needs output mode, so an
image that crosses 180° is meshed in one piece and cut at the world's
edge. Before, unless `_errorSpace: "output"` was set, such a tile hit
the iteration cap and was drawn the long way around the world. The globe
is unchanged: it still draws a uniform grid.
- **Meshing no longer calls the inverse projection.**

**Why**

Output mode needs only the forward projection, and #711 found it at
least as accurate on screen in every case it measured. On a polar
EPSG:3031 COG, input mode alone drew the tiles along the 180th meridian
as streaks across the map, overflowed the stack on some of them, and
stalled at the iteration cap on every tile touching 85.05°. Both modes
fail on the tile that contains the pole.

**Costs**

Every tile meshed as `RasterTileLayer` meshes it in Web Mercator, at
`maxError` 0.125:

- **Ordinary tiles**, 3,328 tiles of raster-reproject's NLCD, MODIS,
NAIP, LINZ and CC11 fixtures built into pyramids of 512 px tiles: 1.9%
more triangles (110,989 vs 108,938) and 50% more meshing time (0.215 vs
0.143 ms per tile, medians of 7 runs). About half of the extra time is
output mode's meshing itself; the rest is the unwrap and the cut at the
world's edge.
- **A global EPSG:4326 pyramid** takes 24% more triangles and 79% more
time. Its tiles touching 85° take about 3x the triangles and 4x the
time, because input mode left them 0.54 to 0.79 output pixels off on the
map, against 0.10 to 0.13 now.
- **Images across 180°** go from the iteration cap (10,003 to 20,004
triangles, drawn across the world) to 2 to 40 triangles.

**Examples**

- cog-basic, land-cover and custom-projection lose their "Mesh error
measured" select, and cog-basic no longer switches modes when an
antimeridian source is picked.
- custom-projection drops its `meshXScale` column stretch, which only
made input-pixel error track error on the map. Its polar views now take
25 to 35% fewer triangles and mesh about 5x faster.
- The reprojection explainer still compares both modes through
`RasterReprojector`.

**Tests**

The layer tests now describe one mode. `RasterLayer` builds its mesh
when its inverse functions throw, and meshes an image across the
antimeridian with `_wrapX` alone. `RasterTileLayer` gives every Web
Mercator tile `_wrapX` 512, and globe tiles none. Six `deck.gl-raster`
tests and eight `deck.gl-geotiff` antimeridian fixture tests fail on
main and pass here. The tests of the removed prop are gone.

**Not changed here**

- custom-projection's 89.5° cut at the poles. Output mode converges up
to the pole, so the cut now saves only about 1% of the triangles, but
removing it would change what the example draws.
- Tiles that contain a pole, which neither mode meshes, and #713's
equator stall, which happens in both modes.

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@willjnz willjnz mentioned this pull request Oct 18, 2026
4 tasks done
kylebarron added a commit that referenced this pull request Oct 22, 2026
<img width="2452" height="1283" alt="image"
src="https://github.com/user-attachments/assets/1bb97dd6-112c-468b-8809-f76f4f6e602b"
/>
<img width="2121" height="1241" alt="image"
src="https://github.com/user-attachments/assets/07cc4b99-ebf9-463d-9cbd-a596b58c8555"
/>


> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Adds `examples/explainers/antimeridian-explainer`, a step-by-step
animation of how deck.gl-raster meshes an image that crosses the
antimeridian (±180°). It replaces #703, which explained #673's design,
with the mechanism on `main` today (#716 and #721).

The explainer follows `antimeridian_UTM_60N.tif` from geotiff-test-data:
42 x 42 pixels of 20 km in UTM zone 60N, over the Aleutian Islands. It
reads the file live from GitHub at a pinned commit. The maps draw
Natural Earth's 1:50m land (public domain) under the meshes, also read
live. In the close-up, the coastlines go over the image too, so the
Aleutians show through it. If the land can't be read, the maps fall back
to a plain graticule. There are nine steps:

1. **An image across 180°**: the image as stored, with the 180° meridian
through it, and where it belongs on the map: at both edges.
2. **Two triangles**: the reprojector starts from two triangles.
3. **Project the corners**: proj4 returns every point in one copy of the
world, so both triangles stretch across it.
4. **Refining can't fix it**: a time-lapse of the reprojector refining
that projection. It stops at its cap, 20,001 triangles, still 616 output
pixels off.
5. **Walk to the corners**: `unwrapAlong`'s walk from the image's
center. Each sample is numbered, and shown where proj4 puts it, in a
whole-world strip, and where it moves to, in a close-up of the seam.
6. **Snap every point**: the reprojector projects four check points in
each triangle, 320 times in all for this image, and the layer snaps
every one to the copy nearest the blend of the unwrapped corners. A
probe, the explainer's own, sweeps the image to show it: proj4's answer
jumps a world at 180°, while the snapped point moves smoothly.
7. **Mesh as usual**: the library's refinement of the snapped
projection, replayed split by split. It finishes in 40 triangles.
8. **Cut at the world's edge**: `clipMeshToWorld` cuts the 10 triangles
that cross -180° and moves the overhang one world over.
9. **On the map**: the world copies put the two parts back together at
the seam.

Steps 3, 5, 6 and 8 play in beats. Each press of Next plays one beat, so
the image panel and the map panels can be followed one at a time.

Every corner, sample, snapped point, split and cut comes from the
functions `RasterLayer` calls, called in its order:

- `makeUnwrappedReprojectionFns`, which uses `unwrapAlong` and
`nearestCopy`;
- `RasterReprojector`, with output-pixel error;
- `clipMeshToWorld`.

`makeUnwrappedReprojectionFns`, `clipMeshToWorld` and
`rescaleEPSG3857ToCommonSpace` aren't exported from
`@developmentseed/deck.gl-raster`, and its export map blocks deep
imports. The explainer reaches them through a private alias in its own
`vite.config.ts` and `tsconfig.json`, pointing at the built `dist/`. The
package's exports don't change.

Also included:

- a card in the Explainers section of the docs examples page;
- the design spec,
`dev-docs/specs/2026-10-21-antimeridian-explainer-design.md`.

As with the other explainers, the code is LLM-generated and unreviewed
(see its README).

Closes #703

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron added a commit to thatbudakguy/deck.gl-raster that referenced this pull request Oct 22, 2026
Resolve import conflicts with developmentseed#716 and developmentseed#732: keep main's new imports
alongside `toPixelInterleaved`.

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

2 participants