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: support split overview/warp resampling #777

Merged
merged 1 commit into from
Jun 18, 2020
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
16 changes: 1 addition & 15 deletions packages/cli/src/cli/cogify/action.job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CommandLineStringParameter,
} from '@rushstack/ts-command-line';
import { CogJobFactory, JobCreationContext, MaxConcurrencyDefault } from '../../cog/job';
import { GdalCogBuilderDefaults, GdalResamplingOptions } from '../../gdal/gdal.config';
import { GdalCogBuilderDefaults } from '../../gdal/gdal.config';
import { CliId } from '../base.cli';

export class CLiInputData {
Expand Down Expand Up @@ -43,7 +43,6 @@ export class ActionJobCreate extends CommandLineAction {
private source: CLiInputData;
private output: CLiInputData;
private maxConcurrency: CommandLineIntegerParameter;
private resampling: CommandLineStringParameter;
private cutline: CommandLineStringParameter;
private cutlineBlend: CommandLineIntegerParameter;
private overrideId: CommandLineStringParameter;
Expand Down Expand Up @@ -90,11 +89,6 @@ export class ActionJobCreate extends CommandLineAction {
const targetProjection = ProjectionTileMatrixSet.tryGet(this.targetProjection?.value);
if (targetProjection == null) throw new Error('Invalid target-projection');

const resampling =
this.resampling?.value == null
? GdalCogBuilderDefaults.resampling
: GdalResamplingOptions[this.resampling?.value];

const ctx: JobCreationContext = {
source,
output,
Expand All @@ -105,7 +99,6 @@ export class ActionJobCreate extends CommandLineAction {
quality: this.quality?.value ?? GdalCogBuilderDefaults.quality,
id: this.overrideId?.value ?? CliId,
projection: Epsg.tryGet(this.sourceProjection?.value),
resampling,
},
batch: this.submitBatch?.value,
};
Expand All @@ -126,13 +119,6 @@ export class ActionJobCreate extends CommandLineAction {
required: false,
});

this.resampling = this.defineStringParameter({
argumentName: 'RESAMPLING',
parameterLongName: '--resampling',
description: 'Resampling method to use',
required: false,
});

this.cutline = this.defineStringParameter({
argumentName: 'CUTLINE',
parameterLongName: '--cutline',
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/cog/__test__/cog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ o.spec('cog', () => {
compression: 'webp',
tilingScheme: TilingScheme.Google,
projection: Epsg.Google,
resampling: 'bilinear',
resampling: { warp: 'bilinear', overview: 'lanczos' },
blockSize: 512,
targetRes: 19.1093,
quality: 90,
Expand All @@ -64,7 +64,9 @@ o.spec('cog', () => {
'-co',
'BLOCKSIZE=512',
'-co',
'RESAMPLING=bilinear',
'WARP_RESAMPLING=bilinear',
'-co',
'OVERVIEW_RESAMPLING=lanczos',
'-co',
'COMPRESS=webp',
'-co',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cog/cog.vrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function buildWarpVrt(
warpOpts.push('-srcnodata', String(job.output.nodata), '-dstnodata', String(job.output.nodata));
}
if (job.output.resampling) {
warpOpts.push('-r', job.output.resampling);
warpOpts.push('-r', job.output.resampling.warp);
}

logger.debug({ warpOpts: warpOpts.join(' ') }, 'gdalwarp');
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/cog/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export interface JobCreationContext {
* Resampling method
* @Default GdalCogBuilderDefaults.resampling
*/
resampling?: GdalCogBuilderOptionsResampling;
resampling?: {
warp: GdalCogBuilderOptionsResampling;
overview: GdalCogBuilderOptionsResampling;
};
};

/**
Expand Down Expand Up @@ -164,7 +167,7 @@ export const CogJobFactory = {
projection: ctx.targetProjection.tms.projection.code,
output: {
...output,
resampling: ctx.override?.resampling ?? GdalCogBuilderDefaults.resampling,
resampling: GdalCogBuilderDefaults.resampling,
quality: ctx.override?.quality ?? GdalCogBuilderDefaults.quality,
cutline: ctx.cutline,
nodata: metadata.nodata,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface CogJob {

/** Folder/S3 bucket to store the output */
output: {
resampling: GdalCogBuilderOptionsResampling;
resampling: { warp: GdalCogBuilderOptionsResampling; overview: GdalCogBuilderOptionsResampling };
nodata?: number;
/**
* Quality level to use
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/gdal/__test__/gdal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ o.spec('GdalCogBuilder', () => {

o(builder.config.bbox).equals(undefined);
o(builder.config.compression).equals('webp');
o(builder.config.resampling).equals('bilinear');
o(builder.config.resampling).deepEquals({ warp: 'bilinear', overview: 'lanczos' });
o(builder.config.blockSize).equals(512);
o(builder.config.alignmentLevels).equals(1);

Expand Down
21 changes: 17 additions & 4 deletions packages/cli/src/gdal/gdal.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@ export interface GdalCogBuilderOptions {
compression: 'webp' | 'jpeg';

/**
* Resampling method to use
* @default 'bilinear'
* Resampling methods to use
*/
resampling: GdalCogBuilderOptionsResampling;
resampling: {
/**
* Resampling for warping
* @default 'bilinear'
*/
warp: GdalCogBuilderOptionsResampling;
/**
* Resampling for overview
* @default 'lanczos'
*/
overview: GdalCogBuilderOptionsResampling;
};
/**
* Output tile size
* @default 512
Expand All @@ -56,7 +66,10 @@ export interface GdalCogBuilderOptions {
}

export const GdalCogBuilderDefaults: GdalCogBuilderOptions = {
resampling: 'bilinear',
resampling: {
warp: 'bilinear',
overview: 'lanczos',
},
compression: 'webp',
tilingScheme: TilingScheme.Google,
projection: Epsg.Google,
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/gdal/gdal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ export class GdalCogBuilder {
// User configured output block size
'-co',
`BLOCKSIZE=${this.config.blockSize}`,
// User configured resampling method
// Configured resampling methods
'-co',
`RESAMPLING=${this.config.resampling}`,
`WARP_RESAMPLING=${this.config.resampling.warp}`,
'-co',
`OVERVIEW_RESAMPLING=${this.config.resampling.overview}`,
// User configured compression
'-co',
`COMPRESS=${this.config.compression}`,
Expand All @@ -121,6 +123,7 @@ export class GdalCogBuilder {
// most of the imagery contains a lot of empty tiles, no need to output them
'-co',
`SPARSE_OK=YES`,
// Force a target resolution to be better than the imagery not worse
'-tr',
tr,
tr,
Expand Down