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): Load MaxImagePixelSize from import api. #2206

Merged
merged 3 commits into from
May 19, 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
4 changes: 2 additions & 2 deletions packages/cli/src/cog/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ export class CogBuilder {
* @param tiffs list of source imagery to be converted
* @returns List of Tile bounds covering tiffs
*/
async build(tiffs: ChunkSource[], cutline: Cutline): Promise<CogBuilderMetadata> {
async build(tiffs: ChunkSource[], cutline: Cutline, maxImageSize?: number): Promise<CogBuilderMetadata> {
const metadata = await this.getMetadata(tiffs);
// Ensure that the projection definition is loaded
await ProjectionLoader.load(metadata.projection);
const files = cutline.optimizeCovering(metadata);
const files = cutline.optimizeCovering(metadata, maxImageSize);
let union: Bounds | null = null;
for (const bounds of files) {
if (union == null) union = Bounds.fromJson(bounds);
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/cog/cog.stac.job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export interface JobCreationContext {
*/
projection?: Epsg;

/**
* Override Maximum Image Pixel Size
*/
maxImageSize?: number;

/**
* Resampling method
* @Default GdalCogBuilderDefaults.resampling
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cog/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Maximum desired image size */
/** Default Maximum desired image size */
export const MaxImagePixelWidth = 256000;

/** When a tile has at least this much covering merge it up to parent */
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cog/cutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class Cutline {
* Generate an optimized WebMercator tile cover for the supplied source images
* @param sourceMetadata contains images bounds and projection info
*/
optimizeCovering(sourceMetadata: SourceMetadata): NamedBounds[] {
optimizeCovering(sourceMetadata: SourceMetadata, maxImageSize: number = MaxImagePixelWidth): NamedBounds[] {
if (this.oneCogCovering) {
const extent = this.tileMatrix.extent.toJson();
return [{ ...extent, name: '0-0-0' }];
Expand All @@ -168,7 +168,7 @@ export class Cutline {
let minZ = resZoom - 1;
while (
minZ > 0 &&
Projection.getImagePixelWidth(this.tileMatrix, { x: 0, y: 0, z: minZ }, resZoom) < MaxImagePixelWidth
Projection.getImagePixelWidth(this.tileMatrix, { x: 0, y: 0, z: minZ }, resZoom) < maxImageSize
) {
--minZ;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cog/job.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const CogJobFactory = {
);

const builder = new CogBuilder(ctx.tileMatrix, maxConcurrency, logger, ctx.override?.projection);
const metadata = await builder.build(tiffSource, cutline);
const metadata = await builder.build(tiffSource, cutline, ctx.override?.maxImageSize);

if (cutline.clipPoly.length === 0) {
// no cutline needed for this imagery set
Expand Down
3 changes: 3 additions & 0 deletions packages/lambda-tiler/src/import/make.cog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { TileMatrixSet } from '@basemaps/geo';
import { Env } from '@basemaps/shared';
import { RoleConfig } from './imagery.find.js';

const MaxImagePixelSize = 256000;

export async function getJobCreationContext(
path: string,
tileMatrix: TileMatrixSet,
Expand All @@ -18,6 +20,7 @@ export async function getJobCreationContext(
warp: 'bilinear',
overview: 'lanczos',
},
maxImageSize: MaxImagePixelSize,
},
outputLocation: { type: 's3' as const, path: `s3://${bucket}` },
sourceLocation: { type: 's3', path, ...role, files: files },
Expand Down
4 changes: 2 additions & 2 deletions packages/lambda-tiler/src/routes/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambd
import { Config, extractYearRangeFromName, fsa } from '@basemaps/shared';
import { createHash } from 'crypto';
import { findImagery, RoleRegister } from '../import/imagery.find.js';
import { Nztm2000Tms, TileMatrixSets } from '@basemaps/geo';
import { Nztm2000QuadTms, TileMatrixSets } from '@basemaps/geo';
import { getJobCreationContext } from '../import/make.cog.js';
import { ConfigProcessingJob, JobStatus } from '@basemaps/config';
import { CogJobFactory } from '@basemaps/cli';
Expand All @@ -21,7 +21,7 @@ export async function Import(req: LambdaHttpRequest): Promise<LambdaHttpResponse
const id = ulid.ulid();

// Parse projection as target, default to process both NZTM2000Quad
let targetTms = Nztm2000Tms;
let targetTms = Nztm2000QuadTms;
if (projection != null) {
const tileMatrix = TileMatrixSets.find(projection);
if (tileMatrix == null) return new LambdaHttpResponse(404, 'Target projection Not found');
Expand Down