Repository navigation
feat(deck.gl-geotiff)!: open COGs with COGSource - #799
Conversation
RasterSource is the base class of opened raster data (the tile grid and geographic bounds), and RasterSourceLayerProps the `source` and `onSourceLoad` props of layers that draw one. RasterTileLayer gains two hooks for them: `_abortMetadataLoad`, for a layer whose metadata no longer needs loading, and `_tileLayerId`, so a subclass can replace the inner TileLayer, which builds its tile grid only once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`COGSource.open(input, options)` opens a COG once: it reads the header, resolves the CRS, and builds the tile grid and geographic bounds, as COGLayer does today. Its options take over COGLayer's data settings: `epsgResolver`, `concurrencyLimiter` and the limiter's `getPriority`. It rejects with an AbortError when its signal aborts, including before any read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
COGLayer takes an opened COGSource as `source`. The `geotiff` prop is now shorthand: the layer opens it with `COGSource.open` and calls the new `onSourceLoad(source)`, which replaces `onGeoTIFFLoad`. `epsgResolver` and `concurrencyLimiter` move to `COGSource.open`. A new source gets a new inner TileLayer, because deck.gl's TileLayer builds its tile grid only once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The RasterSource base class, the clean break, onSourceLoad, and the 2a/2b split are decided; texture formats on the source are deferred. The spec also records why a new source needs a new inner TileLayer, and two open questions: where onSourceLoad lives, and MosaicLayer's own onSourceLoad. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eline can't draw When a live COGLayer's `source` changed to a COG the default pipeline can't draw, inferring the pipeline threw before state changed, so the layer kept drawing the previous source. Clear the state first, as the shorthand path already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
left a comment
There was a problem hiding this comment.
lots of thoughts...
| tilesetDescriptor, | ||
| return { | ||
| source, | ||
| sourceVersion: (this.state.sourceVersion ?? 0) + 1, |
There was a problem hiding this comment.
perhaps this is related to #797 ?
Do we need some way to update when tiles need to be regenerated?
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
The counter is gone. RasterTileLayer now names its inner TileLayer after the descriptor object, so COGLayer doesn't count its sources at all (see my reply on _tileLayerId). In a7f8305.
On #797: it's related, but a different need.
- Forward updateTriggers to the inner TileLayer, so tiles can be refetched #797 refetches on the same grid. Its
updateTriggerswould calltileset.reloadAll(), which refetches tiles on the TileLayer's existing grid. That's what a newgetTileDataorselectionneeds. - A new source usually brings a new grid, which the existing tileset can't take. deck.gl builds it once from
TilesetClass, and its options don't carry our descriptor. So a new grid needs a new TileLayer.
The spec now says this.
🤖 Written by Claude Code
| * Ignored when `source` is set. | ||
| */ | ||
| epsgResolver?: EpsgResolver; | ||
| geotiff?: COGInput; |
There was a problem hiding this comment.
Yeah, we shouldn't have both geotiff and source props; there should only be source.
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Done, as in my reply on RasterSourceLayerProps: there's one source prop, and geotiff is removed. In ec9787d.
🤖 Written by Claude Code
deck.gl's TileLayer builds its tile grid once, from its first descriptor. Instead of COGLayer counting its sources into a subclass hook, RasterTileLayer now names its inner TileLayer after the descriptor, so any new descriptor gets a new TileLayer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
COGLayer's `source` takes either an opened COGSource or what `geotiff` used to take: a URL string, a `URL`, an `ArrayBuffer` or an opened `GeoTIFF`, which the layer opens with `COGSource.open`. The `geotiff` prop is removed, and so is `RasterSourceLayerProps`: COGLayer declares `source` and `onSourceLoad` itself, since each layer takes its own inputs. `RasterSource`'s constructor is protected, for subclasses' factories. The examples move to `source`. land-cover adds its layer once the source opens, with async/await, and naip-mosaic keeps its `geotiffCache` names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Decision 6 now has one `source` prop, the spec explains why each tile grid gets its own inner TileLayer (and how that differs from #797), and the open questions cover MosaicLayer's naming and one class or two for files of one scene. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The COG can open before react-map-gl creates the map, which leaves the map ref empty and skips `fitBounds`. Fit once both the source and the map have loaded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MosaicLayer's items move to deck.gl's `data` prop, `getSource(item)`
stays, and the callbacks receive the opened source as `{ source }`, so
"source" always means a RasterSource.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| const mosaicLayer = new MosaicLayer<PartialSTACItem, GeoTIFF>({ | ||
| const mosaicLayer = new MosaicLayer<PartialSTACItem, COGSource>({ | ||
| id: "naip-mosaic-layer", | ||
| sources: stacItems, |
There was a problem hiding this comment.
doesn't this need to be renamed to data as the prop name?
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Not in this PR: MosaicLayer's API doesn't change here, so its items prop is still sources. The rename to data is recorded for stage 3, together with { source } in the callbacks and MosaicItem (spec question 7). Stage 3 is the one that reworks MosaicLayer and its examples.
If you'd rather have it in this PR, it's contained: MosaicLayer, its tileset and tests, and naip-mosaic, which is the only example that uses it.
🤖 Written by Claude Code
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Decided: sources stays in this PR. The rename to data lands in stage 3 with MosaicLayer's other renames: { source } in the callbacks, and MosaicItem (spec question 7).
🤖 Written by Claude Code
| /** The number of `descriptor`, the same for as long as the object lives. */ | ||
| function descriptorId(descriptor: RasterTilesetDescriptor): number { | ||
| let id = descriptorIds.get(descriptor); | ||
| if (id === undefined) { | ||
| id = nextDescriptorId++; | ||
| descriptorIds.set(descriptor, id); | ||
| } | ||
| return id; | ||
| } |
There was a problem hiding this comment.
this feels like a bit of a hack. Is it possible to do like id(object) like it is in Python?
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
JavaScript has no built-in equivalent of Python's id(): it never exposes an object's identity as a value. There are two ways to give an object a number:
- A WeakMap from object to number, which is what this does. It doesn't mutate the object, and it doesn't keep the object alive.
- A property written onto the object, such as a Symbol. That would mutate a descriptor someone else created.
The WeakMap is the usual idiom. What made it look like a hack was the one-off descriptorId name, so it's now a generic objectId(object), documented as the stand-in for id(). The call site reads `raster-tile-layer-${this.id}-${objectId(descriptor)}`. In 7826ed6.
🤖 Written by Claude Code
kylebarron
left a comment
There was a problem hiding this comment.
just a couple more comments, but lgtm!
`descriptorId` becomes a generic `objectId(object)`, documented as JavaScript's stand-in for Python's `id()`: JavaScript doesn't expose an object's identity, so it hands out numbers from a WeakMap. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| const descriptorIds = new WeakMap<RasterTilesetDescriptor, number>(); | ||
| let nextDescriptorId = 0; | ||
| /** The numbers {@link objectId} has handed out, by object. */ | ||
| const objectIds = new WeakMap<object, number>(); |
There was a problem hiding this comment.
I think we should keep RasterTilesetDescriptor in the type here
eh, actually let's rename that last change. I like descriptorIds better than objectIds
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Reverted: it's descriptorIds and descriptorId(descriptor) again, with the WeakMap typed by RasterTilesetDescriptor. The only thing kept from the rename is a sentence in the WeakMap's doc: JavaScript doesn't expose an object's identity like Python's id(), which is why the numbers live in a WeakMap. In a8ed257.
🤖 Written by Claude Code
Keep the WeakMap typed by `RasterTilesetDescriptor` and named after descriptors, and say in its doc why it's a WeakMap: JavaScript has no equivalent of Python's `id()`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ce (#801) > [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. Stage 2b of the Sources design, `dev-docs/specs/2026-10-22-sources-design.md`: the files of one scene, such as the band files of one Sentinel-2 image, open as a `MultiCOGSource`. Files that don't make up one scene are rejected (#723). ```ts const source = await MultiCOGSource.open( { red: `${base}/B04.tif`, nir: `${base}/B08.tif`, swir: `${base}/B12.tif` }, { epsgResolver, signal }, ); map.fitBounds(source.geographicBounds); new MultiCOGLayer({ id: "s2", source, composite: { r: "swir", g: "nir", b: "red" } }); ``` - **`MultiCOGSource.open(record, options)`** (deck.gl-geotiff) opens every file in parallel. - It checks that the files make up one scene, then resolves their CRS once. - It groups their tile grids, with the finest file as the primary, which drives the tile grid. - It takes the same options as `COGSource.open`. - It holds `geotiffs` (by name), `projection` and `multiTilesetDescriptor`, plus `RasterSource`'s `tilesetDescriptor` and `geographicBounds`, both from the primary. - **The checks (#723).** Each file is compared with the first one. - **CRS:** the CRSs must be identical, comparing EPSG codes by number and WKT or PROJJSON by value. - **Extent:** every edge of a file's bounding box must be within one pixel of the coarser file. Bands of different resolutions may end slightly apart, but a mosaic of different scenes fails. - **Resolution:** no constraint. - **Errors:** a mismatch names both files. - **A file that fails to open is named:** `Failed to open "nir" (<url>): <reason>`, with the original error as its `cause`. An abort stays a plain `AbortError`. - **`MultiCOGLayer`'s single `source` prop** takes an opened `MultiCOGSource`, or a record of COGs that the layer opens itself, as COGLayer does since #799. - A record's values can be URL strings, `URL`s, `ArrayBuffer`s or opened `GeoTIFF`s. - When the layer opens the record itself, it calls `onSourceLoad(source)`. - **Shared code:** `COGSource.open` and `MultiCOGSource.open` share the CRS resolution and projection setup. - **Fix for both sources:** an abort while a header read is in flight now rejects with an `AbortError`. It used to reject with the HTTP source's "Failed to fetch" error. sentinel-2, the only example that uses MultiCOGLayer, moves over. The spec records that `MultiCOGSource` is a class of its own, and the checks as built. Docs that still described the removed props are updated, including the package README's quick start, which #799 missed. Both layers' `signal` docs now say it aborts tile requests but not the open. ## Migration `MultiCOGLayer` no longer takes `sources`, `epsgResolver`, `concurrencyLimiter` or `onGeoTIFFLoad`, and `MultiCOGSourceConfig` is removed. TypeScript rejects them. In JavaScript they're ignored without a warning. `sources` becomes `source`, without the `{ url }` wrapper: ```ts // Before new MultiCOGLayer({ sources: { red: { url: redUrl }, nir: { url: nirUrl } } }); // After new MultiCOGLayer({ source: { red: redUrl, nir: nirUrl } }); ``` `onGeoTIFFLoad` becomes `onSourceLoad`, and its arguments become fields of the source: ```ts // Before onGeoTIFFLoad: (geotiffs, { primaryKey, geographicBounds }) => {}, // After onSourceLoad: ({ geotiffs, geographicBounds, multiTilesetDescriptor: { primaryKey } }) => {}, ``` `epsgResolver` and `concurrencyLimiter` become options of `MultiCOGSource.open`: ```ts const source = await MultiCOGSource.open({ red: redUrl, nir: nirUrl }, { epsgResolver }); new MultiCOGLayer({ source }); ``` Files that don't share a CRS and an extent are now rejected. MultiCOGLayer used to draw them with the first file's CRS. ## Tests - **The checks:** - Sentinel-2-like 10, 20 and 60 m bands of one tile pass. - A 15 m band whose edge is 20 m off, within the coarser 30 m pixel, passes. - Different CRSs, the same CRS given as an EPSG code and as WKT, and an edge 61 m off between 10 m and 60 m bands are rejected, naming the files. - Equal PROJJSON objects pass. - **`MultiCOGSource.open`:** - A mix of `GeoTIFF` and `ArrayBuffer` inputs opens. - A record of one file opens. - Files in different CRSs are rejected before either CRS is resolved. - A failed file is named, with `cause`. - An abort during a header read rejects with an `AbortError`, tested through the real HTTP source, for `COGSource` too. - URLs use the shared limiter by default. - An empty record is rejected. - **`MultiCOGLayer`:** - Stage 1's race test now goes through `MultiCOGSource.open`, and the load signal is passed to the open. - An opened source opens nothing and never sets `loadingMetadata`. - An opened source replacing an open in flight aborts it. - A record replacing an opened source opens. - An empty record draws nothing, without an error. - Type tests pin `source`, `onSourceLoad` and the removed props. - **Mutation checks:** removing any of these makes a test fail: - the CRS check, the coarser pixel as the tolerance, the plain `AbortError`, or the scene check in `open`; - the layer's abort check, `_abortMetadataLoad`, or its handling of an opened source. - **In Chrome:** sentinel-2 loads and fits a scene. The SWIR preset, which mixes 20 m and 10 m bands, draws, and switching scenes fits the new scene. Closes #723 🤖 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. Bumps `version` to `0.10.0-beta.1` in the root `package.json` and in every `packages/*/package.json`, ready for the first 0.10 beta. The publish workflow sees `beta` in the version and publishes to npm under the `beta` dist-tag, so `latest` stays on 0.9.0. `CHANGELOG.md` gets a `v0.10.0-beta.1` section listing the 19 PRs merged since v0.9.0. ## Publish `@developmentseed/range-reader` by hand before tagging `@developmentseed/range-reader` (#806) isn't on npm yet, and `@developmentseed/geotiff` and `@developmentseed/deck.gl-geotiff` depend on it. The publish workflow can't create it: it publishes only through trusted publishing (OIDC), and npm can add a trusted publisher only to a package that [already exists](https://docs.npmjs.com/cli/v11/commands/npm-trust). Pushing the tag first would fail at `range-reader`. `pnpm publish --recursive` stops at the first failure, so packages published before it in the run would be out, and the rest, including `geotiff` and `deck.gl-geotiff`, would not. Once this is merged, from an up-to-date `main`: 1. Publish it once, as a public package under the `beta` tag. Its `prepublishOnly` script builds it first. ```sh cd packages/range-reader pnpm publish --tag beta --access public --no-git-checks ``` 2. Give it the same trusted publisher as the other packages (workflow `release.yml`, environment `release`), in its settings on npmjs.com or with: ```sh npm trust github @developmentseed/range-reader --file release.yml --repo developmentseed/deck.gl-raster --env release --allow-publish ``` 3. Tag the merge commit `v0.10.0-beta.1` and push the tag. The workflow skips `range-reader`, since that version is already on npm, and publishes the other ten packages. ## Breaking changes - #799: `COGLayer` takes a single `source`: an opened `COGSource`, or any input of `COGSource.open`. `geotiff` becomes `source`, `onGeoTIFFLoad` becomes `onSourceLoad`, and `epsgResolver` and `concurrencyLimiter` move to `COGSource.open`. - #801: `MultiCOGLayer` does the same with `MultiCOGSource`. `sources: { red: { url } }` becomes `source: { red: url }`, `MultiCOGSourceConfig` is removed, and files that don't share a CRS and an extent are rejected. - #804: `MosaicLayer`'s `sources` becomes deck.gl's `data`, and `MosaicSource` becomes `MosaicItem`. The callbacks get the item's opened source as `source`, and `onViewportLoad`'s entries are `{ item, source }`. - #821: `renderSource` gets only `{ source }`, without `signal`. - #812: `ZarrLayer` takes a `ZarrSource`, or a zarrita group or array, as `source`. `node`, `variable`, `metadata` and `epsgResolver` are removed (`metadata` becomes `ZarrSource.open`'s `geoZarrMetadata`), and the type parameters are now `ZarrLayer<DataT, Dtype, Store>`. - #807: `GeoTIFF.fromUrl` no longer takes `chunkSize` or `cacheSize`. They're `RangeReader` options now (`minMetadataReadBytes`, `cache.metadataBytes`). Two behavior changes aren't marked breaking: - #809: COG tile reads are coalesced by default, and `COGLayer` and `MultiCOGLayer` default to `maxRequests: 256` and `debounceTime: 50`. - #818: changing `updateTriggers.getTileData`, or ZarrLayer's `selection`, fetches tiles again, and the old tiles are removed at once. 🤖 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. Fixes a regression from #1355. A `RasterLayer` with a tile matrix set (`RasterLayer.from_geotiff`, or the generic constructor) asked Python for every visible tile again whenever the map re-rendered. That includes changing any layer property, panning, and several times during the initial load. deck.gl-raster 0.10 names its inner `TileLayer` after the `tilesetDescriptor` object (developmentseed/deck.gl-raster#799), so a new descriptor makes a new `TileLayer` with an empty cache. `RasterModel.render()` built a new `TileMatrixSetAdaptor` every time. Now it's memoized on the tile matrix set and the CRS converters, which only change when Python sets `_tile_matrix_set` or `_crs`. The PMTiles path uses deck.gl's own `TileLayer` and wasn't affected. ## Testing Tile fetches counted from Python, with a UTM (EPSG:32618) COG loaded through `from_geotiff`: | | Initial load | After setting `opacity` | After a 15 px pan | |---|---|---|---| | deck.gl-raster 0.8.1 (before #1355) | 16 | +0 | +0 | | deck.gl-raster 0.10.0 (`main`) | 22 | **+16** | **+32** | With this PR, using a global `WebMercatorQuad` grid, the initial load has no duplicate requests, and a small pan only requests the row of tiles that comes into view (6 new, 0 repeats). - New UI test `test_tile_matrix_set_tiles_not_refetched_on_rerender` fails on `main` (36 requests instead of 24) and passes here. - `uv run pytest`: 368 passed, 1 skipped. - `pnpm build`, `pnpm check` and `pnpm test` pass. `tsc --noEmit` reports the same 9 errors as `main`. 🤖 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.
Stage 2a of the Sources design,
dev-docs/specs/2026-10-22-sources-design.md: an app can open a COG once, as aCOGSource, and pass it to any number ofCOGLayers.RasterSource(deck.gl-raster) is the base class of opened raster data: the tile grid,tilesetDescriptor, and the WGS84geographicBounds.COGSource.open(input, options)(deck.gl-geotiff) reads the header, resolves the CRS and builds the tile grid, once.URL, anArrayBufferor an openedGeoTIFF.epsgResolverandconcurrencyLimiter, plusgetPriorityandsignal.AbortErrorwhen the signal aborts, including before any read.COGLayer's singlesourceprop takes an openedCOGSource, or any input ofCOGSource.open.isLoadednever waits on it.COGSource.open's defaults and calls the newonSourceLoad(source).getTileData: deck.gl reports the error throughonErroronce, prefixed with "initialization of" or "update of" the layer, and the layer draws nothing.TileLayerbuilds its tile grid once, on its first update.RasterTileLayernow names its inner TileLayer after the descriptor object, so a new descriptor gets a new TileLayer.The examples move to
source. The ones with their own EPSG resolver callCOGSource.open:geotiffCachenow holdsCOGSources.COGSources too.The spec records the stage 2 decisions.
Migration
COGLayerno longer takesgeotiff,epsgResolver,concurrencyLimiteroronGeoTIFFLoad. TypeScript rejects them. In JavaScript they're ignored without a warning.geotiffbecomessource, with the same inputs:onGeoTIFFLoadbecomesonSourceLoad, which gets the opened source:epsgResolverandconcurrencyLimiterbecome options ofCOGSource.open:MultiCOGLayer and ZarrLayer don't change here. Their props move in stages 2b and 4.
Open questions
These are recorded in the spec.
onSourceLoadlives. COGLayer declaressourceandonSourceLoaditself, since each layer'ssourcetakes its own inputs. Whether ZarrLayer shares a props type for them is open until stage 4.MultiCOGSourcewould keepCOGSource.geotiffa singleGeoTIFF. To decide in stage 2b.The spec also records a decision for stage 3. MosaicLayer's items move to deck.gl's
dataprop, and its callbacks receive the opened source as{ source }, so "source" always means aRasterSource.Tests
COGSource.open:epsgResolver, and a WKT or PROJJSON CRS is parsed without it.nulldisables it.COGLayer:loadingMetadata.onSourceLoad.sourcedraws nothing, without an error.COGSource.open.source's type,onSourceLoad'sCOGSource, and the removed props.RasterTileLayer: the same descriptor keeps its inner TileLayer, and a new descriptor replaces it.Ref #723. Stage 2b closes it.
🤖 Written by Claude Code