@basemaps/bathymetry 7.4.0 → 7.6.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.
- package/build/__tests__/hash.test.d.ts +1 -0
- package/build/__tests__/hash.test.js +13 -0
- package/build/__tests__/hash.test.js.map +1 -0
- package/build/__tests__/stac.test.d.ts +1 -0
- package/build/__tests__/stac.test.js +181 -0
- package/build/__tests__/stac.test.js.map +1 -0
- package/build/bathy.maker.d.ts +60 -0
- package/build/bathy.maker.js +233 -0
- package/build/bathy.maker.js.map +1 -0
- package/build/file.d.ts +24 -0
- package/build/file.js +49 -0
- package/build/file.js.map +1 -0
- package/build/gdal/__tests__/gdal.progress.test.d.ts +1 -0
- package/build/gdal/__tests__/gdal.progress.test.js +23 -0
- package/build/gdal/__tests__/gdal.progress.test.js.map +1 -0
- package/build/gdal/gdal.command.d.ts +42 -0
- package/build/gdal/gdal.command.js +118 -0
- package/build/gdal/gdal.command.js.map +1 -0
- package/build/gdal/gdal.d.ts +18 -0
- package/build/gdal/gdal.docker.d.ts +17 -0
- package/build/gdal/gdal.docker.js +87 -0
- package/build/gdal/gdal.docker.js.map +1 -0
- package/build/gdal/gdal.js +28 -0
- package/build/gdal/gdal.js.map +1 -0
- package/build/gdal/gdal.local.d.ts +9 -0
- package/build/gdal/gdal.local.js +22 -0
- package/build/gdal/gdal.local.js.map +1 -0
- package/build/gdal/gdal.progress.d.ts +13 -0
- package/build/gdal/gdal.progress.js +65 -0
- package/build/gdal/gdal.progress.js.map +1 -0
- package/build/hash.d.ts +6 -0
- package/build/hash.js +21 -0
- package/build/hash.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +128 -0
- package/build/index.js.map +1 -0
- package/build/mapnik.d.ts +9 -0
- package/build/mapnik.js +80 -0
- package/build/mapnik.js.map +1 -0
- package/build/stac.d.ts +21 -0
- package/build/stac.js +127 -0
- package/build/stac.js.map +1 -0
- package/package.json +5 -6
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LogType } from '@basemaps/shared';
|
|
2
|
+
import { ChildProcessWithoutNullStreams } from 'child_process';
|
|
3
|
+
import { GdalProgressParser } from './gdal.progress.js';
|
|
4
|
+
/**
|
|
5
|
+
* GDAL uses AWS_DEFAULT_PROFILE while node uses AWS_PROFILE
|
|
6
|
+
* this validates the configuration is sane
|
|
7
|
+
*
|
|
8
|
+
* @param env environment to normalize
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeAwsEnv(env: Record<string, string | undefined>): Record<string, string | undefined>;
|
|
11
|
+
export interface GdalCredentials {
|
|
12
|
+
needsRefresh(): boolean;
|
|
13
|
+
refreshPromise(): Promise<void>;
|
|
14
|
+
accessKeyId: string;
|
|
15
|
+
secretAccessKey: string;
|
|
16
|
+
sessionToken: string;
|
|
17
|
+
}
|
|
18
|
+
export declare abstract class GdalCommand {
|
|
19
|
+
parser?: GdalProgressParser;
|
|
20
|
+
protected child?: ChildProcessWithoutNullStreams;
|
|
21
|
+
protected promise?: Promise<{
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
}>;
|
|
25
|
+
protected startTime?: number;
|
|
26
|
+
/** AWS Access */
|
|
27
|
+
protected credentials?: GdalCredentials;
|
|
28
|
+
mount?(mount: string): void;
|
|
29
|
+
env?(): Promise<Record<string, string | undefined>>;
|
|
30
|
+
/** Pass AWS credentials into the container */
|
|
31
|
+
setCredentials(credentials?: GdalCredentials): void;
|
|
32
|
+
/**
|
|
33
|
+
* Run a GDAL command
|
|
34
|
+
* @param cmd command to run eg "gdal_translate"
|
|
35
|
+
* @param args command arguments
|
|
36
|
+
* @param log logger to use
|
|
37
|
+
*/
|
|
38
|
+
run(cmd: string, args: string[], log: LogType): Promise<{
|
|
39
|
+
stdout: string;
|
|
40
|
+
stderr: string;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
/**
|
|
3
|
+
* GDAL uses AWS_DEFAULT_PROFILE while node uses AWS_PROFILE
|
|
4
|
+
* this validates the configuration is sane
|
|
5
|
+
*
|
|
6
|
+
* @param env environment to normalize
|
|
7
|
+
*/
|
|
8
|
+
export function normalizeAwsEnv(env) {
|
|
9
|
+
const awsProfile = env['AWS_PROFILE'];
|
|
10
|
+
const awsDefaultProfile = env['AWS_DEFAULT_PROFILE'];
|
|
11
|
+
if (awsProfile == null)
|
|
12
|
+
return env;
|
|
13
|
+
if (awsDefaultProfile == null) {
|
|
14
|
+
return { ...env, AWS_DEFAULT_PROFILE: awsProfile };
|
|
15
|
+
}
|
|
16
|
+
if (awsDefaultProfile !== awsProfile) {
|
|
17
|
+
throw new Error(`$AWS_PROFILE: "${awsProfile}" and $AWS_DEFAULT_PROFILE: "${awsDefaultProfile}" are mismatched`);
|
|
18
|
+
}
|
|
19
|
+
return env;
|
|
20
|
+
}
|
|
21
|
+
export class GdalCommand {
|
|
22
|
+
constructor() {
|
|
23
|
+
Object.defineProperty(this, "parser", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "child", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "promise", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "startTime", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
/** AWS Access */
|
|
48
|
+
Object.defineProperty(this, "credentials", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: void 0
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Pass AWS credentials into the container */
|
|
56
|
+
setCredentials(credentials) {
|
|
57
|
+
this.credentials = credentials;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Run a GDAL command
|
|
61
|
+
* @param cmd command to run eg "gdal_translate"
|
|
62
|
+
* @param args command arguments
|
|
63
|
+
* @param log logger to use
|
|
64
|
+
*/
|
|
65
|
+
async run(cmd, args, log) {
|
|
66
|
+
if (this.promise != null)
|
|
67
|
+
throw new Error('Cannot create multiple gdal processes, create a new GdalCommand');
|
|
68
|
+
this.parser?.reset();
|
|
69
|
+
this.startTime = Date.now();
|
|
70
|
+
const env = normalizeAwsEnv(this.env ? await this.env() : process.env);
|
|
71
|
+
const child = spawn(cmd, args, { env });
|
|
72
|
+
this.child = child;
|
|
73
|
+
const outputBuff = [];
|
|
74
|
+
const errBuff = [];
|
|
75
|
+
child.stderr.on('data', (data) => {
|
|
76
|
+
const buf = data.toString();
|
|
77
|
+
/**
|
|
78
|
+
* Example error line
|
|
79
|
+
* `ERROR 1: TIFFReadEncodedTile:Read error at row 4294967295, col 4294967295; got 49005 bytes, expected 49152`
|
|
80
|
+
*/
|
|
81
|
+
if (buf.includes('ERROR 1')) {
|
|
82
|
+
log.error({ data: buf }, 'GdalError');
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
log.warn({ data: buf }, 'GdalWarn');
|
|
86
|
+
}
|
|
87
|
+
errBuff.push(data);
|
|
88
|
+
});
|
|
89
|
+
child.stdout.on('data', (data) => {
|
|
90
|
+
outputBuff.push(data);
|
|
91
|
+
this.parser?.data(data);
|
|
92
|
+
});
|
|
93
|
+
this.promise = new Promise((resolve, reject) => {
|
|
94
|
+
child.on('exit', (code) => {
|
|
95
|
+
const stdout = outputBuff.join('').trim();
|
|
96
|
+
const stderr = errBuff.join('').trim();
|
|
97
|
+
const duration = Date.now() - this.startTime;
|
|
98
|
+
if (code !== 0) {
|
|
99
|
+
log.error({ code, stdout, stderr, duration }, 'GdalFailed');
|
|
100
|
+
return reject(new Error('Failed to execute GDAL command'));
|
|
101
|
+
}
|
|
102
|
+
log.trace({ stdout, stderr, duration }, 'GdalDone');
|
|
103
|
+
this.promise = undefined;
|
|
104
|
+
return resolve({ stdout, stderr });
|
|
105
|
+
});
|
|
106
|
+
child.on('error', (error) => {
|
|
107
|
+
const stdout = outputBuff.join('').trim();
|
|
108
|
+
const stderr = errBuff.join('').trim();
|
|
109
|
+
const duration = Date.now() - this.startTime;
|
|
110
|
+
log.error({ stdout, stderr, duration }, 'GdalFailed');
|
|
111
|
+
this.promise = undefined;
|
|
112
|
+
reject(error);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
return this.promise;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=gdal.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gdal.command.js","sourceRoot":"","sources":["../../src/gdal/gdal.command.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,EAAE,MAAM,eAAe,CAAC;AAItE;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAuC;IACrE,MAAM,UAAU,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;IACtC,MAAM,iBAAiB,GAAG,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAErD,IAAI,UAAU,IAAI,IAAI;QAAE,OAAO,GAAG,CAAC;IACnC,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;QAC9B,OAAO,EAAE,GAAG,GAAG,EAAE,mBAAmB,EAAE,UAAU,EAAE,CAAC;IACrD,CAAC;IACD,IAAI,iBAAiB,KAAK,UAAU,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,gCAAgC,iBAAiB,kBAAkB,CAAC,CAAC;IACnH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;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EH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;gBACjC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;gBAC1C,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;gBACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAU,CAAC;gBAE9C,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,YAAY,CAAC,CAAC;gBACtD,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;gBACzB,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LogType } from '@basemaps/shared';
|
|
2
|
+
import { GdalCommand } from './gdal.command.js';
|
|
3
|
+
export declare class Gdal {
|
|
4
|
+
/**
|
|
5
|
+
* Create a new GdalCommand instance ready to run commands
|
|
6
|
+
*
|
|
7
|
+
* This could be a local or docker container depending on environment variables
|
|
8
|
+
* @see Env.Gdal.UseDocker
|
|
9
|
+
*/
|
|
10
|
+
static create(): GdalCommand;
|
|
11
|
+
/**
|
|
12
|
+
* Run a `gdal_translate --version` to extract the current gdal version
|
|
13
|
+
*
|
|
14
|
+
* @example "GDAL 2.4.2, released 2019/06/28"
|
|
15
|
+
* @example "GDAL 3.2.0dev-69b0c4ec4174fde36c609a4aac6f4281424021b3, released 2020/06/26"
|
|
16
|
+
*/
|
|
17
|
+
static version(logger: LogType): Promise<string>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LogType } from '@basemaps/shared';
|
|
2
|
+
import { GdalCommand } from './gdal.command.js';
|
|
3
|
+
export declare class GdalDocker extends GdalCommand {
|
|
4
|
+
mounts: string[];
|
|
5
|
+
constructor();
|
|
6
|
+
mount(filePath: string): void;
|
|
7
|
+
private getMounts;
|
|
8
|
+
private getCredentials;
|
|
9
|
+
/** this could contain sensitive info like AWS access keys */
|
|
10
|
+
private getDockerArgs;
|
|
11
|
+
/** Provide redacted argument string for logging which removes sensitive information */
|
|
12
|
+
maskArgs(args: string[]): string[];
|
|
13
|
+
run(cmd: string, args: string[], log: LogType): Promise<{
|
|
14
|
+
stdout: string;
|
|
15
|
+
stderr: string;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Env } from '@basemaps/shared';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { GdalCommand } from './gdal.command.js';
|
|
5
|
+
export class GdalDocker extends GdalCommand {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
Object.defineProperty(this, "mounts", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
this.mounts = [];
|
|
15
|
+
}
|
|
16
|
+
mount(filePath) {
|
|
17
|
+
if (filePath.startsWith('s3://'))
|
|
18
|
+
return;
|
|
19
|
+
const basePath = path.dirname(filePath);
|
|
20
|
+
if (this.mounts.includes(basePath))
|
|
21
|
+
return;
|
|
22
|
+
this.mounts.push(basePath);
|
|
23
|
+
}
|
|
24
|
+
getMounts() {
|
|
25
|
+
if (this.mounts.length === 0) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const output = [];
|
|
29
|
+
for (const mount of this.mounts) {
|
|
30
|
+
output.push('-v');
|
|
31
|
+
output.push(`${mount}:${mount}`);
|
|
32
|
+
}
|
|
33
|
+
return output;
|
|
34
|
+
}
|
|
35
|
+
async getCredentials() {
|
|
36
|
+
if (this.credentials == null) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
if (this.credentials.needsRefresh()) {
|
|
40
|
+
await this.credentials.refreshPromise();
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
'--env',
|
|
44
|
+
`AWS_ACCESS_KEY_ID=${this.credentials.accessKeyId}`,
|
|
45
|
+
'--env',
|
|
46
|
+
`AWS_SECRET_ACCESS_KEY=${this.credentials.secretAccessKey}`,
|
|
47
|
+
'--env',
|
|
48
|
+
`AWS_SESSION_TOKEN=${this.credentials.sessionToken}`,
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
/** this could contain sensitive info like AWS access keys */
|
|
52
|
+
async getDockerArgs() {
|
|
53
|
+
const DOCKER_CONTAINER = Env.get(Env.Gdal.DockerContainer) ?? 'ghcr.io/osgeo/gdal';
|
|
54
|
+
const DOCKER_CONTAINER_TAG = Env.get(Env.Gdal.DockerContainerTag) ?? 'ubuntu-small-3.8.0';
|
|
55
|
+
const userInfo = os.userInfo();
|
|
56
|
+
const credentials = await this.getCredentials();
|
|
57
|
+
return [
|
|
58
|
+
'run',
|
|
59
|
+
// Config the container to be run as the current user
|
|
60
|
+
'--user',
|
|
61
|
+
`${userInfo.uid}:${userInfo.gid}`,
|
|
62
|
+
...this.getMounts(),
|
|
63
|
+
...credentials,
|
|
64
|
+
// Docker container
|
|
65
|
+
'-i',
|
|
66
|
+
`${DOCKER_CONTAINER}:${DOCKER_CONTAINER_TAG}`,
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
/** Provide redacted argument string for logging which removes sensitive information */
|
|
70
|
+
maskArgs(args) {
|
|
71
|
+
const cred = this.credentials;
|
|
72
|
+
if (cred == null)
|
|
73
|
+
return args;
|
|
74
|
+
return args.map((c) => c.replace(cred.secretAccessKey, '****').replace(cred.sessionToken, '****'));
|
|
75
|
+
}
|
|
76
|
+
async run(cmd, args, log) {
|
|
77
|
+
const dockerArgs = await this.getDockerArgs();
|
|
78
|
+
log.debug({
|
|
79
|
+
mounts: this.mounts,
|
|
80
|
+
cmd,
|
|
81
|
+
docker: this.maskArgs(dockerArgs).join(' '),
|
|
82
|
+
gdalArgs: args.slice(0, 50).join(' '),
|
|
83
|
+
}, 'StartGdal:Docker');
|
|
84
|
+
return super.run('docker', [...dockerArgs, cmd, ...args], log);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=gdal.docker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gdal.docker.js","sourceRoot":"","sources":["../../src/gdal/gdal.docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAO,UAAW,SAAQ,WAAW;IAGzC;QACE,KAAK,EAAE,CAAC;QAHV;;;;;WAAiB;QAIf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAEQ,KAAK,CAAC,QAAgB;QAC7B,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;YAAE,OAAO;QAEzC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO;QAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAEO,SAAS;QACf,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EA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BAAoB,EAAE;SAC9C,CAAC;IACJ,CAAC;IAED,uFAAuF;IACvF,QAAQ,CAAC,IAAc;QACrB,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC;QAC9B,IAAI,IAAI,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;QAE9B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IACrG,CAAC;IAEQ,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,IAAc,EAAE,GAAY;QAC1D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC9C,GAAG,CAAC,KAAK,CACP;YACE,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG;YACH,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YAC3C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;SACtC,EACD,kBAAkB,CACnB,CAAC;QACF,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IACjE,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Env } from '@basemaps/shared';
|
|
2
|
+
import { GdalDocker } from './gdal.docker.js';
|
|
3
|
+
import { GdalLocal } from './gdal.local.js';
|
|
4
|
+
export class Gdal {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new GdalCommand instance ready to run commands
|
|
7
|
+
*
|
|
8
|
+
* This could be a local or docker container depending on environment variables
|
|
9
|
+
* @see Env.Gdal.UseDocker
|
|
10
|
+
*/
|
|
11
|
+
static create() {
|
|
12
|
+
if (Env.get(Env.Gdal.UseDocker))
|
|
13
|
+
return new GdalDocker();
|
|
14
|
+
return new GdalLocal();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Run a `gdal_translate --version` to extract the current gdal version
|
|
18
|
+
*
|
|
19
|
+
* @example "GDAL 2.4.2, released 2019/06/28"
|
|
20
|
+
* @example "GDAL 3.2.0dev-69b0c4ec4174fde36c609a4aac6f4281424021b3, released 2020/06/26"
|
|
21
|
+
*/
|
|
22
|
+
static async version(logger) {
|
|
23
|
+
const gdal = Gdal.create();
|
|
24
|
+
const { stdout } = await gdal.run('gdal_translate', ['--version'], logger);
|
|
25
|
+
return stdout;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=gdal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gdal.js","sourceRoot":"","sources":["../../src/gdal/gdal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAW,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,IAAI;IACf;;;;;OAKG;IACH,MAAM,CAAC,MAAM;QACX,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;YAAE,OAAO,IAAI,UAAU,EAAE,CAAC;QACzD,OAAO,IAAI,SAAS,EAAE,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAe;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;QAC3E,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LogType } from '@basemaps/shared';
|
|
2
|
+
import { GdalCommand } from './gdal.command.js';
|
|
3
|
+
export declare class GdalLocal extends GdalCommand {
|
|
4
|
+
env(): Promise<Record<string, string | undefined>>;
|
|
5
|
+
run(cmd: string, args: string[], log: LogType): Promise<{
|
|
6
|
+
stdout: string;
|
|
7
|
+
stderr: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GdalCommand } from './gdal.command.js';
|
|
2
|
+
export class GdalLocal extends GdalCommand {
|
|
3
|
+
async env() {
|
|
4
|
+
if (this.credentials == null) {
|
|
5
|
+
return process.env;
|
|
6
|
+
}
|
|
7
|
+
if (this.credentials.needsRefresh()) {
|
|
8
|
+
await this.credentials.refreshPromise();
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
...process.env,
|
|
12
|
+
AWS_ACCESS_KEY_ID: this.credentials.accessKeyId,
|
|
13
|
+
AWS_SECRET_ACCESS_KEY: this.credentials.secretAccessKey,
|
|
14
|
+
AWS_SESSION_TOKEN: this.credentials.sessionToken,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async run(cmd, args, log) {
|
|
18
|
+
log.debug({ cmd, gdalArgs: args.slice(0, 50).join(' ') }, 'StartGdal:Local');
|
|
19
|
+
return super.run(cmd, args, log);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=gdal.local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gdal.local.js","sourceRoot":"","sources":["../../src/gdal/gdal.local.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAO,SAAU,SAAQ,WAAW;IAC/B,KAAK,CAAC,GAAG;QAChB,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,EAAE,CAAC;YAC7B,OAAO,OAAO,CAAC,GAAG,CAAC;QACrB,CAAC;QACD,IAAI,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,EAAE,CAAC;YACpC,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC;QAC1C,CAAC;QACD,OAAO;YACL,GAAG,OAAO,CAAC,GAAG;YACd,iBAAiB,EAAE,IAAI,CAAC,WAAW,CAAC,WAAW;YAC/C,qBAAqB,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe;YACvD,iBAAiB,EAAE,IAAI,CAAC,WAAW,CAAC,YAAY;SACjD,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,IAAc,EAAE,GAAY;QAC1D,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,iBAAiB,CAAC,CAAC;QAC7E,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
/**
|
|
3
|
+
* Emit a "progress" event every time a "." is recorded in the output
|
|
4
|
+
*/
|
|
5
|
+
export declare class GdalProgressParser extends EventEmitter {
|
|
6
|
+
waitNewLine: boolean;
|
|
7
|
+
dotCount: number;
|
|
8
|
+
byteCount: number;
|
|
9
|
+
/** Reset the progress counter */
|
|
10
|
+
reset(): void;
|
|
11
|
+
get progress(): number;
|
|
12
|
+
data(data: Buffer): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
/**
|
|
3
|
+
* Emit a "progress" event every time a "." is recorded in the output
|
|
4
|
+
*/
|
|
5
|
+
export class GdalProgressParser extends EventEmitter {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
// Progress starts with "Input file size is .., ..\n"
|
|
9
|
+
Object.defineProperty(this, "waitNewLine", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "dotCount", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: 0
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "byteCount", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: 0
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** Reset the progress counter */
|
|
29
|
+
reset() {
|
|
30
|
+
this.waitNewLine = true;
|
|
31
|
+
this.dotCount = 0;
|
|
32
|
+
this.byteCount = 0;
|
|
33
|
+
}
|
|
34
|
+
get progress() {
|
|
35
|
+
return this.dotCount * (100 / 31);
|
|
36
|
+
}
|
|
37
|
+
data(data) {
|
|
38
|
+
const str = data.toString('utf8');
|
|
39
|
+
this.byteCount += str.length;
|
|
40
|
+
// In theory only a small amount of output bytes should be recorded
|
|
41
|
+
if (this.byteCount > 1024) {
|
|
42
|
+
throw new Error('Too much data: ' + str);
|
|
43
|
+
}
|
|
44
|
+
if (str === '0') {
|
|
45
|
+
this.waitNewLine = false;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this.waitNewLine) {
|
|
49
|
+
const newLine = str.indexOf('\n');
|
|
50
|
+
if (newLine > -1) {
|
|
51
|
+
this.waitNewLine = false;
|
|
52
|
+
return this.data(Buffer.from(str.substr(newLine + 1)));
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const bytes = str.split('');
|
|
57
|
+
for (const byte of bytes) {
|
|
58
|
+
if (byte === '.') {
|
|
59
|
+
this.dotCount++;
|
|
60
|
+
this.emit('progress', this.progress);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=gdal.progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gdal.progress.js","sourceRoot":"","sources":["../../src/gdal/gdal.progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAApD;;QACE,qDAAqD;QACrD;;;;mBAAc,IAAI;WAAC;QACnB;;;;mBAAW,CAAC;WAAC;QACb;;;;mBAAY,CAAC;WAAC;IA0ChB,CAAC;IAxCC,iCAAiC;IACjC,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACrB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,CAAC,IAAY;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC;QAC7B,mEAAmE;QACnE,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,iBAAiB,GAAG,GAAG,CAAC,CAAC;QAC3C,CAAC;QACD,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;YAChB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAClC,IAAI,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC;gBACjB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;gBACzB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACzD,CAAC;YACD,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBACjB,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/build/hash.d.ts
ADDED
package/build/hash.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
/** Stream a file though */
|
|
4
|
+
function hashFile(filePath, hashName) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const hash = crypto.createHash(hashName);
|
|
7
|
+
const stream = fs.createReadStream(filePath);
|
|
8
|
+
stream.on('error', (err) => reject(err));
|
|
9
|
+
stream.on('data', (chunk) => hash.update(chunk));
|
|
10
|
+
stream.on('end', () => resolve(hash.digest('hex')));
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** Create a multihash of a file */
|
|
14
|
+
async function hash(filePath) {
|
|
15
|
+
const hashData = await hashFile(filePath, 'sha256');
|
|
16
|
+
// 0x12 - sha256
|
|
17
|
+
// 0x20 - 32bytes
|
|
18
|
+
return '1220' + hashData;
|
|
19
|
+
}
|
|
20
|
+
export const Hash = { hash };
|
|
21
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,2BAA2B;AAC3B,SAAS,QAAQ,CAAC,QAAgB,EAAE,QAAgB;IAClD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC7C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACjD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,mCAAmC;AACnC,KAAK,UAAU,IAAI,CAAC,QAAgB;IAClC,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACpD,gBAAgB;IAChB,iBAAiB;IACjB,OAAO,MAAM,GAAG,QAAQ,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,CAAC"}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { makeTempFolder } from '@basemaps/cli/build/cli/folder.js';
|
|
2
|
+
import { GoogleTms, TileMatrixSets } from '@basemaps/geo';
|
|
3
|
+
import { Env, fsa, LogConfig } from '@basemaps/shared';
|
|
4
|
+
import { BaseCommandLine } from '@basemaps/shared/build/cli/base.js';
|
|
5
|
+
import { CommandLineAction } from '@rushstack/ts-command-line';
|
|
6
|
+
import { createReadStream, promises as fs } from 'fs';
|
|
7
|
+
import * as os from 'os';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import * as ulid from 'ulid';
|
|
10
|
+
import { BathyMaker } from './bathy.maker.js';
|
|
11
|
+
import { FilePath } from './file.js';
|
|
12
|
+
/** This zoom level gives a good enough quality world while not making too many tiles */
|
|
13
|
+
const GoodZoom = GoogleTms.def.tileMatrix[4];
|
|
14
|
+
class CreateAction extends CommandLineAction {
|
|
15
|
+
constructor() {
|
|
16
|
+
super({
|
|
17
|
+
actionName: 'create',
|
|
18
|
+
summary: 'create bathymetry imagery',
|
|
19
|
+
documentation: 'Take batheymetric data and convert it into a set of colorized hillshaded geotiffs.',
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "inputPath", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "outputPath", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "docker", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "tileMatrix", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
onDefineParameters() {
|
|
47
|
+
this.inputPath = this.defineStringParameter({
|
|
48
|
+
argumentName: 'PATH',
|
|
49
|
+
parameterLongName: '--input',
|
|
50
|
+
description: 'Folder or S3 Bucket location of Gebco netcdf or tiff file',
|
|
51
|
+
required: true,
|
|
52
|
+
});
|
|
53
|
+
this.outputPath = this.defineStringParameter({
|
|
54
|
+
argumentName: 'PATH',
|
|
55
|
+
parameterLongName: '--output',
|
|
56
|
+
description: 'Folder or S3 Bucket location to store imagery in',
|
|
57
|
+
required: true,
|
|
58
|
+
});
|
|
59
|
+
this.docker = this.defineFlagParameter({
|
|
60
|
+
parameterLongName: '--docker',
|
|
61
|
+
description: 'Run inside a docker container',
|
|
62
|
+
required: false,
|
|
63
|
+
});
|
|
64
|
+
this.tileMatrix = this.defineStringParameter({
|
|
65
|
+
argumentName: 'TILE_MATRIX_SET',
|
|
66
|
+
parameterLongName: '--tile-matrix-set',
|
|
67
|
+
description: 'Tile matrix set to use for the final cutting',
|
|
68
|
+
required: false,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async onExecute() {
|
|
72
|
+
const isDocker = !!this.docker?.value;
|
|
73
|
+
const pathToFile = this.inputPath?.value;
|
|
74
|
+
if (isDocker) {
|
|
75
|
+
process.env[Env.Gdal.UseDocker] = 'true';
|
|
76
|
+
if (process.env[Env.Gdal.DockerContainerTag] == null) {
|
|
77
|
+
process.env[Env.Gdal.DockerContainerTag] = 'ubuntu-full-latest';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const tileMatrixInput = this.tileMatrix?.value ?? GoogleTms.identifier;
|
|
81
|
+
const tileMatrix = TileMatrixSets.find(tileMatrixInput);
|
|
82
|
+
if (tileMatrix == null) {
|
|
83
|
+
throw new Error('Unknown tile matrix set: ' +
|
|
84
|
+
tileMatrixInput +
|
|
85
|
+
' Aviaiable tile matrix sets: ' +
|
|
86
|
+
TileMatrixSets.All.map((c) => c.identifier).join(', '));
|
|
87
|
+
}
|
|
88
|
+
const logger = LogConfig.get();
|
|
89
|
+
logger.info({ source: pathToFile }, 'MakeBathy');
|
|
90
|
+
const tmpFolder = new FilePath(await makeTempFolder(`bathymetry-${ulid.ulid()}`));
|
|
91
|
+
try {
|
|
92
|
+
const outputPath = this.outputPath?.value;
|
|
93
|
+
/** Find a decent zoom level that is close to the good zoom at google's scale */
|
|
94
|
+
let bestZ = tileMatrix.findBestZoom(GoodZoom.scaleDenominator + 1);
|
|
95
|
+
// Make at least a few tiles
|
|
96
|
+
if (bestZ === 0)
|
|
97
|
+
bestZ++;
|
|
98
|
+
const bathy = new BathyMaker({
|
|
99
|
+
id: ulid.ulid(),
|
|
100
|
+
inputPath: this.inputPath?.value,
|
|
101
|
+
outputPath,
|
|
102
|
+
tmpFolder,
|
|
103
|
+
tileMatrix,
|
|
104
|
+
zoom: bestZ,
|
|
105
|
+
threads: os.cpus().length / 2,
|
|
106
|
+
});
|
|
107
|
+
await bathy.render(logger);
|
|
108
|
+
const srcPath = path.join(tmpFolder.sourcePath, String("output" /* FileType.Output */));
|
|
109
|
+
for (const file of await fs.readdir(srcPath)) {
|
|
110
|
+
await fsa.write(fsa.toUrl(path.join(outputPath, file)), createReadStream(path.join(srcPath, file)));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
await fs.rm(tmpFolder.sourcePath, { recursive: true });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export class BathymetryCommandLine extends BaseCommandLine {
|
|
119
|
+
constructor() {
|
|
120
|
+
super({
|
|
121
|
+
toolFilename: 'bathymetry',
|
|
122
|
+
toolDescription: 'Create source imagery from bathymetry data',
|
|
123
|
+
});
|
|
124
|
+
this.addAction(new CreateAction());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
new BathymetryCommandLine().run();
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names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,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACtG,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IACxD;QACE,KAAK,CAAC;YACJ,YAAY,EAAE,YAAY;YAC1B,eAAe,EAAE,4CAA4C;SAC9D,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AAED,IAAI,qBAAqB,EAAE,CAAC,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Tile } from '@basemaps/geo';
|
|
2
|
+
import { LogType } from '@basemaps/shared';
|
|
3
|
+
import { BathyMaker } from './bathy.maker.js';
|
|
4
|
+
/** composite a hillshade and base tile into a hillshaded file with mapnik */
|
|
5
|
+
declare function render(bm: BathyMaker, tile: Tile, logger: LogType): Promise<string>;
|
|
6
|
+
export declare const MapnikRender: {
|
|
7
|
+
render: typeof render;
|
|
8
|
+
};
|
|
9
|
+
export {};
|