@loaders.gl/arrow 4.0.3 → 4.1.0-alpha.1
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/dist/arrow-loader.d.ts +6 -3
- package/dist/arrow-loader.d.ts.map +1 -1
- package/dist/arrow-loader.js +9 -1
- package/dist/arrow-loader.js.map +1 -1
- package/dist/arrow-worker.js +272 -537
- package/dist/dist.dev.js +2399 -269
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +33 -1
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +146 -17
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
- package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts +13 -0
- package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts.map +1 -0
- package/dist/geoarrow/{convert-geoarrow-to-geojson.js → convert-geoarrow-to-geojson-geometry.js} +36 -25
- package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.js.map +1 -0
- package/dist/geoarrow-loader.d.ts +19 -0
- package/dist/geoarrow-loader.d.ts.map +1 -0
- package/dist/geoarrow-loader.js +23 -0
- package/dist/geoarrow-loader.js.map +1 -0
- package/dist/geoarrow-writer.d.ts +9 -0
- package/dist/geoarrow-writer.d.ts.map +1 -0
- package/dist/geoarrow-writer.js +19 -0
- package/dist/geoarrow-writer.js.map +1 -0
- package/dist/index.cjs +481 -255
- package/dist/index.d.ts +9 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -13
- package/dist/index.js.map +1 -1
- package/dist/lib/arrow-table-batch.d.ts.map +1 -1
- package/dist/lib/arrow-table-batch.js.map +1 -1
- package/dist/lib/encode-arrow.d.ts.map +1 -1
- package/dist/lib/encode-arrow.js.map +1 -1
- package/dist/lib/encode-geoarrow.d.ts +15 -0
- package/dist/lib/encode-geoarrow.d.ts.map +1 -0
- package/dist/lib/encode-geoarrow.js +22 -0
- package/dist/lib/encode-geoarrow.js.map +1 -0
- package/dist/{lib → parsers}/parse-arrow-in-batches.d.ts +1 -1
- package/dist/parsers/parse-arrow-in-batches.d.ts.map +1 -0
- package/dist/parsers/parse-arrow-in-batches.js.map +1 -0
- package/dist/parsers/parse-arrow-sync.d.ts +6 -0
- package/dist/parsers/parse-arrow-sync.d.ts.map +1 -0
- package/dist/parsers/parse-arrow-sync.js +28 -0
- package/dist/parsers/parse-arrow-sync.js.map +1 -0
- package/dist/parsers/parse-geoarrow-in-batches.d.ts +6 -0
- package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +1 -0
- package/dist/parsers/parse-geoarrow-in-batches.js +5 -0
- package/dist/parsers/parse-geoarrow-in-batches.js.map +1 -0
- package/dist/parsers/parse-geoarrow-sync.d.ts +6 -0
- package/dist/parsers/parse-geoarrow-sync.d.ts.map +1 -0
- package/dist/parsers/parse-geoarrow-sync.js +14 -0
- package/dist/parsers/parse-geoarrow-sync.js.map +1 -0
- package/dist/tables/convert-arrow-to-columnar-table.d.ts +8 -0
- package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +1 -0
- package/dist/tables/convert-arrow-to-columnar-table.js +15 -0
- package/dist/tables/convert-arrow-to-columnar-table.js.map +1 -0
- package/dist/tables/convert-arrow-to-geojson-table.d.ts +16 -0
- package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +1 -0
- package/dist/tables/convert-arrow-to-geojson-table.js +39 -0
- package/dist/tables/convert-arrow-to-geojson-table.js.map +1 -0
- package/dist/tables/convert-columnar-to-row-table.d.ts +7 -0
- package/dist/tables/convert-columnar-to-row-table.d.ts.map +1 -0
- package/dist/tables/convert-columnar-to-row-table.js +19 -0
- package/dist/tables/convert-columnar-to-row-table.js.map +1 -0
- package/dist/triangulate-on-worker.d.ts +36 -0
- package/dist/triangulate-on-worker.d.ts.map +1 -0
- package/dist/triangulate-on-worker.js +14 -0
- package/dist/triangulate-on-worker.js.map +1 -0
- package/dist/triangulation-worker.js +887 -0
- package/dist/workers/arrow-worker.js +1 -1
- package/dist/workers/arrow-worker.js.map +1 -1
- package/dist/workers/triangulation-worker-node.d.ts +2 -0
- package/dist/workers/triangulation-worker-node.d.ts.map +1 -0
- package/dist/workers/triangulation-worker-node.js +2 -0
- package/dist/workers/triangulation-worker-node.js.map +1 -0
- package/dist/workers/triangulation-worker.d.ts +2 -0
- package/dist/workers/triangulation-worker.d.ts.map +1 -0
- package/dist/workers/triangulation-worker.js +26 -0
- package/dist/workers/triangulation-worker.js.map +1 -0
- package/package.json +20 -12
- package/src/arrow-loader.ts +25 -3
- package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +247 -23
- package/src/geoarrow/{convert-geoarrow-to-geojson.ts → convert-geoarrow-to-geojson-geometry.ts} +58 -44
- package/src/geoarrow-loader.ts +51 -0
- package/src/geoarrow-writer.ts +41 -0
- package/src/index.ts +31 -37
- package/src/lib/arrow-table-batch.ts +3 -0
- package/src/lib/encode-arrow.ts +3 -0
- package/src/lib/encode-geoarrow.ts +45 -0
- package/src/{lib → parsers}/parse-arrow-in-batches.ts +4 -2
- package/src/parsers/parse-arrow-sync.ts +43 -0
- package/src/parsers/parse-geoarrow-in-batches.ts +15 -0
- package/src/parsers/parse-geoarrow-sync.ts +22 -0
- package/src/tables/convert-arrow-to-columnar-table.ts +30 -0
- package/src/tables/convert-arrow-to-geojson-table.ts +65 -0
- package/src/tables/convert-columnar-to-row-table.ts +30 -0
- package/src/triangulate-on-worker.ts +47 -0
- package/src/workers/arrow-worker.ts +1 -1
- package/src/workers/triangulation-worker-node.ts +4 -0
- package/src/workers/triangulation-worker.ts +39 -0
- package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts +0 -19
- package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts.map +0 -1
- package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +0 -1
- package/dist/lib/parse-arrow-in-batches.d.ts.map +0 -1
- package/dist/lib/parse-arrow-in-batches.js.map +0 -1
- package/dist/lib/parse-arrow-sync.d.ts +0 -5
- package/dist/lib/parse-arrow-sync.d.ts.map +0 -1
- package/dist/lib/parse-arrow-sync.js +0 -21
- package/dist/lib/parse-arrow-sync.js.map +0 -1
- package/dist/tables/convert-arrow-to-table.d.ts +0 -21
- package/dist/tables/convert-arrow-to-table.d.ts.map +0 -1
- package/dist/tables/convert-arrow-to-table.js +0 -37
- package/dist/tables/convert-arrow-to-table.js.map +0 -1
- package/src/lib/parse-arrow-sync.ts +0 -35
- package/src/tables/convert-arrow-to-table.ts +0 -68
- /package/dist/{lib → parsers}/parse-arrow-in-batches.js +0 -0
package/dist/dist.dev.js
CHANGED
|
@@ -27,22 +27,29 @@ var __exports__ = (() => {
|
|
|
27
27
|
// src/index.ts
|
|
28
28
|
var src_exports = {};
|
|
29
29
|
__export(src_exports, {
|
|
30
|
-
ArrowLoader: () =>
|
|
31
|
-
ArrowWorkerLoader: () =>
|
|
30
|
+
ArrowLoader: () => ArrowLoader,
|
|
31
|
+
ArrowWorkerLoader: () => ArrowWorkerLoader,
|
|
32
32
|
ArrowWriter: () => ArrowWriter,
|
|
33
33
|
BINARY_GEOMETRY_TEMPLATE: () => BINARY_GEOMETRY_TEMPLATE,
|
|
34
|
+
GeoArrowLoader: () => GeoArrowLoader,
|
|
35
|
+
GeoArrowWorkerLoader: () => GeoArrowWorkerLoader,
|
|
36
|
+
TriangulationWorker: () => TriangulationWorker,
|
|
34
37
|
VECTOR_TYPES: () => VECTOR_TYPES,
|
|
38
|
+
convertArrowToGeoJSONTable: () => convertArrowToGeoJSONTable,
|
|
35
39
|
deserializeArrowField: () => deserializeArrowField,
|
|
36
40
|
deserializeArrowMetadata: () => deserializeArrowMetadata,
|
|
37
41
|
deserializeArrowSchema: () => deserializeArrowSchema,
|
|
38
42
|
deserializeArrowType: () => deserializeArrowType,
|
|
39
43
|
getArrowType: () => getArrowType,
|
|
40
44
|
getBinaryGeometriesFromArrow: () => getBinaryGeometriesFromArrow,
|
|
45
|
+
getMeanCentersFromBinaryGeometries: () => getMeanCentersFromBinaryGeometries,
|
|
46
|
+
getTriangleIndices: () => getTriangleIndices,
|
|
41
47
|
parseGeometryFromArrow: () => parseGeometryFromArrow,
|
|
42
48
|
serializeArrowField: () => serializeArrowField,
|
|
43
49
|
serializeArrowMetadata: () => serializeArrowMetadata,
|
|
44
50
|
serializeArrowSchema: () => serializeArrowSchema,
|
|
45
51
|
serializeArrowType: () => serializeArrowType,
|
|
52
|
+
triangulateOnWorker: () => triangulateOnWorker,
|
|
46
53
|
updateBoundsFromGeoArrowSamples: () => updateBoundsFromGeoArrowSamples
|
|
47
54
|
});
|
|
48
55
|
|
|
@@ -456,10 +463,10 @@ var __exports__ = (() => {
|
|
|
456
463
|
}
|
|
457
464
|
return columnIndex;
|
|
458
465
|
}
|
|
459
|
-
function getTableRowAsObject(table, rowIndex, target,
|
|
466
|
+
function getTableRowAsObject(table, rowIndex, target, copy2) {
|
|
460
467
|
switch (table.shape) {
|
|
461
468
|
case "object-row-table":
|
|
462
|
-
return
|
|
469
|
+
return copy2 ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
|
|
463
470
|
case "array-row-table":
|
|
464
471
|
if (table.schema) {
|
|
465
472
|
const objectRow2 = target || {};
|
|
@@ -505,10 +512,10 @@ var __exports__ = (() => {
|
|
|
505
512
|
throw new Error("shape");
|
|
506
513
|
}
|
|
507
514
|
}
|
|
508
|
-
function getTableRowAsArray(table, rowIndex, target,
|
|
515
|
+
function getTableRowAsArray(table, rowIndex, target, copy2) {
|
|
509
516
|
switch (table.shape) {
|
|
510
517
|
case "array-row-table":
|
|
511
|
-
return
|
|
518
|
+
return copy2 ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
|
|
512
519
|
case "object-row-table":
|
|
513
520
|
if (table.schema) {
|
|
514
521
|
const arrayRow2 = target || [];
|
|
@@ -792,25 +799,6 @@ var __exports__ = (() => {
|
|
|
792
799
|
};
|
|
793
800
|
}
|
|
794
801
|
|
|
795
|
-
// src/arrow-loader.ts
|
|
796
|
-
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
797
|
-
var ArrowLoader = {
|
|
798
|
-
name: "Apache Arrow",
|
|
799
|
-
id: "arrow",
|
|
800
|
-
module: "arrow",
|
|
801
|
-
version: VERSION,
|
|
802
|
-
category: "table",
|
|
803
|
-
extensions: ["arrow", "feather"],
|
|
804
|
-
mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
|
|
805
|
-
binary: true,
|
|
806
|
-
tests: ["ARROW"],
|
|
807
|
-
options: {
|
|
808
|
-
arrow: {
|
|
809
|
-
shape: "columnar-table"
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
|
-
|
|
814
802
|
// ../../node_modules/tslib/tslib.es6.mjs
|
|
815
803
|
function __rest(s, e) {
|
|
816
804
|
var t = {};
|
|
@@ -2796,21 +2784,21 @@ var __exports__ = (() => {
|
|
|
2796
2784
|
function uint16ToFloat64(h) {
|
|
2797
2785
|
const expo = (h & 31744) >> 10;
|
|
2798
2786
|
const sigf = (h & 1023) / 1024;
|
|
2799
|
-
const
|
|
2787
|
+
const sign2 = Math.pow(-1, (h & 32768) >> 15);
|
|
2800
2788
|
switch (expo) {
|
|
2801
2789
|
case 31:
|
|
2802
|
-
return
|
|
2790
|
+
return sign2 * (sigf ? Number.NaN : 1 / 0);
|
|
2803
2791
|
case 0:
|
|
2804
|
-
return
|
|
2792
|
+
return sign2 * (sigf ? 6103515625e-14 * sigf : 0);
|
|
2805
2793
|
}
|
|
2806
|
-
return
|
|
2794
|
+
return sign2 * Math.pow(2, expo - 15) * (1 + sigf);
|
|
2807
2795
|
}
|
|
2808
2796
|
function float64ToUint16(d) {
|
|
2809
2797
|
if (d !== d) {
|
|
2810
2798
|
return 32256;
|
|
2811
2799
|
}
|
|
2812
2800
|
f64[0] = d;
|
|
2813
|
-
const
|
|
2801
|
+
const sign2 = (u32[1] & 2147483648) >> 16 & 65535;
|
|
2814
2802
|
let expo = u32[1] & 2146435072, sigf = 0;
|
|
2815
2803
|
if (expo >= 1089470464) {
|
|
2816
2804
|
if (u32[0] > 0) {
|
|
@@ -2827,7 +2815,7 @@ var __exports__ = (() => {
|
|
|
2827
2815
|
expo = expo - 1056964608 >> 10;
|
|
2828
2816
|
sigf = (u32[1] & 1048575) + 512 >> 10;
|
|
2829
2817
|
}
|
|
2830
|
-
return
|
|
2818
|
+
return sign2 | expo | sigf & 65535;
|
|
2831
2819
|
}
|
|
2832
2820
|
|
|
2833
2821
|
// ../../node_modules/apache-arrow/visitor/set.mjs
|
|
@@ -11592,8 +11580,8 @@ return true;`);
|
|
|
11592
11580
|
return new JSONVectorLoader(body, header.nodes, header.buffers, this.dictionaries).visitMany(types);
|
|
11593
11581
|
}
|
|
11594
11582
|
};
|
|
11595
|
-
function shouldAutoDestroy(
|
|
11596
|
-
return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] :
|
|
11583
|
+
function shouldAutoDestroy(self2, options) {
|
|
11584
|
+
return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self2["autoDestroy"];
|
|
11597
11585
|
}
|
|
11598
11586
|
function* readAllSync(source) {
|
|
11599
11587
|
const reader = RecordBatchReader.from(source);
|
|
@@ -12340,65 +12328,6 @@ return true;`);
|
|
|
12340
12328
|
RecordBatchFileWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
|
|
12341
12329
|
RecordBatchStreamWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
|
|
12342
12330
|
|
|
12343
|
-
// src/tables/convert-arrow-to-table.ts
|
|
12344
|
-
function convertApacheArrowToArrowTable(arrowTable) {
|
|
12345
|
-
return {
|
|
12346
|
-
shape: "arrow-table",
|
|
12347
|
-
data: arrowTable
|
|
12348
|
-
};
|
|
12349
|
-
}
|
|
12350
|
-
function convertArrowToColumnarTable(table) {
|
|
12351
|
-
const arrowTable = table.data;
|
|
12352
|
-
const columnarTable = {};
|
|
12353
|
-
for (const field of arrowTable.schema.fields) {
|
|
12354
|
-
const arrowColumn = arrowTable.getChild(field.name);
|
|
12355
|
-
const values = arrowColumn?.toArray();
|
|
12356
|
-
columnarTable[field.name] = values;
|
|
12357
|
-
}
|
|
12358
|
-
return {
|
|
12359
|
-
shape: "columnar-table",
|
|
12360
|
-
data: columnarTable
|
|
12361
|
-
};
|
|
12362
|
-
}
|
|
12363
|
-
|
|
12364
|
-
// src/lib/parse-arrow-sync.ts
|
|
12365
|
-
function parseArrowSync(arrayBuffer, options) {
|
|
12366
|
-
const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
|
|
12367
|
-
const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
|
|
12368
|
-
const shape = options?.arrow?.shape || "arrow-table";
|
|
12369
|
-
switch (shape) {
|
|
12370
|
-
case "arrow-table":
|
|
12371
|
-
return arrowTable;
|
|
12372
|
-
case "columnar-table":
|
|
12373
|
-
return convertArrowToColumnarTable(arrowTable);
|
|
12374
|
-
case "object-row-table":
|
|
12375
|
-
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
12376
|
-
return convertTable(columnarTable, "object-row-table");
|
|
12377
|
-
default:
|
|
12378
|
-
throw new Error(shape);
|
|
12379
|
-
}
|
|
12380
|
-
}
|
|
12381
|
-
|
|
12382
|
-
// src/lib/parse-arrow-in-batches.ts
|
|
12383
|
-
function parseArrowInBatches(asyncIterator) {
|
|
12384
|
-
async function* makeArrowAsyncIterator() {
|
|
12385
|
-
const readers = RecordBatchReader.readAll(asyncIterator);
|
|
12386
|
-
for await (const reader of readers) {
|
|
12387
|
-
for await (const recordBatch of reader) {
|
|
12388
|
-
const arrowTabledBatch = {
|
|
12389
|
-
shape: "arrow-table",
|
|
12390
|
-
batchType: "data",
|
|
12391
|
-
data: new Table([recordBatch]),
|
|
12392
|
-
length: recordBatch.data.length
|
|
12393
|
-
};
|
|
12394
|
-
yield arrowTabledBatch;
|
|
12395
|
-
}
|
|
12396
|
-
break;
|
|
12397
|
-
}
|
|
12398
|
-
}
|
|
12399
|
-
return makeArrowAsyncIterator();
|
|
12400
|
-
}
|
|
12401
|
-
|
|
12402
12331
|
// src/lib/arrow-table-batch.ts
|
|
12403
12332
|
var ArrowTableBatchAggregator = class extends ColumnarTableBatchAggregator {
|
|
12404
12333
|
constructor(schema, options) {
|
|
@@ -12480,6 +12409,29 @@ return true;`);
|
|
|
12480
12409
|
}
|
|
12481
12410
|
}
|
|
12482
12411
|
|
|
12412
|
+
// src/types.ts
|
|
12413
|
+
var VECTOR_TYPES = function(VECTOR_TYPES2) {
|
|
12414
|
+
VECTOR_TYPES2[VECTOR_TYPES2["FLOAT"] = 0] = "FLOAT";
|
|
12415
|
+
VECTOR_TYPES2[VECTOR_TYPES2["DATE"] = 1] = "DATE";
|
|
12416
|
+
return VECTOR_TYPES2;
|
|
12417
|
+
}({});
|
|
12418
|
+
|
|
12419
|
+
// src/tables/convert-arrow-to-columnar-table.ts
|
|
12420
|
+
function convertArrowToColumnarTable(table) {
|
|
12421
|
+
const arrowTable = table.data;
|
|
12422
|
+
const columnarTable = {};
|
|
12423
|
+
for (const field of arrowTable.schema.fields) {
|
|
12424
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
12425
|
+
const values = arrowColumn?.toArray();
|
|
12426
|
+
columnarTable[field.name] = values;
|
|
12427
|
+
}
|
|
12428
|
+
return {
|
|
12429
|
+
shape: "columnar-table",
|
|
12430
|
+
schema: table.schema,
|
|
12431
|
+
data: columnarTable
|
|
12432
|
+
};
|
|
12433
|
+
}
|
|
12434
|
+
|
|
12483
12435
|
// src/schema/convert-arrow-schema.ts
|
|
12484
12436
|
function serializeArrowSchema(arrowSchema) {
|
|
12485
12437
|
return {
|
|
@@ -12739,12 +12691,75 @@ return true;`);
|
|
|
12739
12691
|
}
|
|
12740
12692
|
}
|
|
12741
12693
|
|
|
12742
|
-
// src/
|
|
12743
|
-
|
|
12744
|
-
|
|
12745
|
-
|
|
12746
|
-
|
|
12747
|
-
|
|
12694
|
+
// src/parsers/parse-arrow-sync.ts
|
|
12695
|
+
function parseArrowSync(arrayBuffer, options) {
|
|
12696
|
+
const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
|
|
12697
|
+
const arrowTable = {
|
|
12698
|
+
shape: "arrow-table",
|
|
12699
|
+
schema: serializeArrowSchema(apacheArrowTable.schema),
|
|
12700
|
+
data: apacheArrowTable
|
|
12701
|
+
};
|
|
12702
|
+
const shape = options?.shape || "arrow-table";
|
|
12703
|
+
switch (shape) {
|
|
12704
|
+
case "arrow-table":
|
|
12705
|
+
return arrowTable;
|
|
12706
|
+
case "columnar-table":
|
|
12707
|
+
return convertArrowToColumnarTable(arrowTable);
|
|
12708
|
+
case "object-row-table":
|
|
12709
|
+
let columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
12710
|
+
return convertTable(columnarTable, "object-row-table");
|
|
12711
|
+
case "array-row-table":
|
|
12712
|
+
columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
12713
|
+
return convertTable(columnarTable, "array-row-table");
|
|
12714
|
+
default:
|
|
12715
|
+
throw new Error(shape);
|
|
12716
|
+
}
|
|
12717
|
+
}
|
|
12718
|
+
|
|
12719
|
+
// src/parsers/parse-arrow-in-batches.ts
|
|
12720
|
+
function parseArrowInBatches(asyncIterator) {
|
|
12721
|
+
async function* makeArrowAsyncIterator() {
|
|
12722
|
+
const readers = RecordBatchReader.readAll(asyncIterator);
|
|
12723
|
+
for await (const reader of readers) {
|
|
12724
|
+
for await (const recordBatch of reader) {
|
|
12725
|
+
const arrowTabledBatch = {
|
|
12726
|
+
shape: "arrow-table",
|
|
12727
|
+
batchType: "data",
|
|
12728
|
+
data: new Table([recordBatch]),
|
|
12729
|
+
length: recordBatch.data.length
|
|
12730
|
+
};
|
|
12731
|
+
yield arrowTabledBatch;
|
|
12732
|
+
}
|
|
12733
|
+
break;
|
|
12734
|
+
}
|
|
12735
|
+
}
|
|
12736
|
+
return makeArrowAsyncIterator();
|
|
12737
|
+
}
|
|
12738
|
+
|
|
12739
|
+
// src/arrow-loader.ts
|
|
12740
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
12741
|
+
var ArrowWorkerLoader = {
|
|
12742
|
+
name: "Apache Arrow",
|
|
12743
|
+
id: "arrow",
|
|
12744
|
+
module: "arrow",
|
|
12745
|
+
version: VERSION,
|
|
12746
|
+
category: "table",
|
|
12747
|
+
extensions: ["arrow", "feather"],
|
|
12748
|
+
mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
|
|
12749
|
+
binary: true,
|
|
12750
|
+
tests: ["ARROW"],
|
|
12751
|
+
options: {
|
|
12752
|
+
arrow: {
|
|
12753
|
+
shape: "columnar-table"
|
|
12754
|
+
}
|
|
12755
|
+
}
|
|
12756
|
+
};
|
|
12757
|
+
var ArrowLoader = {
|
|
12758
|
+
...ArrowWorkerLoader,
|
|
12759
|
+
parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),
|
|
12760
|
+
parseSync: (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),
|
|
12761
|
+
parseInBatches: parseArrowInBatches
|
|
12762
|
+
};
|
|
12748
12763
|
|
|
12749
12764
|
// src/lib/encode-arrow.ts
|
|
12750
12765
|
function encodeArrowSync(data) {
|
|
@@ -12786,101 +12801,879 @@ return true;`);
|
|
|
12786
12801
|
}
|
|
12787
12802
|
};
|
|
12788
12803
|
|
|
12789
|
-
// src/geoarrow
|
|
12790
|
-
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
const
|
|
12797
|
-
if (
|
|
12798
|
-
|
|
12804
|
+
// ../gis/src/lib/geo/geoarrow-metadata.ts
|
|
12805
|
+
var GEOARROW_ENCODINGS = ["geoarrow.multipolygon", "geoarrow.polygon", "geoarrow.multilinestring", "geoarrow.linestring", "geoarrow.multipoint", "geoarrow.point", "geoarrow.wkb", "geoarrow.wkt"];
|
|
12806
|
+
var GEOARROW_COLUMN_METADATA_ENCODING = "ARROW:extension:name";
|
|
12807
|
+
var GEOARROW_COLUMN_METADATA_METADATA = "ARROW:extension:metadata";
|
|
12808
|
+
function getGeometryColumnsFromSchema(schema) {
|
|
12809
|
+
const geometryColumns = {};
|
|
12810
|
+
for (const field of schema.fields) {
|
|
12811
|
+
const metadata = getGeometryMetadataForField(field);
|
|
12812
|
+
if (metadata) {
|
|
12813
|
+
geometryColumns[field.name] = metadata;
|
|
12799
12814
|
}
|
|
12800
|
-
|
|
12801
|
-
|
|
12815
|
+
}
|
|
12816
|
+
return geometryColumns;
|
|
12817
|
+
}
|
|
12818
|
+
function getGeometryMetadataForField(field) {
|
|
12819
|
+
let metadata = null;
|
|
12820
|
+
let geoEncoding = field.metadata?.[GEOARROW_COLUMN_METADATA_ENCODING];
|
|
12821
|
+
if (geoEncoding) {
|
|
12822
|
+
geoEncoding = geoEncoding.toLowerCase();
|
|
12823
|
+
if (geoEncoding === "wkb") {
|
|
12824
|
+
geoEncoding = "geoarrow.wkb";
|
|
12802
12825
|
}
|
|
12803
|
-
if (
|
|
12804
|
-
|
|
12826
|
+
if (geoEncoding === "wkt") {
|
|
12827
|
+
geoEncoding = "geoarrow.wkt";
|
|
12805
12828
|
}
|
|
12806
|
-
if (
|
|
12807
|
-
|
|
12829
|
+
if (!GEOARROW_ENCODINGS.includes(geoEncoding)) {
|
|
12830
|
+
console.warn(`Invalid GeoArrow encoding: ${geoEncoding}`);
|
|
12831
|
+
} else {
|
|
12832
|
+
metadata = metadata || {};
|
|
12833
|
+
metadata.encoding = geoEncoding;
|
|
12808
12834
|
}
|
|
12809
12835
|
}
|
|
12810
|
-
|
|
12836
|
+
const columnMetadata = field.metadata?.[GEOARROW_COLUMN_METADATA_METADATA];
|
|
12837
|
+
if (columnMetadata) {
|
|
12838
|
+
try {
|
|
12839
|
+
metadata = JSON.parse(columnMetadata);
|
|
12840
|
+
} catch (error) {
|
|
12841
|
+
console.warn("Failed to parse GeoArrow metadata", error);
|
|
12842
|
+
}
|
|
12843
|
+
}
|
|
12844
|
+
return metadata || null;
|
|
12811
12845
|
}
|
|
12812
12846
|
|
|
12813
|
-
//
|
|
12814
|
-
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
|
|
12818
|
-
}
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12847
|
+
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
12848
|
+
function _typeof(obj) {
|
|
12849
|
+
"@babel/helpers - typeof";
|
|
12850
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
12851
|
+
return typeof obj2;
|
|
12852
|
+
} : function(obj2) {
|
|
12853
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
12854
|
+
}, _typeof(obj);
|
|
12855
|
+
}
|
|
12856
|
+
|
|
12857
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
|
|
12858
|
+
function _toPrimitive(input, hint) {
|
|
12859
|
+
if (_typeof(input) !== "object" || input === null)
|
|
12860
|
+
return input;
|
|
12861
|
+
var prim = input[Symbol.toPrimitive];
|
|
12862
|
+
if (prim !== void 0) {
|
|
12863
|
+
var res = prim.call(input, hint || "default");
|
|
12864
|
+
if (_typeof(res) !== "object")
|
|
12865
|
+
return res;
|
|
12866
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
12828
12867
|
}
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
|
|
12835
|
-
|
|
12836
|
-
|
|
12837
|
-
|
|
12838
|
-
|
|
12839
|
-
|
|
12840
|
-
|
|
12841
|
-
|
|
12842
|
-
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
|
|
12849
|
-
|
|
12868
|
+
return (hint === "string" ? String : Number)(input);
|
|
12869
|
+
}
|
|
12870
|
+
|
|
12871
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
|
|
12872
|
+
function _toPropertyKey(arg) {
|
|
12873
|
+
var key = _toPrimitive(arg, "string");
|
|
12874
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
12875
|
+
}
|
|
12876
|
+
|
|
12877
|
+
// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
12878
|
+
function _defineProperty(obj, key, value) {
|
|
12879
|
+
key = _toPropertyKey(key);
|
|
12880
|
+
if (key in obj) {
|
|
12881
|
+
Object.defineProperty(obj, key, {
|
|
12882
|
+
value,
|
|
12883
|
+
enumerable: true,
|
|
12884
|
+
configurable: true,
|
|
12885
|
+
writable: true
|
|
12886
|
+
});
|
|
12887
|
+
} else {
|
|
12888
|
+
obj[key] = value;
|
|
12889
|
+
}
|
|
12890
|
+
return obj;
|
|
12891
|
+
}
|
|
12892
|
+
|
|
12893
|
+
// ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
|
|
12894
|
+
var DimIndex = {
|
|
12895
|
+
x: 0,
|
|
12896
|
+
y: 1,
|
|
12897
|
+
z: 2
|
|
12898
|
+
};
|
|
12899
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
12900
|
+
const {
|
|
12901
|
+
start = 0,
|
|
12902
|
+
end = points.length,
|
|
12903
|
+
plane = "xy"
|
|
12904
|
+
} = options;
|
|
12905
|
+
const dim = options.size || 2;
|
|
12906
|
+
let area2 = 0;
|
|
12907
|
+
const i0 = DimIndex[plane[0]];
|
|
12908
|
+
const i1 = DimIndex[plane[1]];
|
|
12909
|
+
for (let i = start, j = end - dim; i < end; i += dim) {
|
|
12910
|
+
area2 += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
|
|
12911
|
+
j = i;
|
|
12912
|
+
}
|
|
12913
|
+
return area2 / 2;
|
|
12914
|
+
}
|
|
12915
|
+
|
|
12916
|
+
// ../../node_modules/@math.gl/polygon/dist/earcut.js
|
|
12917
|
+
function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
|
|
12918
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
12919
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
12920
|
+
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
|
|
12921
|
+
const triangles = [];
|
|
12922
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
12923
|
+
return triangles;
|
|
12924
|
+
let invSize;
|
|
12925
|
+
let maxX;
|
|
12926
|
+
let maxY;
|
|
12927
|
+
let minX;
|
|
12928
|
+
let minY;
|
|
12929
|
+
let x;
|
|
12930
|
+
let y;
|
|
12931
|
+
if (hasHoles)
|
|
12932
|
+
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
|
|
12933
|
+
if (positions.length > 80 * dim) {
|
|
12934
|
+
minX = maxX = positions[0];
|
|
12935
|
+
minY = maxY = positions[1];
|
|
12936
|
+
for (let i = dim; i < outerLen; i += dim) {
|
|
12937
|
+
x = positions[i];
|
|
12938
|
+
y = positions[i + 1];
|
|
12939
|
+
if (x < minX)
|
|
12940
|
+
minX = x;
|
|
12941
|
+
if (y < minY)
|
|
12942
|
+
minY = y;
|
|
12943
|
+
if (x > maxX)
|
|
12944
|
+
maxX = x;
|
|
12945
|
+
if (y > maxY)
|
|
12946
|
+
maxY = y;
|
|
12947
|
+
}
|
|
12948
|
+
invSize = Math.max(maxX - minX, maxY - minY);
|
|
12949
|
+
invSize = invSize !== 0 ? 32767 / invSize : 0;
|
|
12950
|
+
}
|
|
12951
|
+
earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
|
|
12952
|
+
return triangles;
|
|
12953
|
+
}
|
|
12954
|
+
function linkedList(data, start, end, dim, clockwise, area2, plane) {
|
|
12955
|
+
let i;
|
|
12956
|
+
let last;
|
|
12957
|
+
if (area2 === void 0) {
|
|
12958
|
+
area2 = getPolygonSignedArea(data, {
|
|
12959
|
+
start,
|
|
12960
|
+
end,
|
|
12961
|
+
size: dim,
|
|
12962
|
+
plane
|
|
12963
|
+
});
|
|
12964
|
+
}
|
|
12965
|
+
let i0 = DimIndex[plane[0]];
|
|
12966
|
+
let i1 = DimIndex[plane[1]];
|
|
12967
|
+
if (clockwise === area2 < 0) {
|
|
12968
|
+
for (i = start; i < end; i += dim)
|
|
12969
|
+
last = insertNode(i, data[i + i0], data[i + i1], last);
|
|
12970
|
+
} else {
|
|
12971
|
+
for (i = end - dim; i >= start; i -= dim)
|
|
12972
|
+
last = insertNode(i, data[i + i0], data[i + i1], last);
|
|
12973
|
+
}
|
|
12974
|
+
if (last && equals(last, last.next)) {
|
|
12975
|
+
removeNode(last);
|
|
12976
|
+
last = last.next;
|
|
12977
|
+
}
|
|
12978
|
+
return last;
|
|
12979
|
+
}
|
|
12980
|
+
function filterPoints(start, end) {
|
|
12981
|
+
if (!start)
|
|
12982
|
+
return start;
|
|
12983
|
+
if (!end)
|
|
12984
|
+
end = start;
|
|
12985
|
+
let p = start;
|
|
12986
|
+
let again;
|
|
12987
|
+
do {
|
|
12988
|
+
again = false;
|
|
12989
|
+
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
12990
|
+
removeNode(p);
|
|
12991
|
+
p = end = p.prev;
|
|
12992
|
+
if (p === p.next)
|
|
12993
|
+
break;
|
|
12994
|
+
again = true;
|
|
12995
|
+
} else {
|
|
12996
|
+
p = p.next;
|
|
12850
12997
|
}
|
|
12851
|
-
|
|
12852
|
-
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
12998
|
+
} while (again || p !== end);
|
|
12999
|
+
return end;
|
|
13000
|
+
}
|
|
13001
|
+
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
13002
|
+
if (!ear)
|
|
13003
|
+
return;
|
|
13004
|
+
if (!pass && invSize)
|
|
13005
|
+
indexCurve(ear, minX, minY, invSize);
|
|
13006
|
+
let stop = ear;
|
|
13007
|
+
let prev;
|
|
13008
|
+
let next;
|
|
13009
|
+
while (ear.prev !== ear.next) {
|
|
13010
|
+
prev = ear.prev;
|
|
13011
|
+
next = ear.next;
|
|
13012
|
+
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
13013
|
+
triangles.push(prev.i / dim | 0);
|
|
13014
|
+
triangles.push(ear.i / dim | 0);
|
|
13015
|
+
triangles.push(next.i / dim | 0);
|
|
13016
|
+
removeNode(ear);
|
|
13017
|
+
ear = next.next;
|
|
13018
|
+
stop = next.next;
|
|
13019
|
+
continue;
|
|
13020
|
+
}
|
|
13021
|
+
ear = next;
|
|
13022
|
+
if (ear === stop) {
|
|
13023
|
+
if (!pass) {
|
|
13024
|
+
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
13025
|
+
} else if (pass === 1) {
|
|
13026
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
13027
|
+
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
13028
|
+
} else if (pass === 2) {
|
|
13029
|
+
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
13030
|
+
}
|
|
13031
|
+
break;
|
|
13032
|
+
}
|
|
13033
|
+
}
|
|
13034
|
+
}
|
|
13035
|
+
function isEar(ear) {
|
|
13036
|
+
const a = ear.prev;
|
|
13037
|
+
const b = ear;
|
|
13038
|
+
const c = ear.next;
|
|
13039
|
+
if (area(a, b, c) >= 0)
|
|
13040
|
+
return false;
|
|
13041
|
+
const ax = a.x;
|
|
13042
|
+
const bx = b.x;
|
|
13043
|
+
const cx = c.x;
|
|
13044
|
+
const ay = a.y;
|
|
13045
|
+
const by = b.y;
|
|
13046
|
+
const cy = c.y;
|
|
13047
|
+
const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
|
|
13048
|
+
const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
|
|
13049
|
+
const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
|
|
13050
|
+
const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
|
|
13051
|
+
let p = c.next;
|
|
13052
|
+
while (p !== a) {
|
|
13053
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
13054
|
+
return false;
|
|
13055
|
+
p = p.next;
|
|
13056
|
+
}
|
|
13057
|
+
return true;
|
|
13058
|
+
}
|
|
13059
|
+
function isEarHashed(ear, minX, minY, invSize) {
|
|
13060
|
+
const a = ear.prev;
|
|
13061
|
+
const b = ear;
|
|
13062
|
+
const c = ear.next;
|
|
13063
|
+
if (area(a, b, c) >= 0)
|
|
13064
|
+
return false;
|
|
13065
|
+
const ax = a.x;
|
|
13066
|
+
const bx = b.x;
|
|
13067
|
+
const cx = c.x;
|
|
13068
|
+
const ay = a.y;
|
|
13069
|
+
const by = b.y;
|
|
13070
|
+
const cy = c.y;
|
|
13071
|
+
const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
|
|
13072
|
+
const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
|
|
13073
|
+
const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
|
|
13074
|
+
const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
|
|
13075
|
+
const minZ = zOrder(x0, y0, minX, minY, invSize);
|
|
13076
|
+
const maxZ = zOrder(x1, y1, minX, minY, invSize);
|
|
13077
|
+
let p = ear.prevZ;
|
|
13078
|
+
let n = ear.nextZ;
|
|
13079
|
+
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
13080
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
13081
|
+
return false;
|
|
13082
|
+
p = p.prevZ;
|
|
13083
|
+
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
13084
|
+
return false;
|
|
13085
|
+
n = n.nextZ;
|
|
13086
|
+
}
|
|
13087
|
+
while (p && p.z >= minZ) {
|
|
13088
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
13089
|
+
return false;
|
|
13090
|
+
p = p.prevZ;
|
|
13091
|
+
}
|
|
13092
|
+
while (n && n.z <= maxZ) {
|
|
13093
|
+
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
13094
|
+
return false;
|
|
13095
|
+
n = n.nextZ;
|
|
13096
|
+
}
|
|
13097
|
+
return true;
|
|
13098
|
+
}
|
|
13099
|
+
function cureLocalIntersections(start, triangles, dim) {
|
|
13100
|
+
let p = start;
|
|
13101
|
+
do {
|
|
13102
|
+
const a = p.prev;
|
|
13103
|
+
const b = p.next.next;
|
|
13104
|
+
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
13105
|
+
triangles.push(a.i / dim | 0);
|
|
13106
|
+
triangles.push(p.i / dim | 0);
|
|
13107
|
+
triangles.push(b.i / dim | 0);
|
|
13108
|
+
removeNode(p);
|
|
13109
|
+
removeNode(p.next);
|
|
13110
|
+
p = start = b;
|
|
13111
|
+
}
|
|
13112
|
+
p = p.next;
|
|
13113
|
+
} while (p !== start);
|
|
13114
|
+
return filterPoints(p);
|
|
13115
|
+
}
|
|
13116
|
+
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
13117
|
+
let a = start;
|
|
13118
|
+
do {
|
|
13119
|
+
let b = a.next.next;
|
|
13120
|
+
while (b !== a.prev) {
|
|
13121
|
+
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
13122
|
+
let c = splitPolygon(a, b);
|
|
13123
|
+
a = filterPoints(a, a.next);
|
|
13124
|
+
c = filterPoints(c, c.next);
|
|
13125
|
+
earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
|
|
13126
|
+
earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
|
|
13127
|
+
return;
|
|
13128
|
+
}
|
|
13129
|
+
b = b.next;
|
|
13130
|
+
}
|
|
13131
|
+
a = a.next;
|
|
13132
|
+
} while (a !== start);
|
|
13133
|
+
}
|
|
13134
|
+
function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
|
|
13135
|
+
const queue = [];
|
|
13136
|
+
let i;
|
|
13137
|
+
let len;
|
|
13138
|
+
let start;
|
|
13139
|
+
let end;
|
|
13140
|
+
let list;
|
|
13141
|
+
for (i = 0, len = holeIndices.length; i < len; i++) {
|
|
13142
|
+
start = holeIndices[i] * dim;
|
|
13143
|
+
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
|
13144
|
+
list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
|
|
13145
|
+
if (list === list.next)
|
|
13146
|
+
list.steiner = true;
|
|
13147
|
+
queue.push(getLeftmost(list));
|
|
13148
|
+
}
|
|
13149
|
+
queue.sort(compareX);
|
|
13150
|
+
for (i = 0; i < queue.length; i++) {
|
|
13151
|
+
outerNode = eliminateHole(queue[i], outerNode);
|
|
13152
|
+
}
|
|
13153
|
+
return outerNode;
|
|
13154
|
+
}
|
|
13155
|
+
function compareX(a, b) {
|
|
13156
|
+
return a.x - b.x;
|
|
13157
|
+
}
|
|
13158
|
+
function eliminateHole(hole, outerNode) {
|
|
13159
|
+
const bridge = findHoleBridge(hole, outerNode);
|
|
13160
|
+
if (!bridge) {
|
|
13161
|
+
return outerNode;
|
|
13162
|
+
}
|
|
13163
|
+
const bridgeReverse = splitPolygon(bridge, hole);
|
|
13164
|
+
filterPoints(bridgeReverse, bridgeReverse.next);
|
|
13165
|
+
return filterPoints(bridge, bridge.next);
|
|
13166
|
+
}
|
|
13167
|
+
function findHoleBridge(hole, outerNode) {
|
|
13168
|
+
let p = outerNode;
|
|
13169
|
+
const hx = hole.x;
|
|
13170
|
+
const hy = hole.y;
|
|
13171
|
+
let qx = -Infinity;
|
|
13172
|
+
let m;
|
|
13173
|
+
do {
|
|
13174
|
+
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
13175
|
+
const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
13176
|
+
if (x <= hx && x > qx) {
|
|
13177
|
+
qx = x;
|
|
13178
|
+
m = p.x < p.next.x ? p : p.next;
|
|
13179
|
+
if (x === hx)
|
|
13180
|
+
return m;
|
|
13181
|
+
}
|
|
13182
|
+
}
|
|
13183
|
+
p = p.next;
|
|
13184
|
+
} while (p !== outerNode);
|
|
13185
|
+
if (!m)
|
|
13186
|
+
return null;
|
|
13187
|
+
const stop = m;
|
|
13188
|
+
const mx = m.x;
|
|
13189
|
+
const my = m.y;
|
|
13190
|
+
let tanMin = Infinity;
|
|
13191
|
+
let tan;
|
|
13192
|
+
p = m;
|
|
13193
|
+
do {
|
|
13194
|
+
if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
|
13195
|
+
tan = Math.abs(hy - p.y) / (hx - p.x);
|
|
13196
|
+
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
13197
|
+
m = p;
|
|
13198
|
+
tanMin = tan;
|
|
13199
|
+
}
|
|
13200
|
+
}
|
|
13201
|
+
p = p.next;
|
|
13202
|
+
} while (p !== stop);
|
|
13203
|
+
return m;
|
|
13204
|
+
}
|
|
13205
|
+
function sectorContainsSector(m, p) {
|
|
13206
|
+
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
13207
|
+
}
|
|
13208
|
+
function indexCurve(start, minX, minY, invSize) {
|
|
13209
|
+
let p = start;
|
|
13210
|
+
do {
|
|
13211
|
+
if (p.z === 0)
|
|
13212
|
+
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
13213
|
+
p.prevZ = p.prev;
|
|
13214
|
+
p.nextZ = p.next;
|
|
13215
|
+
p = p.next;
|
|
13216
|
+
} while (p !== start);
|
|
13217
|
+
p.prevZ.nextZ = null;
|
|
13218
|
+
p.prevZ = null;
|
|
13219
|
+
sortLinked(p);
|
|
13220
|
+
}
|
|
13221
|
+
function sortLinked(list) {
|
|
13222
|
+
let e;
|
|
13223
|
+
let i;
|
|
13224
|
+
let inSize = 1;
|
|
13225
|
+
let numMerges;
|
|
13226
|
+
let p;
|
|
13227
|
+
let pSize;
|
|
13228
|
+
let q;
|
|
13229
|
+
let qSize;
|
|
13230
|
+
let tail;
|
|
13231
|
+
do {
|
|
13232
|
+
p = list;
|
|
13233
|
+
list = null;
|
|
13234
|
+
tail = null;
|
|
13235
|
+
numMerges = 0;
|
|
13236
|
+
while (p) {
|
|
13237
|
+
numMerges++;
|
|
13238
|
+
q = p;
|
|
13239
|
+
pSize = 0;
|
|
13240
|
+
for (i = 0; i < inSize; i++) {
|
|
13241
|
+
pSize++;
|
|
13242
|
+
q = q.nextZ;
|
|
13243
|
+
if (!q)
|
|
13244
|
+
break;
|
|
13245
|
+
}
|
|
13246
|
+
qSize = inSize;
|
|
13247
|
+
while (pSize > 0 || qSize > 0 && q) {
|
|
13248
|
+
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
13249
|
+
e = p;
|
|
13250
|
+
p = p.nextZ;
|
|
13251
|
+
pSize--;
|
|
13252
|
+
} else {
|
|
13253
|
+
e = q;
|
|
13254
|
+
q = q.nextZ;
|
|
13255
|
+
qSize--;
|
|
13256
|
+
}
|
|
13257
|
+
if (tail)
|
|
13258
|
+
tail.nextZ = e;
|
|
13259
|
+
else
|
|
13260
|
+
list = e;
|
|
13261
|
+
e.prevZ = tail;
|
|
13262
|
+
tail = e;
|
|
13263
|
+
}
|
|
13264
|
+
p = q;
|
|
13265
|
+
}
|
|
13266
|
+
tail.nextZ = null;
|
|
13267
|
+
inSize *= 2;
|
|
13268
|
+
} while (numMerges > 1);
|
|
13269
|
+
return list;
|
|
13270
|
+
}
|
|
13271
|
+
function zOrder(x, y, minX, minY, invSize) {
|
|
13272
|
+
x = (x - minX) * invSize | 0;
|
|
13273
|
+
y = (y - minY) * invSize | 0;
|
|
13274
|
+
x = (x | x << 8) & 16711935;
|
|
13275
|
+
x = (x | x << 4) & 252645135;
|
|
13276
|
+
x = (x | x << 2) & 858993459;
|
|
13277
|
+
x = (x | x << 1) & 1431655765;
|
|
13278
|
+
y = (y | y << 8) & 16711935;
|
|
13279
|
+
y = (y | y << 4) & 252645135;
|
|
13280
|
+
y = (y | y << 2) & 858993459;
|
|
13281
|
+
y = (y | y << 1) & 1431655765;
|
|
13282
|
+
return x | y << 1;
|
|
13283
|
+
}
|
|
13284
|
+
function getLeftmost(start) {
|
|
13285
|
+
let p = start;
|
|
13286
|
+
let leftmost = start;
|
|
13287
|
+
do {
|
|
13288
|
+
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
|
|
13289
|
+
leftmost = p;
|
|
13290
|
+
p = p.next;
|
|
13291
|
+
} while (p !== start);
|
|
13292
|
+
return leftmost;
|
|
13293
|
+
}
|
|
13294
|
+
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
13295
|
+
return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
|
|
13296
|
+
}
|
|
13297
|
+
function isValidDiagonal(a, b) {
|
|
13298
|
+
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
|
|
13299
|
+
}
|
|
13300
|
+
function area(p, q, r) {
|
|
13301
|
+
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
13302
|
+
}
|
|
13303
|
+
function equals(p1, p2) {
|
|
13304
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
13305
|
+
}
|
|
13306
|
+
function intersects(p1, q1, p2, q2) {
|
|
13307
|
+
const o1 = sign(area(p1, q1, p2));
|
|
13308
|
+
const o2 = sign(area(p1, q1, q2));
|
|
13309
|
+
const o3 = sign(area(p2, q2, p1));
|
|
13310
|
+
const o4 = sign(area(p2, q2, q1));
|
|
13311
|
+
if (o1 !== o2 && o3 !== o4)
|
|
13312
|
+
return true;
|
|
13313
|
+
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
13314
|
+
return true;
|
|
13315
|
+
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
13316
|
+
return true;
|
|
13317
|
+
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
13318
|
+
return true;
|
|
13319
|
+
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
13320
|
+
return true;
|
|
13321
|
+
return false;
|
|
13322
|
+
}
|
|
13323
|
+
function onSegment(p, q, r) {
|
|
13324
|
+
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
|
|
13325
|
+
}
|
|
13326
|
+
function sign(num) {
|
|
13327
|
+
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
13328
|
+
}
|
|
13329
|
+
function intersectsPolygon(a, b) {
|
|
13330
|
+
let p = a;
|
|
13331
|
+
do {
|
|
13332
|
+
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
|
|
13333
|
+
return true;
|
|
13334
|
+
p = p.next;
|
|
13335
|
+
} while (p !== a);
|
|
13336
|
+
return false;
|
|
13337
|
+
}
|
|
13338
|
+
function locallyInside(a, b) {
|
|
13339
|
+
return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
|
13340
|
+
}
|
|
13341
|
+
function middleInside(a, b) {
|
|
13342
|
+
let p = a;
|
|
13343
|
+
let inside = false;
|
|
13344
|
+
const px = (a.x + b.x) / 2;
|
|
13345
|
+
const py = (a.y + b.y) / 2;
|
|
13346
|
+
do {
|
|
13347
|
+
if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
|
|
13348
|
+
inside = !inside;
|
|
13349
|
+
p = p.next;
|
|
13350
|
+
} while (p !== a);
|
|
13351
|
+
return inside;
|
|
13352
|
+
}
|
|
13353
|
+
function splitPolygon(a, b) {
|
|
13354
|
+
const a2 = new Vertex(a.i, a.x, a.y);
|
|
13355
|
+
const b2 = new Vertex(b.i, b.x, b.y);
|
|
13356
|
+
const an = a.next;
|
|
13357
|
+
const bp = b.prev;
|
|
13358
|
+
a.next = b;
|
|
13359
|
+
b.prev = a;
|
|
13360
|
+
a2.next = an;
|
|
13361
|
+
an.prev = a2;
|
|
13362
|
+
b2.next = a2;
|
|
13363
|
+
a2.prev = b2;
|
|
13364
|
+
bp.next = b2;
|
|
13365
|
+
b2.prev = bp;
|
|
13366
|
+
return b2;
|
|
13367
|
+
}
|
|
13368
|
+
function insertNode(i, x, y, last) {
|
|
13369
|
+
const p = new Vertex(i, x, y);
|
|
13370
|
+
if (!last) {
|
|
13371
|
+
p.prev = p;
|
|
13372
|
+
p.next = p;
|
|
13373
|
+
} else {
|
|
13374
|
+
p.next = last.next;
|
|
13375
|
+
p.prev = last;
|
|
13376
|
+
last.next.prev = p;
|
|
13377
|
+
last.next = p;
|
|
13378
|
+
}
|
|
13379
|
+
return p;
|
|
13380
|
+
}
|
|
13381
|
+
function removeNode(p) {
|
|
13382
|
+
p.next.prev = p.prev;
|
|
13383
|
+
p.prev.next = p.next;
|
|
13384
|
+
if (p.prevZ)
|
|
13385
|
+
p.prevZ.nextZ = p.nextZ;
|
|
13386
|
+
if (p.nextZ)
|
|
13387
|
+
p.nextZ.prevZ = p.prevZ;
|
|
13388
|
+
}
|
|
13389
|
+
var Vertex = class {
|
|
13390
|
+
constructor(i, x, y) {
|
|
13391
|
+
_defineProperty(this, "i", void 0);
|
|
13392
|
+
_defineProperty(this, "x", void 0);
|
|
13393
|
+
_defineProperty(this, "y", void 0);
|
|
13394
|
+
_defineProperty(this, "prev", null);
|
|
13395
|
+
_defineProperty(this, "next", null);
|
|
13396
|
+
_defineProperty(this, "z", 0);
|
|
13397
|
+
_defineProperty(this, "prevZ", null);
|
|
13398
|
+
_defineProperty(this, "nextZ", null);
|
|
13399
|
+
_defineProperty(this, "steiner", false);
|
|
13400
|
+
this.i = i;
|
|
13401
|
+
this.x = x;
|
|
13402
|
+
this.y = y;
|
|
13403
|
+
}
|
|
13404
|
+
};
|
|
13405
|
+
|
|
13406
|
+
// ../gis/src/lib/binary-features/binary-to-geojson.ts
|
|
13407
|
+
function binaryToGeometry(data, startIndex, endIndex) {
|
|
13408
|
+
switch (data.type) {
|
|
13409
|
+
case "Point":
|
|
13410
|
+
return pointToGeoJson(data, startIndex, endIndex);
|
|
13411
|
+
case "LineString":
|
|
13412
|
+
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
13413
|
+
case "Polygon":
|
|
13414
|
+
return polygonToGeoJson(data, startIndex, endIndex);
|
|
13415
|
+
default:
|
|
13416
|
+
const unexpectedInput = data;
|
|
13417
|
+
throw new Error(`Unsupported geometry type: ${unexpectedInput?.type}`);
|
|
13418
|
+
}
|
|
13419
|
+
}
|
|
13420
|
+
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
13421
|
+
const {
|
|
13422
|
+
positions
|
|
13423
|
+
} = data;
|
|
13424
|
+
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
13425
|
+
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
13426
|
+
const multi = polygonIndices.length > 2;
|
|
13427
|
+
if (!multi) {
|
|
13428
|
+
const coordinates2 = [];
|
|
13429
|
+
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
13430
|
+
const startRingIndex = primitivePolygonIndices[i];
|
|
13431
|
+
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
13432
|
+
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
13433
|
+
coordinates2.push(ringCoordinates);
|
|
13434
|
+
}
|
|
13435
|
+
return {
|
|
13436
|
+
type: "Polygon",
|
|
13437
|
+
coordinates: coordinates2
|
|
13438
|
+
};
|
|
13439
|
+
}
|
|
13440
|
+
const coordinates = [];
|
|
13441
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
13442
|
+
const startPolygonIndex = polygonIndices[i];
|
|
13443
|
+
const endPolygonIndex = polygonIndices[i + 1];
|
|
13444
|
+
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
13445
|
+
coordinates.push(polygonCoordinates);
|
|
13446
|
+
}
|
|
13447
|
+
return {
|
|
13448
|
+
type: "MultiPolygon",
|
|
13449
|
+
coordinates
|
|
13450
|
+
};
|
|
13451
|
+
}
|
|
13452
|
+
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
13453
|
+
const {
|
|
13454
|
+
positions
|
|
13455
|
+
} = data;
|
|
13456
|
+
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
13457
|
+
const multi = pathIndices.length > 2;
|
|
13458
|
+
if (!multi) {
|
|
13459
|
+
const coordinates2 = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
13460
|
+
return {
|
|
13461
|
+
type: "LineString",
|
|
13462
|
+
coordinates: coordinates2
|
|
13463
|
+
};
|
|
13464
|
+
}
|
|
13465
|
+
const coordinates = [];
|
|
13466
|
+
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
13467
|
+
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
13468
|
+
coordinates.push(ringCoordinates);
|
|
13469
|
+
}
|
|
13470
|
+
return {
|
|
13471
|
+
type: "MultiLineString",
|
|
13472
|
+
coordinates
|
|
13473
|
+
};
|
|
13474
|
+
}
|
|
13475
|
+
function pointToGeoJson(data, startIndex, endIndex) {
|
|
13476
|
+
const {
|
|
13477
|
+
positions
|
|
13478
|
+
} = data;
|
|
13479
|
+
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
13480
|
+
const multi = coordinates.length > 1;
|
|
13481
|
+
if (multi) {
|
|
13482
|
+
return {
|
|
13483
|
+
type: "MultiPoint",
|
|
13484
|
+
coordinates
|
|
13485
|
+
};
|
|
13486
|
+
}
|
|
13487
|
+
return {
|
|
13488
|
+
type: "Point",
|
|
13489
|
+
coordinates: coordinates[0]
|
|
13490
|
+
};
|
|
13491
|
+
}
|
|
13492
|
+
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
13493
|
+
startIndex = startIndex || 0;
|
|
13494
|
+
endIndex = endIndex || positions.value.length / positions.size;
|
|
13495
|
+
const ringCoordinates = [];
|
|
13496
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
13497
|
+
const coord = Array();
|
|
13498
|
+
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
13499
|
+
coord.push(Number(positions.value[k]));
|
|
13500
|
+
}
|
|
13501
|
+
ringCoordinates.push(coord);
|
|
13502
|
+
}
|
|
13503
|
+
return ringCoordinates;
|
|
13504
|
+
}
|
|
13505
|
+
|
|
13506
|
+
// src/tables/convert-arrow-to-geojson-table.ts
|
|
13507
|
+
function convertArrowToGeoJSONTable(table) {
|
|
13508
|
+
const arrowTable = table.data;
|
|
13509
|
+
const schema = serializeArrowSchema(arrowTable.schema);
|
|
13510
|
+
const geometryColumns = getGeometryColumnsFromSchema(schema);
|
|
13511
|
+
const encoding = geometryColumns.geometry.encoding;
|
|
13512
|
+
const features = [];
|
|
13513
|
+
const propertyColumnNames = arrowTable.schema.fields.map((field) => field.name).filter((name) => !(name in geometryColumns));
|
|
13514
|
+
const propertiesTable = arrowTable.select(propertyColumnNames);
|
|
13515
|
+
const arrowGeometryColumn = arrowTable.getChild("geometry");
|
|
13516
|
+
for (let row = 0; row < arrowTable.numRows; row++) {
|
|
13517
|
+
const arrowGeometry = arrowGeometryColumn?.get(row);
|
|
13518
|
+
const feature = parseGeometryFromArrow(arrowGeometry, encoding);
|
|
13519
|
+
if (feature) {
|
|
13520
|
+
const properties = propertiesTable.get(row)?.toJSON() || {};
|
|
13521
|
+
features.push({
|
|
13522
|
+
type: "Feature",
|
|
13523
|
+
geometry: feature,
|
|
13524
|
+
properties
|
|
13525
|
+
});
|
|
13526
|
+
}
|
|
13527
|
+
}
|
|
13528
|
+
return {
|
|
13529
|
+
shape: "geojson-table",
|
|
13530
|
+
type: "FeatureCollection",
|
|
13531
|
+
schema: table.schema,
|
|
13532
|
+
features
|
|
13533
|
+
};
|
|
13534
|
+
}
|
|
13535
|
+
|
|
13536
|
+
// src/parsers/parse-geoarrow-sync.ts
|
|
13537
|
+
function parseGeoArrowSync(arrayBuffer, options) {
|
|
13538
|
+
const table = parseArrowSync(arrayBuffer, {
|
|
13539
|
+
shape: "arrow-table"
|
|
13540
|
+
});
|
|
13541
|
+
switch (options?.shape) {
|
|
13542
|
+
case "geojson-table":
|
|
13543
|
+
return convertArrowToGeoJSONTable(table);
|
|
13544
|
+
default:
|
|
13545
|
+
return table;
|
|
13546
|
+
}
|
|
13547
|
+
}
|
|
13548
|
+
|
|
13549
|
+
// src/parsers/parse-geoarrow-in-batches.ts
|
|
13550
|
+
function parseGeoArrowInBatches(asyncIterator) {
|
|
13551
|
+
return parseArrowInBatches(asyncIterator);
|
|
13552
|
+
}
|
|
13553
|
+
|
|
13554
|
+
// src/geoarrow-loader.ts
|
|
13555
|
+
var GeoArrowWorkerLoader = {
|
|
13556
|
+
...ArrowWorkerLoader,
|
|
13557
|
+
options: {
|
|
13558
|
+
arrow: {
|
|
13559
|
+
shape: "arrow-table"
|
|
13560
|
+
}
|
|
13561
|
+
}
|
|
13562
|
+
};
|
|
13563
|
+
var GeoArrowLoader = {
|
|
13564
|
+
...ArrowWorkerLoader,
|
|
13565
|
+
options: {
|
|
13566
|
+
arrow: {
|
|
13567
|
+
shape: "arrow-table"
|
|
13568
|
+
}
|
|
13569
|
+
},
|
|
13570
|
+
parse: async (arraybuffer, options) => parseGeoArrowSync(arraybuffer, options?.arrow),
|
|
13571
|
+
parseSync: (arraybuffer, options) => parseGeoArrowSync(arraybuffer, options?.arrow),
|
|
13572
|
+
parseInBatches: parseGeoArrowInBatches
|
|
13573
|
+
};
|
|
13574
|
+
|
|
13575
|
+
// src/geoarrow/get-arrow-bounds.ts
|
|
13576
|
+
function updateBoundsFromGeoArrowSamples(flatCoords, nDim, bounds, sampleSize = 100) {
|
|
13577
|
+
const numberOfFeatures = flatCoords.length / nDim;
|
|
13578
|
+
const sampleStep = Math.max(Math.floor(numberOfFeatures / sampleSize), 1);
|
|
13579
|
+
const newBounds = [...bounds];
|
|
13580
|
+
for (let i = 0; i < numberOfFeatures; i += sampleStep) {
|
|
13581
|
+
const lng = flatCoords[i * nDim];
|
|
13582
|
+
const lat = flatCoords[i * nDim + 1];
|
|
13583
|
+
if (lng < newBounds[0]) {
|
|
13584
|
+
newBounds[0] = lng;
|
|
13585
|
+
}
|
|
13586
|
+
if (lat < newBounds[1]) {
|
|
13587
|
+
newBounds[1] = lat;
|
|
13588
|
+
}
|
|
13589
|
+
if (lng > newBounds[2]) {
|
|
13590
|
+
newBounds[2] = lng;
|
|
13591
|
+
}
|
|
13592
|
+
if (lat > newBounds[3]) {
|
|
13593
|
+
newBounds[3] = lat;
|
|
13594
|
+
}
|
|
13595
|
+
}
|
|
13596
|
+
return newBounds;
|
|
13597
|
+
}
|
|
13598
|
+
|
|
13599
|
+
// src/geoarrow/convert-geoarrow-to-binary-geometry.ts
|
|
13600
|
+
var BinaryGeometryType = function(BinaryGeometryType2) {
|
|
13601
|
+
BinaryGeometryType2["points"] = "points";
|
|
13602
|
+
BinaryGeometryType2["lines"] = "lines";
|
|
13603
|
+
BinaryGeometryType2["polygons"] = "polygons";
|
|
13604
|
+
return BinaryGeometryType2;
|
|
13605
|
+
}(BinaryGeometryType || {});
|
|
13606
|
+
var BINARY_GEOMETRY_TEMPLATE = {
|
|
13607
|
+
globalFeatureIds: {
|
|
13608
|
+
value: new Uint32Array(0),
|
|
13609
|
+
size: 1
|
|
13610
|
+
},
|
|
13611
|
+
positions: {
|
|
13612
|
+
value: new Float32Array(0),
|
|
13613
|
+
size: 2
|
|
13614
|
+
},
|
|
13615
|
+
properties: [],
|
|
13616
|
+
numericProps: {},
|
|
13617
|
+
featureIds: {
|
|
13618
|
+
value: new Uint32Array(0),
|
|
13619
|
+
size: 1
|
|
13620
|
+
}
|
|
13621
|
+
};
|
|
13622
|
+
function getBinaryGeometriesFromArrow(geoColumn, geoEncoding, options) {
|
|
13623
|
+
const featureTypes = {
|
|
13624
|
+
polygon: geoEncoding === "geoarrow.multipolygon" || geoEncoding === "geoarrow.polygon",
|
|
13625
|
+
point: geoEncoding === "geoarrow.multipoint" || geoEncoding === "geoarrow.point",
|
|
13626
|
+
line: geoEncoding === "geoarrow.multilinestring" || geoEncoding === "geoarrow.linestring"
|
|
13627
|
+
};
|
|
13628
|
+
const chunks = options?.chunkIndex ? [geoColumn.data[options?.chunkIndex]] : geoColumn.data;
|
|
13629
|
+
let bounds = [Infinity, Infinity, -Infinity, -Infinity];
|
|
13630
|
+
let globalFeatureIdOffset = 0;
|
|
13631
|
+
const binaryGeometries = [];
|
|
13632
|
+
chunks.forEach((chunk) => {
|
|
13633
|
+
const {
|
|
13634
|
+
featureIds,
|
|
13635
|
+
flatCoordinateArray,
|
|
13636
|
+
nDim,
|
|
13637
|
+
geomOffset,
|
|
13638
|
+
triangles
|
|
13639
|
+
} = getBinaryGeometriesFromChunk(chunk, geoEncoding, options);
|
|
13640
|
+
const globalFeatureIds = new Uint32Array(featureIds.length);
|
|
13641
|
+
for (let i = 0; i < featureIds.length; i++) {
|
|
13642
|
+
globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
|
|
13643
|
+
}
|
|
13644
|
+
const binaryContent = {
|
|
13645
|
+
globalFeatureIds: {
|
|
13646
|
+
value: globalFeatureIds,
|
|
13647
|
+
size: 1
|
|
13648
|
+
},
|
|
13649
|
+
positions: {
|
|
13650
|
+
value: flatCoordinateArray,
|
|
13651
|
+
size: nDim
|
|
13652
|
+
},
|
|
13653
|
+
featureIds: {
|
|
13654
|
+
value: featureIds,
|
|
13655
|
+
size: 1
|
|
13656
|
+
},
|
|
13657
|
+
properties: [...Array(chunk.length).keys()].map((i) => ({
|
|
13658
|
+
index: i + globalFeatureIdOffset
|
|
13659
|
+
}))
|
|
13660
|
+
};
|
|
13661
|
+
globalFeatureIdOffset += chunk.length;
|
|
13662
|
+
binaryGeometries.push({
|
|
13663
|
+
shape: "binary-feature-collection",
|
|
13664
|
+
points: {
|
|
13665
|
+
type: "Point",
|
|
13666
|
+
...BINARY_GEOMETRY_TEMPLATE,
|
|
13667
|
+
...featureTypes.point ? binaryContent : {}
|
|
13668
|
+
},
|
|
13669
|
+
lines: {
|
|
13670
|
+
type: "LineString",
|
|
13671
|
+
...BINARY_GEOMETRY_TEMPLATE,
|
|
13672
|
+
...featureTypes.line ? binaryContent : {},
|
|
13673
|
+
pathIndices: {
|
|
13674
|
+
value: featureTypes.line ? geomOffset : new Uint16Array(0),
|
|
13675
|
+
size: 1
|
|
13676
|
+
}
|
|
12884
13677
|
},
|
|
12885
13678
|
polygons: {
|
|
12886
13679
|
type: "Polygon",
|
|
@@ -12893,7 +13686,13 @@ return true;`);
|
|
|
12893
13686
|
primitivePolygonIndices: {
|
|
12894
13687
|
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
12895
13688
|
size: 1
|
|
12896
|
-
}
|
|
13689
|
+
},
|
|
13690
|
+
...triangles ? {
|
|
13691
|
+
triangles: {
|
|
13692
|
+
value: triangles,
|
|
13693
|
+
size: 1
|
|
13694
|
+
}
|
|
13695
|
+
} : {}
|
|
12897
13696
|
}
|
|
12898
13697
|
});
|
|
12899
13698
|
bounds = updateBoundsFromGeoArrowSamples(flatCoordinateArray, nDim, bounds);
|
|
@@ -12901,10 +13700,66 @@ return true;`);
|
|
|
12901
13700
|
return {
|
|
12902
13701
|
binaryGeometries,
|
|
12903
13702
|
bounds,
|
|
12904
|
-
featureTypes
|
|
13703
|
+
featureTypes,
|
|
13704
|
+
...options?.calculateMeanCenters ? {
|
|
13705
|
+
meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries)
|
|
13706
|
+
} : {}
|
|
12905
13707
|
};
|
|
12906
13708
|
}
|
|
12907
|
-
function
|
|
13709
|
+
function getMeanCentersFromBinaryGeometries(binaryGeometries) {
|
|
13710
|
+
const globalMeanCenters = [];
|
|
13711
|
+
binaryGeometries.forEach((binaryGeometry) => {
|
|
13712
|
+
let binaryGeometryType = null;
|
|
13713
|
+
if (binaryGeometry.points && binaryGeometry.points.positions.value.length > 0) {
|
|
13714
|
+
binaryGeometryType = BinaryGeometryType.points;
|
|
13715
|
+
} else if (binaryGeometry.lines && binaryGeometry.lines.positions.value.length > 0) {
|
|
13716
|
+
binaryGeometryType = BinaryGeometryType.lines;
|
|
13717
|
+
} else if (binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0) {
|
|
13718
|
+
binaryGeometryType = BinaryGeometryType.polygons;
|
|
13719
|
+
}
|
|
13720
|
+
const binaryContent = binaryGeometryType ? binaryGeometry[binaryGeometryType] : null;
|
|
13721
|
+
if (binaryContent && binaryGeometryType !== null) {
|
|
13722
|
+
const featureIds = binaryContent.featureIds.value;
|
|
13723
|
+
const flatCoordinateArray = binaryContent.positions.value;
|
|
13724
|
+
const nDim = binaryContent.positions.size;
|
|
13725
|
+
const primitivePolygonIndices = binaryContent.type === "Polygon" ? binaryContent.primitivePolygonIndices?.value : void 0;
|
|
13726
|
+
const meanCenters = getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, binaryGeometryType, primitivePolygonIndices);
|
|
13727
|
+
meanCenters.forEach((center) => {
|
|
13728
|
+
globalMeanCenters.push(center);
|
|
13729
|
+
});
|
|
13730
|
+
}
|
|
13731
|
+
});
|
|
13732
|
+
return globalMeanCenters;
|
|
13733
|
+
}
|
|
13734
|
+
function getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, geometryType, primitivePolygonIndices) {
|
|
13735
|
+
const meanCenters = [];
|
|
13736
|
+
const vertexCount = flatCoordinateArray.length;
|
|
13737
|
+
let vertexIndex = 0;
|
|
13738
|
+
let coordIdx = 0;
|
|
13739
|
+
let primitiveIdx = 0;
|
|
13740
|
+
while (vertexIndex < vertexCount) {
|
|
13741
|
+
const featureId = featureIds[vertexIndex / nDim];
|
|
13742
|
+
const center = [0, 0];
|
|
13743
|
+
let vertexCountInFeature = 0;
|
|
13744
|
+
while (vertexIndex < vertexCount && featureIds[coordIdx] === featureId) {
|
|
13745
|
+
if (geometryType === BinaryGeometryType.polygons && primitivePolygonIndices?.[primitiveIdx] === coordIdx) {
|
|
13746
|
+
vertexIndex += nDim;
|
|
13747
|
+
primitiveIdx++;
|
|
13748
|
+
} else {
|
|
13749
|
+
center[0] += flatCoordinateArray[vertexIndex];
|
|
13750
|
+
center[1] += flatCoordinateArray[vertexIndex + 1];
|
|
13751
|
+
vertexIndex += nDim;
|
|
13752
|
+
vertexCountInFeature++;
|
|
13753
|
+
}
|
|
13754
|
+
coordIdx += 1;
|
|
13755
|
+
}
|
|
13756
|
+
center[0] /= vertexCountInFeature;
|
|
13757
|
+
center[1] /= vertexCountInFeature;
|
|
13758
|
+
meanCenters.push(center);
|
|
13759
|
+
}
|
|
13760
|
+
return meanCenters;
|
|
13761
|
+
}
|
|
13762
|
+
function getBinaryGeometriesFromChunk(chunk, geoEncoding, options) {
|
|
12908
13763
|
switch (geoEncoding) {
|
|
12909
13764
|
case "geoarrow.point":
|
|
12910
13765
|
case "geoarrow.multipoint":
|
|
@@ -12914,12 +13769,44 @@ return true;`);
|
|
|
12914
13769
|
return getBinaryLinesFromChunk(chunk, geoEncoding);
|
|
12915
13770
|
case "geoarrow.polygon":
|
|
12916
13771
|
case "geoarrow.multipolygon":
|
|
12917
|
-
return getBinaryPolygonsFromChunk(chunk, geoEncoding);
|
|
13772
|
+
return getBinaryPolygonsFromChunk(chunk, geoEncoding, options);
|
|
12918
13773
|
default:
|
|
12919
13774
|
throw Error("invalid geoarrow encoding");
|
|
12920
13775
|
}
|
|
12921
13776
|
}
|
|
12922
|
-
function
|
|
13777
|
+
function getTriangleIndices(polygonIndices, primitivePolygonIndices, flatCoordinateArray, nDim) {
|
|
13778
|
+
try {
|
|
13779
|
+
let primitiveIndex = 0;
|
|
13780
|
+
const triangles = [];
|
|
13781
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
13782
|
+
const startIdx = polygonIndices[i];
|
|
13783
|
+
const endIdx = polygonIndices[i + 1];
|
|
13784
|
+
const slicedFlatCoords = flatCoordinateArray.subarray(startIdx * nDim, endIdx * nDim);
|
|
13785
|
+
const holeIndices = [];
|
|
13786
|
+
while (primitivePolygonIndices[primitiveIndex] < endIdx) {
|
|
13787
|
+
if (primitivePolygonIndices[primitiveIndex] > startIdx) {
|
|
13788
|
+
holeIndices.push(primitivePolygonIndices[primitiveIndex] - startIdx);
|
|
13789
|
+
}
|
|
13790
|
+
primitiveIndex++;
|
|
13791
|
+
}
|
|
13792
|
+
const triangleIndices = earcut(slicedFlatCoords, holeIndices.length > 0 ? holeIndices : void 0, nDim);
|
|
13793
|
+
if (triangleIndices.length === 0) {
|
|
13794
|
+
throw Error("can not tesselate invalid polygon");
|
|
13795
|
+
}
|
|
13796
|
+
for (let j = 0; j < triangleIndices.length; j++) {
|
|
13797
|
+
triangles.push(triangleIndices[j] + startIdx);
|
|
13798
|
+
}
|
|
13799
|
+
}
|
|
13800
|
+
const trianglesUint32 = new Uint32Array(triangles.length);
|
|
13801
|
+
for (let i = 0; i < triangles.length; i++) {
|
|
13802
|
+
trianglesUint32[i] = triangles[i];
|
|
13803
|
+
}
|
|
13804
|
+
return trianglesUint32;
|
|
13805
|
+
} catch (error) {
|
|
13806
|
+
return null;
|
|
13807
|
+
}
|
|
13808
|
+
}
|
|
13809
|
+
function getBinaryPolygonsFromChunk(chunk, geoEncoding, options) {
|
|
12923
13810
|
const isMultiPolygon = geoEncoding === "geoarrow.multipolygon";
|
|
12924
13811
|
const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
|
|
12925
13812
|
const polygonOffset = polygonData.valueOffsets;
|
|
@@ -12943,98 +13830,788 @@ return true;`);
|
|
|
12943
13830
|
featureIds[j] = i;
|
|
12944
13831
|
}
|
|
12945
13832
|
}
|
|
13833
|
+
const triangles = options?.triangulate ? getTriangleIndices(geometryIndicies, geomOffset, flatCoordinateArray, nDim) : null;
|
|
13834
|
+
return {
|
|
13835
|
+
featureIds,
|
|
13836
|
+
flatCoordinateArray,
|
|
13837
|
+
nDim,
|
|
13838
|
+
geomOffset,
|
|
13839
|
+
geometryIndicies,
|
|
13840
|
+
...options?.triangulate && triangles ? {
|
|
13841
|
+
triangles
|
|
13842
|
+
} : {}
|
|
13843
|
+
};
|
|
13844
|
+
}
|
|
13845
|
+
function getBinaryLinesFromChunk(chunk, geoEncoding) {
|
|
13846
|
+
const isMultiLineString = geoEncoding === "geoarrow.multilinestring";
|
|
13847
|
+
const lineData = isMultiLineString ? chunk.children[0] : chunk;
|
|
13848
|
+
const pointData = lineData.children[0];
|
|
13849
|
+
const coordData = pointData.children[0];
|
|
13850
|
+
const nDim = pointData.stride;
|
|
13851
|
+
const geomOffset = lineData.valueOffsets;
|
|
13852
|
+
const flatCoordinateArray = coordData.values;
|
|
13853
|
+
const geometryIndicies = new Uint16Array(0);
|
|
13854
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
13855
|
+
const featureIds = new Uint32Array(numOfVertices);
|
|
13856
|
+
if (isMultiLineString) {
|
|
13857
|
+
const partData = chunk.valueOffsets;
|
|
13858
|
+
for (let i = 0; i < partData.length - 1; i++) {
|
|
13859
|
+
const startIdx = geomOffset[partData[i]];
|
|
13860
|
+
const endIdx = geomOffset[partData[i + 1]];
|
|
13861
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
13862
|
+
featureIds[j] = i;
|
|
13863
|
+
}
|
|
13864
|
+
}
|
|
13865
|
+
} else {
|
|
13866
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
13867
|
+
const startIdx = geomOffset[i];
|
|
13868
|
+
const endIdx = geomOffset[i + 1];
|
|
13869
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
13870
|
+
featureIds[j] = i;
|
|
13871
|
+
}
|
|
13872
|
+
}
|
|
13873
|
+
}
|
|
13874
|
+
return {
|
|
13875
|
+
featureIds,
|
|
13876
|
+
flatCoordinateArray,
|
|
13877
|
+
nDim,
|
|
13878
|
+
geomOffset,
|
|
13879
|
+
geometryIndicies
|
|
13880
|
+
};
|
|
13881
|
+
}
|
|
13882
|
+
function getBinaryPointsFromChunk(chunk, geoEncoding) {
|
|
13883
|
+
const isMultiPoint = geoEncoding === "geoarrow.multipoint";
|
|
13884
|
+
const pointData = isMultiPoint ? chunk.children[0] : chunk;
|
|
13885
|
+
const coordData = pointData.children[0];
|
|
13886
|
+
const nDim = pointData.stride;
|
|
13887
|
+
const flatCoordinateArray = coordData.values;
|
|
13888
|
+
const geometryIndicies = new Uint16Array(0);
|
|
13889
|
+
const geomOffset = new Int32Array(0);
|
|
13890
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
13891
|
+
const featureIds = new Uint32Array(numOfVertices);
|
|
13892
|
+
if (isMultiPoint) {
|
|
13893
|
+
const partData = chunk.valueOffsets;
|
|
13894
|
+
for (let i = 0; i < partData.length - 1; i++) {
|
|
13895
|
+
const startIdx = partData[i];
|
|
13896
|
+
const endIdx = partData[i + 1];
|
|
13897
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
13898
|
+
featureIds[j] = i;
|
|
13899
|
+
}
|
|
13900
|
+
}
|
|
13901
|
+
} else {
|
|
13902
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
13903
|
+
featureIds[i] = i;
|
|
13904
|
+
}
|
|
13905
|
+
}
|
|
13906
|
+
return {
|
|
13907
|
+
featureIds,
|
|
13908
|
+
flatCoordinateArray,
|
|
13909
|
+
nDim,
|
|
13910
|
+
geomOffset,
|
|
13911
|
+
geometryIndicies
|
|
13912
|
+
};
|
|
13913
|
+
}
|
|
13914
|
+
|
|
13915
|
+
// ../wkt/src/lib/utils/version.ts
|
|
13916
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
13917
|
+
|
|
13918
|
+
// ../wkt/src/lib/parse-wkt.ts
|
|
13919
|
+
var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
|
|
13920
|
+
var tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
|
|
13921
|
+
var WKT_MAGIC_STRINGS = ["POINT(", "LINESTRING(", "POLYGON(", "MULTIPOINT(", "MULTILINESTRING(", "MULTIPOLYGON(", "GEOMETRYCOLLECTION("];
|
|
13922
|
+
function isWKT(input) {
|
|
13923
|
+
return WKT_MAGIC_STRINGS.some((magicString) => input.startsWith(magicString));
|
|
13924
|
+
}
|
|
13925
|
+
function parseWKT(input, options) {
|
|
13926
|
+
return parseWKTToGeometry(input, options);
|
|
13927
|
+
}
|
|
13928
|
+
function parseWKTToGeometry(input, options) {
|
|
13929
|
+
const parts = input.split(";");
|
|
13930
|
+
let _ = parts.pop();
|
|
13931
|
+
const srid = (parts.shift() || "").split("=").pop();
|
|
13932
|
+
const state = {
|
|
13933
|
+
parts,
|
|
13934
|
+
_,
|
|
13935
|
+
i: 0
|
|
13936
|
+
};
|
|
13937
|
+
const geometry = parseGeometry(state);
|
|
13938
|
+
return options?.wkt?.crs ? addCRS(geometry, srid) : geometry;
|
|
13939
|
+
}
|
|
13940
|
+
function parseGeometry(state) {
|
|
13941
|
+
return parsePoint(state) || parseLineString(state) || parsePolygon(state) || parseMultiPoint(state) || parseMultiLineString(state) || parseMultiPolygon(state) || parseGeometryCollection(state);
|
|
13942
|
+
}
|
|
13943
|
+
function addCRS(obj, srid) {
|
|
13944
|
+
if (obj && srid?.match(/\d+/)) {
|
|
13945
|
+
const crs = {
|
|
13946
|
+
type: "name",
|
|
13947
|
+
properties: {
|
|
13948
|
+
name: "urn:ogc:def:crs:EPSG::" + srid
|
|
13949
|
+
}
|
|
13950
|
+
};
|
|
13951
|
+
obj.crs = crs;
|
|
13952
|
+
}
|
|
13953
|
+
return obj;
|
|
13954
|
+
}
|
|
13955
|
+
function parsePoint(state) {
|
|
13956
|
+
if (!$(/^(POINT(\sz)?)/i, state)) {
|
|
13957
|
+
return null;
|
|
13958
|
+
}
|
|
13959
|
+
white(state);
|
|
13960
|
+
if (!$(/^(\()/, state)) {
|
|
13961
|
+
return null;
|
|
13962
|
+
}
|
|
13963
|
+
const c = coords(state);
|
|
13964
|
+
if (!c) {
|
|
13965
|
+
return null;
|
|
13966
|
+
}
|
|
13967
|
+
white(state);
|
|
13968
|
+
if (!$(/^(\))/, state)) {
|
|
13969
|
+
return null;
|
|
13970
|
+
}
|
|
13971
|
+
return {
|
|
13972
|
+
type: "Point",
|
|
13973
|
+
coordinates: c[0]
|
|
13974
|
+
};
|
|
13975
|
+
}
|
|
13976
|
+
function parseMultiPoint(state) {
|
|
13977
|
+
if (!$(/^(MULTIPOINT)/i, state)) {
|
|
13978
|
+
return null;
|
|
13979
|
+
}
|
|
13980
|
+
white(state);
|
|
13981
|
+
const newCoordsFormat = state._?.substring(state._?.indexOf("(") + 1, state._.length - 1).replace(/\(/g, "").replace(/\)/g, "");
|
|
13982
|
+
state._ = "MULTIPOINT (" + newCoordsFormat + ")";
|
|
13983
|
+
const c = multicoords(state);
|
|
13984
|
+
if (!c) {
|
|
13985
|
+
return null;
|
|
13986
|
+
}
|
|
13987
|
+
white(state);
|
|
13988
|
+
return {
|
|
13989
|
+
type: "MultiPoint",
|
|
13990
|
+
coordinates: c
|
|
13991
|
+
};
|
|
13992
|
+
}
|
|
13993
|
+
function parseLineString(state) {
|
|
13994
|
+
if (!$(/^(LINESTRING(\sz)?)/i, state)) {
|
|
13995
|
+
return null;
|
|
13996
|
+
}
|
|
13997
|
+
white(state);
|
|
13998
|
+
if (!$(/^(\()/, state)) {
|
|
13999
|
+
return null;
|
|
14000
|
+
}
|
|
14001
|
+
const c = coords(state);
|
|
14002
|
+
if (!c) {
|
|
14003
|
+
return null;
|
|
14004
|
+
}
|
|
14005
|
+
if (!$(/^(\))/, state)) {
|
|
14006
|
+
return null;
|
|
14007
|
+
}
|
|
14008
|
+
return {
|
|
14009
|
+
type: "LineString",
|
|
14010
|
+
coordinates: c
|
|
14011
|
+
};
|
|
14012
|
+
}
|
|
14013
|
+
function parseMultiLineString(state) {
|
|
14014
|
+
if (!$(/^(MULTILINESTRING)/i, state))
|
|
14015
|
+
return null;
|
|
14016
|
+
white(state);
|
|
14017
|
+
const c = multicoords(state);
|
|
14018
|
+
if (!c) {
|
|
14019
|
+
return null;
|
|
14020
|
+
}
|
|
14021
|
+
white(state);
|
|
14022
|
+
return {
|
|
14023
|
+
type: "MultiLineString",
|
|
14024
|
+
coordinates: c
|
|
14025
|
+
};
|
|
14026
|
+
}
|
|
14027
|
+
function parsePolygon(state) {
|
|
14028
|
+
if (!$(/^(POLYGON(\sz)?)/i, state)) {
|
|
14029
|
+
return null;
|
|
14030
|
+
}
|
|
14031
|
+
white(state);
|
|
14032
|
+
const c = multicoords(state);
|
|
14033
|
+
if (!c) {
|
|
14034
|
+
return null;
|
|
14035
|
+
}
|
|
14036
|
+
return {
|
|
14037
|
+
type: "Polygon",
|
|
14038
|
+
coordinates: c
|
|
14039
|
+
};
|
|
14040
|
+
}
|
|
14041
|
+
function parseMultiPolygon(state) {
|
|
14042
|
+
if (!$(/^(MULTIPOLYGON)/i, state)) {
|
|
14043
|
+
return null;
|
|
14044
|
+
}
|
|
14045
|
+
white(state);
|
|
14046
|
+
const c = multicoords(state);
|
|
14047
|
+
if (!c) {
|
|
14048
|
+
return null;
|
|
14049
|
+
}
|
|
14050
|
+
return {
|
|
14051
|
+
type: "MultiPolygon",
|
|
14052
|
+
coordinates: c
|
|
14053
|
+
};
|
|
14054
|
+
}
|
|
14055
|
+
function parseGeometryCollection(state) {
|
|
14056
|
+
const geometries = [];
|
|
14057
|
+
let geometry;
|
|
14058
|
+
if (!$(/^(GEOMETRYCOLLECTION)/i, state)) {
|
|
14059
|
+
return null;
|
|
14060
|
+
}
|
|
14061
|
+
white(state);
|
|
14062
|
+
if (!$(/^(\()/, state)) {
|
|
14063
|
+
return null;
|
|
14064
|
+
}
|
|
14065
|
+
while (geometry = parseGeometry(state)) {
|
|
14066
|
+
geometries.push(geometry);
|
|
14067
|
+
white(state);
|
|
14068
|
+
$(/^(,)/, state);
|
|
14069
|
+
white(state);
|
|
14070
|
+
}
|
|
14071
|
+
if (!$(/^(\))/, state)) {
|
|
14072
|
+
return null;
|
|
14073
|
+
}
|
|
14074
|
+
return {
|
|
14075
|
+
type: "GeometryCollection",
|
|
14076
|
+
geometries
|
|
14077
|
+
};
|
|
14078
|
+
}
|
|
14079
|
+
function multicoords(state) {
|
|
14080
|
+
white(state);
|
|
14081
|
+
let depth = 0;
|
|
14082
|
+
const rings = [];
|
|
14083
|
+
const stack = [rings];
|
|
14084
|
+
let pointer = rings;
|
|
14085
|
+
let elem;
|
|
14086
|
+
while (elem = $(/^(\()/, state) || $(/^(\))/, state) || $(/^(,)/, state) || $(tuples, state)) {
|
|
14087
|
+
if (elem === "(") {
|
|
14088
|
+
stack.push(pointer);
|
|
14089
|
+
pointer = [];
|
|
14090
|
+
stack[stack.length - 1].push(pointer);
|
|
14091
|
+
depth++;
|
|
14092
|
+
} else if (elem === ")") {
|
|
14093
|
+
if (pointer.length === 0)
|
|
14094
|
+
return null;
|
|
14095
|
+
pointer = stack.pop();
|
|
14096
|
+
if (!pointer)
|
|
14097
|
+
return null;
|
|
14098
|
+
depth--;
|
|
14099
|
+
if (depth === 0)
|
|
14100
|
+
break;
|
|
14101
|
+
} else if (elem === ",") {
|
|
14102
|
+
pointer = [];
|
|
14103
|
+
stack[stack.length - 1].push(pointer);
|
|
14104
|
+
} else if (!elem.split(/\s/g).some(isNaN)) {
|
|
14105
|
+
Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
|
|
14106
|
+
} else {
|
|
14107
|
+
return null;
|
|
14108
|
+
}
|
|
14109
|
+
white(state);
|
|
14110
|
+
}
|
|
14111
|
+
if (depth !== 0)
|
|
14112
|
+
return null;
|
|
14113
|
+
return rings;
|
|
14114
|
+
}
|
|
14115
|
+
function coords(state) {
|
|
14116
|
+
const list = [];
|
|
14117
|
+
let item;
|
|
14118
|
+
let pt;
|
|
14119
|
+
while (pt = $(tuples, state) || $(/^(,)/, state)) {
|
|
14120
|
+
if (pt === ",") {
|
|
14121
|
+
list.push(item);
|
|
14122
|
+
item = [];
|
|
14123
|
+
} else if (!pt.split(/\s/g).some(isNaN)) {
|
|
14124
|
+
if (!item)
|
|
14125
|
+
item = [];
|
|
14126
|
+
Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
|
|
14127
|
+
}
|
|
14128
|
+
white(state);
|
|
14129
|
+
}
|
|
14130
|
+
if (item)
|
|
14131
|
+
list.push(item);
|
|
14132
|
+
else
|
|
14133
|
+
return null;
|
|
14134
|
+
return list.length ? list : null;
|
|
14135
|
+
}
|
|
14136
|
+
function $(regexp, state) {
|
|
14137
|
+
const match = state._?.substring(state.i).match(regexp);
|
|
14138
|
+
if (!match)
|
|
14139
|
+
return null;
|
|
14140
|
+
else {
|
|
14141
|
+
state.i += match[0].length;
|
|
14142
|
+
return match[0];
|
|
14143
|
+
}
|
|
14144
|
+
}
|
|
14145
|
+
function white(state) {
|
|
14146
|
+
$(/^\s*/, state);
|
|
14147
|
+
}
|
|
14148
|
+
|
|
14149
|
+
// ../wkt/src/wkt-loader.ts
|
|
14150
|
+
var WKTWorkerLoader = {
|
|
14151
|
+
name: "WKT (Well-Known Text)",
|
|
14152
|
+
id: "wkt",
|
|
14153
|
+
module: "wkt",
|
|
14154
|
+
version: VERSION3,
|
|
14155
|
+
worker: true,
|
|
14156
|
+
extensions: ["wkt"],
|
|
14157
|
+
mimeTypes: ["text/plain"],
|
|
14158
|
+
category: "geometry",
|
|
14159
|
+
text: true,
|
|
14160
|
+
tests: WKT_MAGIC_STRINGS,
|
|
14161
|
+
testText: isWKT,
|
|
14162
|
+
options: {
|
|
14163
|
+
wkt: {
|
|
14164
|
+
shape: "geojson-geometry",
|
|
14165
|
+
crs: true
|
|
14166
|
+
}
|
|
14167
|
+
}
|
|
14168
|
+
};
|
|
14169
|
+
var WKTLoader = {
|
|
14170
|
+
...WKTWorkerLoader,
|
|
14171
|
+
parse: async (arrayBuffer, options) => parseWKT(new TextDecoder().decode(arrayBuffer), options),
|
|
14172
|
+
parseTextSync: parseWKT
|
|
14173
|
+
};
|
|
14174
|
+
|
|
14175
|
+
// ../wkt/src/lib/parse-wkb-header.ts
|
|
14176
|
+
var EWKB_FLAG_Z = 2147483648;
|
|
14177
|
+
var EWKB_FLAG_M = 1073741824;
|
|
14178
|
+
var EWKB_FLAG_SRID = 536870912;
|
|
14179
|
+
var MAX_SRID = 1e4;
|
|
14180
|
+
var WKBGeometryType = function(WKBGeometryType2) {
|
|
14181
|
+
WKBGeometryType2[WKBGeometryType2["Point"] = 1] = "Point";
|
|
14182
|
+
WKBGeometryType2[WKBGeometryType2["LineString"] = 2] = "LineString";
|
|
14183
|
+
WKBGeometryType2[WKBGeometryType2["Polygon"] = 3] = "Polygon";
|
|
14184
|
+
WKBGeometryType2[WKBGeometryType2["MultiPoint"] = 4] = "MultiPoint";
|
|
14185
|
+
WKBGeometryType2[WKBGeometryType2["MultiLineString"] = 5] = "MultiLineString";
|
|
14186
|
+
WKBGeometryType2[WKBGeometryType2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
14187
|
+
WKBGeometryType2[WKBGeometryType2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
14188
|
+
return WKBGeometryType2;
|
|
14189
|
+
}({});
|
|
14190
|
+
function isWKB(arrayBuffer) {
|
|
14191
|
+
const dataView = new DataView(arrayBuffer);
|
|
14192
|
+
let byteOffset = 0;
|
|
14193
|
+
const endianness = dataView.getUint8(byteOffset);
|
|
14194
|
+
byteOffset += 1;
|
|
14195
|
+
if (endianness > 1) {
|
|
14196
|
+
return false;
|
|
14197
|
+
}
|
|
14198
|
+
const littleEndian = endianness === 1;
|
|
14199
|
+
const geometry = dataView.getUint32(byteOffset, littleEndian);
|
|
14200
|
+
byteOffset += 4;
|
|
14201
|
+
const geometryType = geometry & 7;
|
|
14202
|
+
if (geometryType === 0 || geometryType > 7) {
|
|
14203
|
+
return false;
|
|
14204
|
+
}
|
|
14205
|
+
const geometryFlags = geometry - geometryType;
|
|
14206
|
+
if (geometryFlags === 0 || geometryFlags === 1e3 || geometryFlags === 2e3 || geometryFlags === 3e3) {
|
|
14207
|
+
return true;
|
|
14208
|
+
}
|
|
14209
|
+
if ((geometryFlags & ~(EWKB_FLAG_Z | EWKB_FLAG_M | EWKB_FLAG_SRID)) !== 0) {
|
|
14210
|
+
return false;
|
|
14211
|
+
}
|
|
14212
|
+
if (geometryFlags & EWKB_FLAG_SRID) {
|
|
14213
|
+
const srid = dataView.getUint32(byteOffset, littleEndian);
|
|
14214
|
+
byteOffset += 4;
|
|
14215
|
+
if (srid > MAX_SRID) {
|
|
14216
|
+
return false;
|
|
14217
|
+
}
|
|
14218
|
+
}
|
|
14219
|
+
return true;
|
|
14220
|
+
}
|
|
14221
|
+
function parseWKBHeader(dataView, target) {
|
|
14222
|
+
const wkbHeader = Object.assign(target || {}, {
|
|
14223
|
+
type: "wkb",
|
|
14224
|
+
geometryType: 1,
|
|
14225
|
+
dimensions: 2,
|
|
14226
|
+
coordinates: "xy",
|
|
14227
|
+
littleEndian: true,
|
|
14228
|
+
byteOffset: 0
|
|
14229
|
+
});
|
|
14230
|
+
wkbHeader.littleEndian = dataView.getUint8(wkbHeader.byteOffset) === 1;
|
|
14231
|
+
wkbHeader.byteOffset++;
|
|
14232
|
+
const geometryCode = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
14233
|
+
wkbHeader.byteOffset += 4;
|
|
14234
|
+
wkbHeader.geometryType = geometryCode & 7;
|
|
14235
|
+
const isoType = (geometryCode - wkbHeader.geometryType) / 1e3;
|
|
14236
|
+
switch (isoType) {
|
|
14237
|
+
case 0:
|
|
14238
|
+
break;
|
|
14239
|
+
case 1:
|
|
14240
|
+
wkbHeader.type = "iso-wkb";
|
|
14241
|
+
wkbHeader.dimensions = 3;
|
|
14242
|
+
wkbHeader.coordinates = "xyz";
|
|
14243
|
+
break;
|
|
14244
|
+
case 2:
|
|
14245
|
+
wkbHeader.type = "iso-wkb";
|
|
14246
|
+
wkbHeader.dimensions = 3;
|
|
14247
|
+
wkbHeader.coordinates = "xym";
|
|
14248
|
+
break;
|
|
14249
|
+
case 3:
|
|
14250
|
+
wkbHeader.type = "iso-wkb";
|
|
14251
|
+
wkbHeader.dimensions = 4;
|
|
14252
|
+
wkbHeader.coordinates = "xyzm";
|
|
14253
|
+
break;
|
|
14254
|
+
default:
|
|
14255
|
+
throw new Error(`WKB: Unsupported iso-wkb type: ${isoType}`);
|
|
14256
|
+
}
|
|
14257
|
+
const ewkbZ = geometryCode & EWKB_FLAG_Z;
|
|
14258
|
+
const ewkbM = geometryCode & EWKB_FLAG_M;
|
|
14259
|
+
const ewkbSRID = geometryCode & EWKB_FLAG_SRID;
|
|
14260
|
+
if (ewkbZ && ewkbM) {
|
|
14261
|
+
wkbHeader.type = "ewkb";
|
|
14262
|
+
wkbHeader.dimensions = 4;
|
|
14263
|
+
wkbHeader.coordinates = "xyzm";
|
|
14264
|
+
} else if (ewkbZ) {
|
|
14265
|
+
wkbHeader.type = "ewkb";
|
|
14266
|
+
wkbHeader.dimensions = 3;
|
|
14267
|
+
wkbHeader.coordinates = "xyz";
|
|
14268
|
+
} else if (ewkbM) {
|
|
14269
|
+
wkbHeader.type = "ewkb";
|
|
14270
|
+
wkbHeader.dimensions = 3;
|
|
14271
|
+
wkbHeader.coordinates = "xym";
|
|
14272
|
+
}
|
|
14273
|
+
if (ewkbSRID) {
|
|
14274
|
+
wkbHeader.type = "ewkb";
|
|
14275
|
+
wkbHeader.srid = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
14276
|
+
wkbHeader.byteOffset += 4;
|
|
14277
|
+
}
|
|
14278
|
+
return wkbHeader;
|
|
14279
|
+
}
|
|
14280
|
+
|
|
14281
|
+
// ../wkt/src/lib/parse-wkb.ts
|
|
14282
|
+
function parseWKB(arrayBuffer, options) {
|
|
14283
|
+
const binaryGeometry = parseWKBToBinary(arrayBuffer, options);
|
|
14284
|
+
const shape = options?.wkb?.shape || "binary-geometry";
|
|
14285
|
+
switch (shape) {
|
|
14286
|
+
case "binary-geometry":
|
|
14287
|
+
return binaryGeometry;
|
|
14288
|
+
case "geojson-geometry":
|
|
14289
|
+
return binaryToGeometry(binaryGeometry);
|
|
14290
|
+
case "geometry":
|
|
14291
|
+
console.error('WKBLoader: "geometry" shape is deprecated, use "binary-geometry" instead');
|
|
14292
|
+
return binaryToGeometry(binaryGeometry);
|
|
14293
|
+
default:
|
|
14294
|
+
throw new Error(shape);
|
|
14295
|
+
}
|
|
14296
|
+
}
|
|
14297
|
+
function parseWKBToBinary(arrayBuffer, options) {
|
|
14298
|
+
const dataView = new DataView(arrayBuffer);
|
|
14299
|
+
const wkbHeader = parseWKBHeader(dataView);
|
|
14300
|
+
const {
|
|
14301
|
+
geometryType,
|
|
14302
|
+
dimensions,
|
|
14303
|
+
littleEndian
|
|
14304
|
+
} = wkbHeader;
|
|
14305
|
+
const offset = wkbHeader.byteOffset;
|
|
14306
|
+
switch (geometryType) {
|
|
14307
|
+
case WKBGeometryType.Point:
|
|
14308
|
+
const point = parsePoint2(dataView, offset, dimensions, littleEndian);
|
|
14309
|
+
return point.geometry;
|
|
14310
|
+
case WKBGeometryType.LineString:
|
|
14311
|
+
const line = parseLineString2(dataView, offset, dimensions, littleEndian);
|
|
14312
|
+
return line.geometry;
|
|
14313
|
+
case WKBGeometryType.Polygon:
|
|
14314
|
+
const polygon = parsePolygon2(dataView, offset, dimensions, littleEndian);
|
|
14315
|
+
return polygon.geometry;
|
|
14316
|
+
case WKBGeometryType.MultiPoint:
|
|
14317
|
+
const multiPoint = parseMultiPoint2(dataView, offset, dimensions, littleEndian);
|
|
14318
|
+
multiPoint.type = "Point";
|
|
14319
|
+
return multiPoint;
|
|
14320
|
+
case WKBGeometryType.MultiLineString:
|
|
14321
|
+
const multiLine = parseMultiLineString2(dataView, offset, dimensions, littleEndian);
|
|
14322
|
+
multiLine.type = "LineString";
|
|
14323
|
+
return multiLine;
|
|
14324
|
+
case WKBGeometryType.MultiPolygon:
|
|
14325
|
+
const multiPolygon = parseMultiPolygon2(dataView, offset, dimensions, littleEndian);
|
|
14326
|
+
multiPolygon.type = "Polygon";
|
|
14327
|
+
return multiPolygon;
|
|
14328
|
+
default:
|
|
14329
|
+
throw new Error(`WKB: Unsupported geometry type: ${geometryType}`);
|
|
14330
|
+
}
|
|
14331
|
+
}
|
|
14332
|
+
function parsePoint2(dataView, offset, dimension, littleEndian) {
|
|
14333
|
+
const positions = new Float64Array(dimension);
|
|
14334
|
+
for (let i = 0; i < dimension; i++) {
|
|
14335
|
+
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
14336
|
+
offset += 8;
|
|
14337
|
+
}
|
|
14338
|
+
return {
|
|
14339
|
+
geometry: {
|
|
14340
|
+
type: "Point",
|
|
14341
|
+
positions: {
|
|
14342
|
+
value: positions,
|
|
14343
|
+
size: dimension
|
|
14344
|
+
}
|
|
14345
|
+
},
|
|
14346
|
+
offset
|
|
14347
|
+
};
|
|
14348
|
+
}
|
|
14349
|
+
function parseLineString2(dataView, offset, dimension, littleEndian) {
|
|
14350
|
+
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
14351
|
+
offset += 4;
|
|
14352
|
+
const positions = new Float64Array(nPoints * dimension);
|
|
14353
|
+
for (let i = 0; i < nPoints * dimension; i++) {
|
|
14354
|
+
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
14355
|
+
offset += 8;
|
|
14356
|
+
}
|
|
14357
|
+
const pathIndices = [0];
|
|
14358
|
+
if (nPoints > 0) {
|
|
14359
|
+
pathIndices.push(nPoints);
|
|
14360
|
+
}
|
|
12946
14361
|
return {
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
14362
|
+
geometry: {
|
|
14363
|
+
type: "LineString",
|
|
14364
|
+
positions: {
|
|
14365
|
+
value: positions,
|
|
14366
|
+
size: dimension
|
|
14367
|
+
},
|
|
14368
|
+
pathIndices: {
|
|
14369
|
+
value: new Uint16Array(pathIndices),
|
|
14370
|
+
size: 1
|
|
14371
|
+
}
|
|
14372
|
+
},
|
|
14373
|
+
offset
|
|
12952
14374
|
};
|
|
12953
14375
|
}
|
|
12954
|
-
|
|
12955
|
-
|
|
12956
|
-
const
|
|
12957
|
-
|
|
12958
|
-
const
|
|
12959
|
-
|
|
12960
|
-
|
|
12961
|
-
|
|
12962
|
-
|
|
12963
|
-
|
|
12964
|
-
|
|
12965
|
-
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
|
|
14376
|
+
var cumulativeSum = (sum2) => (value) => sum2 += value;
|
|
14377
|
+
function parsePolygon2(dataView, offset, dimension, littleEndian) {
|
|
14378
|
+
const nRings = dataView.getUint32(offset, littleEndian);
|
|
14379
|
+
offset += 4;
|
|
14380
|
+
const rings = [];
|
|
14381
|
+
for (let i = 0; i < nRings; i++) {
|
|
14382
|
+
const parsed = parseLineString2(dataView, offset, dimension, littleEndian);
|
|
14383
|
+
const {
|
|
14384
|
+
positions
|
|
14385
|
+
} = parsed.geometry;
|
|
14386
|
+
offset = parsed.offset;
|
|
14387
|
+
rings.push(positions.value);
|
|
14388
|
+
}
|
|
14389
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(rings).buffer);
|
|
14390
|
+
const polygonIndices = [0];
|
|
14391
|
+
if (concatenatedPositions.length > 0) {
|
|
14392
|
+
polygonIndices.push(concatenatedPositions.length / dimension);
|
|
14393
|
+
}
|
|
14394
|
+
const primitivePolygonIndices = rings.map((l) => l.length / dimension).map(cumulativeSum(0));
|
|
14395
|
+
primitivePolygonIndices.unshift(0);
|
|
14396
|
+
return {
|
|
14397
|
+
geometry: {
|
|
14398
|
+
type: "Polygon",
|
|
14399
|
+
positions: {
|
|
14400
|
+
value: concatenatedPositions,
|
|
14401
|
+
size: dimension
|
|
14402
|
+
},
|
|
14403
|
+
polygonIndices: {
|
|
14404
|
+
value: new Uint16Array(polygonIndices),
|
|
14405
|
+
size: 1
|
|
14406
|
+
},
|
|
14407
|
+
primitivePolygonIndices: {
|
|
14408
|
+
value: new Uint16Array(primitivePolygonIndices),
|
|
14409
|
+
size: 1
|
|
14410
|
+
}
|
|
14411
|
+
},
|
|
14412
|
+
offset
|
|
14413
|
+
};
|
|
14414
|
+
}
|
|
14415
|
+
function parseMultiPoint2(dataView, offset, dimension, littleEndian) {
|
|
14416
|
+
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
14417
|
+
offset += 4;
|
|
14418
|
+
const binaryPointGeometries = [];
|
|
14419
|
+
for (let i = 0; i < nPoints; i++) {
|
|
14420
|
+
const littleEndianPoint = dataView.getUint8(offset) === 1;
|
|
14421
|
+
offset++;
|
|
14422
|
+
if (dataView.getUint32(offset, littleEndianPoint) % 1e3 !== 1) {
|
|
14423
|
+
throw new Error("WKB: Inner geometries of MultiPoint not of type Point");
|
|
14424
|
+
}
|
|
14425
|
+
offset += 4;
|
|
14426
|
+
const parsed = parsePoint2(dataView, offset, dimension, littleEndianPoint);
|
|
14427
|
+
offset = parsed.offset;
|
|
14428
|
+
binaryPointGeometries.push(parsed.geometry);
|
|
14429
|
+
}
|
|
14430
|
+
return concatenateBinaryPointGeometries(binaryPointGeometries, dimension);
|
|
14431
|
+
}
|
|
14432
|
+
function parseMultiLineString2(dataView, offset, dimension, littleEndian) {
|
|
14433
|
+
const nLines = dataView.getUint32(offset, littleEndian);
|
|
14434
|
+
offset += 4;
|
|
14435
|
+
const binaryLineGeometries = [];
|
|
14436
|
+
for (let i = 0; i < nLines; i++) {
|
|
14437
|
+
const littleEndianLine = dataView.getUint8(offset) === 1;
|
|
14438
|
+
offset++;
|
|
14439
|
+
if (dataView.getUint32(offset, littleEndianLine) % 1e3 !== 2) {
|
|
14440
|
+
throw new Error("WKB: Inner geometries of MultiLineString not of type LineString");
|
|
14441
|
+
}
|
|
14442
|
+
offset += 4;
|
|
14443
|
+
const parsed = parseLineString2(dataView, offset, dimension, littleEndianLine);
|
|
14444
|
+
offset = parsed.offset;
|
|
14445
|
+
binaryLineGeometries.push(parsed.geometry);
|
|
14446
|
+
}
|
|
14447
|
+
return concatenateBinaryLineGeometries(binaryLineGeometries, dimension);
|
|
14448
|
+
}
|
|
14449
|
+
function parseMultiPolygon2(dataView, offset, dimension, littleEndian) {
|
|
14450
|
+
const nPolygons = dataView.getUint32(offset, littleEndian);
|
|
14451
|
+
offset += 4;
|
|
14452
|
+
const binaryPolygonGeometries = [];
|
|
14453
|
+
for (let i = 0; i < nPolygons; i++) {
|
|
14454
|
+
const littleEndianPolygon = dataView.getUint8(offset) === 1;
|
|
14455
|
+
offset++;
|
|
14456
|
+
if (dataView.getUint32(offset, littleEndianPolygon) % 1e3 !== 3) {
|
|
14457
|
+
throw new Error("WKB: Inner geometries of MultiPolygon not of type Polygon");
|
|
14458
|
+
}
|
|
14459
|
+
offset += 4;
|
|
14460
|
+
const parsed = parsePolygon2(dataView, offset, dimension, littleEndianPolygon);
|
|
14461
|
+
offset = parsed.offset;
|
|
14462
|
+
binaryPolygonGeometries.push(parsed.geometry);
|
|
14463
|
+
}
|
|
14464
|
+
return concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension);
|
|
14465
|
+
}
|
|
14466
|
+
function concatenateBinaryPointGeometries(binaryPointGeometries, dimension) {
|
|
14467
|
+
const positions = binaryPointGeometries.map((geometry) => geometry.positions.value);
|
|
14468
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
|
|
14469
|
+
return {
|
|
14470
|
+
type: "Point",
|
|
14471
|
+
positions: {
|
|
14472
|
+
value: concatenatedPositions,
|
|
14473
|
+
size: dimension
|
|
12970
14474
|
}
|
|
12971
|
-
}
|
|
14475
|
+
};
|
|
14476
|
+
}
|
|
14477
|
+
function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
|
|
14478
|
+
const lines = binaryLineGeometries.map((geometry) => geometry.positions.value);
|
|
14479
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
|
|
14480
|
+
const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
|
|
14481
|
+
pathIndices.unshift(0);
|
|
12972
14482
|
return {
|
|
12973
|
-
|
|
12974
|
-
|
|
12975
|
-
|
|
12976
|
-
|
|
12977
|
-
|
|
14483
|
+
type: "LineString",
|
|
14484
|
+
positions: {
|
|
14485
|
+
value: concatenatedPositions,
|
|
14486
|
+
size: dimension
|
|
14487
|
+
},
|
|
14488
|
+
pathIndices: {
|
|
14489
|
+
value: new Uint16Array(pathIndices),
|
|
14490
|
+
size: 1
|
|
14491
|
+
}
|
|
12978
14492
|
};
|
|
12979
14493
|
}
|
|
12980
|
-
function
|
|
12981
|
-
const
|
|
12982
|
-
const
|
|
12983
|
-
const
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
|
|
14494
|
+
function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
|
|
14495
|
+
const polygons = [];
|
|
14496
|
+
const primitivePolygons = [];
|
|
14497
|
+
for (const binaryPolygon of binaryPolygonGeometries) {
|
|
14498
|
+
const {
|
|
14499
|
+
positions,
|
|
14500
|
+
primitivePolygonIndices: primitivePolygonIndices2
|
|
14501
|
+
} = binaryPolygon;
|
|
14502
|
+
polygons.push(positions.value);
|
|
14503
|
+
primitivePolygons.push(primitivePolygonIndices2.value);
|
|
14504
|
+
}
|
|
14505
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
|
|
14506
|
+
const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
|
|
14507
|
+
polygonIndices.unshift(0);
|
|
14508
|
+
const primitivePolygonIndices = [0];
|
|
14509
|
+
for (const primitivePolygon of primitivePolygons) {
|
|
14510
|
+
primitivePolygonIndices.push(...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
|
|
12992
14511
|
}
|
|
12993
14512
|
return {
|
|
12994
|
-
|
|
12995
|
-
|
|
12996
|
-
|
|
12997
|
-
|
|
12998
|
-
|
|
14513
|
+
type: "Polygon",
|
|
14514
|
+
positions: {
|
|
14515
|
+
value: concatenatedPositions,
|
|
14516
|
+
size: dimension
|
|
14517
|
+
},
|
|
14518
|
+
polygonIndices: {
|
|
14519
|
+
value: new Uint16Array(polygonIndices),
|
|
14520
|
+
size: 1
|
|
14521
|
+
},
|
|
14522
|
+
primitivePolygonIndices: {
|
|
14523
|
+
value: new Uint16Array(primitivePolygonIndices),
|
|
14524
|
+
size: 1
|
|
14525
|
+
}
|
|
12999
14526
|
};
|
|
13000
14527
|
}
|
|
14528
|
+
function concatTypedArrays(arrays) {
|
|
14529
|
+
let byteLength = 0;
|
|
14530
|
+
for (let i = 0; i < arrays.length; ++i) {
|
|
14531
|
+
byteLength += arrays[i].byteLength;
|
|
14532
|
+
}
|
|
14533
|
+
const buffer = new Uint8Array(byteLength);
|
|
14534
|
+
let byteOffset = 0;
|
|
14535
|
+
for (let i = 0; i < arrays.length; ++i) {
|
|
14536
|
+
const data = new Uint8Array(arrays[i].buffer);
|
|
14537
|
+
byteLength = data.length;
|
|
14538
|
+
for (let j = 0; j < byteLength; ++j) {
|
|
14539
|
+
buffer[byteOffset++] = data[j];
|
|
14540
|
+
}
|
|
14541
|
+
}
|
|
14542
|
+
return buffer;
|
|
14543
|
+
}
|
|
14544
|
+
|
|
14545
|
+
// ../wkt/src/wkb-loader.ts
|
|
14546
|
+
var WKBWorkerLoader = {
|
|
14547
|
+
name: "WKB",
|
|
14548
|
+
id: "wkb",
|
|
14549
|
+
module: "wkt",
|
|
14550
|
+
version: VERSION3,
|
|
14551
|
+
worker: true,
|
|
14552
|
+
category: "geometry",
|
|
14553
|
+
extensions: ["wkb"],
|
|
14554
|
+
mimeTypes: [],
|
|
14555
|
+
tests: [isWKB],
|
|
14556
|
+
options: {
|
|
14557
|
+
wkb: {
|
|
14558
|
+
shape: "binary-geometry"
|
|
14559
|
+
}
|
|
14560
|
+
}
|
|
14561
|
+
};
|
|
14562
|
+
var WKBLoader = {
|
|
14563
|
+
...WKBWorkerLoader,
|
|
14564
|
+
parse: async (arrayBuffer) => parseWKB(arrayBuffer),
|
|
14565
|
+
parseSync: parseWKB
|
|
14566
|
+
};
|
|
13001
14567
|
|
|
13002
|
-
// src/geoarrow/convert-geoarrow-to-geojson.ts
|
|
13003
|
-
function parseGeometryFromArrow(
|
|
13004
|
-
|
|
13005
|
-
|
|
13006
|
-
if (!encoding || !data) {
|
|
14568
|
+
// src/geoarrow/convert-geoarrow-to-geojson-geometry.ts
|
|
14569
|
+
function parseGeometryFromArrow(arrowCellValue, encoding) {
|
|
14570
|
+
encoding = encoding?.toLowerCase();
|
|
14571
|
+
if (!encoding || !arrowCellValue) {
|
|
13007
14572
|
return null;
|
|
13008
14573
|
}
|
|
13009
14574
|
let geometry;
|
|
13010
14575
|
switch (encoding) {
|
|
13011
14576
|
case "geoarrow.multipolygon":
|
|
13012
|
-
geometry = arrowMultiPolygonToFeature(
|
|
14577
|
+
geometry = arrowMultiPolygonToFeature(arrowCellValue);
|
|
13013
14578
|
break;
|
|
13014
14579
|
case "geoarrow.polygon":
|
|
13015
|
-
geometry = arrowPolygonToFeature(
|
|
14580
|
+
geometry = arrowPolygonToFeature(arrowCellValue);
|
|
13016
14581
|
break;
|
|
13017
14582
|
case "geoarrow.multipoint":
|
|
13018
|
-
geometry = arrowMultiPointToFeature(
|
|
14583
|
+
geometry = arrowMultiPointToFeature(arrowCellValue);
|
|
13019
14584
|
break;
|
|
13020
14585
|
case "geoarrow.point":
|
|
13021
|
-
geometry = arrowPointToFeature(
|
|
14586
|
+
geometry = arrowPointToFeature(arrowCellValue);
|
|
13022
14587
|
break;
|
|
13023
14588
|
case "geoarrow.multilinestring":
|
|
13024
|
-
geometry = arrowMultiLineStringToFeature(
|
|
14589
|
+
geometry = arrowMultiLineStringToFeature(arrowCellValue);
|
|
13025
14590
|
break;
|
|
13026
14591
|
case "geoarrow.linestring":
|
|
13027
|
-
geometry = arrowLineStringToFeature(
|
|
14592
|
+
geometry = arrowLineStringToFeature(arrowCellValue);
|
|
14593
|
+
break;
|
|
14594
|
+
case "geoarrow.wkb":
|
|
14595
|
+
geometry = arrowWKBToFeature(arrowCellValue);
|
|
14596
|
+
break;
|
|
14597
|
+
case "geoarrow.wkt":
|
|
14598
|
+
geometry = arrowWKTToFeature(arrowCellValue);
|
|
13028
14599
|
break;
|
|
13029
14600
|
default: {
|
|
13030
14601
|
throw Error(`GeoArrow encoding not supported ${encoding}`);
|
|
13031
14602
|
}
|
|
13032
14603
|
}
|
|
13033
|
-
return
|
|
13034
|
-
|
|
13035
|
-
|
|
13036
|
-
|
|
13037
|
-
|
|
14604
|
+
return geometry;
|
|
14605
|
+
}
|
|
14606
|
+
function arrowWKBToFeature(arrowCellValue) {
|
|
14607
|
+
const arrayBuffer = arrowCellValue.buffer.slice(arrowCellValue.byteOffset, arrowCellValue.byteOffset + arrowCellValue.byteLength);
|
|
14608
|
+
const binaryGeometry = WKBLoader.parseSync?.(arrayBuffer);
|
|
14609
|
+
const geometry = binaryToGeometry(binaryGeometry);
|
|
14610
|
+
return geometry;
|
|
14611
|
+
}
|
|
14612
|
+
function arrowWKTToFeature(arrowCellValue) {
|
|
14613
|
+
const string = arrowCellValue;
|
|
14614
|
+
return WKTLoader.parseTextSync?.(string);
|
|
13038
14615
|
}
|
|
13039
14616
|
function arrowMultiPolygonToFeature(arrowMultiPolygon) {
|
|
13040
14617
|
const multiPolygon = [];
|
|
@@ -13066,8 +14643,8 @@ return true;`);
|
|
|
13066
14643
|
const ring = [];
|
|
13067
14644
|
for (let j = 0; arrowRing && j < arrowRing.length; j++) {
|
|
13068
14645
|
const arrowCoord = arrowRing.get(j);
|
|
13069
|
-
const
|
|
13070
|
-
ring.push(
|
|
14646
|
+
const coords2 = Array.from(arrowCoord);
|
|
14647
|
+
ring.push(coords2);
|
|
13071
14648
|
}
|
|
13072
14649
|
polygon.push(ring);
|
|
13073
14650
|
}
|
|
@@ -13086,19 +14663,17 @@ return true;`);
|
|
|
13086
14663
|
multiPoint.push(coord);
|
|
13087
14664
|
}
|
|
13088
14665
|
}
|
|
13089
|
-
|
|
14666
|
+
return {
|
|
13090
14667
|
type: "MultiPoint",
|
|
13091
14668
|
coordinates: multiPoint
|
|
13092
14669
|
};
|
|
13093
|
-
return geometry;
|
|
13094
14670
|
}
|
|
13095
14671
|
function arrowPointToFeature(arrowPoint) {
|
|
13096
14672
|
const point = Array.from(arrowPoint);
|
|
13097
|
-
|
|
14673
|
+
return {
|
|
13098
14674
|
type: "Point",
|
|
13099
14675
|
coordinates: point
|
|
13100
14676
|
};
|
|
13101
|
-
return geometry;
|
|
13102
14677
|
}
|
|
13103
14678
|
function arrowMultiLineStringToFeature(arrowMultiLineString) {
|
|
13104
14679
|
const multiLineString = [];
|
|
@@ -13108,42 +14683,597 @@ return true;`);
|
|
|
13108
14683
|
for (let j = 0; arrowLineString && j < arrowLineString.length; j++) {
|
|
13109
14684
|
const arrowCoord = arrowLineString.get(j);
|
|
13110
14685
|
if (arrowCoord) {
|
|
13111
|
-
const
|
|
13112
|
-
lineString.push(
|
|
14686
|
+
const coords2 = Array.from(arrowCoord);
|
|
14687
|
+
lineString.push(coords2);
|
|
13113
14688
|
}
|
|
13114
14689
|
}
|
|
13115
14690
|
multiLineString.push(lineString);
|
|
13116
14691
|
}
|
|
13117
|
-
|
|
14692
|
+
return {
|
|
13118
14693
|
type: "MultiLineString",
|
|
13119
14694
|
coordinates: multiLineString
|
|
13120
14695
|
};
|
|
13121
|
-
return geometry;
|
|
13122
14696
|
}
|
|
13123
14697
|
function arrowLineStringToFeature(arrowLineString) {
|
|
13124
14698
|
const lineString = [];
|
|
13125
14699
|
for (let i = 0; arrowLineString && i < arrowLineString.length; i++) {
|
|
13126
14700
|
const arrowCoord = arrowLineString.get(i);
|
|
13127
14701
|
if (arrowCoord) {
|
|
13128
|
-
const
|
|
13129
|
-
lineString.push(
|
|
14702
|
+
const coords2 = Array.from(arrowCoord);
|
|
14703
|
+
lineString.push(coords2);
|
|
13130
14704
|
}
|
|
13131
14705
|
}
|
|
13132
|
-
|
|
14706
|
+
return {
|
|
13133
14707
|
type: "LineString",
|
|
13134
14708
|
coordinates: lineString
|
|
13135
14709
|
};
|
|
13136
|
-
|
|
14710
|
+
}
|
|
14711
|
+
|
|
14712
|
+
// ../worker-utils/src/lib/env-utils/version.ts
|
|
14713
|
+
var NPM_TAG = "latest";
|
|
14714
|
+
function getVersion() {
|
|
14715
|
+
if (!globalThis._loadersgl_?.version) {
|
|
14716
|
+
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
14717
|
+
if (typeof __VERSION__ === "undefined") {
|
|
14718
|
+
console.warn("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
|
|
14719
|
+
globalThis._loadersgl_.version = NPM_TAG;
|
|
14720
|
+
} else {
|
|
14721
|
+
globalThis._loadersgl_.version = __VERSION__;
|
|
14722
|
+
}
|
|
14723
|
+
}
|
|
14724
|
+
return globalThis._loadersgl_.version;
|
|
14725
|
+
}
|
|
14726
|
+
var VERSION4 = getVersion();
|
|
14727
|
+
|
|
14728
|
+
// ../worker-utils/src/lib/env-utils/assert.ts
|
|
14729
|
+
function assert(condition, message) {
|
|
14730
|
+
if (!condition) {
|
|
14731
|
+
throw new Error(message || "loaders.gl assertion failed.");
|
|
14732
|
+
}
|
|
14733
|
+
}
|
|
14734
|
+
|
|
14735
|
+
// ../worker-utils/src/lib/env-utils/globals.ts
|
|
14736
|
+
var globals = {
|
|
14737
|
+
self: typeof self !== "undefined" && self,
|
|
14738
|
+
window: typeof window !== "undefined" && window,
|
|
14739
|
+
global: typeof global !== "undefined" && global,
|
|
14740
|
+
document: typeof document !== "undefined" && document
|
|
14741
|
+
};
|
|
14742
|
+
var self_ = globals.self || globals.window || globals.global || {};
|
|
14743
|
+
var window_ = globals.window || globals.self || globals.global || {};
|
|
14744
|
+
var global_ = globals.global || globals.self || globals.window || {};
|
|
14745
|
+
var document_ = globals.document || {};
|
|
14746
|
+
var isBrowser = typeof process !== "object" || String(process) !== "[object process]" || process.browser;
|
|
14747
|
+
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
14748
|
+
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
14749
|
+
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
14750
|
+
|
|
14751
|
+
// ../worker-utils/src/lib/worker-farm/worker-job.ts
|
|
14752
|
+
var WorkerJob = class {
|
|
14753
|
+
isRunning = true;
|
|
14754
|
+
_resolve = () => {
|
|
14755
|
+
};
|
|
14756
|
+
_reject = () => {
|
|
14757
|
+
};
|
|
14758
|
+
constructor(jobName, workerThread) {
|
|
14759
|
+
this.name = jobName;
|
|
14760
|
+
this.workerThread = workerThread;
|
|
14761
|
+
this.result = new Promise((resolve, reject) => {
|
|
14762
|
+
this._resolve = resolve;
|
|
14763
|
+
this._reject = reject;
|
|
14764
|
+
});
|
|
14765
|
+
}
|
|
14766
|
+
postMessage(type, payload) {
|
|
14767
|
+
this.workerThread.postMessage({
|
|
14768
|
+
source: "loaders.gl",
|
|
14769
|
+
type,
|
|
14770
|
+
payload
|
|
14771
|
+
});
|
|
14772
|
+
}
|
|
14773
|
+
done(value) {
|
|
14774
|
+
assert(this.isRunning);
|
|
14775
|
+
this.isRunning = false;
|
|
14776
|
+
this._resolve(value);
|
|
14777
|
+
}
|
|
14778
|
+
error(error) {
|
|
14779
|
+
assert(this.isRunning);
|
|
14780
|
+
this.isRunning = false;
|
|
14781
|
+
this._reject(error);
|
|
14782
|
+
}
|
|
14783
|
+
};
|
|
14784
|
+
|
|
14785
|
+
// ../worker-utils/src/lib/node/worker_threads-browser.ts
|
|
14786
|
+
var NodeWorker = class {
|
|
14787
|
+
terminate() {
|
|
14788
|
+
}
|
|
14789
|
+
};
|
|
14790
|
+
|
|
14791
|
+
// ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
|
|
14792
|
+
var workerURLCache = /* @__PURE__ */ new Map();
|
|
14793
|
+
function getLoadableWorkerURL(props) {
|
|
14794
|
+
assert(props.source && !props.url || !props.source && props.url);
|
|
14795
|
+
let workerURL = workerURLCache.get(props.source || props.url);
|
|
14796
|
+
if (!workerURL) {
|
|
14797
|
+
if (props.url) {
|
|
14798
|
+
workerURL = getLoadableWorkerURLFromURL(props.url);
|
|
14799
|
+
workerURLCache.set(props.url, workerURL);
|
|
14800
|
+
}
|
|
14801
|
+
if (props.source) {
|
|
14802
|
+
workerURL = getLoadableWorkerURLFromSource(props.source);
|
|
14803
|
+
workerURLCache.set(props.source, workerURL);
|
|
14804
|
+
}
|
|
14805
|
+
}
|
|
14806
|
+
assert(workerURL);
|
|
14807
|
+
return workerURL;
|
|
14808
|
+
}
|
|
14809
|
+
function getLoadableWorkerURLFromURL(url) {
|
|
14810
|
+
if (!url.startsWith("http")) {
|
|
14811
|
+
return url;
|
|
14812
|
+
}
|
|
14813
|
+
const workerSource = buildScriptSource(url);
|
|
14814
|
+
return getLoadableWorkerURLFromSource(workerSource);
|
|
14815
|
+
}
|
|
14816
|
+
function getLoadableWorkerURLFromSource(workerSource) {
|
|
14817
|
+
const blob = new Blob([workerSource], {
|
|
14818
|
+
type: "application/javascript"
|
|
14819
|
+
});
|
|
14820
|
+
return URL.createObjectURL(blob);
|
|
14821
|
+
}
|
|
14822
|
+
function buildScriptSource(workerUrl) {
|
|
14823
|
+
return `try {
|
|
14824
|
+
importScripts('${workerUrl}');
|
|
14825
|
+
} catch (error) {
|
|
14826
|
+
console.error(error);
|
|
14827
|
+
throw error;
|
|
14828
|
+
}`;
|
|
14829
|
+
}
|
|
14830
|
+
|
|
14831
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
14832
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
14833
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
14834
|
+
if (!object) {
|
|
14835
|
+
} else if (isTransferable(object)) {
|
|
14836
|
+
transfersSet.add(object);
|
|
14837
|
+
} else if (isTransferable(object.buffer)) {
|
|
14838
|
+
transfersSet.add(object.buffer);
|
|
14839
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
14840
|
+
} else if (recursive && typeof object === "object") {
|
|
14841
|
+
for (const key in object) {
|
|
14842
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
14843
|
+
}
|
|
14844
|
+
}
|
|
14845
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
14846
|
+
}
|
|
14847
|
+
function isTransferable(object) {
|
|
14848
|
+
if (!object) {
|
|
14849
|
+
return false;
|
|
14850
|
+
}
|
|
14851
|
+
if (object instanceof ArrayBuffer) {
|
|
14852
|
+
return true;
|
|
14853
|
+
}
|
|
14854
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
14855
|
+
return true;
|
|
14856
|
+
}
|
|
14857
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
14858
|
+
return true;
|
|
14859
|
+
}
|
|
14860
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
14861
|
+
return true;
|
|
14862
|
+
}
|
|
14863
|
+
return false;
|
|
14864
|
+
}
|
|
14865
|
+
function getTransferListForWriter(object) {
|
|
14866
|
+
if (object === null) {
|
|
14867
|
+
return {};
|
|
14868
|
+
}
|
|
14869
|
+
const clone = Object.assign({}, object);
|
|
14870
|
+
Object.keys(clone).forEach((key) => {
|
|
14871
|
+
if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
14872
|
+
clone[key] = getTransferListForWriter(object[key]);
|
|
14873
|
+
} else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
|
|
14874
|
+
clone[key] = {};
|
|
14875
|
+
} else {
|
|
14876
|
+
clone[key] = object[key];
|
|
14877
|
+
}
|
|
14878
|
+
});
|
|
14879
|
+
return clone;
|
|
14880
|
+
}
|
|
14881
|
+
|
|
14882
|
+
// ../worker-utils/src/lib/worker-farm/worker-thread.ts
|
|
14883
|
+
var NOOP = () => {
|
|
14884
|
+
};
|
|
14885
|
+
var WorkerThread = class {
|
|
14886
|
+
terminated = false;
|
|
14887
|
+
_loadableURL = "";
|
|
14888
|
+
static isSupported() {
|
|
14889
|
+
return typeof Worker !== "undefined" && isBrowser || typeof NodeWorker !== "undefined" && !isBrowser;
|
|
14890
|
+
}
|
|
14891
|
+
constructor(props) {
|
|
14892
|
+
const {
|
|
14893
|
+
name,
|
|
14894
|
+
source,
|
|
14895
|
+
url
|
|
14896
|
+
} = props;
|
|
14897
|
+
assert(source || url);
|
|
14898
|
+
this.name = name;
|
|
14899
|
+
this.source = source;
|
|
14900
|
+
this.url = url;
|
|
14901
|
+
this.onMessage = NOOP;
|
|
14902
|
+
this.onError = (error) => console.log(error);
|
|
14903
|
+
this.worker = isBrowser ? this._createBrowserWorker() : this._createNodeWorker();
|
|
14904
|
+
}
|
|
14905
|
+
destroy() {
|
|
14906
|
+
this.onMessage = NOOP;
|
|
14907
|
+
this.onError = NOOP;
|
|
14908
|
+
this.worker.terminate();
|
|
14909
|
+
this.terminated = true;
|
|
14910
|
+
}
|
|
14911
|
+
get isRunning() {
|
|
14912
|
+
return Boolean(this.onMessage);
|
|
14913
|
+
}
|
|
14914
|
+
postMessage(data, transferList) {
|
|
14915
|
+
transferList = transferList || getTransferList(data);
|
|
14916
|
+
this.worker.postMessage(data, transferList);
|
|
14917
|
+
}
|
|
14918
|
+
_getErrorFromErrorEvent(event) {
|
|
14919
|
+
let message = "Failed to load ";
|
|
14920
|
+
message += `worker ${this.name} from ${this.url}. `;
|
|
14921
|
+
if (event.message) {
|
|
14922
|
+
message += `${event.message} in `;
|
|
14923
|
+
}
|
|
14924
|
+
if (event.lineno) {
|
|
14925
|
+
message += `:${event.lineno}:${event.colno}`;
|
|
14926
|
+
}
|
|
14927
|
+
return new Error(message);
|
|
14928
|
+
}
|
|
14929
|
+
_createBrowserWorker() {
|
|
14930
|
+
this._loadableURL = getLoadableWorkerURL({
|
|
14931
|
+
source: this.source,
|
|
14932
|
+
url: this.url
|
|
14933
|
+
});
|
|
14934
|
+
const worker = new Worker(this._loadableURL, {
|
|
14935
|
+
name: this.name
|
|
14936
|
+
});
|
|
14937
|
+
worker.onmessage = (event) => {
|
|
14938
|
+
if (!event.data) {
|
|
14939
|
+
this.onError(new Error("No data received"));
|
|
14940
|
+
} else {
|
|
14941
|
+
this.onMessage(event.data);
|
|
14942
|
+
}
|
|
14943
|
+
};
|
|
14944
|
+
worker.onerror = (error) => {
|
|
14945
|
+
this.onError(this._getErrorFromErrorEvent(error));
|
|
14946
|
+
this.terminated = true;
|
|
14947
|
+
};
|
|
14948
|
+
worker.onmessageerror = (event) => console.error(event);
|
|
14949
|
+
return worker;
|
|
14950
|
+
}
|
|
14951
|
+
_createNodeWorker() {
|
|
14952
|
+
let worker;
|
|
14953
|
+
if (this.url) {
|
|
14954
|
+
const absolute = this.url.includes(":/") || this.url.startsWith("/");
|
|
14955
|
+
const url = absolute ? this.url : `./${this.url}`;
|
|
14956
|
+
worker = new NodeWorker(url, {
|
|
14957
|
+
eval: false
|
|
14958
|
+
});
|
|
14959
|
+
} else if (this.source) {
|
|
14960
|
+
worker = new NodeWorker(this.source, {
|
|
14961
|
+
eval: true
|
|
14962
|
+
});
|
|
14963
|
+
} else {
|
|
14964
|
+
throw new Error("no worker");
|
|
14965
|
+
}
|
|
14966
|
+
worker.on("message", (data) => {
|
|
14967
|
+
this.onMessage(data);
|
|
14968
|
+
});
|
|
14969
|
+
worker.on("error", (error) => {
|
|
14970
|
+
this.onError(error);
|
|
14971
|
+
});
|
|
14972
|
+
worker.on("exit", (code) => {
|
|
14973
|
+
});
|
|
14974
|
+
return worker;
|
|
14975
|
+
}
|
|
14976
|
+
};
|
|
14977
|
+
|
|
14978
|
+
// ../worker-utils/src/lib/worker-farm/worker-pool.ts
|
|
14979
|
+
var WorkerPool = class {
|
|
14980
|
+
name = "unnamed";
|
|
14981
|
+
maxConcurrency = 1;
|
|
14982
|
+
maxMobileConcurrency = 1;
|
|
14983
|
+
onDebug = () => {
|
|
14984
|
+
};
|
|
14985
|
+
reuseWorkers = true;
|
|
14986
|
+
props = {};
|
|
14987
|
+
jobQueue = [];
|
|
14988
|
+
idleQueue = [];
|
|
14989
|
+
count = 0;
|
|
14990
|
+
isDestroyed = false;
|
|
14991
|
+
static isSupported() {
|
|
14992
|
+
return WorkerThread.isSupported();
|
|
14993
|
+
}
|
|
14994
|
+
constructor(props) {
|
|
14995
|
+
this.source = props.source;
|
|
14996
|
+
this.url = props.url;
|
|
14997
|
+
this.setProps(props);
|
|
14998
|
+
}
|
|
14999
|
+
destroy() {
|
|
15000
|
+
this.idleQueue.forEach((worker) => worker.destroy());
|
|
15001
|
+
this.isDestroyed = true;
|
|
15002
|
+
}
|
|
15003
|
+
setProps(props) {
|
|
15004
|
+
this.props = {
|
|
15005
|
+
...this.props,
|
|
15006
|
+
...props
|
|
15007
|
+
};
|
|
15008
|
+
if (props.name !== void 0) {
|
|
15009
|
+
this.name = props.name;
|
|
15010
|
+
}
|
|
15011
|
+
if (props.maxConcurrency !== void 0) {
|
|
15012
|
+
this.maxConcurrency = props.maxConcurrency;
|
|
15013
|
+
}
|
|
15014
|
+
if (props.maxMobileConcurrency !== void 0) {
|
|
15015
|
+
this.maxMobileConcurrency = props.maxMobileConcurrency;
|
|
15016
|
+
}
|
|
15017
|
+
if (props.reuseWorkers !== void 0) {
|
|
15018
|
+
this.reuseWorkers = props.reuseWorkers;
|
|
15019
|
+
}
|
|
15020
|
+
if (props.onDebug !== void 0) {
|
|
15021
|
+
this.onDebug = props.onDebug;
|
|
15022
|
+
}
|
|
15023
|
+
}
|
|
15024
|
+
async startJob(name, onMessage2 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
|
|
15025
|
+
const startPromise = new Promise((onStart) => {
|
|
15026
|
+
this.jobQueue.push({
|
|
15027
|
+
name,
|
|
15028
|
+
onMessage: onMessage2,
|
|
15029
|
+
onError,
|
|
15030
|
+
onStart
|
|
15031
|
+
});
|
|
15032
|
+
return this;
|
|
15033
|
+
});
|
|
15034
|
+
this._startQueuedJob();
|
|
15035
|
+
return await startPromise;
|
|
15036
|
+
}
|
|
15037
|
+
async _startQueuedJob() {
|
|
15038
|
+
if (!this.jobQueue.length) {
|
|
15039
|
+
return;
|
|
15040
|
+
}
|
|
15041
|
+
const workerThread = this._getAvailableWorker();
|
|
15042
|
+
if (!workerThread) {
|
|
15043
|
+
return;
|
|
15044
|
+
}
|
|
15045
|
+
const queuedJob = this.jobQueue.shift();
|
|
15046
|
+
if (queuedJob) {
|
|
15047
|
+
this.onDebug({
|
|
15048
|
+
message: "Starting job",
|
|
15049
|
+
name: queuedJob.name,
|
|
15050
|
+
workerThread,
|
|
15051
|
+
backlog: this.jobQueue.length
|
|
15052
|
+
});
|
|
15053
|
+
const job = new WorkerJob(queuedJob.name, workerThread);
|
|
15054
|
+
workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
|
|
15055
|
+
workerThread.onError = (error) => queuedJob.onError(job, error);
|
|
15056
|
+
queuedJob.onStart(job);
|
|
15057
|
+
try {
|
|
15058
|
+
await job.result;
|
|
15059
|
+
} catch (error) {
|
|
15060
|
+
console.error(`Worker exception: ${error}`);
|
|
15061
|
+
} finally {
|
|
15062
|
+
this.returnWorkerToQueue(workerThread);
|
|
15063
|
+
}
|
|
15064
|
+
}
|
|
15065
|
+
}
|
|
15066
|
+
returnWorkerToQueue(worker) {
|
|
15067
|
+
const shouldDestroyWorker = !isBrowser || this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency();
|
|
15068
|
+
if (shouldDestroyWorker) {
|
|
15069
|
+
worker.destroy();
|
|
15070
|
+
this.count--;
|
|
15071
|
+
} else {
|
|
15072
|
+
this.idleQueue.push(worker);
|
|
15073
|
+
}
|
|
15074
|
+
if (!this.isDestroyed) {
|
|
15075
|
+
this._startQueuedJob();
|
|
15076
|
+
}
|
|
15077
|
+
}
|
|
15078
|
+
_getAvailableWorker() {
|
|
15079
|
+
if (this.idleQueue.length > 0) {
|
|
15080
|
+
return this.idleQueue.shift() || null;
|
|
15081
|
+
}
|
|
15082
|
+
if (this.count < this._getMaxConcurrency()) {
|
|
15083
|
+
this.count++;
|
|
15084
|
+
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
15085
|
+
return new WorkerThread({
|
|
15086
|
+
name,
|
|
15087
|
+
source: this.source,
|
|
15088
|
+
url: this.url
|
|
15089
|
+
});
|
|
15090
|
+
}
|
|
15091
|
+
return null;
|
|
15092
|
+
}
|
|
15093
|
+
_getMaxConcurrency() {
|
|
15094
|
+
return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
|
|
15095
|
+
}
|
|
15096
|
+
};
|
|
15097
|
+
|
|
15098
|
+
// ../worker-utils/src/lib/worker-farm/worker-farm.ts
|
|
15099
|
+
var DEFAULT_PROPS = {
|
|
15100
|
+
maxConcurrency: 3,
|
|
15101
|
+
maxMobileConcurrency: 1,
|
|
15102
|
+
reuseWorkers: true,
|
|
15103
|
+
onDebug: () => {
|
|
15104
|
+
}
|
|
15105
|
+
};
|
|
15106
|
+
var WorkerFarm = class {
|
|
15107
|
+
workerPools = /* @__PURE__ */ new Map();
|
|
15108
|
+
static isSupported() {
|
|
15109
|
+
return WorkerThread.isSupported();
|
|
15110
|
+
}
|
|
15111
|
+
static getWorkerFarm(props = {}) {
|
|
15112
|
+
WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({});
|
|
15113
|
+
WorkerFarm._workerFarm.setProps(props);
|
|
15114
|
+
return WorkerFarm._workerFarm;
|
|
15115
|
+
}
|
|
15116
|
+
constructor(props) {
|
|
15117
|
+
this.props = {
|
|
15118
|
+
...DEFAULT_PROPS
|
|
15119
|
+
};
|
|
15120
|
+
this.setProps(props);
|
|
15121
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
15122
|
+
}
|
|
15123
|
+
destroy() {
|
|
15124
|
+
for (const workerPool of this.workerPools.values()) {
|
|
15125
|
+
workerPool.destroy();
|
|
15126
|
+
}
|
|
15127
|
+
this.workerPools = /* @__PURE__ */ new Map();
|
|
15128
|
+
}
|
|
15129
|
+
setProps(props) {
|
|
15130
|
+
this.props = {
|
|
15131
|
+
...this.props,
|
|
15132
|
+
...props
|
|
15133
|
+
};
|
|
15134
|
+
for (const workerPool of this.workerPools.values()) {
|
|
15135
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
15136
|
+
}
|
|
15137
|
+
}
|
|
15138
|
+
getWorkerPool(options) {
|
|
15139
|
+
const {
|
|
15140
|
+
name,
|
|
15141
|
+
source,
|
|
15142
|
+
url
|
|
15143
|
+
} = options;
|
|
15144
|
+
let workerPool = this.workerPools.get(name);
|
|
15145
|
+
if (!workerPool) {
|
|
15146
|
+
workerPool = new WorkerPool({
|
|
15147
|
+
name,
|
|
15148
|
+
source,
|
|
15149
|
+
url
|
|
15150
|
+
});
|
|
15151
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
15152
|
+
this.workerPools.set(name, workerPool);
|
|
15153
|
+
}
|
|
15154
|
+
return workerPool;
|
|
15155
|
+
}
|
|
15156
|
+
_getWorkerPoolProps() {
|
|
15157
|
+
return {
|
|
15158
|
+
maxConcurrency: this.props.maxConcurrency,
|
|
15159
|
+
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
15160
|
+
reuseWorkers: this.props.reuseWorkers,
|
|
15161
|
+
onDebug: this.props.onDebug
|
|
15162
|
+
};
|
|
15163
|
+
}
|
|
15164
|
+
};
|
|
15165
|
+
|
|
15166
|
+
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
15167
|
+
function getWorkerName(worker) {
|
|
15168
|
+
const warning = worker.version !== VERSION4 ? ` (worker-utils@${VERSION4})` : "";
|
|
15169
|
+
return `${worker.name}@${worker.version}${warning}`;
|
|
15170
|
+
}
|
|
15171
|
+
function getWorkerURL(worker, options = {}) {
|
|
15172
|
+
const workerOptions = options[worker.id] || {};
|
|
15173
|
+
const workerFile = isBrowser ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`;
|
|
15174
|
+
let url = workerOptions.workerUrl;
|
|
15175
|
+
if (!url && worker.id === "compression") {
|
|
15176
|
+
url = options.workerUrl;
|
|
15177
|
+
}
|
|
15178
|
+
if (options._workerType === "test") {
|
|
15179
|
+
if (isBrowser) {
|
|
15180
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
15181
|
+
} else {
|
|
15182
|
+
url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`;
|
|
15183
|
+
}
|
|
15184
|
+
}
|
|
15185
|
+
if (!url) {
|
|
15186
|
+
let version = worker.version;
|
|
15187
|
+
if (version === "latest") {
|
|
15188
|
+
version = NPM_TAG;
|
|
15189
|
+
}
|
|
15190
|
+
const versionTag = version ? `@${version}` : "";
|
|
15191
|
+
url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
15192
|
+
}
|
|
15193
|
+
assert(url);
|
|
15194
|
+
return url;
|
|
15195
|
+
}
|
|
15196
|
+
|
|
15197
|
+
// ../worker-utils/src/lib/worker-api/process-on-worker.ts
|
|
15198
|
+
async function processOnWorker(worker, data, options = {}, context = {}) {
|
|
15199
|
+
const name = getWorkerName(worker);
|
|
15200
|
+
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
15201
|
+
const {
|
|
15202
|
+
source
|
|
15203
|
+
} = options;
|
|
15204
|
+
const workerPoolProps = {
|
|
15205
|
+
name,
|
|
15206
|
+
source
|
|
15207
|
+
};
|
|
15208
|
+
if (!source) {
|
|
15209
|
+
workerPoolProps.url = getWorkerURL(worker, options);
|
|
15210
|
+
}
|
|
15211
|
+
const workerPool = workerFarm.getWorkerPool(workerPoolProps);
|
|
15212
|
+
const jobName = options.jobName || worker.name;
|
|
15213
|
+
const job = await workerPool.startJob(jobName, onMessage.bind(null, context));
|
|
15214
|
+
const transferableOptions = getTransferListForWriter(options);
|
|
15215
|
+
job.postMessage("process", {
|
|
15216
|
+
input: data,
|
|
15217
|
+
options: transferableOptions
|
|
15218
|
+
});
|
|
15219
|
+
const result = await job.result;
|
|
15220
|
+
return result.result;
|
|
15221
|
+
}
|
|
15222
|
+
async function onMessage(context, job, type, payload) {
|
|
15223
|
+
switch (type) {
|
|
15224
|
+
case "done":
|
|
15225
|
+
job.done(payload);
|
|
15226
|
+
break;
|
|
15227
|
+
case "error":
|
|
15228
|
+
job.error(new Error(payload.error));
|
|
15229
|
+
break;
|
|
15230
|
+
case "process":
|
|
15231
|
+
const {
|
|
15232
|
+
id,
|
|
15233
|
+
input,
|
|
15234
|
+
options
|
|
15235
|
+
} = payload;
|
|
15236
|
+
try {
|
|
15237
|
+
if (!context.process) {
|
|
15238
|
+
job.postMessage("error", {
|
|
15239
|
+
id,
|
|
15240
|
+
error: "Worker not set up to process on main thread"
|
|
15241
|
+
});
|
|
15242
|
+
return;
|
|
15243
|
+
}
|
|
15244
|
+
const result = await context.process(input, options);
|
|
15245
|
+
job.postMessage("done", {
|
|
15246
|
+
id,
|
|
15247
|
+
result
|
|
15248
|
+
});
|
|
15249
|
+
} catch (error) {
|
|
15250
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
15251
|
+
job.postMessage("error", {
|
|
15252
|
+
id,
|
|
15253
|
+
error: message
|
|
15254
|
+
});
|
|
15255
|
+
}
|
|
15256
|
+
break;
|
|
15257
|
+
default:
|
|
15258
|
+
console.warn(`process-on-worker: unknown message ${type}`);
|
|
15259
|
+
}
|
|
15260
|
+
}
|
|
15261
|
+
|
|
15262
|
+
// src/triangulate-on-worker.ts
|
|
15263
|
+
var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
15264
|
+
var TriangulationWorker = {
|
|
15265
|
+
id: "triangulation",
|
|
15266
|
+
name: "Triangulate",
|
|
15267
|
+
module: "arrow",
|
|
15268
|
+
version: VERSION5,
|
|
15269
|
+
options: {}
|
|
15270
|
+
};
|
|
15271
|
+
function triangulateOnWorker(data, options = {}) {
|
|
15272
|
+
return processOnWorker(TriangulationWorker, data, options);
|
|
13137
15273
|
}
|
|
13138
15274
|
|
|
13139
15275
|
// src/index.ts
|
|
13140
15276
|
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
13141
|
-
var ArrowLoader2 = {
|
|
13142
|
-
...ArrowLoader,
|
|
13143
|
-
parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options),
|
|
13144
|
-
parseSync: parseArrowSync,
|
|
13145
|
-
parseInBatches: parseArrowInBatches
|
|
13146
|
-
};
|
|
13147
15277
|
return __toCommonJS(src_exports);
|
|
13148
15278
|
})();
|
|
13149
15279
|
return __exports__;
|