diff --git a/packages/cli/src/cli/cogify/action.cog.ts b/packages/cli/src/cli/cogify/action.cog.ts index 057bc7fb9..ca3be95b4 100644 --- a/packages/cli/src/cli/cogify/action.cog.ts +++ b/packages/cli/src/cli/cogify/action.cog.ts @@ -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'; @@ -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; diff --git a/packages/cli/src/cli/cogify/imagery.config.ts b/packages/cli/src/cli/cogify/imagery.config.ts new file mode 100644 index 000000000..4aaaae3a7 --- /dev/null +++ b/packages/cli/src/cli/cogify/imagery.config.ts @@ -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 { + 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, + 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 { + 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'); +} diff --git a/packages/config/src/config/imagery.ts b/packages/config/src/config/imagery.ts index 62cfaf109..502250a3c 100644 --- a/packages/config/src/config/imagery.ts +++ b/packages/config/src/config/imagery.ts @@ -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; diff --git a/packages/lambda-tiler/src/routes/__test__/attribution.test.ts b/packages/lambda-tiler/src/routes/__test__/attribution.test.ts index 4c3d53a67..70299610e 100644 --- a/packages/lambda-tiler/src/routes/__test__/attribution.test.ts +++ b/packages/lambda-tiler/src/routes/__test__/attribution.test.ts @@ -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) => {