Repository navigation
feat(raster-reproject): add an experimental target-space error metric - #708
Closed
kylebarron wants to merge 10 commits into
Closed
kylebarron wants to merge 10 commits into
kylebarron wants to merge 10 commits into
Conversation
Design for an opt-in mode in RasterReprojector that measures mesh error on the map instead of in source pixels, plus the tools to compare the two before choosing a default: an undocumented layer prop, toggles in two examples, and a metric toggle and Arctic scenario in the reprojection explainer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`new RasterReprojector(fns, w, h, { errorSpace: "target" })` measures each
test point's error on the map (where the GPU draws) instead of in source
pixels, in units of one source pixel's size on the map at the center of
the meshed area, so `maxError` keeps meaning a number of pixels. It never
calls the inverse functions, and a test point that becomes a vertex keeps
the position it was already projected to. The default stays "source".
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`RasterLayer` and `RasterTileLayer` (and so `COGLayer`, `ZarrLayer` and `MultiCOGLayer`) take an undocumented `_errorSpace: "source" | "target"` and pass it to the reprojector. Changing it rebuilds the mesh from data already loaded. The globe path ignores it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…projection A "Mesh error measured: in source pixels / on the map" selector next to each example's debug overlay switches `_errorSpace`, so the two metrics can be compared over the same view. In target mode, custom-projection skips the column stretch (`meshXScale`) that only approximates target-space error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`COMPARE_ERROR_SPACES=1 pnpm exec vitest run tests/compare-error-spaces.test.ts` prints, for real-world fixtures (scaled to overviews) and a few high-latitude and polar cases, each mode's triangle count, worst error on the map and in source pixels, projection calls and time. It is skipped in normal runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Everything specific to the NLCD image (the image, its projections, the 49th parallel, the panel subtitles, kilometers per pixel, tolerance choices, and the text of steps 1 and 3) moves into an NLCD `Scenario`, which the scene builder, story, HUD, tuning panel and app take as input. The default explainer is unchanged; a test pins its hand-written text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…xplainer A band of NASA Blue Marble imagery from 30°N to 85°N in longitude/latitude, rolled into a ring on a north polar stereographic map (EPSG:3413). Its two corners per side land on one meridian, so the 2-triangle mesh collapses the whole image onto a line: a far more dramatic first attempt than NLCD's. Its step 1 and step 3 text is a draft, marked "[Draft]". The tuning panel gets a Scenario select, and `?scenario=arctic` opens the explainer on it. Outline samples are set per image edge, since a band's top edge is a small circle on the map and its bottom edge a large one. The default-tolerance triangle count now runs up to 100,000 iterations: the library's 10,000 stopped the Arctic at 19,826 triangles of 33,830. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tuning panel's "Error measured" select, the M key, and `?metric=target` switch the explainer between the library's two error spaces. Each mode draws the gap it measures: source mode adds, in the input image, a line from each test point to where the GPU's drawn position maps back, and labels it there; target mode labels the gap on the map, as before. The counter says "px on the map" and step 3 "pixels on the map" in target mode (draft wording). Step 3 now names where the 2-triangle mesh is worst instead of assuming the image center: measured on the map, NLCD's worst point is the middle of the top edge, where Web Mercator stretches the map most. The NLCD text is unchanged in source mode. Error labels sit past the true end of their gap and move beside their dot when that would cover the panel titles, the counter or the description, and the counter no longer wraps under a narrow map. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The explainer's README covers the scenario picker, the error-metric toggle (the M key, `?metric=target`), and how to regenerate the Arctic image, whose commands reproduce the checked-in JPEG byte for byte with GDAL 3.13. The spec records what building it showed: the comparison script's actual cases, the Arctic's exact triangle counts, label placement, and that the 2-triangle mesh's worst point moves with the metric. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
marked this pull request as draft
October 13, 2026 23:43
The example toggle's label and placement now match the code; changing the prop re-meshes every cached tile, not only visible ones; NLCD's triangle change is +9% or -11% depending on the image size; and the explainer's default view does change in step 4, though not in the refactor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 14, 2026
kylebarron
added a commit
that referenced
this pull request
Oct 14, 2026
…711) We originally drafted this PR in #708, then I decided I wanted to move forward with it, and this PR is the careful implementation I did, step by step with claude. Previously, we used _input space_ to compute the error metric for when to stop mesh refinement. We used input space because gdalwarp's linear approximator also uses input space, and we wanted to be as similar to gdalwarp as possible. But that has some problems. Foremost, it requires you to have a projection function where the inverse projection is defined and valid. This means that only projections that are `1:1` bijective are supported. This leads to problems with the antimeridian (where +- 180 deg longitude both map to the antimeridian), with mapping lat/lon to polar stereographic (where the lines of +-90 deg latitude map to a single point) and with efficient globe reprojections. Instead, we're implementing the first step to switching to _output pixel_ error computations. In all of my inspections I can't see any perceptible difference visually, and claude created some statistics arguing that it's more effective for the same number of triangles. This requires a few more forward projections (we compute the local jacobian / aka local partial derivatives at the center of the input image) in order to find the screen pixel size of one pixel. But it doesn't require _any_ inverse projections, which makes it a much more reliable reprojection approach. This PR makes the output-pixel error mode experimental and opt-in. A follow-up PR will make it the default. Perhaps we'll remove input-pixel error mode altogether for the next release. ---- > [!NOTE] > This PR was written by Claude (Claude Code) on behalf of @kylebarron, not by @kylebarron. `RasterReprojector` refines its mesh until every test point's error is below `maxError`. Until now that error was measured in input pixels: the GPU's drawn position is mapped back through the inverse projection and compared with the test point, as gdalwarp's `-et` does. This adds an experimental `_errorSpace: "output"` mode that measures in output pixels instead: the distance on the map between where a test point belongs and where the GPU draws it, divided by one input pixel's size on the map. The default stays `"input"`, which builds the same meshes as before. Output mode only needs the forward projection. Input mode needs to invert the projection, which fails where the projection is N:1 rather than 1:1: at the pole of a polar map, where a whole row of a lat/lon tile meets at one point, and along the antimeridian. A 512 px EPSG:4326 tile reaching 90°N, projected to EPSG:3413, never converges in input mode; output mode meshes it with 3,439 triangles in 20 ms. ## Changes - **`@developmentseed/raster-reproject`:** `new RasterReprojector(fns, w, h, { _errorSpace: "output" })`. - The unit, one output pixel, is measured once per mesh at the center of the seed: √|det J| from half-pixel steps, the side of a square with the pixel's area on the map ([code](https://github.com/developmentseed/deck.gl-raster/blob/d148b94fe14f8db56a2fbf1f0de49d4e75f4f65e/packages/raster-reproject/src/delatin.ts#L570-L619)). Unlike the geometric mean of the pixel's two sides, it doesn't overstate sheared pixels. - Output mode never calls the inverse functions ([code](https://github.com/developmentseed/deck.gl-raster/blob/d148b94fe14f8db56a2fbf1f0de49d4e75f4f65e/packages/raster-reproject/src/delatin.ts#L422-L428)), and each split reuses its test point's projected position for the new vertex. - **`@developmentseed/deck.gl-raster`:** - `RasterLayer` and `RasterTileLayer` get an `@internal` `_errorSpace` prop, so `COGLayer`, `ZarrLayer` and `MultiCOGLayer` do too. Changing it rebuilds meshes from the tiles already loaded. - If a mesh can't be built, `RasterLayer` now draws nothing and reports the error through `raiseError` ([code](https://github.com/developmentseed/deck.gl-raster/blob/d148b94fe14f8db56a2fbf1f0de49d4e75f4f65e/packages/deck.gl-raster/src/raster-layer.ts#L262-L280)). Before, the error escaped `updateState` and the layer kept drawing its old mesh. - **Examples:** land-cover and custom-projection get a "Mesh error measured" select (input or output pixels) under "Debug overlay". In output mode, custom-projection skips its `meshXScale` column stretch, which only exists to make input-pixel error track error on the map. - **`tests/compare-error-spaces.test.ts`:** an on-demand comparison of both modes (`COMPARE_ERROR_SPACES=1`), skipped in normal test runs. - **Spec:** [`dev-docs/specs/2026-10-13-output-pixel-error-design.md`](https://github.com/developmentseed/deck.gl-raster/blob/d148b94fe14f8db56a2fbf1f0de49d4e75f4f65e/dev-docs/specs/2026-10-13-output-pixel-error-design.md). ## Comparison Triangles at the default tolerance of 0.125 px. In parentheses: each mesh's worst error in the other mode's unit. | Case | Input mode | Output mode | |---|---|---| | NLCD, Albers → Web Mercator | 5,288 (0.158 output px) | 4,726 (0.145 input px) | | NAIP in UTM 18N, LINZ in NZTM | same mesh | same mesh | | MODIS, sinusoidal → Web Mercator | 2,382 (0.188) | 2,848 (0.139) | | EPSG:4326 60–85°N tile → Web Mercator | 2,394 (0.536) | 5,598 (0.124) | | EPSG:4326 67.5–89.9°N tile → EPSG:3413 | 11,880 (0.177) | 3,426 (15.4) | | EPSG:4326 30–85°N band → EPSG:3413 | 33,810 (0.205) | 33,004 (0.953) | - **Where input pixels grow on the map**, input mode misses its tolerance on screen. That happens at high latitudes in Web Mercator, and with MODIS, whose sinusoidal pixels are sheared. On the 60–85°N tile it's 4× over; output mode adds the triangles that takes. - **Where they shrink**, toward a polar map's pole, input mode spends 3.5× the triangles on detail smaller than an output pixel. - **Projection calls:** per triangle, both modes make about as many; output mode's are all forward. ## Follow-ups - **Output mode only.** Make it the only mode, before or after the next release. That can also delete the custom-projection example's input-mode workarounds: `meshXScale`, the 89.5° pole cut, and `tileInverseReproject`'s longitude unwrap. - **The reprojection explainer** gets a metric toggle and an Arctic scenario, previewed in #708. - **#710:** pass these props to tiles through `updateTriggers`. - **#566 (globe) and #673 (antimeridian)** build on output mode. 🤖 Written by [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron
added a commit
to willjnz/deck.gl-raster
that referenced
this pull request
Oct 21, 2026
…ion explainer (developmentseed#712) > [!NOTE] > This PR was written by Claude (Claude Code) on behalf of @kylebarron, not by @kylebarron. The reprojection explainer can now show the reprojector's two error spaces, input pixels and output pixels (`_errorSpace`, from developmentseed#711), and a second scenario where they differ strongly. - **Scenarios.** The explainer is driven by a scenario: an image, its projections, a reference line and its text. NLCD (Albers → Web Mercator) stays the default and looks the same. - A new Arctic scenario rolls a 30–85°N band of NASA's Blue Marble from longitude/latitude into a ring on a polar stereographic map (EPSG:3413), with the Arctic Circle as its reference line. - A "Scenario" select in the tuning panel switches between them, as does `?scenario=arctic` in the URL. - **Error space.** The "Error measured" select, the M key, or `?metric=output` switch between the two modes. Each mode draws and labels the gap it measures: - input mode shows, in the input image, a line from each test point to where the GPU's drawn position maps back; - output mode labels the gap on the map. Step 3 names where the 2-triangle mesh is worst, because that moves with the mode: in output pixels, NLCD's worst point is the middle of the top edge, not the center. The library-default triangle count in the closing caption is computed per scenario and mode, capped at 25,000 iterations. - **Tuning panel.** It's now a sidebar beside the slide, so it never covers the animation. It starts collapsed to a slim rail, and P (for "panel", formerly H) opens it. On screens under 700 px wide it floats instead. The keys are drawn as keycaps. - **Layout fixes.** Error labels stay clear of the panel titles, the counter and the description; the counter no longer wraps under a narrow map; and the description sits lower, clear of the counter when the map fills its panel. - **README:** the scenarios, the error metric, the keys, and commands that regenerate the Arctic image from NASA's source. The Arctic image is NASA Earth Observatory's Blue Marble Next Generation (July 2004), which is free to use with credit, cropped and resampled to 2048×313 px. To try it: ```bash pnpm install pnpm build cd examples/explainers/reprojection-explainer pnpm dev ``` Then open `?scenario=arctic`, `?metric=output`, or both. Closes developmentseed#708 🤖 Written by [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR was written by Claude (Claude Code) on behalf of @kylebarron, not by @kylebarron.
Important
This is a preview: the whole design built end to end, to try out before reviewing it one step at a time. Each commit is one step, listed below in review order. Some text is a draft to replace before merge.
RasterReprojectormeasures a mesh's error in source pixels: it maps where the GPU draws each test point back through the inverse projection, like gdalwarp's-et. This adds an opt-in mode that measures the error on the map instead, where the GPU draws, in units of one source pixel's size there.maxErrorkeeps meaning "pixels", and the new mode never calls the inverse projection.What's in it
@developmentseed/raster-reproject: an experimentalerrorSpace: "source" | "target"option onRasterReprojector. The default,"source", builds the same meshes as before. In target mode, a test point's error is the distance on the map between its exact position and the GPU's linear blend of the triangle's corners, divided by one pixel's size there (code). That size is measured once per mesh, at the center of the seed: the geometric mean of how far one pixel right and one pixel down move on the map (code). Each split reuses its test point's exact position for the new vertex instead of projecting it again.@developmentseed/deck.gl-raster: an undocumented_errorSpaceprop onRasterLayerandRasterTileLayer, passed to each tile'sRasterLayer, soCOGLayer,ZarrLayerandMultiCOGLayertake it too. Changing it rebuilds the mesh.Try it
In the explainer, H opens the tuning panel and M switches the metric. These URLs open on a given setup:
?scenario=arctic: the Arctic band.?metric=target: NLCD, with the error measured on the map.?scenario=arctic&metric=target: both.In the land-cover and custom-projection examples, check "Debug overlay" and switch "Mesh error measured" to compare the two meshes.
To print the comparison table:
What the comparison shows
Triangles at the default tolerance of 0.125 px. In parentheses: the worst error in the other mode's unit.
Full table
Drafts to replace before merge
Not in this PR
Commits, in review order
08327c9fdocs(specs): the design.1a5c5e9cfeat(raster-reproject): theerrorSpaceoption.3bce939ffeat(deck.gl-raster): the_errorSpaceprop.cd465bb1feat(examples): the land-cover and custom-projection toggles.487eb05etest(raster-reproject): the comparison script.ce9b72ferefactor(examples): the explainer becomes scenario-driven, with NLCD unchanged.9f8894c7feat(examples): the Arctic scenario and the scenario picker.2a66880efeat(examples): the explainer's metric toggle.645c1a11docs: the explainer's README, and spec updates.8fb91cd4docs(specs): four corrections from a final review of the whole branch.Testing
The Arctic image is NASA's Blue Marble Next Generation, which is free to use with credit. The README has commands that regenerate it byte for byte with GDAL 3.13. The EOxCloudless mosaic in the custom-projection example would have looked more current, but it is CC BY-NC-SA 4.0, so a copy can't be checked in here.
Related to #673, #566 and #694.
🤖 Written by Claude Code