Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/cog-basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig } from "vite";
export default defineConfig({
plugins: [react()],
base: "/deck.gl-raster/examples/cog-basic/",
worker: { format: "es" },
server: {
port: 3000,
},
Expand Down
1 change: 1 addition & 0 deletions examples/land-cover/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineConfig({
plugins: [react()],
assetsInclude: ["**/*.csv.gz"],
base: "/deck.gl-raster/examples/land-cover/",
worker: { format: "es" },
server: {
port: 3000,
},
Expand Down
1 change: 1 addition & 0 deletions examples/naip-mosaic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig } from "vite";
export default defineConfig({
plugins: [react()],
base: "/deck.gl-raster/examples/naip-mosaic/",
worker: { format: "es" },
server: {
port: 3000,
},
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
},
"pnpm": {
"overrides": {
"@deck.gl/aggregation-layers": "^9.2.8",
"@deck.gl/core": "^9.2.8",
"@deck.gl/extensions": "^9.2.8",
"@deck.gl/geo-layers": "^9.2.8",
"@deck.gl/layers": "^9.2.8",
"@deck.gl/mapbox": "^9.2.8",
"@deck.gl/mesh-layers": "^9.2.8",
"@deck.gl/widgets": "^9.2.8",
"@deck.gl/aggregation-layers": "^9.2.10",
"@deck.gl/core": "^9.2.10",
"@deck.gl/extensions": "^9.2.10",
"@deck.gl/geo-layers": "^9.2.10",
"@deck.gl/layers": "^9.2.10",
"@deck.gl/mapbox": "^9.2.10",
"@deck.gl/mesh-layers": "^9.2.10",
"@deck.gl/widgets": "^9.2.10",
"@loaders.gl/core": "^4.3.4",
"@luma.gl/constants": "^9.2.6",
"@luma.gl/core": "^9.2.6",
Expand Down
18 changes: 9 additions & 9 deletions packages/deck.gl-geotiff/src/cog-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import {
RasterLayer,
TileMatrixSetTileset,
} from "@developmentseed/deck.gl-raster";
import type { GeoTIFF, Overview } from "@developmentseed/geotiff";
import { generateTileMatrixSet } from "@developmentseed/geotiff";
import type { DecoderPool, GeoTIFF, Overview } from "@developmentseed/geotiff";
import {
defaultDecoderPool,
generateTileMatrixSet,
} from "@developmentseed/geotiff";
import type { TileMatrixSet } from "@developmentseed/morecantile";
import { tileTransform } from "@developmentseed/morecantile";
import type { ReprojectionFns } from "@developmentseed/raster-reproject";
Expand Down Expand Up @@ -61,8 +64,7 @@ export type GetTileDataOptions = {
signal?: AbortSignal;

/** The decoder pool to use. */
// TODO: restore pool with new GeoTIFF backend
// pool: Pool;
pool: DecoderPool;
};

type GetTileDataResult<DataT> = {
Expand Down Expand Up @@ -94,13 +96,12 @@ export interface COGLayerProps<DataT extends MinimalDataT = DefaultDataT>
epsgResolver?: EpsgResolver;

/**
* GeoTIFF.js Pool for decoding image chunks.
* Worker pool for decoding image chunks.
*
* If none is provided, a default Pool will be created and shared between all
* COGLayer and GeoTIFFLayer instances.
*/
// TODO: Restore a sort of worker pool with our geotiff implementation
// pool?: Pool;
pool?: DecoderPool;

/**
* Maximum reprojection error in pixels for mesh refinement.
Expand Down Expand Up @@ -304,8 +305,7 @@ export class COGLayer<
x,
y,
signal: combinedSignal,
// TODO: restore pool
// pool: this.props.pool || defaultPool(),
pool: this.props.pool ?? defaultDecoderPool(),
});

return {
Expand Down
11 changes: 5 additions & 6 deletions packages/deck.gl-geotiff/src/geotiff-layer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CompositeLayerProps, UpdateParameters } from "@deck.gl/core";
import { CompositeLayer } from "@deck.gl/core";
import { RasterLayer } from "@developmentseed/deck.gl-raster";
import type { GeoTIFF } from "@developmentseed/geotiff";
import type { DecoderPool, GeoTIFF } from "@developmentseed/geotiff";
import type { ReprojectionFns } from "@developmentseed/raster-reproject";
import proj4 from "proj4";
import type { ProjectionDefinition } from "wkt-parser";
Expand Down Expand Up @@ -33,13 +33,12 @@ export interface GeoTIFFLayerProps extends CompositeLayerProps {
epsgResolver?: EpsgResolver;

/**
* GeoTIFF.js Pool for decoding image chunks.
* Decoder pool for decoding image chunks.
*
* If none is provided, a default Pool will be created and shared between all
* COGLayer and GeoTIFFLayer instances.
* If none is provided, a default DecoderPool will be created and shared
* between all COGLayer and GeoTIFFLayer instances.
*/
// TODO: Restore a sort of worker pool with our geotiff implementation
// pool?: Pool;
pool?: DecoderPool;

/**
* Maximum reprojection error in pixels for mesh refinement.
Expand Down
8 changes: 6 additions & 2 deletions packages/deck.gl-geotiff/src/geotiff/render-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ function createUnormPipeline(
image: GeoTIFF | Overview,
options: GetTileDataOptions,
) => {
const { device, x, y, signal } = options;
const tile = await image.fetchTile(x, y, { signal, boundless: false });
const { device, x, y, signal, pool } = options;
const tile = await image.fetchTile(x, y, {
boundless: false,
pool,
signal,
});
let { array } = tile;

let numSamples = samplesPerPixel;
Expand Down
6 changes: 6 additions & 0 deletions packages/geotiff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ For user-defined CRSes, we automatically parse the CRS into a PROJJSON object, w

If you have an image where the CRS fails to parse, please create an issue.

### Configurable Web Worker pool for image decoding

The `DecoderPool` allows for decoding image data off the main thread.

By default workers are created up to `navigator.hardwareConcurrency`, but you can customize how large the web worker pool is by passing options to the `DecoderPool` constructor.

### Dynamically load compressions as needed

Instead of bundling support for all compressions out of the box, dynamically load the decompressors as required.
Expand Down
4 changes: 4 additions & 0 deletions packages/geotiff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./pool/worker": {
"types": "./dist/pool/worker.d.ts",
"default": "./dist/pool/worker.js"
}
},
"sideEffects": false,
Expand Down
25 changes: 17 additions & 8 deletions packages/geotiff/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { RasterArray } from "./array.js";
import type { ProjJson } from "./crs.js";
import { decode } from "./decode.js";
import type { CachedTags } from "./ifd.js";
import type { DecoderPool } from "./pool/pool.js";
import type { Tile } from "./tile";
import type { HasTransform } from "./transform";

Expand Down Expand Up @@ -35,13 +36,21 @@ export async function fetchTile(
self: HasTiffReference,
x: number,
y: number,
options: { boundless?: boolean; signal?: AbortSignal } = {},
{
boundless,
pool,
signal,
}: {
boundless?: boolean;
pool?: DecoderPool;
signal?: AbortSignal;
} = {},
): Promise<Tile> {
if (self.maskImage != null) {
throw new Error("Mask fetching not implemented yet");
}

const tile = await self.image.getTile(x, y, options);
const tile = await self.image.getTile(x, y, { signal });
if (tile === null) {
throw new Error("Tile not found");
}
Expand All @@ -65,15 +74,18 @@ export async function fetchTile(

const samplesPerPixel = self.image.value(TiffTag.SamplesPerPixel) ?? 1;

const decodedPixels = await decode(bytes, compression, {
const decoderMetadata = {
sampleFormat,
bitsPerSample,
samplesPerPixel,
width: self.tileWidth,
height: self.tileHeight,
predictor,
planarConfiguration,
});
};
const decodedPixels = await (pool
? pool.decode(bytes, compression, decoderMetadata)
: decode(bytes, compression, decoderMetadata));

const array: RasterArray = {
...decodedPixels,
Expand All @@ -89,10 +101,7 @@ export async function fetchTile(
return {
x,
y,
array:
options.boundless === false
? clipToImageBounds(self, x, y, array)
: array,
array: boundless === false ? clipToImageBounds(self, x, y, array) : array,
};
}

Expand Down
9 changes: 7 additions & 2 deletions packages/geotiff/src/geotiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { fetchTile } from "./fetch.js";
import type { CachedTags, GeoKeyDirectory } from "./ifd.js";
import { extractGeoKeyDirectory, prefetchTags } from "./ifd.js";
import { Overview } from "./overview.js";
import type { DecoderPool } from "./pool/pool.js";
import type { Tile } from "./tile.js";
import { createTransform, index, xy } from "./transform.js";

/**
* A higher-level GeoTIFF abstraction built on @cogeotiff/core.
* A high-level GeoTIFF abstraction built on @cogeotiff/core.
*
* Separates data IFDs from mask IFDs, pairs them by resolution level,
* and exposes sorted overviews. Mirrors the Python async-geotiff API.
Expand Down Expand Up @@ -263,7 +264,11 @@ export class GeoTIFF {
async fetchTile(
x: number,
y: number,
options: { boundless?: boolean; signal?: AbortSignal } = {},
options: {
boundless?: boolean;
pool?: DecoderPool;
signal?: AbortSignal;
} = {},
): Promise<Tile> {
return await fetchTile(this, x, y, options);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/geotiff/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export type { DecodedPixels, Decoder, DecoderMetadata } from "./decode.js";
export { decode, registry } from "./decode.js";
export { GeoTIFF } from "./geotiff.js";
export { Overview } from "./overview.js";
export type { DecoderPoolOptions } from "./pool/pool.js";
export { DecoderPool, defaultDecoderPool } from "./pool/pool.js";
export type { Tile } from "./tile.js";
export { generateTileMatrixSet } from "./tile-matrix-set.js";
7 changes: 6 additions & 1 deletion packages/geotiff/src/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ProjJson } from "./crs.js";
import { fetchTile } from "./fetch.js";
import type { GeoTIFF } from "./geotiff.js";
import type { CachedTags, GeoKeyDirectory } from "./ifd.js";
import type { DecoderPool } from "./pool/pool.js";
import type { Tile } from "./tile.js";
import { index, xy } from "./transform.js";

Expand Down Expand Up @@ -82,7 +83,11 @@ export class Overview {
async fetchTile(
x: number,
y: number,
options: { boundless?: boolean; signal?: AbortSignal } = {},
options: {
boundless?: boolean;
pool?: DecoderPool;
signal?: AbortSignal;
} = {},
): Promise<Tile> {
return await fetchTile(this, x, y, options);
}
Expand Down
Loading
Loading