Skip to content

feat(examples): experimental custom projection example with polar stereographic COGs - #694

Merged
kylebarron merged 9 commits into
mainfrom
kyle/custom-projection-example
Oct 7, 2026
Merged

kylebarron merged 9 commits into
mainfrom
kyle/custom-projection-example

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

I noticed and am excited about upstream deck.gl support for custom projections (visgl/deck.gl#10739).

I asked Claude to vendor the current upstream implementation (from visgl/deck.gl#10740 and visgl/deck.gl#10741) and write an experimental example. This PR should show off what we'll support in deck.gl-raster once upstream v10 deck.gl is released.


Note

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

Adds examples/experimental/custom-projection, which renders COGs in arbitrary planar map projections with no basemap. Polar stereographic is the headline, since Web Mercator can't show polar data at all. Equal Earth and Web Mercator (for comparison) go through the same pipeline.

Closes #646
Ref #330

deck.gl merged experimental support for custom projections as _CustomProjectionView in visgl/deck.gl#10741 (tracker visgl/deck.gl#10739). It ships with deck.gl v10, and master is already on luma.gl 10 alpha. This example runs on deck.gl 9.4 through a stand-in with the same API. No library code changes.

What's in it

  • src/custom-projection/: a stand-in for _CustomProjectionView, its viewport and its controller, built on OrthographicView.

    • It takes the same options (projection as a proj4 converter, fromCrs, toCrs, fromBounds) and the same {center: [lng, lat], zoom} view state.
    • Common space and zoom match upstream (NORMALIZATION_SCALE), as do preproject, postUnproject, projectFlat and projectionSignature.
  • src/projected-cog-layer/: ProjectedCOGLayer, a COGLayer that also works in a custom-projection view. In any other view it behaves like COGLayer.

    • CustomProjectionTileset2D selects tiles in the map's CRS: frustum culling in common space, an LOD measured from each tile's drawn area on screen, and domain-aware culling.
    • Each tile's RasterLayer mesh is reprojected straight into map meters and drawn with coordinateSystem: "cartesian", upstream's convention for preprojected positions. The existing fp64 split keeps it precise.
    • Source pixels reach the map through lng/lat (projectTo4326 composed with the view's converter), so the layer never needs a proj4 definition of the map CRS.
    • Geographic grids get mesh seeds that trim them to the projection's domain and stop one source row short of the poles. Their inverse longitudes are unwrapped per tile at the antimeridian.
  • Vector context (coastlines, graticule, domain outline) is projected on the CPU.

  • Data:

    • GEBCO 2026 (global EPSG:4326, colored on the GPU)
    • the NASA Explorer Base Map (native EPSG:3031)
    • EOxCloudless
    • an ITS_LIVE ice-velocity overlay (native EPSG:3031 for Antarctica, EPSG:3413 for Greenland)

    Views can be bookmarked with URL parameters; the README lists some.

Moving to _CustomProjectionView in v10

The two changes have to land together:

  1. In the example: change the view import and delete src/custom-projection/. The layers already take the domain through a fromBounds prop, because upstream's viewport doesn't expose it.
  2. In deck.gl-raster: detect the globe with instanceof GlobeViewport instead of viewport.resolution !== undefined. Upstream's viewport sets resolution = 0, which would send RasterLayer down its globe-only mesh path.

Longer term, ProjectedCOGLayer's logic could become a third projection mode in RasterTileset2D/RasterTileLayer, so COGLayer, ZarrLayer and MultiCOGLayer would all work in a custom-projection view.

Limitations

  • No pitch or bearing.
  • Polar-native rasters that contain a pole render only in their own polar projection, so the UI only offers them there.
  • Switching projection refetches tiles.

Notes for review

  • Overlap with Kyle/elevation example #647: the pnpm-workspace.yaml line and the docs.yml loop change (first commit) are byte-identical to Kyle/elevation example #647's, so the two merge cleanly in either order. Without the docs.yml change, adding examples/experimental/ breaks the docs deploy.
  • Lockfile: the diff only adds entries: the new importer and @deck.gl/react.
  • Checks: 43 unit tests run in CI with the repo's pnpm test. They cover the stand-in, the traversal, and mesh convergence for polar views at RasterLayer's real iteration cap. Typecheck and Biome are clean, and the example builds.
  • Manual testing: checked in a real headed Chrome across all projections and datasets, including projection switching and pan/zoom.

🤖 Written by Claude Code

kylebarron and others added 2 commits October 7, 2026 09:32
Add `examples/experimental/*` to the pnpm workspace and to the docs
workflow's example build loop. The loop skips directories without a
package.json: `examples/experimental/` itself matches `examples/*/`, and a
failed `node -p` would abort the step under `bash -e`.

Both hunks are byte-identical to the ones in #647, so the two branches
merge cleanly in either order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Render COGs in arbitrary planar map projections (Arctic and Antarctic
polar stereographic, Equal Earth, Web Mercator), with no basemap. Polar
data can't be shown in Web Mercator at all, and choosing a projection is
routine in GIS workflows.

deck.gl merged experimental support for this as `_CustomProjectionView`
(visgl/deck.gl#10741), but it ships with deck.gl v10. The example uses a
stand-in on deck.gl 9.4's `OrthographicView` with the same options and
`{center, zoom}` view state, so moving to the official view is an import
swap in the example plus a globe-detection fix in deck.gl-raster (see the
README).

- `src/custom-projection/`: the view, viewport and controller stand-in.
  Common space and zoom match upstream, and so do `preproject`,
  `postUnproject`, `projectFlat` and `projectionSignature`.
- `src/projected-cog-layer/`: `ProjectedCOGLayer`, a `COGLayer` that selects
  tiles in the map CRS and has `RasterLayer` mesh each tile in map meters
  (`coordinateSystem: "cartesian"`). Domain-aware culling and trimming,
  pole and antimeridian handling, and LOD measured on screen.
- Vector context (coastlines, graticule, domain outline) is projected on
  the CPU.
- Data: GEBCO 2026, the NASA Explorer Base Map (native EPSG:3031),
  EOxCloudless, and ITS_LIVE ice velocity (EPSG:3031 and EPSG:3413).

No library code changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron and others added 7 commits October 7, 2026 12:45
Zooming in over a pole was slow: a view at zoom 8 meshed 1.15M
triangles and spent ~26 s in proj4. The reprojector measures error in
source pixels as if they were square, but lng/lat pixels near a pole are
only cos(lat) as wide as they are tall on a polar map, so it kept
splitting triangles to fix sub-screen-pixel column errors.

- Stretch each geographic tile's pixel grid horizontally by the pixels'
  aspect ratio on the map before meshing (columnErrorScale). RasterLayer
  only uses `width` to size the mesh grid, so passing width * scale with
  matching transforms reweighs column error without changing UVs. The
  ratio is measured in the output map, so it also holds for Equal Earth.
- Stop meshing geographic tiles at 89.5° instead of one row from the
  pole, which halves the remaining pole triangles.

Over the pole at zoom 8: 1.15M -> 31k triangles, ~26 s -> 0.7 s of
meshing. Visible map-space error is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kylebarron
kylebarron enabled auto-merge (squash) October 7, 2026 21:21
@kylebarron
kylebarron disabled auto-merge October 7, 2026 21:22
@kylebarron
kylebarron merged commit d8c7bb4 into main Oct 7, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/custom-projection-example branch October 7, 2026 21:22
kylebarron added a commit that referenced this pull request Nov 13, 2026
…'s crs-based API (#882)

> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

deck.gl published
[`10.0.0-alpha.1`](https://github.com/visgl/deck.gl/releases/tag/v10.0.0-alpha.1).
Its experimental `_CustomProjectionView` API has changed since the
custom projection example copied it in October (#694). This moves the
example's deck.gl 9.4 stand-in to the alpha.1 API, so the example shows
how upstream works now. The example stays on deck.gl 9.4, and nothing
under `packages/` changes.

Ref #695

### What changed upstream

| | October (visgl/deck.gl#10741) | `10.0.0-alpha.1` |
| --- | --- | --- |
| Projection input | `projection: {forward, inverse}`, `fromCrs`,
`toCrs` | **`crs`**: an EPSG code, PROJ string, WKT or PROJJSON,
resolved by math.gl's `projectionEngine.getCRS` |
| Resolution | synchronous | **asynchronous**: `view.initialize()`,
which `Deck` awaits |
| World coordinates | `fromCrs` | **always WGS84** |
| Domain | `fromBounds` | **set by the projection**:
`crs.converter.WGS84.normalize` |
| Conversions | `viewport.preproject` / `postUnproject` |
`viewport.crs.converter.WGS84.from` / `to` |

### What changes in the example

- **The stand-in** (`src/custom-projection/`) takes a `crs` and resolves
it with `@math.gl/geospatial` `5.0.0-beta.8`, the version alpha.1 pins,
through a cached `resolveCRS`. The viewport exposes `crs`, and
`projectionSignature` is `[crs.signature, resolution]`. It still differs
from upstream in three ways:
  - top-down camera only;
- meter-based CRSs only, because deck.gl 9.4's `Viewport` constructor
calls `projectFlat` before a subclass can store a per-CRS scale;
  - `project` and `unproject` stay in map meters.
- **`ProjectedCOGLayer`** converts through
`viewport.crs.converter.WGS84`, and takes its lng/lat domain from the
CRS's `normalize` clamp. It no longer has a `fromBounds` prop, and the
presets no longer carry one.
- **The app** resolves the selected preset's CRS before handing the view
to `DeckGL`, because deck.gl 9.4 doesn't await `initialize()`. Until the
new CRS resolves, the previous projection stays on screen, so `DeckGL`
never remounts.
- **The README** says how to move the example to deck.gl v10.
- **`examples/_shared`** now declares `@math.gl/web-mercator: ^4.1.0`.
Without it, pnpm resolved `@deck.gl/mapbox`'s `@math.gl/web-mercator`
peer (range `^4.1.0`) to the new 5.0 beta for every example with a
MapLibre overlay.

### Visible change

The polar maps now reach math.gl's extent, 60° past the equator, instead
of the example's 20°. The default views look the same.

<!-- before/after screenshots -->

### Checks

math.gl's conversions match proj4's to within a micrometer at sample
points inside each preset's extent, for all four presets.

COG range requests per view, in headed Chrome:

| View | `main` | This PR |
| --- | --- | --- |
| Arctic, default | 10 | 10 |
| Antarctic, default | 10 | 10 |
| Equal Earth, default | 4 | 4 |
| Web Mercator, default | 8 | 8 |
| Antarctic, NASA basemap and ITS_LIVE | 13 | 13 |
| Arctic, zoom 0.6 | 3 | **13** |
| Antarctic, zoom 0.6 | 4 | **14** |

Every view finished loading in under 8 seconds, with no new console
messages.

- **Switching projections:** switching five times, 40 ms apart, kept one
`Deck` instance and only custom projection viewports.
- **Cursor:** off the map (above, below or beside it) it reads "—".
Beside the Equal Earth and Web Mercator maps, math.gl's inverse returns
a wrapped longitude instead of throwing, so the stand-in keeps the
October stand-in's round-trip check.

The example's main bundle chunk grows from 1,592 KB to 1,801 KB, **+67
KB gzipped**, all of it math.gl's projection engine. Apache Arrow isn't
bundled.

The example's 56 tests pass, and so do `pnpm -r --filter=!docs
typecheck` and `pnpm check`.

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

Public example of deck.gl-raster over south pole with cartesian coordinate system rendering

1 participant