Skip to content

feat(deck.gl-geotiff): add parseVRT to load GDAL VRT mosaics - #835

Merged
kylebarron merged 11 commits into
mainfrom
kyle/vrt-mosaic-example
Nov 3, 2026
Merged

kylebarron merged 11 commits into
mainfrom
kyle/vrt-mosaic-example

Conversation

@kylebarron

@kylebarron kylebarron commented Nov 3, 2026 •

Copy link
Copy Markdown
Member
image

Note

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

Adds parseVRT to @developmentseed/deck.gl-geotiff, which reads a GDAL VRT mosaic of COGs into MosaicLayer items, and a vrt-mosaic example that uses it.

  • parseVRT(xml, vrtUrl) returns one item per source file, in VRT order. Each item has the file's URL and its WGS84 bbox, computed from the file's DstRect and the VRT's GeoTransform and SRS. It uses DOMParser and @developmentseed/proj, and tree-shakes away when unused.
    • It throws on a warped VRT, a derived band, or a source path that isn't a URL, a /vsicurl/ path, or relative to the VRT.
    • It ignores per-source options such as SrcRect, scaling and NODATA, since each COG is drawn with its own georeferencing.
  • @developmentseed/affine gets fromGDAL, which reads a GDAL-ordered geotransform like Python's Affine.from_gdal. parseVRT uses it, so a rotated VRT is placed correctly.
  • The example reads the USGS 3DEP 1 arc-second seamless elevation VRT: 2.2 MB of XML listing 3,811 one-degree COGs.
    • It draws every file's footprint, and hovering one shows the file's name.
    • Past zoom 7, it opens and draws the files in view, under the basemap's roads, boundaries, water and labels.
    • The COG layer's default pipeline only renders unsigned integers, so the example brings its own Float32 elevation pipeline (src/elevation.ts).
  • The docs examples page gets a card for the example.

In Chrome, fetching the VRT took 1.1 s and parsing it took about 50-90 ms. A fresh zoom-7 view of 40 files finished loading in 3.7 s.

Two known limits:

  • Overlap order. Where files overlap, GDAL draws the later source over the earlier one. MosaicLayer doesn't draw overlapping items in a set order: the Flatbush search order and then TileLayer's cache order decide. That doesn't show in this example, since the USGS files only overlap by a few pixels of the same data.
  • Size. The whole XML loads before anything draws. GDAL's GTI driver keeps the tile index in FlatGeobuf or GeoParquet, which could be read by range for just the area in view, so it would scale further.

Testing:

  • 12 tests for parseVRT and one for fromGDAL. All deck.gl-geotiff (212) and affine (18) tests pass.
  • Typecheck, Biome and the example's vite build all pass.
  • Checked in a headed Chrome:
    • the Grand Canyon at zoom 8
    • Denver at zoom 10, with the basemap's roads and labels over the elevation
    • zoom 5, which shows footprints and the zoom notice and makes no COG requests
    • the antimeridian in the Aleutians
    • the hover tooltip
    • switching the colormap
    • the new card on the docs examples page

🤖 Written by Claude Code

kylebarron and others added 2 commits November 2, 2026 18:57
Reads a VRT mosaic's source files, in VRT order, into MosaicLayer items:
one per file, with its WGS84 bbox from its DstRect and the VRT's
GeoTransform and SRS. Rejects VRTs that aren't plain mosaics: warped
VRTs, derived bands, rotated geotransforms and non-URL source paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Loads the USGS 3DEP 1 arc-second seamless elevation VRT (3,811 COGs)
into a MosaicLayer: parses the VRT into items, draws every file's
footprint, and opens and draws the files in view past zoom 7 with a
Float32 elevation pipeline and a colormap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the feat label Nov 3, 2026
kylebarron and others added 8 commits November 2, 2026 19:39
Past zoom 7 the mosaic draws no elevation, so the map now stops there
instead of showing a notice. MosaicLayer's own minZoom and the notice
are removed.

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

Moves the elevation under the Dark Matter style's waterways, so its
boundaries, water, roads and labels all draw on top, and starts the
colormap's default range at 0 m.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… zoom 7"

Zooming out past the mosaic's minZoom shows every file's footprint, the
VRT's coverage, so the map can zoom out again and the notice is back.

This reverts commit 081f42b.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Centers the "zoom in" notice on the map so it's easy to see, and lets
pointer events through so the map still pans and zooms under it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mirrors Affine.from_gdal in Python's affine: reorders GDAL's
[c, a, b, f, d, e] to [a, b, c, d, e, f].

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Moves the VRT parser from the example into deck.gl-geotiff as parseVRT,
which returns a MosaicLayer item per source file. It reads the
GeoTransform with fromGDAL and places each file's DstRect through it, so
a rotated VRT is read instead of rejected. The example now imports it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Footprints only draw when their checkbox is on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kylebarron kylebarron changed the title feat(examples): add a VRT mosaic example feat(deck.gl-geotiff): add parseVRT to load GDAL VRT mosaics Nov 3, 2026
Comment thread examples/vrt-mosaic/src/zoom-notice.tsx Outdated
</Text>
<Text fontSize="xs" color="gray.500">
Each file is a 1° tile, so this far out a view would open hundreds of
them at once. Only their footprints are drawn.

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.

Only their footprints are drawn.

This is only true based on whether the footprints checkbox is drawn

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.

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Good catch. I dropped that sentence, since footprints only draw while their checkbox is on; the notice now only says why the elevation isn't drawn. Fixed in 5c629323.

🤖 Written by Claude Code

