Skip to content

Commit

Permalink
Give ulid for tmp job folder and remove gdalwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentao-Kuang committed Dec 18, 2024
1 parent fadb57c commit ae4a30e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 56 deletions.
3 changes: 1 addition & 2 deletions src/commands/basemaps-topo-import/gdal/gdal-build-cog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GdalCommand } from '@basemaps/cogify/build/cogify/gdal.runner.js';

import { urlToString } from '../../common.js';
import { urlToString } from '@basemaps/shared';

export const DEFAULT_TRIM_PIXEL_RIGHT = 1.7;

Expand Down
34 changes: 0 additions & 34 deletions src/commands/basemaps-topo-import/gdal/gdal-build-vrt-warp.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/commands/basemaps-topo-import/gdal/gdal-build-vrt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GdalCommand } from '@basemaps/cogify/build/cogify/gdal.runner.js';

import { urlToString } from '../../common.js';
import { urlToString } from '@basemaps/shared';

/**
* Constructs a 'gdalBuildVrt' GdalCommand.
Expand Down
22 changes: 4 additions & 18 deletions src/commands/basemaps-topo-import/topo-cog-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { tmpdir } from 'node:os';

import { GdalRunner } from '@basemaps/cogify/build/cogify/gdal.runner.js';
import { createFileStats } from '@basemaps/cogify/build/cogify/stac.js';
import { Epsg } from '@basemaps/geo';
import { fsa, Tiff } from '@basemaps/shared';
import { CliId } from '@basemaps/shared/build/cli/info.js';
import { command, number, option, optional, restPositionals, string } from 'cmd-ts';
import { mkdir, rm } from 'fs/promises';
import pLimit from 'p-limit';
import path from 'path';
import ulid from 'ulid';

import { CliInfo } from '../../cli.info.js';
import { logger } from '../../log.js';
Expand All @@ -17,7 +17,6 @@ import { config, forceOutput, registerCli, tryParseUrl, verbose } from '../commo
import { loadInput } from '../group/group.js';
import { gdalBuildCogCommands as gdalBuildCog } from './gdal/gdal-build-cog.js';
import { gdalBuildVrt } from './gdal/gdal-build-vrt.js';
import { gdalBuildVrtWarp } from './gdal/gdal-build-vrt-warp.js';
import { MapSheetStacItem } from './types/map-sheet-stac-item.js';

const Q = pLimit(10);
Expand Down Expand Up @@ -91,7 +90,8 @@ export const topoCogCreation = command({
async function createCogs(input: URL, tmp: URL, pixelTrim?: number): Promise<void> {
const startTime = performance.now();
const item = await fsa.readJson<MapSheetStacItem>(input);
const tmpFolder = new URL(item.id, tmp);
const jobId = ulid.ulid();
const tmpFolder = new URL(jobId, tmp);
try {
// Extract the source URL from the item
logger.info({ item: item.id }, 'CogCreation:Start');
Expand Down Expand Up @@ -131,20 +131,6 @@ async function createCogs(input: URL, tmp: URL, pixelTrim?: number): Promise<voi

await new GdalRunner(commandBuildVrt).run(logger);

/**
* command: gdal build warp vrt
*/
logger.info({ item: item.id }, 'CogCreation:gdalwarp');

const sourceEpsg = item.properties['proj:epsg'];
const sourceProj = Epsg.tryGet(sourceEpsg);
if (sourceProj == null) throw new Error(`Unknown source projection ${sourceEpsg}`);

const vrtWarpPath = new URL(`${item.id}-warp.vrt`, tmpFolder);
const commandBuildVrtWarp = gdalBuildVrtWarp(vrtWarpPath, vrtPath, sourceProj);

await new GdalRunner(commandBuildVrtWarp).run(logger);

/**
* command: gdal build cog
*/
Expand All @@ -153,7 +139,7 @@ async function createCogs(input: URL, tmp: URL, pixelTrim?: number): Promise<voi
const width = item.properties['source.width'];
const height = item.properties['source.height'];
const tempPath = new URL(`${item.id}.tiff`, tmpFolder);
const commandTranslate = gdalBuildCog(vrtWarpPath, tempPath, width, height, { pixelTrim });
const commandTranslate = gdalBuildCog(vrtPath, tempPath, width, height, { pixelTrim });

await new GdalRunner(commandTranslate).run(logger);

Expand Down

0 comments on commit ae4a30e

Please sign in to comment.