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: allow excluding date from the survey name when generating path TDE-1261 #1067

Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ lds-fetch-layer --target ./output 51002 51000
### `generate-path`

Generate target path for ODR buckets using collection metadata.

The date can be omitted from the survey name (example: `s3://nz-elevation/new-zealand/new-zealand/dem_1m/2193/`) by passing the `--no-date-in-survey-path` flag.

For imagery naming conventions see: https://github.com/linz/imagery/blob/master/docs/naming.md
For elevation naming conventions see: https://github.com/linz/elevation/blob/master/docs/naming.md

Expand Down
15 changes: 15 additions & 0 deletions src/commands/path/__test__/generate.path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ describe('GeneratePathHistoricImagery', () => {
});
});

describe('GeneratePathDemIgnoringDate', () => {
it('Should not include the date in the survey name', () => {
const metadata: PathMetadata = {
targetBucketName: 'nz-elevation',
category: 'dem',
geographicDescription: 'new-zealand',
region: 'new-zealand',
date: '',
gsd: 1,
epsg: 2193,
};
assert.equal(generatePath(metadata), 's3://nz-elevation/new-zealand/new-zealand/dem_1m/2193/');
});
});

describe('formatName', () => {
it('Should match - region', () => {
assert.equal(formatName('hawkes-bay', undefined), 'hawkes-bay');
Expand Down
20 changes: 15 additions & 5 deletions src/commands/path/path.generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Epsg } from '@basemaps/geo';
import { fsa } from '@chunkd/fs';
import { Tiff } from '@cogeotiff/core';
import { command, option, positional, string } from 'cmd-ts';
import { boolean, command, flag, option, positional, string } from 'cmd-ts';
import { StacCollection, StacItem } from 'stac-ts';

import { CliInfo } from '../../cli.info.js';
Expand Down Expand Up @@ -45,6 +45,14 @@ export const commandGeneratePath = command({
description: 'Target bucket name, e.g. nz-imagery',
}),

noDateInSurveyPath: flag({
type: boolean,
defaultValue: () => false,
long: 'no-date-in-survey-path',
description: 'Do not include the date in the survey path',
defaultValueIsSerializable: true,
}),

source: positional({
type: string,
displayName: 'path',
Expand All @@ -70,7 +78,7 @@ export const commandGeneratePath = command({
category: collection['linz:geospatial_category'],
region: collection['linz:region'],
geographicDescription: collection['linz:geographic_description'],
date: formatDate(collection),
date: args.noDateInSurveyPath ? '' : formatDate(collection),
gsd: extractGsd(tiff),
epsg: extractEpsg(tiff),
};
Expand All @@ -94,21 +102,23 @@ export const commandGeneratePath = command({
*/
export function generatePath(metadata: PathMetadata): string {
const name = formatName(metadata.region, metadata.geographicDescription);
const surveyName = metadata.date ? `${name}_${metadata.date}` : name;

if (metadata.category === dataCategories.SCANNED_AERIAL_PHOTOS) {
// nb: Historic Imagery is out of scope as survey number is not yet recorded in collection metadata
throw new Error(`Automated target generation not implemented for historic imagery`);
}

if ([dataCategories.URBAN_AERIAL_PHOTOS, dataCategories.RURAL_AERIAL_PHOTOS].includes(metadata.category)) {
return `s3://${metadata.targetBucketName}/${metadata.region}/${name}_${metadata.date}_${metadata.gsd}m/rgb/${metadata.epsg}/`;
return `s3://${metadata.targetBucketName}/${metadata.region}/${surveyName}_${metadata.gsd}m/rgb/${metadata.epsg}/`;
}

if (metadata.category === dataCategories.SATELLITE_IMAGERY) {
return `s3://${metadata.targetBucketName}/${metadata.region}/${name}_${metadata.date}_${metadata.gsd}m/rgb/${metadata.epsg}/`;
return `s3://${metadata.targetBucketName}/${metadata.region}/${surveyName}_${metadata.gsd}m/rgb/${metadata.epsg}/`;
}

if ([dataCategories.DEM, dataCategories.DSM].includes(metadata.category)) {
return `s3://${metadata.targetBucketName}/${metadata.region}/${name}_${metadata.date}/${metadata.category}_${metadata.gsd}m/${metadata.epsg}/`;
return `s3://${metadata.targetBucketName}/${metadata.region}/${surveyName}/${metadata.category}_${metadata.gsd}m/${metadata.epsg}/`;
}

throw new Error(`Path Can't be generated from collection as no matching category: ${metadata.category}.`);
Expand Down
Loading