@versatiles/versatiles-rs 4.7.0 → 4.9.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/README.md +149 -4
- package/index.cjs +60 -54
- package/index.d.ts +270 -18
- package/index.js +61 -55
- package/package.json +9 -9
- package/vpl.d.ts +173 -5
- package/vpl.js +104 -31
package/vpl.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
// AUTO-GENERATED — DO NOT EDIT
|
|
2
2
|
// Generated from Rust VPL operation metadata
|
|
3
|
-
import { TileSource } from './index.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
import { TileSource, parseVpl, parseVplCst, stringifyVpl, stringifyVplCst } from './index.js';
|
|
4
|
+
/** Parse VPL text into a lossless syntax tree, returning the error rather than throwing. */
|
|
5
|
+
export function parseCstResult(vpl) {
|
|
6
|
+
return JSON.parse(parseVplCst(vpl));
|
|
7
|
+
}
|
|
8
|
+
/** Parse VPL text into a lossless syntax tree, throwing on a syntax error. */
|
|
9
|
+
export function parseCst(vpl) {
|
|
10
|
+
const result = parseCstResult(vpl);
|
|
11
|
+
if (!result.ok) {
|
|
12
|
+
const error = new SyntaxError(result.error.message);
|
|
13
|
+
error.vpl = result.error;
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
return result.cst;
|
|
17
|
+
}
|
|
18
|
+
/** Write a lossless syntax tree back out as VPL text. */
|
|
19
|
+
export function stringifyCst(cst) {
|
|
20
|
+
return stringifyVplCst(JSON.stringify(cst));
|
|
19
21
|
}
|
|
20
22
|
export class VPL {
|
|
21
23
|
steps;
|
|
@@ -37,6 +39,8 @@ export class VPL {
|
|
|
37
39
|
static fromContainer(options) {
|
|
38
40
|
const params = {};
|
|
39
41
|
params['filename'] = options.filename;
|
|
42
|
+
if (options.sshIdentity !== undefined)
|
|
43
|
+
params['ssh_identity'] = options.sshIdentity;
|
|
40
44
|
return new VPL([{ name: 'from_container', params }]);
|
|
41
45
|
}
|
|
42
46
|
/** Reads a CSV file with longitude/latitude columns and emits MVT point tiles. */
|
|
@@ -116,7 +120,50 @@ export class VPL {
|
|
|
116
120
|
params['ignore_id'] = options.ignoreId;
|
|
117
121
|
return new VPL([{ name: 'from_geo', params }]);
|
|
118
122
|
}
|
|
119
|
-
/**
|
|
123
|
+
/** Generates vector tiles containing the cells of a projected square grid, ready to be joined with data keyed on the cell id. */
|
|
124
|
+
static fromGrid(options) {
|
|
125
|
+
const params = {};
|
|
126
|
+
params['epsg'] = options.epsg;
|
|
127
|
+
params['size'] = options.size;
|
|
128
|
+
params['bbox'] = options.bbox;
|
|
129
|
+
if (options.offset !== undefined)
|
|
130
|
+
params['offset'] = options.offset;
|
|
131
|
+
if (options.maxCellsPerTile !== undefined)
|
|
132
|
+
params['max_cells_per_tile'] = options.maxCellsPerTile;
|
|
133
|
+
if (options.maxZoom !== undefined)
|
|
134
|
+
params['max_zoom'] = options.maxZoom;
|
|
135
|
+
if (options.idPreset !== undefined)
|
|
136
|
+
params['id_preset'] = options.idPreset;
|
|
137
|
+
if (options.idTemplate !== undefined)
|
|
138
|
+
params['id_template'] = options.idTemplate;
|
|
139
|
+
if (options.idField !== undefined)
|
|
140
|
+
params['id_field'] = options.idField;
|
|
141
|
+
if (options.xField !== undefined)
|
|
142
|
+
params['x_field'] = options.xField;
|
|
143
|
+
if (options.yField !== undefined)
|
|
144
|
+
params['y_field'] = options.yField;
|
|
145
|
+
if (options.densifyTolerance !== undefined)
|
|
146
|
+
params['densify_tolerance'] = options.densifyTolerance;
|
|
147
|
+
if (options.layerName !== undefined)
|
|
148
|
+
params['layer_name'] = options.layerName;
|
|
149
|
+
return new VPL([{ name: 'from_grid', params }]);
|
|
150
|
+
}
|
|
151
|
+
/** Generates vector tiles containing H3 grid cells, ready to be joined with data keyed on the H3 index. */
|
|
152
|
+
static fromH3(options) {
|
|
153
|
+
const params = {};
|
|
154
|
+
params['resolution'] = options.resolution;
|
|
155
|
+
params['bbox'] = options.bbox;
|
|
156
|
+
if (options.maxCellsPerTile !== undefined)
|
|
157
|
+
params['max_cells_per_tile'] = options.maxCellsPerTile;
|
|
158
|
+
if (options.maxZoom !== undefined)
|
|
159
|
+
params['max_zoom'] = options.maxZoom;
|
|
160
|
+
if (options.layerName !== undefined)
|
|
161
|
+
params['layer_name'] = options.layerName;
|
|
162
|
+
if (options.idField !== undefined)
|
|
163
|
+
params['id_field'] = options.idField;
|
|
164
|
+
return new VPL([{ name: 'from_h3', params }]);
|
|
165
|
+
}
|
|
166
|
+
/** Merges multiple vector tile sources. Each resulting tile will contain all the features and properties from all the sources. */
|
|
120
167
|
static fromMergedVector(sources) {
|
|
121
168
|
const params = {};
|
|
122
169
|
return new VPL([{ name: 'from_merged_vector', params, sources }]);
|
|
@@ -141,7 +188,7 @@ export class VPL {
|
|
|
141
188
|
params['filename'] = options.filename;
|
|
142
189
|
return new VPL([{ name: 'from_tile', params }]);
|
|
143
190
|
}
|
|
144
|
-
/** Reads tiles from a remote tile server via a TileJSON endpoint. */
|
|
191
|
+
/** Reads tiles from a remote tile server via a TileJSON endpoint. The TileJSON is fetched from the given URL, and tiles are loaded individually using the URL template from the TileJSON `tiles` array. */
|
|
145
192
|
static fromTilejson(options) {
|
|
146
193
|
const params = {};
|
|
147
194
|
params['url'] = options.url;
|
|
@@ -156,6 +203,8 @@ export class VPL {
|
|
|
156
203
|
const params = {};
|
|
157
204
|
if (options?.bbox !== undefined)
|
|
158
205
|
params['bbox'] = options?.bbox;
|
|
206
|
+
if (options?.bboxBorder !== undefined)
|
|
207
|
+
params['bbox_border'] = options?.bboxBorder;
|
|
159
208
|
if (options?.levelMin !== undefined)
|
|
160
209
|
params['level_min'] = options?.levelMin;
|
|
161
210
|
if (options?.levelMax !== undefined)
|
|
@@ -197,6 +246,17 @@ export class VPL {
|
|
|
197
246
|
params['vector_layers_file'] = options?.vectorLayersFile;
|
|
198
247
|
return new VPL([...this.steps, { name: 'meta_update', params }]);
|
|
199
248
|
}
|
|
249
|
+
/** Relabels tile coordinates, e.g. to correct a source that uses TMS row order or `z/y/x` paths. */
|
|
250
|
+
remapCoords(options) {
|
|
251
|
+
const params = {};
|
|
252
|
+
if (options?.flipX !== undefined)
|
|
253
|
+
params['flip_x'] = options?.flipX;
|
|
254
|
+
if (options?.flipY !== undefined)
|
|
255
|
+
params['flip_y'] = options?.flipY;
|
|
256
|
+
if (options?.swapXy !== undefined)
|
|
257
|
+
params['swap_xy'] = options?.swapXy;
|
|
258
|
+
return new VPL([...this.steps, { name: 'remap_coords', params }]);
|
|
259
|
+
}
|
|
200
260
|
/** Generate lower-zoom DEM overview tiles by averaging 24-bit elevation values. */
|
|
201
261
|
demOverview(options) {
|
|
202
262
|
const params = {};
|
|
@@ -257,7 +317,7 @@ export class VPL {
|
|
|
257
317
|
params['gamma'] = options?.gamma;
|
|
258
318
|
return new VPL([...this.steps, { name: 'raster_levels', params }]);
|
|
259
319
|
}
|
|
260
|
-
/** Apply a polygon mask from GeoJSON to raster tiles. */
|
|
320
|
+
/** Apply a polygon mask from GeoJSON to raster tiles. Pixels outside the polygon become transparent. */
|
|
261
321
|
rasterMask(options) {
|
|
262
322
|
const params = {};
|
|
263
323
|
params['geojson'] = options.geojson;
|
|
@@ -294,7 +354,7 @@ export class VPL {
|
|
|
294
354
|
params['tile_size'] = options?.tileSize;
|
|
295
355
|
return new VPL([...this.steps, { name: 'raster_tile_resize', params }]);
|
|
296
356
|
}
|
|
297
|
-
/** Drops vector features in selected layers that do not satisfy a boolean CEL expression. */
|
|
357
|
+
/** Drops vector features in selected layers that do not satisfy a boolean CEL expression. Features in layers outside `layer` pass through untouched. */
|
|
298
358
|
vectorFilterFeatures(options) {
|
|
299
359
|
const params = {};
|
|
300
360
|
params['layer'] = options.layer;
|
|
@@ -358,17 +418,7 @@ export class VPL {
|
|
|
358
418
|
}
|
|
359
419
|
/** Serialize this VPL pipeline to a string. */
|
|
360
420
|
toString() {
|
|
361
|
-
return this.
|
|
362
|
-
let result = step.name;
|
|
363
|
-
if (step.sources && step.sources.length > 0) {
|
|
364
|
-
const pipelines = step.sources.map(s => s.toString());
|
|
365
|
-
result += ' [ ' + pipelines.join(', ') + ' ]';
|
|
366
|
-
}
|
|
367
|
-
for (const [key, value] of Object.entries(step.params)) {
|
|
368
|
-
result += ' ' + serializeParam(key, value);
|
|
369
|
-
}
|
|
370
|
-
return result;
|
|
371
|
-
}).join(' | ');
|
|
421
|
+
return stringifyVpl(JSON.stringify(this.toJSON()));
|
|
372
422
|
}
|
|
373
423
|
/** Convert this VPL pipeline to a JSON-serializable array of steps. */
|
|
374
424
|
toJSON() {
|
|
@@ -380,6 +430,29 @@ export class VPL {
|
|
|
380
430
|
return obj;
|
|
381
431
|
});
|
|
382
432
|
}
|
|
433
|
+
/** A syntax error, with byte offsets into the parsed text. */
|
|
434
|
+
static parseError(vpl) {
|
|
435
|
+
const result = JSON.parse(parseVpl(vpl));
|
|
436
|
+
return result.ok ? undefined : result.error;
|
|
437
|
+
}
|
|
438
|
+
/** Rebuild a pipeline from the JSON form, nesting child pipelines as VPL. */
|
|
439
|
+
static fromJSON(steps) {
|
|
440
|
+
return new VPL(steps.map(step => ({
|
|
441
|
+
name: step.name,
|
|
442
|
+
params: step.params,
|
|
443
|
+
sources: step.sources?.map(source => VPL.fromJSON(source)),
|
|
444
|
+
})));
|
|
445
|
+
}
|
|
446
|
+
/** Parse VPL text, throwing on a syntax error. */
|
|
447
|
+
static parse(vpl) {
|
|
448
|
+
const result = JSON.parse(parseVpl(vpl));
|
|
449
|
+
if (!result.ok) {
|
|
450
|
+
const error = new SyntaxError(result.error.message);
|
|
451
|
+
error.vpl = result.error;
|
|
452
|
+
throw error;
|
|
453
|
+
}
|
|
454
|
+
return VPL.fromJSON(result.pipeline);
|
|
455
|
+
}
|
|
383
456
|
/** Execute this VPL pipeline and return a TileSource. */
|
|
384
457
|
async fromPath(dir) {
|
|
385
458
|
return TileSource.fromPipeline(JSON.stringify(this.toJSON()), dir);
|