Comment thread examples/vrt-mosaic/src/vrt.ts Outdated
Comment on lines +107 to +116
/** The VRT's six `GeoTransform` coefficients, in GDAL's order. */
function readGeoTransform(
root: Element,
): [number, number, number, number, number, number] {
const values = childText(root, "GeoTransform").split(",").map(Number);
if (values.length !== 6 || values.some((v) => !Number.isFinite(v))) {
throw new Error(`Invalid VRT GeoTransform: ${values.join(", ")}`);
}
return values as [number, number, number, number, number, number];
}

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.

Don't we have a specific type-def for an Affine? Inside @developmentseed/affine. Perhaps we should read the geotransform and then immediately convert it to a standard Affine-ordered geotransform (not GDAL-order)

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.

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Done in 4ee704d0. readGeoTransform now returns an Affine, converted from GDAL order right away with the new fromGDAL, and each DstRect corner goes through apply.

That also means a rotated VRT is now placed correctly instead of rejected, so the "rejects a rotated GeoTransform" test became "places a file in a rotated VRT".

🤖 Written by Claude Code

Comment thread examples/vrt-mosaic/src/vrt.ts Outdated
throw new Error(`Unsupported VRT: ${subClass}`);
}

const [x0, dx, rx, y0, ry, dy] = readGeoTransform(root);

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.

Also, perhaps we should have a fromGdal or fromGDAL constructor in @developmentseed/affine (mimicking what Affine implements)

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.

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Added fromGDAL to @developmentseed/affine in 4077fef0, mirroring Affine.from_gdal.

Two differences from Python's version:

  • It takes the geotransform as one tuple instead of six positional arguments, so a parsed GeoTransform passes straight in.
  • I spelled it fromGDAL rather than fromGdal, to match parseGDALMetadata in @developmentseed/geotiff.

🤖 Written by Claude Code

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.

This parsing is simple enough that I think it makes sense to put inside of library code (as long as it can be fully tree-shaken if unused)

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.

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Moved to @developmentseed/deck.gl-geotiff as parseVRT (with its VRTItem type), in src/mosaic-layer/vrt.ts next to MosaicLayer, in 4ee704d0. The example now imports it, and the tests moved to packages/deck.gl-geotiff/tests/vrt.test.ts.

It tree-shakes: the package is "sideEffects": false and the module has no top-level side effects. I checked by building naip-mosaic, which doesn't use it: the bundle has no trace of the parser (no VRTDataset or relativeToVRT), while the vrt-mosaic bundle does.

🤖 Written by Claude Code

@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.

✅

bbox: [number, number, number, number];
};

const VSICURL = "/vsicurl/";

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.

What is this doing? It's a regex to take off vsicurl in GDAL urls?

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.

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Yes, though it's a plain prefix, not a regex. /vsicurl/ is GDAL's virtual file system for reading a file over HTTP(S), and gdalbuildvrt writes remote sources as /vsicurl/https://..., as in the USGS VRT. sourceUrl checks for the prefix with startsWith and strips it, leaving a URL we can fetch.

I added a doc comment on the constant, linking GDAL's virtual file system docs, in bab5be2e.

🤖 Written by Claude Code

*
* Uses `DOMParser`, so it needs a browser or a DOM implementation.
*
* @param xml The VRT's XML.

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.

Suggested change
* @param xml The VRT's XML.
* @param xml The VRT's XML body.

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.

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Applied in bab5be2e.

🤖 Written by Claude Code

* Uses `DOMParser`, so it needs a browser or a DOM implementation.
*
* @param xml The VRT's XML.
* @param vrtUrl The VRT's URL, which `relativeToVRT` paths resolve against.

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.

this is so that it can find sibling files/COGs?

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.

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Yes. A SourceFilename with relativeToVRT="1" holds a path relative to the VRT, such as tiles/a.tif for COGs next to it, so parseVRT resolves it against the VRT's URL. Absolute sources, like the USGS VRT's /vsicurl/https://... paths, don't use it.

I reworded the docstring to say so in bab5be2e.

🤖 Written by Claude Code

@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.

✅

@kylebarron
kylebarron merged commit d88b1d9 into main Nov 3, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/vrt-mosaic-example branch November 3, 2026 02:07
kylebarron added a commit that referenced this pull request Nov 5, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Bumps `version` to `0.10.0-beta.3` in the root `package.json` and in
every `packages/*/package.json`. The publish workflow publishes it under
the `beta` dist-tag, so `latest` stays on 0.9.0.

`CHANGELOG.md` gets a `v0.10.0-beta.3` section with GitHub's generated
notes for the 17 PRs merged since v0.10.0-beta.2.

## Breaking change

- #843: `MosaicLayer` no longer takes `maxCacheByteSize`. To bound an
item's memory by bytes, set `maxCacheByteSize` on the layer that
`renderSource` returns.

## Behavior changes

- #839: a `MosaicLayer` item out of view keeps its opened source in the
cache but drops its layers, which frees their textures.
- #785: `parseGeoZarrMetadata` takes Y from the first entry of
`spatial:dimensions` and X from the second, whatever their names, as
v0.1 of the spatial convention says. Lists that aren't two entries long
are rejected.
- #841: `RasterTileset2D.getParentIndex` picks the parent tile that
contains the child's centre.

## New APIs

- #835: `parseVRT` in `@developmentseed/deck.gl-geotiff`, and `fromGDAL`
in `@developmentseed/affine`.
- #789: `renderSource` gets the props that `MosaicLayer` passes to its
sublayers.

## Not included

#838 (`ZarrSource` opens from a store with a `path`) and #837
(`DEFAULT_RANGE_READER` moves to `@developmentseed/deck.gl-raster`) are
still open. Both are breaking.

🤖 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