Repository navigation
refactor(proj): share projectionFunctions and geographicBounds through @developmentseed/proj - #811
Merged
Merged
Conversation
Two helpers move here from deck.gl-geotiff, so that COGSource, MultiCOGSource and ZarrSource can share them: - `projectionFunctions(projection)` gives the functions that project a CRS to and from WGS84 and Web Mercator, and its meters per unit. - `geographicBounds(outline, projectTo4326)` gives the WGS84 bounds of a ring of points in a CRS, such as an image's corners. It walks the ring so that a ring across the antimeridian is bounded the short way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
COGSource and MultiCOGSource take `projectionFunctions` from proj, and `getGeographicBounds` passes a GeoTIFF's bounding box to proj's `geographicBounds`. It now takes a projection function rather than proj4's converter, which `projectionFunctions` no longer returns. ZarrLayer drops its own copy of the projection functions. Neither package's source imports proj4 anymore. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- `geographicBounds` doesn't walk the edge from the last point back to the first, so a ring around a pole isn't bounded correctly. Its latitudes come from the points alone. The docs no longer claim the pole case, and say to add points along curved edges. - `projectTo3857` clamps a latitude only where proj4 can't project the point, not always. The whole-world test now uses a projection that wraps longitudes, so only the walk along the ring can see that the ring goes all the way around. The old one passed without the walk. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
commented
Oct 27, 2026
| import { epsgResolver as defaultEpsgResolver } from "@developmentseed/proj"; | ||
| import { | ||
| epsgResolver as defaultEpsgResolver, | ||
| projectionFunctions, |
Member
Author
There was a problem hiding this comment.
I don't like the name projectionFunctions as a public export from @developmentseed/proj.
Someone just coming to that library would have no idea what it does
Member
Author
There was a problem hiding this comment.
eh, I think this is fine for now
Member
Author
There was a problem hiding this comment.
Note
This comment was written by Claude (Claude Code), not by @kylebarron.
We discussed projectionsTo4326And3857 and crsToWgs84AndWebMercator, which name the targets. We're keeping projectionFunctions for now, and can rename it later if it confuses people. The JSDoc spells out what it returns: the four functions to and from WGS84 and Web Mercator, and the CRS's meters per unit.
🤖 Written by Claude Code
A global grid whose cells are centered on the poles, such as a 0.25° grid of 721 rows from 90°N, reaches half a cell past them, so its bounds came out at -90.125° or -90.25°. MapLibre's `fitBounds` throws on a latitude outside -90° to 90°. The bounds now clamp it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
added a commit
that referenced
this pull request
Oct 28, 2026
> [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. Stage 4b of the Sources design, part 2 of 2 (`dev-docs/specs/2026-10-22-sources-design.md`, decisions 21 to 23). It builds on #811, which moved the projection helpers into `@developmentseed/proj`. `ZarrSource.open` opens GeoZarr data once, and `ZarrLayer` draws it: ```ts import { ZarrLayer, ZarrSource } from "@developmentseed/deck.gl-zarr"; const source = await ZarrSource.open(group, { variable: "temperature" }); const { west, south, east, north } = source.geographicBounds; new ZarrLayer({ id: "temperature", source, selection: { time: 0 }, getTileData, renderTile, }); ``` - **`ZarrSource.open(node, options)`** takes a zarrita group or array. It does four things: - reads the GeoZarr metadata from the node's attributes, or from `geoZarrMetadata`; - opens the array of each level; - resolves the CRS; - builds the tile grid and the WGS84 bounds of the finest level. Its options are `variable`, `geoZarrMetadata`, `epsgResolver` and `signal`. - **The source holds:** - `arrays`, one per level, finest first; - `dimensionNames` and `spatialDims`; - `projection`; - `tilesetDescriptor` and `geographicBounds`. Bounds are new for Zarr. It doesn't keep the parsed GeoZarr metadata, since nothing outside `open` needs it (question 9). - **ZarrLayer's `source`** takes a `ZarrSource`, or a group or array for the layer to open with the defaults. `onSourceLoad` gets the source the layer opened. As in COGLayer, RasterTileLayer handles the rest. - **`selection` stays on the layer** (decision 22). The layer checks it against the source whenever either differs from the pair it last checked. That includes a source opened from input arriving, and a selection that changed while no source was drawn. - A selection that doesn't fit goes to `onError` as "Can't draw the selection in ZarrLayer: ...", and the layer draws nothing until the selection is fixed. Before, an invalid selection failed the whole load, as "Metadata loading failed in ZarrLayer: ...". - Changing the selection never opens the source again. - Selections are compared by value, so an inline literal isn't checked again on every render. - Tiles already loaded still keep the data of the selection they were fetched with, until stage 4c. The `selection` docs now say so; the old docs recommended `updateTriggers`, which doesn't fetch again. - **Edge tiles** are clipped to each array's own shape, rather than to the GeoZarr metadata's. - **Cleanup:** the `window.*` debug lines are gone. - **Readonly:** `arrays` and `dimensionNames` are readonly, since layers share a source. ## Migration `node`, `variable`, `metadata` and `epsgResolver` are removed from ZarrLayer. `metadata` becomes the `geoZarrMetadata` option of `ZarrSource.open`. ```ts // Before new ZarrLayer({ node: group, variable: "temperature", metadata: attrs, selection, getTileData, renderTile, }); // After: a group or array as the source... new ZarrLayer({ source: group, selection, getTileData, renderTile }); // ...or, to use the options, an opened source const source = await ZarrSource.open(group, { variable: "temperature", geoZarrMetadata: attrs, }); new ZarrLayer({ source, selection, getTileData, renderTile }); ``` TypeScript rejects the removed props. JavaScript ignores them, and without a `source` the layer draws nothing. The type parameters are reordered: - **ZarrLayer:** `ZarrLayer<Store, Dtype, DataT>` becomes `ZarrLayer<DataT, Dtype, Store>`, and `ZarrLayerProps` changes the same way. The tile data type comes first, as in deck.gl's `TileLayer<DataT>` and `COGLayer<DataT>`, and then zarrita's order, as in `zarr.Array<Dtype, Store>`. - **ZarrSource:** it follows zarrita: `ZarrSource<Dtype, Store>`. ```ts // Before new ZarrLayer<zarr.Readable, "int8", TileData>({ ... }); // After new ZarrLayer<TileData, "int8">({ ... }); ``` ## Examples and docs - **Three examples open a `ZarrSource`:** aef-mosaic, dynamical-zarr-ecmwf and nldas-icechunk pass `geoZarrMetadata`, in the effect that already opens their array. In nldas-icechunk, the store module returns the source. - **zarr-sentinel2-tci** passes its group as `source`. - **README:** deck.gl-zarr's README shows both forms. - **Spec:** it records the answer to question 9, and stage 4b as built. ## Tests - **`ZarrSource`:** 12 tests against an in-memory GeoZarr store. They cover: - levels finest first, `variable`, `geoZarrMetadata`, the dimension names and the tile grid; - the bounds, checked against proj4's corners; - node registration moving the bounds by half a pixel; - a global grid centered on the poles staying within -90° to 90°, using #811's clamp; - the signal reaching every read, and an aborted signal; - dimensions without names, and x before y. - **ZarrLayer:** - An opened source draws without opening anything. - The load signal reaches `ZarrSource.open`. - The newer source wins a race. - A selection that doesn't fit: - is reported, and draws nothing; - draws again once fixed, without opening the source again; - isn't reported again for an equal selection; - is checked, at its newest value, once a source opened from input arrives; - is checked when it changed while there was no source and the old source comes back. - The tile callback reads the finest level's edge tile at the selection. The test checks the array, the clipped 176-pixel width and height, and the slice spec. - The 4 `isLoaded` tests and the error-routing test now use `source`. - **Type tests:** - `state.source` is exactly `ZarrSource`, and `ZarrSource<"int8">` for an int8 layer. - `onSourceLoad` gets a `ZarrSource`. - The removed props are rejected, and so is a string as `source`. - **Mutation checks:** each of these makes a test fail: - not checking the selection when a source arrives; - comparing the selection with the old props instead of with the pair last checked; - comparing selections by identity; - drawing while the selection doesn't fit; - mapping levels the wrong way; - not clipping edge tiles; - leaving the selection out of the slice spec; - removing #811's latitude clamp. - **In Chrome:** - dynamical-zarr-ecmwf draws as before. Its animation changes the selection at every step. - aef-mosaic draws as before. Switching the year reads no `zarr.json`. - nldas-icechunk draws as before. - zarr-sentinel2-tci reads from a local data server, which I didn't run, so I only typechecked it. 🤖 Written by [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
Stage 4b of the Sources design, part 1 of 2 (
dev-docs/specs/2026-10-22-sources-design.md, decision 23). Two projection helpers move into@developmentseed/proj, so that COGSource, MultiCOGSource and the coming ZarrSource share one copy. Behavior is unchanged except for one fix, described below.projectionFunctions(projection)moves from deck.gl-geotiff. It gives the functions that project a CRS to and from WGS84 and Web Mercator, and the CRS's meters per unit. It no longer returns proj4's converter, which only the bounds calculation used.geographicBounds(outline, projectTo4326)is the antimeridian-aware walk from deck.gl-geotiff'sgetGeographicBounds. It takes any ring of points in a CRS and returns[west, south, east, north]. A ring across the antimeridian is bounded the short way, witheastpast 180°. COG bounds pass the image's bounding box as the ring. ZarrSource will pass the corners of its finest level.resolveProjection, which reads a GeoTIFF'scrs.getGeographicBoundsstays internal, and now takes a projection function.Neither deck.gl-geotiff's source nor deck.gl-zarr's imports proj4 anymore. deck.gl-geotiff's tests still do. deck.gl-zarr's package.json lists proj4 and wkt-parser, which nothing there imports now. I left both package.json files alone; trimming them can be a follow-up.
One fix
geographicBoundskeeps latitudes within -90° to 90°.fitBoundsthrows on such a latitude. The ZarrSource review found this for that grid.Limits, now documented
geographicBounds's docs state two limits that the old code already had:Fixing either would change behavior, so I left them for their own PR.
Tests
projectionFunctions, on UTM 60N and WGS84 parsed from WKT: projects to WGS84 and back, matches proj4 for Web Mercator, gives the meters per unit, and rejects a projection without units.geographicBounds, on five rings:getGeographicBoundskeep their expected values. They cover the antimeridian, a rotated image and the whole world. Only their helper changed, to pass a projection function. COGSource's and MultiCOGSource's tests run the realprojectionFunctions.projectionFunctions.🤖 Written by Claude Code