Repository navigation
feat(deck.gl-geotiff): add parseVRT to load GDAL VRT mosaics - #835
Conversation
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]>
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]>
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]>
| </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. |
There was a problem hiding this comment.
Only their footprints are drawn.
This is only true based on whether the footprints checkbox is drawn
There was a problem hiding this comment.
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
| /** 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]; | ||
| } |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
| throw new Error(`Unsupported VRT: ${subClass}`); | ||
| } | ||
|
|
||
| const [x0, dx, rx, y0, ry, dy] = readGeoTransform(root); |
There was a problem hiding this comment.
Also, perhaps we should have a fromGdal or fromGDAL constructor in @developmentseed/affine (mimicking what Affine implements)
There was a problem hiding this comment.
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
fromGDALrather thanfromGdal, to matchparseGDALMetadatain@developmentseed/geotiff.
🤖 Written by Claude Code
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
| bbox: [number, number, number, number]; | ||
| }; | ||
|
|
||
| const VSICURL = "/vsicurl/"; |
There was a problem hiding this comment.
What is this doing? It's a regex to take off vsicurl in GDAL urls?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| * @param xml The VRT's XML. | |
| * @param xml The VRT's XML body. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
this is so that it can find sibling files/COGs?
There was a problem hiding this comment.
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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
> [!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]>
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
Adds
parseVRTto@developmentseed/deck.gl-geotiff, which reads a GDAL VRT mosaic of COGs intoMosaicLayeritems, and avrt-mosaicexample 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'sDstRectand the VRT'sGeoTransformandSRS. It usesDOMParserand@developmentseed/proj, and tree-shakes away when unused./vsicurl/path, or relative to the VRT.SrcRect, scaling andNODATA, since each COG is drawn with its own georeferencing.@developmentseed/affinegetsfromGDAL, which reads a GDAL-ordered geotransform like Python'sAffine.from_gdal.parseVRTuses it, so a rotated VRT is placed correctly.src/elevation.ts).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:
MosaicLayerdoesn't draw overlapping items in a set order: the Flatbush search order and thenTileLayer'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.Testing:
parseVRTand one forfromGDAL. Alldeck.gl-geotiff(212) andaffine(18) tests pass.vite buildall pass.🤖 Written by Claude Code