Skip to content

feat(geotiff): add a read method for arbitrary pixel windows - #792

Merged
kylebarron merged 2 commits into
mainfrom
kyle/geotiff-read
Nov 6, 2026
Merged

kylebarron merged 2 commits into
mainfrom
kyle/geotiff-read

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

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

Reading a region that isn't exactly one tile meant working out the covering tiles, calling fetchTiles, stitching them with assembleTiles and cropping by hand. This adds read({ window, pool, signal }) to GeoTIFF and Overview, mirroring async-geotiff's read(window=...). It fetches the tiles the window touches, stitches them, and returns a RasterArray covering exactly the window. Without a window, it reads the whole image.

Changes

  • New read.ts: works out the tiles a window touches, fetches them with fetchTiles(xy, { boundless: false, pool, signal }), stitches them with assembleTiles, and crops to the window. Reading the whole image needs no crop. The result's transform is the image transform moved to the window's origin, and it has a mask when the image has a mask IFD.
  • New Window type (colOff, rowOff, width, height) and WindowError class in window.ts, both exported. read throws WindowError for non-integer, negative or empty offsets and sizes, or a window outside the image or overview.
  • GeoTIFF.read and Overview.read are thin wrappers, like fetchTile and fetchTiles.
  • README: new "Read any pixel window" section.

Tests

  • New tests/read.test.ts with 17 tests, all failing against main:
    • whole-image reads of four fixtures: pixel-interleaved, clipped edge tiles, band-separate, and masked
    • windows that span several tiles or sit inside one tile, a band-separate window, and a masked window that reaches clipped edge tiles
    • whole and windowed overview reads
    • invalid windows, including one outside an overview but inside the full image
    • an aborted signal
  • Expected pixels come from the fixtures' rasterio-generated .npy tiles, assembled pixel by pixel in the test.

Notes

  • Window and WindowError match async-geotiff's names. WindowError is the first custom error class in these packages; it lets callers tell a bad window from a failed fetch. A file that imports Window hides the DOM's built-in Window type, which importing it under another name avoids.
  • The overview tests check pixel data only, as async-geotiff's do. The fixtures' overview mask files (mask-1-*.npy) look out of date: Overview.read masks match GDAL 3.12's overview masks exactly, but those files don't.

Closes #405

🤖 Written by Claude Code

…verview.read

Reading a region that isn't one tile meant computing the covering tiles,
calling fetchTiles, stitching them with assembleTiles and cropping the
result by hand. async-geotiff has a `read(window=...)` method for this, and
this package mirrors its API.

Add `read({ window, pool, signal })` to GeoTIFF and Overview. It fetches
the tiles the window touches with `boundless: false` (the clipped edge
tiles that assembleTiles stitches), assembles them, and crops to the window.
A whole-image read, the default, needs no crop. The result's transform is
the image transform translated to the window's origin, and it carries a mask
when the image has a mask IFD. A window with non-integer, negative or empty
offsets or sizes, or one extending outside the image, throws a new
WindowError, as in async-geotiff. Window and WindowError are exported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the feat label Oct 23, 2026
export async function read(
self: CanFetchTiles,
{
window = { colOff: 0, rowOff: 0, width: self.width, height: self.height },

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.

TIL these default values can reference self like this

@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 f4a1d90 into main Nov 6, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/geotiff-read branch November 6, 2026 16:07
kylebarron added a commit that referenced this pull request Nov 6, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Bumps `version` to `0.10.0-beta.4` in the root `package.json` and in
every `packages/*/package.json`. The publish workflow publishes it under
the `beta` dist-tag, so `latest` doesn't change.

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

## Breaking changes

- #837: `DEFAULT_RANGE_READER` moves from
`@developmentseed/deck.gl-geotiff` to `@developmentseed/deck.gl-raster`.
- #838: `ZarrSource.open` takes the store and a `path` option, instead
of a group you opened and `variable`. ZarrLayer's `source` takes a store
too.
- `open` returns a general `ZarrSource`. Narrow its data type with
`source.is("float32")`.
  - `source.arrays` is renamed to `source.levels`.
- `ZarrSource`, `ZarrLayer` and `ZarrLayerProps` lose their `Store` type
argument.

## Behavior changes

- #838: an array passed in inherits its parent group's `proj:` and
`spatial:` attributes, unless you pass `geoZarrMetadata`.
- #851: `parseGeoZarrMetadata` orders a multiscales group's levels
finest first by pixel size, whatever order its `layout` lists them in.
- #848: a change to `MosaicLayer`'s `updateTriggers.getSource` (or
`all`) unloads every item's source and opens the sources in view again.
The old items stop drawing at once.

## New APIs

- #792: `read({ window, pool, signal })` on `GeoTIFF` and `Overview`,
with the `Window` type and the `WindowError` class.
- #838: `ZarrSource.is(dtype)` and `source.node`.

## Not included

The fix for #826 (the range reader sends a read again when it arrives as
the stream holding its bytes finishes) isn't written yet.

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

geotiff: Support read method with arbitrary pixel window

1 participant