Skip to content

Commit

Permalink
refactor(cogify): restructure background colour support code
Browse files Browse the repository at this point in the history
  • Loading branch information
tawera-manaena committed Dec 12, 2024
1 parent d721141 commit 5397586
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions packages/cogify/src/cogify/cli/cli.cog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,28 +331,28 @@ async function createCog(ctx: CogCreationContext): Promise<URL> {
);
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;
}

/**
Expand Down

0 comments on commit 5397586

Please sign in to comment.