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
12 changes: 7 additions & 5 deletions packages/deck.gl-geotiff/src/cog-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,13 @@ export class COGLayer<
const inverseReproject = (x: number, y: number) =>
converter.inverse<[number, number]>([x, y], false);

const geographicBounds = getGeographicBounds(image, converter);
this.props.onGeoTIFFLoad?.(geotiff, {
projection: sourceProjection,
geographicBounds,
});
if (this.props.onGeoTIFFLoad) {
const geographicBounds = getGeographicBounds(image, converter);
this.props.onGeoTIFFLoad(geotiff, {
projection: sourceProjection,
geographicBounds,
});
}

this.setState({
metadata,
Expand Down
37 changes: 33 additions & 4 deletions packages/deck.gl-geotiff/src/geotiff-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import { RasterLayer } from "@developmentseed/deck.gl-raster";
import type { ReprojectionFns } from "@developmentseed/raster-reproject";
import type { BaseClient, GeoTIFF, Pool } from "geotiff";
import { extractGeotiffReprojectors } from "./geotiff-reprojection.js";
import { defaultPool, fetchGeoTIFF, loadRgbImage } from "./geotiff.js";
import {
defaultPool,
fetchGeoTIFF,
getGeographicBounds,
loadRgbImage,
} from "./geotiff.js";
import type { GeoKeysParser, ProjectionInfo } from "./proj.js";
import { epsgIoGeoKeyParser } from "./proj.js";
import proj4 from "proj4";

const DEFAULT_MAX_ERROR = 0.125;

Expand Down Expand Up @@ -65,7 +71,22 @@ export interface GeoTIFFLayerProps extends CompositeLayerProps {
* @param {GeoTIFF} geotiff
* @param {ProjectionInfo} projection
*/
onGeoTIFFLoad?: (geotiff: GeoTIFF, projection: ProjectionInfo) => void;
onGeoTIFFLoad?: (
geotiff: GeoTIFF,
options: {
projection: ProjectionInfo;
/**
* Bounds of the image in geographic coordinates (WGS84) [minLon, minLat,
* maxLon, maxLat]
*/
geographicBounds: {
west: number;
south: number;
east: number;
north: number;
};
},
) => void;
}

const defaultProps = {
Expand Down Expand Up @@ -122,11 +143,19 @@ export class GeoTIFFLayer extends CompositeLayer<GeoTIFFLayerProps> {
);
}

this.props.onGeoTIFFLoad?.(geotiff, sourceProjection);
const converter = proj4(sourceProjection.def, "EPSG:4326");

if (this.props.onGeoTIFFLoad) {
const geographicBounds = getGeographicBounds(image, converter);
this.props.onGeoTIFFLoad(geotiff, {
projection: sourceProjection,
geographicBounds,
});
}

const reprojectionFns = await extractGeotiffReprojectors(
geotiff,
this.props.geoKeysParser!,
sourceProjection.def,
);
const { texture, height, width } = await loadRgbImage(image, {
pool: this.props.pool || defaultPool(),
Expand Down
11 changes: 2 additions & 9 deletions packages/deck.gl-geotiff/src/geotiff-reprojection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import proj4 from "proj4";
import type { PROJJSONDefinition } from "proj4/dist/lib/core";
import type Projection from "proj4/dist/lib/Proj";
import type { GeoKeysParser } from "./proj";

export const OGC_84: PROJJSONDefinition = {
$schema: "https://proj.org/schemas/v0.7/projjson.schema.json",
Expand Down Expand Up @@ -90,7 +89,7 @@ export const OGC_84: PROJJSONDefinition = {
// TODO: return a RasterReprojector instance, given the IFD and tile of interest?
export async function extractGeotiffReprojectors(
tiff: GeoTIFF,
geoKeysParser: GeoKeysParser,
sourceProjection: string | PROJJSONDefinition,
outputCrs: string | PROJJSONDefinition | Projection = OGC_84,
): Promise<ReprojectionFns> {
const image = await tiff.getImage();
Expand All @@ -99,13 +98,7 @@ export async function extractGeotiffReprojectors(
// Only the top-level IFD has geo keys, so we'll derive overviews from this
const baseGeotransform = extractGeotransform(image);

const sourceProjection = await geoKeysParser(image.getGeoKeys());
if (sourceProjection === null) {
throw new Error(
"Could not determine source projection from GeoTIFF geo keys",
);
}
const converter = proj4(sourceProjection.def, outputCrs);
const converter = proj4(sourceProjection, outputCrs);
const { forwardTransform, inverseTransform } =
fromGeoTransform(baseGeotransform);

Expand Down