From 53975868e168917cc7d65d568478ddf38bdbe8ea Mon Sep 17 00:00:00 2001 From: Tawera Manaena Date: Thu, 12 Dec 2024 16:25:21 +1300 Subject: [PATCH] refactor(cogify): restructure background colour support code --- packages/cogify/src/cogify/cli/cli.cog.ts | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/cogify/src/cogify/cli/cli.cog.ts b/packages/cogify/src/cogify/cli/cli.cog.ts index 44018a113..c9dfeca00 100644 --- a/packages/cogify/src/cogify/cli/cli.cog.ts +++ b/packages/cogify/src/cogify/cli/cli.cog.ts @@ -331,28 +331,28 @@ async function createCog(ctx: CogCreationContext): Promise { ); await new GdalRunner(vrtWarpCommand).run(logger); - if (options.background) { - // Create a tiff with background to fill the empty space in the target cog - const gdalCreateCommand = gdalCreate(new URL(`${tileId}-bg.tiff`, ctx.tempFolder), options); - await new GdalRunner(gdalCreateCommand).run(logger); - - // Create a vrt layering with the backgroud tiff - const vrtMergeCommand = gdalBuildVrt(new URL(`${tileId}-merged.vrt`, ctx.tempFolder), [ - gdalCreateCommand.output, - vrtWarpCommand.output, - ]); - await new GdalRunner(vrtMergeCommand).run(logger); - - // Create the COG from the merged Vrt with background - const cogCreateCommand = gdalBuildCog(new URL(`${tileId}.tiff`, ctx.tempFolder), vrtMergeCommand.output, options); - await new GdalRunner(cogCreateCommand).run(logger); - return cogCreateCommand.output; - } else { + if (options.background == null) { // Create the COG from the warped vrt without background const cogCreateCommand = gdalBuildCog(new URL(`${tileId}.tiff`, ctx.tempFolder), vrtWarpCommand.output, options); await new GdalRunner(cogCreateCommand).run(logger); return cogCreateCommand.output; } + + // Create a tiff with background to fill the empty space in the target cog + const gdalCreateCommand = gdalCreate(new URL(`${tileId}-bg.tiff`, ctx.tempFolder), options); + await new GdalRunner(gdalCreateCommand).run(logger); + + // Create a vrt layering with the background tiff + const vrtMergeCommand = gdalBuildVrt(new URL(`${tileId}-merged.vrt`, ctx.tempFolder), [ + gdalCreateCommand.output, + vrtWarpCommand.output, + ]); + await new GdalRunner(vrtMergeCommand).run(logger); + + // Create the COG from the merged Vrt with background + const cogCreateCommand = gdalBuildCog(new URL(`${tileId}.tiff`, ctx.tempFolder), vrtMergeCommand.output, options); + await new GdalRunner(cogCreateCommand).run(logger); + return cogCreateCommand.output; } /**