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(cli): Insert imagery and tileset config after cog creation complete #2191

Merged
merged 4 commits into from
May 13, 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
7 changes: 6 additions & 1 deletion packages/cli/src/cli/cogify/action.cog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Gdal } from '../../gdal/gdal.js';
import { CliId } from '../base.cli.js';
import { makeTempFolder } from '../folder.js';
import path from 'path';
import { insertConfigImagery, insertConfigTileSet } from './imagery.config.js';
import { JobStatus, ProcessingJobComplete, ProcessingJobFailed } from '@basemaps/config';
import { prepareUrl } from '../util.js';

Expand Down Expand Up @@ -160,9 +161,13 @@ export class ActionCogCreate extends CommandLineAction {
}

if (expectedTiffs.size === 0) {
// Insert Imagery and TileSet Config
await insertConfigImagery(job, logger);
await insertConfigTileSet(job, logger);

// Update job status if this is the processing job.
const url = await prepareUrl(job);
if (job.processingId != null) {
// Update job status if this is the processing job.
const jobConfig = await Config.ProcessingJob.get(job.processingId);
if (jobConfig == null) throw new Error('Unable to find Job Processing Config:' + job.processingId);
const jobComplete = jobConfig as ProcessingJobComplete;
Expand Down
47 changes: 47 additions & 0 deletions packages/cli/src/cli/cogify/imagery.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Config, ConfigImagery, ConfigTileSet, TileSetType } from '@basemaps/config';
import { ImageFormat } from '@basemaps/geo';
import { LogType } from '@basemaps/shared';
import { CogStacJob } from '../../cog/cog.stac.job';

/**
* Prepare and insert Imagery Config for the cog creation job.
* @returns
*/
export async function insertConfigImagery(job: CogStacJob, logger: LogType): Promise<void> {
const now = Date.now();
const imgId = Config.Imagery.id(job.id);
const configImagery: ConfigImagery = {
id: imgId,
name: job.name,
createdAt: now,
updatedAt: now,
projection: job.tileMatrix.projection.code,
blacha marked this conversation as resolved.
Show resolved Hide resolved
tileMatrix: job.tileMatrix.identifier,
uri: job.output.location.path,
bounds: job.output.bounds,
files: job.output.files,
};
if (Config.Imagery.isWriteable()) Config.Imagery.put(configImagery);
logger.info({ imgId }, 'CogCreate:InsertConfigImagery');
}

/**
* Prepare and insert TileSet Config for the cog creation job.
* @returns
*/
export async function insertConfigTileSet(job: CogStacJob, logger: LogType): Promise<void> {
const now = Date.now();
const tsId = Config.TileSet.id(job.id);
const tileSet: ConfigTileSet = {
type: TileSetType.Raster,
format: ImageFormat.Webp,
id: tsId,
name: job.name,
layers: [{ [job.tileMatrix.projection.code]: tsId, name: job.name, minZoom: 0, maxZoom: 32 }],
background: { r: 0, g: 0, b: 0, alpha: 0 },
createdAt: now,
updatedAt: now,
};
if (Config.TileSet.isWriteable()) Config.TileSet.put(tileSet);
logger.info({ tsId }, 'CogCreate:InsertConfigTileSet');
}
3 changes: 3 additions & 0 deletions packages/config/src/config/imagery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { BaseConfig } from './base.js';
export interface ConfigImagery extends BaseConfig {
projection: EpsgCode;

/** tileMatrix identifier */
tileMatrix: string;

/** The tile for the imagery set and showing name if not defined */
title?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ function makeImageRecord(id: string, name: string, x = 10): ConfigImagery {
id,
name,
projection: EpsgCode.Google,
tileMatrix: 'WebMercatorQuad',
uri: 's3://bucket/path/' + name,
bounds: GoogleTms.tileToSourceBounds({ x, y: 10, z: 5 }),
files: [0, 1].map((i) => {
Expand Down