Skip to content

feat(deck.gl-geotiff)!: open the files of one scene with MultiCOGSource - #801

Merged
kylebarron merged 6 commits into
mainfrom
kyle/multi-cog-source
Oct 26, 2026
Merged

kylebarron merged 6 commits into
mainfrom
kyle/multi-cog-source

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

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

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 (MultiCOGLayer: error when sources have different CRSs or extents #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 feat(deck.gl-geotiff)!: open COGs with COGSource #799.
    • A record's values can be URL strings, URLs, ArrayBuffers or opened GeoTIFFs.
    • 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:

// 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:

// Before
onGeoTIFFLoad: (geotiffs, { primaryKey, geographicBounds }) => {},

// After
onSourceLoad: ({ geotiffs, geographicBounds, multiTilesetDescriptor: { primaryKey } }) => {},

epsgResolver and concurrencyLimiter become options of MultiCOGSource.open:

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

kylebarron and others added 5 commits October 26, 2026 13:09
Resolving a GeoTIFF's CRS and building its projection functions move
into `projection.ts`, for MultiCOGSource to share.

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

`MultiCOGSource.open({ red: url, nir: url })` opens the files of one
scene in parallel and rejects files that don't make one scene (#723):
they must share a CRS, and every edge must be within one pixel of the
coarser file. It resolves the CRS once and groups the files' tile grids,
with the finest file as primary. A file that fails to open is named in
the error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MultiCOGLayer's `source` takes an opened MultiCOGSource, or a record of
COGs for the layer to open with `MultiCOGSource.open`. It replaces
`sources` and its `{ url }` wrapper (`MultiCOGSourceConfig`).
`epsgResolver` and `concurrencyLimiter` move to `MultiCOGSource.open`,
and `onSourceLoad(source)` replaces `onGeoTIFFLoad`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`MultiCOGSource` is a class of its own (question 8). The spec states the
scene checks as built, sketches MultiCOGSource, and records
MultiCOGLayer's single `source` prop and its removed props.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed mid-read

chunkd's HTTP source wraps every failed fetch, aborts included, in a
`SourceError` named "Error", so aborting `COGSource.open` or
`MultiCOGSource.open` during a header read rejected with "Failed to
fetch" instead of an AbortError. `fetchGeoTIFF` now throws the signal's
abort reason instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment on lines +303 to +307
// An opened source needs no loading
return (
props.source !== oldProps.source &&
!(props.source instanceof MultiCOGSource)
);

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.

I wonder if perhaps we could somehow get this to work by making source an async prop and overriding how the loading works? It's a little annoying here to have to check if it's an instance of the MultiCOGSource class

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.

I looked at how deck.gl 9.4 loads async props, and I don't think they fit here, for three reasons.

  • Nothing gets aborted. deck.gl calls fetch(url, { propName, layer }) without a signal (layer-state.ts), and the newest value wins only through a load counter. A replaced or removed open would keep reading headers and holding limiter slots. Stage 1's _loadMetadata aborts it today.
  • Only strings and promises are loaded (component-state.ts). Every other value is set as it is, so a record, an ArrayBuffer or a GeoTIFF would reach the layer unopened, and we'd need the check anyway. An app could pass MultiCOGSource.open(record) as a promise, though.
  • There's no load callback. deck.gl calls onDataLoad only for data, so onSourceLoad would need its own detection.

The check bothers me too. The cleaner fix is to stop repeating it. When ZarrLayer becomes the third layer with a source (stage 4), RasterTileLayer can own this plumbing once, with two hooks per layer, say isOpenedSource(value) and openSource(input, signal). The instanceof would then be one line per layer. I'd do that in stage 4 rather than here.

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

lgtm

- The package README's quick start passes COGLayer `source`, not the removed
  `geotiff`.
- `DEFAULT_CONCURRENCY_LIMITER` is the default of `COGSource.open`,
  `MultiCOGSource.open` and MosaicLayer, not of the layers' removed
  `concurrencyLimiter` prop.
- Both layers' `signal` docs say it aborts tile requests, not the open.
- MultiCOGLayer's `source` doc says an empty record draws nothing, and
  `geotiffs` is documented in the record's key order.
- The spec's goals, decision 13, `open()` steps and open questions 5 and 6
  match 2b as built.

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

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

lgtm

@kylebarron
kylebarron merged commit 6a58013 into main Oct 26, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/multi-cog-source branch October 26, 2026 18:08
kylebarron added a commit that referenced this pull request Oct 30, 2026
> [!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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MultiCOGLayer: error when sources have different CRSs or extents

1 participant