Skip to content

feat: Split COG tile traversal off TileMatrixSet - #480

Merged
kylebarron merged 20 commits into
mainfrom
kyle/affine-tileset
Apr 27, 2026
Merged

kylebarron merged 20 commits into
mainfrom
kyle/affine-tileset

Conversation

@kylebarron

@kylebarron kylebarron commented Apr 27, 2026 •

Copy link
Copy Markdown
Member

Working test image render from #375: (@cbdj is this a public image that's ok to host in an example?)

image

Working rotated umbra image from #327 (http://umbra-open-data-catalog.s3.amazonaws.com/sar-data/tasks/Port%20of%20Rotterdam%2C%20Netherlands/00864c2c-0b0f-49ef-b283-997735b27878/2025-07-29-11-17-12_UMBRA-08/2025-07-29-11-17-12_UMBRA-08_GEC.tif):

image

Summary

  • Introduces AffineTilesetLevel and AffineTileset in @developmentseed/deck.gl-raster — a generic TilesetDescriptor shape backed by a per-level affine transform plus tile and array sizes. Handles axis-aligned, rotated/skewed, and non-square-pixel grids uniformly.
  • Routes COGLayer and MultiCOGLayer through a new geoTiffToDescriptor glue function instead of generateTileMatrixSet + TileMatrixSetAdaptor. Fixes Support COGs with rotated transforms #327 (rotated COGs no longer throw) and Failing rendering with non-square pixels #375 (non-square-pixel COGs render correctly).
  • Migrates geoZarrToDescriptor onto the same shared primitives — the inline ZarrTilesetLevel and bounds derivation are gone.
  • MultiCOGLayer per-tile reprojection now goes through TilesetLevel.tileTransform() instead of morecantile + fromAffine, dropping a small layer of indirection.
  • Adds rotation() to @developmentseed/affine (port of Python rasterio/affine's rotation classmethod), and switches identity documentation along with a few other small cleanups.
  • Drops generateTileMatrixSet from the @developmentseed/geotiff public exports. The implementation and its tests stay in the source tree in case TMS-from-COG synthesis is needed in the future.

Spec: dev-docs/specs/2026-04-27-affine-tileset-design.md

Closes #456
Fixes #327
Fixes #375

Test plan

  • All 248 tests across 10 packages pass (pnpm -w test)
  • New unit tests for AffineTilesetLevel cover axis-aligned, rotated, non-square pixels, and the empty-range case
  • New unit tests for AffineTileset cover bounds derivation for axis-aligned and rotated coarsest levels
  • New unit tests for geoTiffToDescriptor cover level ordering and bounds propagation
  • New unit tests for affine.rotation() cover origin pivot, non-origin pivot, and pivot-fixed-point invariant
  • Manually verify: render an EPSG:4326 COG with non-square pixels (the dataset from Failing rendering with non-square pixels #375) — should appear in the right geographic location with no missing southern strip
  • Manually verify: render a COG with a rotated geotransform (e.g. the Umbra SAR sample from Support COGs with rotated transforms #327) — should not throw and should render correctly oriented

🤖 Generated with Claude Code

kylebarron and others added 15 commits April 27, 2026 11:02
Splits COG tile traversal off TileMatrixSet by introducing a generic
AffineTilesetLevel/AffineTileset pair in deck.gl-raster, fixing #327
(rotated COGs) and #375 (non-square pixel COGs) and unifying the COG
and Zarr tileset code paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Generic TilesetLevel implementation parameterized by an affine transform
plus tile and array sizes. Handles axis-aligned, rotated, and
non-square-pixel grids uniformly.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Move matrixWidth, matrixHeight, metersPerPixel, tileWidth, and
tileHeight to readonly fields set in the constructor. Avoids repeating
the ceil/sqrt math on every getter access during traversal.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
For bboxes that lie entirely outside the array, the symmetric
[0, maxIdx] clamp on both ends collapsed the range to a single
spurious tile (e.g., {minCol: maxIdx, maxCol: maxIdx}). Asymmetric
clamping only floor-clamps minCol/minRow and ceiling-clamps
maxCol/maxRow, so non-overlapping bboxes naturally produce min > max
and the consumer's `for (i = min; i <= max; i++)` loop emits no
tiles.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Port rotation() from the Python affine library — counter-clockwise
rotation by an angle in degrees about an optional pivot. Use it in the
AffineTilesetLevel test to express rotated/scaled affines via library
chaining instead of hand-written matrix elements.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The comment described the operations in the wrong order. compose(A, B)
applies B first then A, so the actual pixel→CRS sequence is scale,
rotate, translate — not rotate, scale, translate.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Calls out the lineage (port of Python rasterio/affine), the subset of
operations covered, and the compose() ordering convention that trips
people up.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
A TilesetDescriptor backed by per-level affine transforms. Adds a
projectedBounds field to AffineTilesetLevel (computed from the affine
applied to the array corners) and AffineTileset delegates to the
coarsest level for the dataset bounds. Exports both new primitives
from the raster-tileset barrel.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Delete the inline ZarrTilesetLevel class and projectedBounds derivation;
geoZarrToDescriptor is now thin glue around the shared primitives in
deck.gl-raster. Also re-exports the new primitives from the
deck.gl-raster top-level barrel so downstream packages can import them.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Builds an AffineTileset from a GeoTIFF without going through TMS,
correctly handling rotated, skewed, and non-square-pixel COGs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replaces generateTileMatrixSet + TileMatrixSetAdaptor with the new
affine-based descriptor. Fixes rendering for COGs with rotated/skewed
transforms (#327) and non-square pixels (#375). The mpu calculation
moves out of the helper and into the layer, mirroring how ZarrLayer
already computes it.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replaces generateTileMatrixSet + TileMatrixSetAdaptor with the new
affine-based descriptor and drops morecantile/fromAffine helpers in
favor of TilesetLevel.tileTransform. The internal SourceState's tms
field is dropped (it was unused outside the per-tile transform lookup).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replaces [geotiff, ...overviews] spread + index lookup with a direct
selection. Also corrects the off-by-one in the previous TODO comment:
the full-res level is at z === overviews.length (the last index), not
overviews.length - 1.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The function is no longer used internally; COG layers now use
geoTiffToDescriptor instead. The implementation and its tests stay in
the source tree in case TMS-from-COG synthesis is needed in the future.
The tile-matrix-set test imports the function via a relative path so
it continues to exercise the implementation.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron kylebarron changed the title Split COG tile traversal off TileMatrixSet feat: Split COG tile traversal off TileMatrixSet Apr 27, 2026
@github-actions github-actions Bot added the feat label Apr 27, 2026
Comment thread packages/affine/src/affine.ts Resolved
kylebarron and others added 5 commits April 27, 2026 12:07
CI typecheck was failing because tile-matrix-set.test.ts mixed barrel
imports (dist GeoTIFF type) with relative imports (src GeoTIFF type)
of generateTileMatrixSet — TypeScript treats the two as distinct
nominal types because of a private field on DecoderPool. Switching all
package-internal tests + helpers + polyfills to relative imports keeps
the type universe consistent.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Port cos_sin_deg from the Python rasterio/affine library: rotation()
now returns exact 0 / ±1 entries for multiples of 90° instead of the
~6e-17 floating-point noise from Math.cos/Math.sin.

Slots derived from -sa carry -0 when sa is 0, matching upstream Python
behavior (Affine.rotation(180) returns Affine(-1, -0, 0, 0, -1, 0)
there too).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Only consumed internally by COGLayer and MultiCOGLayer (both via
relative imports). External users either go through those layers (the
intended path) or build their own AffineTileset out of
AffineTilesetLevel directly. The barrel export was dead surface area.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron
kylebarron enabled auto-merge (squash) April 27, 2026 16:50
@kylebarron
kylebarron merged commit afb3dd0 into main Apr 27, 2026
5 checks passed
@kylebarron
kylebarron deleted the kyle/affine-tileset branch April 27, 2026 16:51
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.

Split off COG tile traversal from TileMatrixSet Failing rendering with non-square pixels Support COGs with rotated transforms

1 participant