Skip to content

feat: measure mesh error in output pixels in every layer - #721

Merged
kylebarron merged 2 commits into
mainfrom
kyle/output-mode-only
Oct 16, 2026
Merged

kylebarron merged 2 commits into
mainfrom
kyle/output-mode-only

Conversation

@kylebarron

Copy link
Copy Markdown
Member

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 feat: draw imagery across the antimeridian in output mode #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

🤖 Written by Claude Code

RasterLayer now always builds its mesh with RasterReprojector's output
mode, and RasterTileLayer gives every Web Mercator tile the antimeridian
unwrap, which needs it. The experimental _errorSpace prop is removed from
both layers; raster-reproject keeps both modes.

Input mode alone drew tiles along the 180th meridian as streaks, overflowed
the stack on some of them, and stalled on tiles touching 85.05 degrees. The
examples lose their error-space toggles, and custom-projection its column
stretch, which only imitated output-pixel error in input mode.

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

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🚀

? tile.meshInverseTransform
: tile.inverseTransform,
forwardTransform: tile.forwardTransform,
inverseTransform: tile.inverseTransform,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hmm, it would be kinda nice if we didn't even have to pass inverse transforms down into the layer.

Perhaps RasterLayer could only take forwardTransform and forwardReproject?

Perhaps we could have an overload for RasterReprojector to only require forward functions when error mode is output, not input?

initialTriangulation,
_errorSpace,
// Output mode measures error on the map and never calls the inverse
// functions, which `_wrapX`'s unwrapped projection doesn't match.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

which _wrapX's unwrapped projection doesn't match

This text is unclear

@kylebarron

Copy link
Copy Markdown
Member Author

lgtm

@kylebarron
kylebarron merged commit 50d8d12 into main Oct 16, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/output-mode-only branch October 16, 2026 17:35
kylebarron added a commit that referenced this pull request Oct 16, 2026
main removed RasterTileLayer's `_errorSpace` prop (#721), so the conflict in
raster-tile-layer.test.ts keeps this branch's zRange tests and drops the
`_errorSpace` test that main deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
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.

1 participant