Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lambda-tiler): tiff paths should allow trailing slashes #2223

Merged
merged 2 commits into from
May 31, 2022
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
7 changes: 0 additions & 7 deletions packages/lambda-tiler/src/__test__/tile.set.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { ConfigImagery } from '@basemaps/config';
import { GoogleTms, Nztm2000Tms } from '@basemaps/geo';
import o from 'ospec';
import { TileSetRaster } from '../tile.set.raster.js';

o.spec('tile.set', () => {
o('basePath', () => {
const rec = { uri: 's3://test-bucket/3857/aerail/job123' } as ConfigImagery;
o(TileSetRaster.basePath(rec)).equals('s3://test-bucket/3857/aerail/job123');
o(TileSetRaster.basePath(rec, '31223')).equals('s3://test-bucket/3857/aerail/job123/31223.tiff');
});

o('extent', () => {
o(new TileSetRaster('google', GoogleTms).extent.toBbox()).deepEquals([
-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892,
Expand Down
26 changes: 10 additions & 16 deletions packages/lambda-tiler/src/tile.set.raster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export interface TileSetResponse {
const DefaultResizeKernel = { in: 'lanczos3', out: 'lanczos3' } as const;
const DefaultBackground = { r: 0, g: 0, b: 0, alpha: 0 };

export function getTiffName(name: string): string {
if (name.endsWith('.tif') || name.endsWith('.tiff')) return name;
return `${name}.tiff`;
}

export class TileSetRaster {
type: TileSetType.Raster = TileSetType.Raster;

Expand All @@ -46,17 +51,6 @@ export class TileSetRaster {
components: TileSetNameComponents;
tileSet: ConfigTileSetRaster;

/**
* Return the location of a imagery `record`
* @param record
* @param name the COG to locate. Return just the directory if `null`
*/
static basePath(record: ConfigImagery, name?: string): string {
if (name == null) return record.uri;
if (record.uri.endsWith('/')) throw new Error("Invalid uri ending with '/' " + record.uri);
return `${record.uri}/${name}.tiff`;
}

constructor(name: string, tileMatrix: TileMatrixSet) {
this.components = TileSetNameParser.parse(name);
this.tileMatrix = tileMatrix;
Expand Down Expand Up @@ -180,18 +174,18 @@ export class TileSetRaster {
const output: CogTiff[] = [];
for (const c of record.files) {
if (!tileBounds.intersects(Bounds.fromJson(c))) continue;
const tiffPath = fsa.join(record.uri, getTiffName(c.name));

const tiffKey = `${record.id}_${c.name}`;
let existing = TiffCache.get(tiffKey);
let existing = TiffCache.get(tiffPath);
if (existing == null) {
const source = fsa.source(TileSetRaster.basePath(record, c.name));
const source = fsa.source(tiffPath);
if (source == null) {
throw new Error(`Failed to create CogSource from ${TileSetRaster.basePath(record, c.name)}`);
throw new Error(`Failed to create CogSource from ${tiffPath}`);
}

St.trace(source);
existing = new CogTiff(source);
TiffCache.set(tiffKey, existing);
TiffCache.set(tiffPath, existing);
}

output.push(existing);
Expand Down