Skip to content

Commit 48c29ac

Browse files
amfagepaulfouquetblacha
authored
feat: generate path from slug TDE-1319 (#1136)
#### Motivation The previous logic to construct the ODR path has partially been replaced by the `linz:slug` field that is constructed in the [stac-setup Argo Tasks command](https://github.com/linz/argo-tasks/tree/master/src/commands/stac-setup). `generate-path` can be simplified to use the pre-constructed slug when publishing to the ODR. #### Modification - Read the `linz:slug` field from the standardised collection.json file and use this to construct the ODR path. - Remove unused functions from the `generate-path` command. - Refactor where it makes sense to reduce duplication of code. #### Checklist - [x] Tests updated - [x] Docs updated - [x] Issue linked in Title --------- Co-authored-by: paulfouquet <[email protected]> Co-authored-by: Blayne Chard <[email protected]>
1 parent 40e8e0e commit 48c29ac

File tree

15 files changed

+147
-345
lines changed

15 files changed

+147
-345
lines changed

src/commands/generate-path/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ generate-path <options> <path>
2121

2222
### Flags
2323

24-
| Usage | Description | Options |
25-
| ------------------------- | ----------------------------------- | ------------- |
26-
| --verbose | Verbose logging | |
27-
| --add-date-in-survey-path | Include the date in the survey path | default: true |
24+
| Usage | Description | Options |
25+
| --------- | --------------- | ------- |
26+
| --verbose | Verbose logging | |
2827

2928
<!-- This file has been autogenerated by src/readme/readme.generate.ts -->
Lines changed: 38 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,86 @@
11
import assert from 'node:assert';
22
import { describe, it } from 'node:test';
33

4+
import { SampleCollection } from '../../generate-path/__test__/sample.js';
45
import { FakeCogTiff } from '../../tileindex-validate/__test__/tileindex.validate.data.js';
5-
import { extractEpsg, extractGsd, formatName, generatePath, PathMetadata } from '../path.generate.js';
6-
import { SampleCollection } from './sample.js';
6+
import { extractEpsg, extractGsd, generatePath, PathMetadata } from '../path.generate.js';
77

88
describe('GeneratePathImagery', () => {
9-
it('Should match - geographic description', () => {
9+
it('Should match - urban aerial from slug', () => {
1010
const metadata: PathMetadata = {
1111
targetBucketName: 'nz-imagery',
12-
category: 'urban-aerial-photos',
13-
geographicDescription: 'Napier',
14-
region: 'hawkes-bay',
15-
date: '2017-2018',
16-
gsd: 0.05,
17-
epsg: 2193,
18-
};
19-
assert.equal(generatePath(metadata), 's3://nz-imagery/hawkes-bay/napier_2017-2018_0.05m/rgb/2193/');
20-
});
21-
it('Should match - event', () => {
22-
const metadata: PathMetadata = {
23-
targetBucketName: 'nz-imagery',
24-
category: 'rural-aerial-photos',
25-
geographicDescription: 'North Island Weather Event',
26-
region: 'hawkes-bay',
27-
date: '2023',
28-
gsd: 0.25,
29-
epsg: 2193,
30-
};
31-
assert.equal(generatePath(metadata), 's3://nz-imagery/hawkes-bay/north-island-weather-event_2023_0.25m/rgb/2193/');
32-
});
33-
it('Should match - no optional metadata', () => {
34-
const metadata: PathMetadata = {
35-
targetBucketName: 'nz-imagery',
36-
category: 'urban-aerial-photos',
37-
geographicDescription: undefined,
12+
geospatialCategory: 'urban-aerial-photos',
3813
region: 'auckland',
39-
date: '2023',
14+
slug: 'auckland_2023_0.3m',
4015
gsd: 0.3,
4116
epsg: 2193,
4217
};
4318
assert.equal(generatePath(metadata), 's3://nz-imagery/auckland/auckland_2023_0.3m/rgb/2193/');
4419
});
4520
});
4621

47-
describe('GeneratePathElevation', () => {
48-
it('Should match - dem (no optional metadata)', () => {
22+
describe('GeneratePathGeospatialDataCategories', () => {
23+
it('Should match - dem from slug', () => {
4924
const metadata: PathMetadata = {
5025
targetBucketName: 'nz-elevation',
51-
category: 'dem',
52-
geographicDescription: undefined,
26+
geospatialCategory: 'dem',
5327
region: 'auckland',
54-
date: '2023',
28+
slug: 'auckland_2023',
5529
gsd: 1,
5630
epsg: 2193,
5731
};
5832
assert.equal(generatePath(metadata), 's3://nz-elevation/auckland/auckland_2023/dem_1m/2193/');
5933
});
60-
it('Should match - dsm (no optional metadata)', () => {
34+
it('Should match - dsm from slug', () => {
6135
const metadata: PathMetadata = {
6236
targetBucketName: 'nz-elevation',
63-
category: 'dsm',
64-
geographicDescription: undefined,
37+
geospatialCategory: 'dsm',
6538
region: 'auckland',
66-
date: '2023',
39+
slug: 'auckland_2023',
6740
gsd: 1,
6841
epsg: 2193,
6942
};
7043
assert.equal(generatePath(metadata), 's3://nz-elevation/auckland/auckland_2023/dsm_1m/2193/');
7144
});
72-
});
73-
74-
describe('GeneratePathSatelliteImagery', () => {
75-
it('Should match - geographic description & event', () => {
45+
it('Should error - invalid geospatial category', () => {
7646
const metadata: PathMetadata = {
7747
targetBucketName: 'nz-imagery',
78-
category: 'satellite-imagery',
79-
geographicDescription: 'North Island Cyclone Gabrielle',
80-
region: 'new-zealand',
81-
date: '2023',
48+
geospatialCategory: 'not-a-valid-category',
49+
region: 'wellington',
50+
slug: 'napier_2017-2018_0.05m',
8251
gsd: 0.5,
8352
epsg: 2193,
8453
};
85-
assert.equal(
86-
generatePath(metadata),
87-
's3://nz-imagery/new-zealand/north-island-cyclone-gabrielle_2023_0.5m/rgb/2193/',
88-
);
54+
assert.throws(() => {
55+
generatePath(metadata);
56+
}, Error("Path can't be generated from collection as no matching category for not-a-valid-category."));
8957
});
90-
});
91-
92-
describe('GeneratePathHistoricImagery', () => {
93-
it('Should error', () => {
58+
it('Should error - does not support historical aerial photos', () => {
9459
const metadata: PathMetadata = {
9560
targetBucketName: 'nz-imagery',
96-
category: 'scanned-aerial-imagery',
97-
geographicDescription: undefined,
61+
geospatialCategory: 'scanned-aerial-photos',
9862
region: 'wellington',
99-
date: '1963',
63+
slug: 'napier_2017-2018_0.05m',
10064
gsd: 0.5,
10165
epsg: 2193,
10266
};
10367
assert.throws(() => {
10468
generatePath(metadata);
105-
}, Error);
69+
}, Error('Historic Imagery scanned-aerial-photos is out of scope for automated path generation.'));
10670
});
10771
});
10872

109-
describe('GeneratePathDemIgnoringDate', () => {
110-
it('Should not include the date in the survey name', () => {
73+
describe('GeneratePathImagery', () => {
74+
it('Should match - urban aerial from slug', () => {
11175
const metadata: PathMetadata = {
112-
targetBucketName: 'nz-elevation',
113-
category: 'dem',
114-
geographicDescription: 'new-zealand',
115-
region: 'new-zealand',
116-
date: '',
117-
gsd: 1,
76+
targetBucketName: 'nz-imagery',
77+
geospatialCategory: 'urban-aerial-photos',
78+
region: 'auckland',
79+
slug: 'auckland_2023_0.3m',
80+
gsd: 0.3,
11881
epsg: 2193,
11982
};
120-
assert.equal(generatePath(metadata), 's3://nz-elevation/new-zealand/new-zealand/dem_1m/2193/');
121-
});
122-
});
123-
124-
describe('formatName', () => {
125-
it('Should match - region', () => {
126-
assert.equal(formatName('hawkes-bay', undefined), 'hawkes-bay');
127-
});
128-
it('Should match - region & geographic description', () => {
129-
assert.equal(formatName('hawkes-bay', 'Napier'), 'napier');
130-
});
131-
it('Should match - region & event', () => {
132-
assert.equal(formatName('canterbury', 'Christchurch Earthquake'), 'christchurch-earthquake');
83+
assert.equal(generatePath(metadata), 's3://nz-imagery/auckland/auckland_2023_0.3m/rgb/2193/');
13384
});
13485
});
13586

@@ -171,52 +122,18 @@ describe('gsd', () => {
171122
});
172123
});
173124

174-
describe('category', () => {
175-
it('Should return category', async () => {
176-
const collection = structuredClone(SampleCollection);
177-
178-
assert.equal(collection['linz:geospatial_category'], 'urban-aerial-photos');
179-
});
180-
});
181-
182-
describe('geographicDescription', () => {
183-
it('Should return geographic description', async () => {
184-
const collection = structuredClone(SampleCollection);
185-
186-
assert.equal(collection['linz:geographic_description'], 'Palmerston North');
187-
const metadata: PathMetadata = {
188-
targetBucketName: 'bucket',
189-
category: 'urban-aerial-photos',
190-
geographicDescription: collection['linz:geographic_description'],
191-
region: 'manawatu-whanganui',
192-
date: '2020',
193-
gsd: 0.05,
194-
epsg: 2193,
195-
};
196-
assert.equal(generatePath(metadata), 's3://bucket/manawatu-whanganui/palmerston-north_2020_0.05m/rgb/2193/');
197-
});
198-
it('Should return undefined - no geographic description metadata', async () => {
125+
describe('metadata from collection', () => {
126+
it('Should return urban aerial photos path', async () => {
199127
const collection = structuredClone(SampleCollection);
200128

201-
delete collection['linz:geographic_description'];
202-
assert.equal(collection['linz:geographic_description'], undefined);
203129
const metadata: PathMetadata = {
204130
targetBucketName: 'bucket',
205-
category: 'urban-aerial-photos',
206-
geographicDescription: collection['linz:geographic_description'],
207-
region: 'manawatu-whanganui',
208-
date: '2020',
209-
gsd: 0.05,
131+
geospatialCategory: collection['linz:geospatial_category'],
132+
region: collection['linz:region'],
133+
slug: collection['linz:slug'],
134+
gsd: 0.3,
210135
epsg: 2193,
211136
};
212-
assert.equal(generatePath(metadata), 's3://bucket/manawatu-whanganui/manawatu-whanganui_2020_0.05m/rgb/2193/');
213-
});
214-
});
215-
216-
describe('region', () => {
217-
it('Should return region', async () => {
218-
const collection = structuredClone(SampleCollection);
219-
220-
assert.equal(collection['linz:region'], 'manawatu-whanganui');
137+
assert.equal(generatePath(metadata), 's3://bucket/manawatu-whanganui/palmerston-north_2024_0.3m/rgb/2193/');
221138
});
222139
});

src/commands/generate-path/__test__/path.date.test.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
import { StacCollection } from 'stac-ts';
22

3-
import { StacCollectionLinz } from '../path.generate.js';
3+
import { StacCollectionLinz } from '../../../utils/metadata.js';
44

55
export const SampleCollection: StacCollection & StacCollectionLinz = {
66
type: 'Collection',
77
stac_version: '1.0.0',
8-
id: '01HGF4RAQSM53Z26Y7C27T1GMB',
9-
title: 'Palmerston North 0.3m Storm Satellite Imagery (2024) - Preview',
10-
description:
11-
'Satellite imagery within the Manawatū-Whanganui region captured in 2024, published as a record of the Storm event.',
8+
id: '01J0Q2CCGQKXK0TSBEJ4HRKR2X',
9+
title: 'Palmerston North 0.3m Urban Aerial Photos (2024)',
10+
description: 'Orthophotography within the Manawatū-Whanganui region captured in the 2024 flying season.',
1211
license: 'CC-BY-4.0',
1312
links: [
1413
{ rel: 'self', href: './collection.json', type: 'application/json' },
1514
{
1615
rel: 'item',
17-
href: './BA34_1000_3040.json',
16+
href: './BM34_1000_3040.json',
1817
type: 'application/json',
1918
},
2019
{
2120
rel: 'item',
22-
href: './BA34_1000_3041.json',
21+
href: './BM34_1000_3041.json',
2322
type: 'application/json',
2423
},
2524
],
2625
providers: [
2726
{ name: 'Aerial Surveys', roles: ['producer'] },
28-
{ name: 'Aerial Surveys', roles: ['licensor'] },
27+
{ name: 'Palmerston North City Council', roles: ['licensor'] },
2928
{
3029
name: 'Toitū Te Whenua Land Information New Zealand',
3130
roles: ['host', 'processor'],
3231
},
3332
],
34-
'linz:lifecycle': 'preview',
33+
'linz:lifecycle': 'completed',
3534
'linz:geospatial_category': 'urban-aerial-photos',
3635
'linz:region': 'manawatu-whanganui',
36+
'linz:slug': 'palmerston-north_2024_0.3m',
3737
'linz:security_classification': 'unclassified',
38-
'linz:event_name': 'Storm',
3938
'linz:geographic_description': 'Palmerston North',
4039
extent: {
4140
spatial: {
4241
bbox: [[175.4961876, -36.8000575, 175.5071491, -36.7933469]],
4342
},
4443
temporal: {
45-
interval: [['2022-12-31T11:00:00Z', '2022-12-31T11:00:00Z']],
44+
interval: [['2024-02-14T11:00:00Z', '2024-04-28T12:00:00Z']],
4645
},
4746
},
4847
};

src/commands/generate-path/path.constants.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/commands/generate-path/path.date.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)