@basemaps/bathymetry 7.4.0 → 7.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/build/__tests__/hash.test.d.ts +1 -0
  2. package/build/__tests__/hash.test.js +13 -0
  3. package/build/__tests__/hash.test.js.map +1 -0
  4. package/build/__tests__/stac.test.d.ts +1 -0
  5. package/build/__tests__/stac.test.js +181 -0
  6. package/build/__tests__/stac.test.js.map +1 -0
  7. package/build/bathy.maker.d.ts +60 -0
  8. package/build/bathy.maker.js +233 -0
  9. package/build/bathy.maker.js.map +1 -0
  10. package/build/file.d.ts +24 -0
  11. package/build/file.js +49 -0
  12. package/build/file.js.map +1 -0
  13. package/build/gdal/__tests__/gdal.progress.test.d.ts +1 -0
  14. package/build/gdal/__tests__/gdal.progress.test.js +23 -0
  15. package/build/gdal/__tests__/gdal.progress.test.js.map +1 -0
  16. package/build/gdal/gdal.command.d.ts +43 -0
  17. package/build/gdal/gdal.command.js +118 -0
  18. package/build/gdal/gdal.command.js.map +1 -0
  19. package/build/gdal/gdal.d.ts +18 -0
  20. package/build/gdal/gdal.docker.d.ts +17 -0
  21. package/build/gdal/gdal.docker.js +87 -0
  22. package/build/gdal/gdal.docker.js.map +1 -0
  23. package/build/gdal/gdal.js +28 -0
  24. package/build/gdal/gdal.js.map +1 -0
  25. package/build/gdal/gdal.local.d.ts +9 -0
  26. package/build/gdal/gdal.local.js +22 -0
  27. package/build/gdal/gdal.local.js.map +1 -0
  28. package/build/gdal/gdal.progress.d.ts +15 -0
  29. package/build/gdal/gdal.progress.js +65 -0
  30. package/build/gdal/gdal.progress.js.map +1 -0
  31. package/build/hash.d.ts +6 -0
  32. package/build/hash.js +21 -0
  33. package/build/hash.js.map +1 -0
  34. package/build/index.d.ts +4 -0
  35. package/build/index.js +128 -0
  36. package/build/index.js.map +1 -0
  37. package/build/mapnik.d.ts +9 -0
  38. package/build/mapnik.js +80 -0
  39. package/build/mapnik.js.map +1 -0
  40. package/build/stac.d.ts +21 -0
  41. package/build/stac.js +127 -0
  42. package/build/stac.js.map +1 -0
  43. package/package.json +5 -6
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import assert from 'node:assert';
2
+ import * as fs from 'node:fs';
3
+ import { describe, it } from 'node:test';
4
+ import { Hash } from '../hash.js';
5
+ describe('hash', () => {
6
+ it('hash', async () => {
7
+ fs.writeFileSync('./test-file', Buffer.from('I am a test file for hashing\n'));
8
+ const ans = await Hash.hash('./test-file');
9
+ assert.equal(ans, '122076427149ca45100f317f16821ef934885cc49352447ee64c9f5e9655c95c695e');
10
+ fs.unlinkSync('./test-file');
11
+ });
12
+ });
13
+ //# sourceMappingURL=hash.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.test.js","sourceRoot":"","sources":["../../src/__tests__/hash.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;QACpB,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC,CAAC;QAC/E,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,sEAAsE,CAAC,CAAC;QAC1F,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,181 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
+ import assert from 'node:assert';
5
+ import { afterEach, beforeEach, describe, it } from 'node:test';
6
+ import { GoogleTms } from '@basemaps/geo';
7
+ import { fsa, FsMemory, LogConfig } from '@basemaps/shared';
8
+ import { round } from '@basemaps/test/build/rounding.js';
9
+ import { basename, dirname } from 'path';
10
+ import { FilePath } from '../file.js';
11
+ import { Hash } from '../hash.js';
12
+ import { Stac } from '../stac.js';
13
+ describe('stac', () => {
14
+ const origHash = Hash.hash;
15
+ const fsMemory = new FsMemory();
16
+ beforeEach(() => {
17
+ fsa.register('memory://', fsMemory);
18
+ });
19
+ afterEach(() => {
20
+ Hash.hash = origHash;
21
+ fsMemory.files.clear();
22
+ });
23
+ it('createItem', async () => {
24
+ Hash.hash = (v) => 'hash_' + basename(v);
25
+ const bm = {
26
+ id: 'id123',
27
+ tileMatrix: GoogleTms,
28
+ inputPath: 's3://test-source-bucket/gebco-2020/',
29
+ outputPath: 's3://test-bucket/bathy-2020/',
30
+ tmpFolder: new FilePath('/tmp/path'),
31
+ };
32
+ bm.config = bm;
33
+ const now = Date.now();
34
+ const stac = round(await Stac.createItem(bm, { x: 22, y: 33, z: 13 }));
35
+ const date = Date.parse(stac.properties['datetime']);
36
+ assert.equal(date >= now && date < now + 2000, true);
37
+ assert.deepEqual(round(stac, 4), {
38
+ stac_version: Stac.Version,
39
+ stac_extensions: ['projection', Stac.BaseMapsExtension],
40
+ id: 'id123/13-22-33',
41
+ collection: 'id123',
42
+ type: 'Feature',
43
+ bbox: [-179.0332, 84.9205, -178.9893, 84.9244],
44
+ geometry: {
45
+ type: 'Polygon',
46
+ coordinates: [
47
+ [
48
+ [-179.0332, 84.9205],
49
+ [-179.0332, 84.9244],
50
+ [-178.9893, 84.9244],
51
+ [-178.9893, 84.9205],
52
+ [-179.0332, 84.9205],
53
+ ],
54
+ ],
55
+ },
56
+ properties: {
57
+ datetime: stac.properties['datetime'],
58
+ 'checksum:multihash': 'hash_13-22-33.tiff',
59
+ 'proj:epsg': 3857,
60
+ 'linz:gdal:version': undefined,
61
+ 'linz:tile_matrix_set': 'WebMercatorQuad',
62
+ },
63
+ assets: {
64
+ tiff: {
65
+ href: '13-22-33.tiff',
66
+ title: 'GeoTiff',
67
+ roles: ['data'],
68
+ type: 'image/tiff; application=geotiff',
69
+ },
70
+ },
71
+ links: [{ rel: 'collection', href: 'collection.json' }],
72
+ });
73
+ });
74
+ describe('createCollection', () => {
75
+ const logger = LogConfig.get();
76
+ LogConfig.disable();
77
+ const bm = {
78
+ id: 'id123',
79
+ tileMatrix: GoogleTms,
80
+ inputPath: 'memory://test-source-bucket/gebco-2020/gebco_2020.nc',
81
+ outputPath: 'memory://test-bucket/bathy-2020/',
82
+ tmpFolder: new FilePath('/tmp/path'),
83
+ createSourceHash(l) {
84
+ return 'multihashResult' + (l === logger);
85
+ },
86
+ get inputFolder() {
87
+ return dirname(this.inputPath);
88
+ },
89
+ };
90
+ bm.config = bm;
91
+ it('createCollection without source collection.json', async () => {
92
+ const bounds = GoogleTms.tileToSourceBounds({ x: 1, y: 2, z: 4 });
93
+ const items = ['1-1-2.json'];
94
+ const stac = await Stac.createCollection(bm, bounds, items, logger);
95
+ assert.deepEqual(round(stac, 4), {
96
+ stac_version: Stac.Version,
97
+ stac_extensions: ['projection'],
98
+ id: 'id123',
99
+ title: 'Gebco 2020.nc',
100
+ description: 'No description',
101
+ extent: {
102
+ spatial: { bbox: [[-157.5, 74.0195, -135, 79.1713]] },
103
+ temporal: {
104
+ interval: [['2020-01-01T00:00:00Z', '2021-01-01T00:00:00Z']],
105
+ },
106
+ },
107
+ license: Stac.License,
108
+ links: stac.links,
109
+ providers: [
110
+ {
111
+ name: 'Land Information New Zealand',
112
+ url: 'https://www.linz.govt.nz/',
113
+ roles: ['processor'],
114
+ },
115
+ ],
116
+ keywords: ['Bathymetry'],
117
+ summaries: { 'proj:epsg': [3857] },
118
+ });
119
+ });
120
+ it('createCollection with source collection.json', async () => {
121
+ await fsa.write(fsa.toUrl('memory://test-source-bucket/gebco-2020/collection.json'), JSON.stringify({
122
+ title: 'fancy title',
123
+ description: 'collection description',
124
+ providers: [{ name: 'source provider', roles: ['source'] }],
125
+ extent: {
126
+ spatial: { bbox: [[-180, 84, -178, 85]] },
127
+ temporal: { interval: [['2020-01-01T00:00:00Z', '2020-10-12T01:02:03Z']] },
128
+ },
129
+ }));
130
+ const bounds = GoogleTms.tileToSourceBounds({ x: 22, y: 33, z: 13 });
131
+ const items = ['13-22-33.json', '13-22-34.json'];
132
+ const stac = await Stac.createCollection(bm, bounds, items, logger);
133
+ const gitHubLink = stac.links[2];
134
+ assert.equal(gitHubLink.href.startsWith('https://github.com/linz/basemaps.git'), true);
135
+ assert.equal(gitHubLink.rel, 'derived_from');
136
+ assert.equal(/^\d+\.\d+\.\d+$/.test(gitHubLink['version']), true);
137
+ assert.deepEqual(round(stac, 4), {
138
+ stac_version: Stac.Version,
139
+ stac_extensions: ['projection'],
140
+ id: 'id123',
141
+ title: 'fancy title',
142
+ description: 'collection description',
143
+ extent: {
144
+ spatial: { bbox: [[-179.0332, 84.9205, -178.9893, 84.9244]] },
145
+ temporal: { interval: [['2020-01-01T00:00:00Z', '2020-10-12T01:02:03Z']] },
146
+ },
147
+ license: Stac.License,
148
+ links: [
149
+ {
150
+ rel: 'self',
151
+ href: 'memory://test-bucket/bathy-2020/collection.json',
152
+ },
153
+ {
154
+ rel: 'derived_from',
155
+ href: 'memory://test-source-bucket/gebco-2020/gebco_2020.nc',
156
+ 'checksum:multihash': 'multihashResulttrue',
157
+ },
158
+ gitHubLink,
159
+ { rel: 'item', href: '13-22-33.json', type: 'application/geo+json' },
160
+ { rel: 'item', href: '13-22-34.json', type: 'application/geo+json' },
161
+ {
162
+ href: 'memory://test-source-bucket/gebco-2020/collection.json',
163
+ rel: 'sourceImagery',
164
+ type: 'application/json',
165
+ },
166
+ ],
167
+ providers: [
168
+ {
169
+ name: 'Land Information New Zealand',
170
+ url: 'https://www.linz.govt.nz/',
171
+ roles: ['processor'],
172
+ },
173
+ { name: 'source provider', roles: ['source'] },
174
+ ],
175
+ keywords: ['Bathymetry'],
176
+ summaries: { 'proj:epsg': [3857] },
177
+ });
178
+ });
179
+ });
180
+ });
181
+ //# sourceMappingURL=stac.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stac.test.js","sourceRoot":"","sources":["../../src/__tests__/stac.test.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,0DAA0D;AAC1D,4DAA4D;AAC5D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAW,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;IAE3B,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,UAAU,CAAC,GAAG,EAAE;QACd,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;QACrB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,EAAE,CAAC,YAAY,CAAC;gBACxB,SAAS,EAAE,EAAE,WAAW,EAAE,CAAC,IAAI,CAAC,EAAE;aACnC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { Bounds, Tile, TileMatrixSet } from '@basemaps/geo';
2
+ import { LogType } from '@basemaps/shared';
3
+ import type { LimitFunction } from 'p-limit';
4
+ import { FilePath } from './file.js';
5
+ interface BathyMakerContext {
6
+ /** unique id for this build */
7
+ id: string;
8
+ /** Source netcdf or tiff file path */
9
+ inputPath: string;
10
+ /** Output directory path */
11
+ outputPath: string;
12
+ tmpFolder: FilePath;
13
+ /** TileMatrixSet to cut the bathy up into tiles */
14
+ tileMatrix: TileMatrixSet;
15
+ /** zoom level of the tms to cut the tiles too */
16
+ zoom: number;
17
+ /** Number of threads used to convert @default NUM_CPUS */
18
+ threads?: number;
19
+ /** Mapnik render tilesize @default 8192 */
20
+ tileSize?: number;
21
+ }
22
+ export declare const BathyMakerContextDefault: {
23
+ threads: number;
24
+ /** Making this much larger than this takes quite a long time to render */
25
+ tileSize: number;
26
+ };
27
+ export declare class BathyMaker {
28
+ config: BathyMakerContext & typeof BathyMakerContextDefault;
29
+ /** Current gdal version @see Gdal.version */
30
+ gdalVersion?: Promise<string>;
31
+ /** Concurrent limiting queue, all work should be done inside the queue */
32
+ q: LimitFunction;
33
+ constructor(ctx: BathyMakerContext);
34
+ get inputPath(): string;
35
+ get inputFolder(): string;
36
+ get outputPath(): string;
37
+ get tmpFolder(): FilePath;
38
+ isTiffInput(): boolean;
39
+ /** Most operations need a tiff file */
40
+ get tiffPath(): string;
41
+ /** File name of the path */
42
+ get fileName(): string;
43
+ render(logger: LogType): Promise<void>;
44
+ /** Create a multi hash of the source file */
45
+ createSourceHash(logger: LogType): Promise<string>;
46
+ /** Render a specific tile */
47
+ renderTile(tile: Tile, logger: LogType): Promise<string>;
48
+ /** convert a input file into one that can be processed by this script */
49
+ createSourceGeoTiff(logger: LogType): Promise<void>;
50
+ /** Create a tile in the output TMS's CRS */
51
+ createTile(tile: Tile, logger: LogType): Promise<void>;
52
+ /** Create a hillshade for a tile */
53
+ createHillShadedTile(tile: Tile, logger: LogType): Promise<void>;
54
+ /** Use mapnik to composite the hillshaded tile and the rendered tile */
55
+ createCompositeTile(tile: Tile, logger: LogType): Promise<void>;
56
+ /** Create and write a stac metadata item for a single tile */
57
+ createTileMetadata(tile: Tile): Promise<string>;
58
+ createMetadata(bounds: Bounds, itemPaths: string[], logger: LogType): Promise<void>;
59
+ }
60
+ export {};
@@ -0,0 +1,233 @@
1
+ import { Epsg, TileMatrixSet } from '@basemaps/geo';
2
+ import { fsa, s3ToVsis3 } from '@basemaps/shared';
3
+ import * as os from 'os';
4
+ import PLimit from 'p-limit';
5
+ import * as path from 'path';
6
+ import { basename } from 'path';
7
+ import { Gdal } from './gdal/gdal.js';
8
+ import { Hash } from './hash.js';
9
+ import { MapnikRender } from './mapnik.js';
10
+ import { Stac } from './stac.js';
11
+ function createMountedGdal(...paths) {
12
+ const gdal = Gdal.create();
13
+ if (gdal.mount != null) {
14
+ for (const path of paths)
15
+ gdal.mount(path);
16
+ }
17
+ return gdal;
18
+ }
19
+ export const BathyMakerContextDefault = {
20
+ threads: os.cpus().length,
21
+ /** Making this much larger than this takes quite a long time to render */
22
+ tileSize: 8192,
23
+ };
24
+ export class BathyMaker {
25
+ constructor(ctx) {
26
+ Object.defineProperty(this, "config", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ /** Current gdal version @see Gdal.version */
33
+ Object.defineProperty(this, "gdalVersion", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ /** Concurrent limiting queue, all work should be done inside the queue */
40
+ Object.defineProperty(this, "q", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: void 0
45
+ });
46
+ this.config = { ...BathyMakerContextDefault, ...ctx };
47
+ this.q = PLimit(this.config.threads);
48
+ }
49
+ get inputPath() {
50
+ return this.config.inputPath;
51
+ }
52
+ get inputFolder() {
53
+ return path.dirname(this.inputPath);
54
+ }
55
+ get outputPath() {
56
+ return this.config.outputPath;
57
+ }
58
+ get tmpFolder() {
59
+ return this.config.tmpFolder;
60
+ }
61
+ isTiffInput() {
62
+ return this.inputPath.endsWith('.tiff');
63
+ }
64
+ /** Most operations need a tiff file */
65
+ get tiffPath() {
66
+ if (this.isTiffInput())
67
+ return this.inputPath;
68
+ return this.tmpFolder.name("sourceTiff" /* FileType.SourceTiff */);
69
+ }
70
+ /** File name of the path */
71
+ get fileName() {
72
+ return path.basename(this.inputPath);
73
+ }
74
+ async render(logger) {
75
+ this.gdalVersion = Gdal.version(logger);
76
+ const isNc = this.inputPath.endsWith('.nc');
77
+ // NetCdf files need to be converted to GeoTiff before processing
78
+ if (isNc)
79
+ await this.createSourceGeoTiff(logger);
80
+ await this.createSourceHash(logger);
81
+ const { tileMatrix: tms, zoom } = this.config;
82
+ const tmsZoom = tms.zooms[zoom];
83
+ logger.info({ file: this.fileName, zoom, tileCount: tmsZoom.matrixWidth * tmsZoom.matrixHeight }, 'Splitting Tiles');
84
+ const gdalVersion = await this.gdalVersion;
85
+ logger.info({ gdalVersion }, 'GdalVersion');
86
+ const promises = [];
87
+ let extent = null;
88
+ for (let x = 0; x < tmsZoom.matrixWidth; x++) {
89
+ for (let y = 0; y < tmsZoom.matrixHeight; y++) {
90
+ const promise = this.q(() => {
91
+ const tile = { x, y, z: zoom };
92
+ const bounds = tms.tileToSourceBounds(tile);
93
+ extent = extent == null ? bounds : extent.union(bounds);
94
+ const tileId = TileMatrixSet.tileToName(tile);
95
+ return this.renderTile(tile, logger.child({ index: tileId }));
96
+ });
97
+ promises.push(promise);
98
+ }
99
+ }
100
+ try {
101
+ const tileNames = await Promise.all(promises);
102
+ if (extent == null)
103
+ return;
104
+ await this.createMetadata(extent, tileNames, logger);
105
+ }
106
+ catch (err) {
107
+ logger.fatal({ err }, 'FailedToRun');
108
+ throw err;
109
+ }
110
+ }
111
+ /** Create a multi hash of the source file */
112
+ async createSourceHash(logger) {
113
+ const hashPath = fsa.toUrl(this.tmpFolder.name("hash" /* FileType.Hash */));
114
+ if (await fsa.exists(hashPath))
115
+ return (await fsa.read(hashPath)).toString();
116
+ logger.info({ hashPath }, 'CreateHash');
117
+ const outputHash = await Hash.hash(this.inputPath);
118
+ await fsa.write(hashPath, Buffer.from(outputHash));
119
+ return outputHash;
120
+ }
121
+ /** Render a specific tile */
122
+ async renderTile(tile, logger) {
123
+ try {
124
+ await this.createTile(tile, logger);
125
+ await this.createHillShadedTile(tile, logger);
126
+ await this.createCompositeTile(tile, logger);
127
+ return await this.createTileMetadata(tile);
128
+ }
129
+ catch (err) {
130
+ logger.error({ err }, 'Failed');
131
+ throw err;
132
+ }
133
+ }
134
+ /** convert a input file into one that can be processed by this script */
135
+ async createSourceGeoTiff(logger) {
136
+ if (this.isTiffInput())
137
+ return;
138
+ logger.info({ path: this.tiffPath }, 'Converting to GeoTiff');
139
+ const gdal = createMountedGdal(this.tmpFolder.sourcePath, this.inputFolder);
140
+ await gdal.run('gdal_translate', [
141
+ '-of',
142
+ 'GTiff',
143
+ // Files need to be converted to Float32 to fix a weird outline bug with the resampling
144
+ // see https://github.com/linz/basemaps-team/issues/241
145
+ '-ot',
146
+ 'Float32',
147
+ s3ToVsis3(this.inputPath),
148
+ this.tiffPath,
149
+ ], logger);
150
+ }
151
+ /** Create a tile in the output TMS's CRS */
152
+ async createTile(tile, logger) {
153
+ const tileId = TileMatrixSet.tileToName(tile);
154
+ const warpedPath = this.tmpFolder.name("warped" /* FileType.Warped */, tileId);
155
+ if (await fsa.exists(fsa.toUrl(warpedPath)))
156
+ return;
157
+ const tms = this.config.tileMatrix;
158
+ const bounds = tms.tileToSourceBounds(tile);
159
+ const warpCommand = [
160
+ '-of',
161
+ 'GTIFF',
162
+ '-co',
163
+ 'NUM_THREADS=ALL_CPUS',
164
+ '-s_srs',
165
+ Epsg.Wgs84.toEpsgString(),
166
+ '-t_srs',
167
+ tms.projection.toEpsgString(),
168
+ '-r',
169
+ 'bilinear',
170
+ '-te',
171
+ ...bounds.toBbox(),
172
+ this.tiffPath,
173
+ warpedPath,
174
+ ].map(String);
175
+ logger.trace({ file: warpedPath }, 'Warping');
176
+ const gdal = createMountedGdal(this.tmpFolder.sourcePath, this.tiffPath);
177
+ await gdal.run('gdalwarp', warpCommand, logger);
178
+ }
179
+ /** Create a hillshade for a tile */
180
+ async createHillShadedTile(tile, logger) {
181
+ const tileId = TileMatrixSet.tileToName(tile);
182
+ const warped = this.tmpFolder.name("warped" /* FileType.Warped */, tileId);
183
+ const target = this.tmpFolder.name("hillshade" /* FileType.HillShade */, tileId);
184
+ if (await fsa.exists(fsa.toUrl(target)))
185
+ return;
186
+ logger.trace({ file: target }, 'Shading');
187
+ const gdal = createMountedGdal(this.inputPath, this.tmpFolder.sourcePath);
188
+ await gdal.run('gdaldem', ['hillshade', '-compute_edges', '-multidirectional', warped, target], logger);
189
+ }
190
+ /** Use mapnik to composite the hillshaded tile and the rendered tile */
191
+ async createCompositeTile(tile, logger) {
192
+ const tileId = TileMatrixSet.tileToName(tile);
193
+ const renderedPath = await MapnikRender.render(this, tile, logger);
194
+ const outputPath = this.tmpFolder.name("output" /* FileType.Output */, tileId);
195
+ if (await fsa.exists(fsa.toUrl(outputPath)))
196
+ return;
197
+ const gdal = createMountedGdal(this.tmpFolder.sourcePath);
198
+ const tileMatrix = this.config.tileMatrix;
199
+ const bounds = tileMatrix.tileToSourceBounds(tile);
200
+ await gdal.run('gdal_translate', [
201
+ '-of',
202
+ 'GTiff',
203
+ '-co',
204
+ 'NUM_THREADS=ALL_CPUS',
205
+ '-co',
206
+ 'COMPRESS=webp',
207
+ '-co',
208
+ 'WEBP_LEVEL=100',
209
+ '-r',
210
+ 'bilinear',
211
+ '-a_srs',
212
+ tileMatrix.projection.toEpsgString(),
213
+ '-a_ullr',
214
+ ...[bounds.x, bounds.bottom, bounds.right, bounds.y],
215
+ renderedPath,
216
+ outputPath,
217
+ ].map(String), logger);
218
+ }
219
+ /** Create and write a stac metadata item for a single tile */
220
+ async createTileMetadata(tile) {
221
+ const output = await Stac.createItem(this, tile);
222
+ const tileId = TileMatrixSet.tileToName(tile);
223
+ const stacOutputPath = this.tmpFolder.name("stac" /* FileType.Stac */, tileId);
224
+ await fsa.write(fsa.toUrl(stacOutputPath), JSON.stringify(output, null, 2));
225
+ return basename(stacOutputPath);
226
+ }
227
+ async createMetadata(bounds, itemPaths, logger) {
228
+ const output = await Stac.createCollection(this, bounds, itemPaths, logger);
229
+ const stacOutputPath = this.tmpFolder.name("stac" /* FileType.Stac */, 'collection');
230
+ await fsa.write(fsa.toUrl(stacOutputPath), JSON.stringify(output, null, 2));
231
+ }
232
+ }
233
+ //# sourceMappingURL=bathy.maker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bathy.maker.js","sourceRoot":"","sources":["../src/bathy.maker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,IAAI,EAAQ,aAAa,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,GAAG,EAAW,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAIhC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAoBjC,SAAS,iBAAiB,CAAC,GAAG,KAAe;IAC3C,MAAM,IAA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IAAI,CAAC,SAAS,CAAC,IAAI,6BAAgB,YAAY,CAAC,CAAC;QACxE,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC9E,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ export declare const enum FileType {
2
+ Output = "output",
3
+ Hash = "hash",
4
+ Warped = "warped",
5
+ HillShade = "hillshade",
6
+ Rendered = "rendered",
7
+ Stac = "stac",
8
+ SourceTiff = "sourceTiff"
9
+ }
10
+ export declare class FilePath {
11
+ sourcePath: string;
12
+ constructor(sourcePath: string);
13
+ /**
14
+ * Determine the basename for a file type
15
+ */
16
+ basename(fileType: FileType, id?: string): string;
17
+ /**
18
+ * Create some temp files and folders
19
+ *
20
+ * output into folder ./output
21
+ * temp files into temp folder ./.bathy/
22
+ */
23
+ name(fileType: FileType, id?: string): string;
24
+ }
package/build/file.js ADDED
@@ -0,0 +1,49 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ const PrefixMade = {};
4
+ const BathyTempFolder = '.bathy';
5
+ const SuffixMap = {
6
+ ["hash" /* FileType.Hash */]: 'multihash',
7
+ ["stac" /* FileType.Stac */]: 'json',
8
+ ["rendered" /* FileType.Rendered */]: 'png',
9
+ };
10
+ export class FilePath {
11
+ constructor(sourcePath) {
12
+ Object.defineProperty(this, "sourcePath", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ this.sourcePath = sourcePath;
19
+ }
20
+ /**
21
+ * Determine the basename for a file type
22
+ */
23
+ basename(fileType, id = String(fileType)) {
24
+ const suffix = SuffixMap[fileType] ?? 'tiff';
25
+ return `${id}.${suffix}`;
26
+ }
27
+ /**
28
+ * Create some temp files and folders
29
+ *
30
+ * output into folder ./output
31
+ * temp files into temp folder ./.bathy/
32
+ */
33
+ name(fileType, id = String(fileType)) {
34
+ const basename = this.basename(fileType, id);
35
+ let tempPath = this.sourcePath;
36
+ if (fileType === "output" /* FileType.Output */ || fileType === "stac" /* FileType.Stac */) {
37
+ tempPath = path.join(tempPath, "output" /* FileType.Output */);
38
+ }
39
+ else {
40
+ tempPath = path.join(tempPath, BathyTempFolder, fileType);
41
+ }
42
+ if (PrefixMade[tempPath] == null) {
43
+ fs.mkdirSync(tempPath, { recursive: true });
44
+ PrefixMade[tempPath] = true;
45
+ }
46
+ return `${tempPath}/${basename}`;
47
+ }
48
+ }
49
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,UAAU,GAA4B,EAAE,CAAC;AAE/C,MAAM,eAAe,GAAG,QAAQ,CAAC;AAYjC,MAAM,SAAS,GAAsC;IACnD,4BAAe,EAAE,WAAW;IAC5B,4BAAe,EAAE,MAAM;IACvB,oCAAmB,EAAE,KAAK;CAC3B,CAAC;AAEF,MAAM,OAAO,QAAQ;IAGnB,YAAY,UAAkB;QAF9B;;;;;WAAmB;QAGjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IACD;;OAEG;IACH,QAAQ,CAAC,QAAkB,EAAE,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChD,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC;QAC7C,OAAO,GAAG,EAAE,IAAI,MAAM,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,QAAkB,EAAE,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAE7C,IAAI,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC;QAE/B,IAAI,QAAQ,mCAAoB,IAAI,QAAQ,+BAAkB,EAAE,CAAC;YAC/D,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,iCAAkB,CAAC;QAClD,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;YACjC,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5C,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;QAC9B,CAAC;QACD,OAAO,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { GdalProgressParser } from '../gdal.progress.js';
4
+ describe('GdalProgressParser', () => {
5
+ it('should emit on progress', () => {
6
+ const prog = new GdalProgressParser();
7
+ assert.equal(prog.progress, 0);
8
+ prog.data(Buffer.from('\n.'));
9
+ assert.equal(prog.progress.toFixed(2), '3.23');
10
+ });
11
+ it('should take 31 dots to finish', () => {
12
+ const prog = new GdalProgressParser();
13
+ let processCount = 0;
14
+ prog.data(Buffer.from('\n'));
15
+ prog.on('progress', () => processCount++);
16
+ for (let i = 0; i < 31; i++) {
17
+ prog.data(Buffer.from('.'));
18
+ assert.equal(processCount, i + 1);
19
+ }
20
+ assert.equal(prog.progress.toFixed(2), '100.00');
21
+ });
22
+ });
23
+ //# sourceMappingURL=gdal.progress.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gdal.progress.test.js","sourceRoot":"","sources":["../../../src/gdal/__tests__/gdal.progress.test.ts"],"names":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