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): Make cog to output paths for create overviews. #2615

Merged
merged 1 commit into from
Dec 1, 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
1 change: 0 additions & 1 deletion packages/cli/src/cli/cogify/action.make.cog.pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { MakeCogGithub } from '../github/make.cog.pr.js';

export class CommandCogPullRequest extends CommandLineAction {
private layer: CommandLineStringParameter;
private urls: CommandLineStringParameter;
private output: CommandLineStringParameter;
private jira: CommandLineStringParameter;

Expand Down
33 changes: 6 additions & 27 deletions packages/cli/src/cli/cogify/action.make.cog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Epsg, TileMatrixSet, TileMatrixSets } from '@basemaps/geo';
import { Env, FileConfigS3Role, fsa, LogConfig, LogType, Projection, titleizeImageryName } from '@basemaps/shared';
import { Env, FileConfigS3Role, fsa, LogConfig, LogType, titleizeImageryName } from '@basemaps/shared';
import {
CommandLineAction,
CommandLineFlagParameter,
Expand All @@ -21,11 +21,6 @@ interface OutputJobs {
names: string[];
}

interface ImageryUrl {
tileMatrix: string;
url: string;
}

export class CommandMakeCog extends CommandLineAction {
private imagery: CommandLineStringParameter;
private tileMatrix: CommandLineStringParameter;
Expand Down Expand Up @@ -125,7 +120,7 @@ export class CommandMakeCog extends CommandLineAction {

const outputJobs: OutputJobs[] = [];
const configLayer: ConfigLayer = { name, title: titleizeImageryName(name) };
const urls: ImageryUrl[] = [];
const paths: string[] = [];
for (const identifier of tileMatrixSets) {
const id = ulid.ulid();
const tileMatrix = TileMatrixSets.find(identifier);
Expand All @@ -140,18 +135,16 @@ export class CommandMakeCog extends CommandLineAction {
}

// Set config layer for output
configLayer[tileMatrix.projection.code] = jobLocation.replace('/job.json', '');

// Get urls for ouput
const url = await this.prepareUrl(job);
urls.push({ tileMatrix: identifier, url });
const path = jobLocation.replace('/job.json', '');
configLayer[tileMatrix.projection.code] = path;
paths.push(path);
}

const output = this.output.value;
if (output) {
fsa.write(fsa.join(output, 'jobs.json'), JSON.stringify(outputJobs));
fsa.write(fsa.join(output, 'layer.json'), JSON.stringify(configLayer));
fsa.write(fsa.join(output, 'urls.json'), JSON.stringify(urls));
fsa.write(fsa.join(output, 'paths.json'), JSON.stringify(paths));
}
}

Expand Down Expand Up @@ -231,18 +224,4 @@ export class CommandMakeCog extends CommandLineAction {
}
throw new Error(`No valid role to find the path: ${path}`);
}

/**
* Prepare QA urls with center location
*/
async prepareUrl(job: CogStacJob): Promise<string> {
const bounds = job.output.bounds;
const center = { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };
const proj = Projection.get(job.tileMatrix.projection);
const centerLatLon = proj.toWgs84([center.x, center.y]).map((c) => c.toFixed(6));
const targetZoom = Math.max(job.tileMatrix.findBestZoom(job.output.gsd) - 12, 0);
const base = Env.get(Env.PublicUrlBase);
const url = `${base}/?i=${job.id}&p=${job.tileMatrix.identifier}&debug#@${centerLatLon[1]},${centerLatLon[0]},z${targetZoom}`;
return url;
}
}