@loaders.gl/arrow 4.0.4 → 4.1.0-alpha.10
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 +1 -0
- package/dist/arrow-loader.d.ts.map +1 -1
- package/dist/arrow-loader.js +1 -1
- package/dist/arrow-loader.js.map +1 -1
- package/dist/arrow-worker.js +241 -3
- package/dist/arrow-writer.js +1 -1
- package/dist/arrow-writer.js.map +1 -1
- package/dist/dist.dev.js +1496 -641
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +8 -4
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +75 -54
- 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} +34 -27
- package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.js.map +1 -0
- package/dist/geoarrow/get-arrow-bounds.d.ts.map +1 -1
- package/dist/geoarrow/get-arrow-bounds.js.map +1 -1
- package/dist/geoarrow-loader.d.ts.map +1 -1
- package/dist/geoarrow-loader.js +0 -1
- package/dist/geoarrow-loader.js.map +1 -1
- package/dist/geoarrow-writer.js +1 -1
- package/dist/geoarrow-writer.js.map +1 -1
- package/dist/index.cjs +436 -347
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- 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/arrow-table.d.ts.map +1 -1
- package/dist/lib/arrow-table.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.map +1 -1
- package/dist/lib/encode-geoarrow.js.map +1 -1
- package/dist/parsers/parse-arrow-in-batches.d.ts +2 -1
- package/dist/parsers/parse-arrow-in-batches.d.ts.map +1 -1
- package/dist/parsers/parse-arrow-in-batches.js +8 -1
- package/dist/parsers/parse-arrow-in-batches.js.map +1 -1
- package/dist/parsers/parse-arrow-sync.d.ts.map +1 -1
- package/dist/parsers/parse-arrow-sync.js +2 -0
- package/dist/parsers/parse-arrow-sync.js.map +1 -1
- package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +1 -1
- package/dist/parsers/parse-geoarrow-in-batches.js.map +1 -1
- package/dist/parsers/parse-geoarrow-sync.d.ts.map +1 -1
- package/dist/parsers/parse-geoarrow-sync.js.map +1 -1
- package/dist/schema/arrow-type-utils.d.ts.map +1 -1
- package/dist/schema/arrow-type-utils.js.map +1 -1
- package/dist/schema/convert-arrow-schema.d.ts.map +1 -1
- package/dist/schema/convert-arrow-schema.js.map +1 -1
- package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +1 -1
- package/dist/tables/convert-arrow-to-columnar-table.js +1 -0
- package/dist/tables/convert-arrow-to-columnar-table.js.map +1 -1
- package/dist/tables/convert-arrow-to-geojson-table.d.ts +1 -1
- package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +1 -1
- package/dist/tables/convert-arrow-to-geojson-table.js +14 -8
- package/dist/tables/convert-arrow-to-geojson-table.js.map +1 -1
- package/dist/tables/convert-columnar-to-row-table.d.ts.map +1 -1
- package/dist/tables/convert-columnar-to-row-table.js +1 -0
- package/dist/tables/convert-columnar-to-row-table.js.map +1 -1
- package/dist/tables/convert-table-to-arrow.d.ts.map +1 -1
- package/dist/tables/convert-table-to-arrow.js.map +1 -1
- package/dist/triangulate-on-worker.d.ts +40 -6
- package/dist/triangulate-on-worker.d.ts.map +1 -1
- package/dist/triangulate-on-worker.js +12 -2
- package/dist/triangulate-on-worker.js.map +1 -1
- package/dist/triangulation-worker.js +11703 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/workers/arrow-worker.js.map +1 -1
- package/dist/workers/hard-clone.d.ts +23 -0
- package/dist/workers/hard-clone.d.ts.map +1 -0
- package/dist/workers/hard-clone.js +57 -0
- package/dist/workers/hard-clone.js.map +1 -0
- package/dist/workers/triangulation-worker-node.d.ts.map +1 -1
- package/dist/workers/triangulation-worker-node.js.map +1 -1
- package/dist/workers/triangulation-worker.js +37 -2
- package/dist/workers/triangulation-worker.js.map +1 -1
- package/package.json +18 -12
- package/src/arrow-loader.ts +3 -1
- package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +105 -62
- package/src/geoarrow/{convert-geoarrow-to-geojson.ts → convert-geoarrow-to-geojson-geometry.ts} +58 -47
- package/src/geoarrow/get-arrow-bounds.ts +2 -1
- package/src/geoarrow-loader.ts +2 -5
- package/src/index.ts +11 -4
- package/src/lib/arrow-table-batch.ts +2 -1
- package/src/lib/arrow-table.ts +2 -1
- package/src/lib/encode-arrow.ts +2 -1
- package/src/lib/encode-geoarrow.ts +2 -1
- package/src/parsers/parse-arrow-in-batches.ts +9 -2
- package/src/parsers/parse-arrow-sync.ts +8 -2
- package/src/parsers/parse-geoarrow-in-batches.ts +2 -1
- package/src/parsers/parse-geoarrow-sync.ts +2 -1
- package/src/schema/arrow-type-utils.ts +2 -1
- package/src/schema/convert-arrow-schema.ts +2 -1
- package/src/tables/convert-arrow-to-columnar-table.ts +3 -1
- package/src/tables/convert-arrow-to-geojson-table.ts +20 -8
- package/src/tables/convert-columnar-to-row-table.ts +3 -1
- package/src/tables/convert-table-to-arrow.ts +2 -1
- package/src/triangulate-on-worker.ts +53 -9
- package/src/types.ts +2 -1
- package/src/workers/arrow-worker.ts +2 -1
- package/src/workers/hard-clone.ts +162 -0
- package/src/workers/triangulation-worker-node.ts +2 -1
- package/src/workers/triangulation-worker.ts +59 -4
- package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts +0 -20
- 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/dist.dev.js
CHANGED
|
@@ -30,7 +30,6 @@ var __exports__ = (() => {
|
|
|
30
30
|
ArrowLoader: () => ArrowLoader,
|
|
31
31
|
ArrowWorkerLoader: () => ArrowWorkerLoader,
|
|
32
32
|
ArrowWriter: () => ArrowWriter,
|
|
33
|
-
BINARY_GEOMETRY_TEMPLATE: () => BINARY_GEOMETRY_TEMPLATE,
|
|
34
33
|
GeoArrowLoader: () => GeoArrowLoader,
|
|
35
34
|
GeoArrowWorkerLoader: () => GeoArrowWorkerLoader,
|
|
36
35
|
TriangulationWorker: () => TriangulationWorker,
|
|
@@ -42,8 +41,11 @@ var __exports__ = (() => {
|
|
|
42
41
|
deserializeArrowType: () => deserializeArrowType,
|
|
43
42
|
getArrowType: () => getArrowType,
|
|
44
43
|
getBinaryGeometriesFromArrow: () => getBinaryGeometriesFromArrow,
|
|
44
|
+
getBinaryGeometryTemplate: () => getBinaryGeometryTemplate,
|
|
45
45
|
getMeanCentersFromBinaryGeometries: () => getMeanCentersFromBinaryGeometries,
|
|
46
46
|
getTriangleIndices: () => getTriangleIndices,
|
|
47
|
+
hardClone: () => hardClone,
|
|
48
|
+
parseGeoArrowOnWorker: () => parseGeoArrowOnWorker,
|
|
47
49
|
parseGeometryFromArrow: () => parseGeometryFromArrow,
|
|
48
50
|
serializeArrowField: () => serializeArrowField,
|
|
49
51
|
serializeArrowMetadata: () => serializeArrowMetadata,
|
|
@@ -77,6 +79,7 @@ var __exports__ = (() => {
|
|
|
77
79
|
if (Number.isFinite(cursor)) {
|
|
78
80
|
this.cursor = cursor;
|
|
79
81
|
}
|
|
82
|
+
this.shape = "array-row-table";
|
|
80
83
|
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
81
84
|
this.rows[this.length] = row;
|
|
82
85
|
this.length++;
|
|
@@ -85,6 +88,7 @@ var __exports__ = (() => {
|
|
|
85
88
|
if (Number.isFinite(cursor)) {
|
|
86
89
|
this.cursor = cursor;
|
|
87
90
|
}
|
|
91
|
+
this.shape = "object-row-table";
|
|
88
92
|
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
89
93
|
this.rows[this.length] = row;
|
|
90
94
|
this.length++;
|
|
@@ -97,7 +101,7 @@ var __exports__ = (() => {
|
|
|
97
101
|
rows = rows.slice(0, this.length);
|
|
98
102
|
this.rows = null;
|
|
99
103
|
const batch = {
|
|
100
|
-
shape: this.
|
|
104
|
+
shape: this.shape || "array-row-table",
|
|
101
105
|
batchType: "data",
|
|
102
106
|
data: rows,
|
|
103
107
|
length: this.length,
|
|
@@ -113,12 +117,16 @@ var __exports__ = (() => {
|
|
|
113
117
|
if (!arrayRow) {
|
|
114
118
|
throw new Error("null row");
|
|
115
119
|
}
|
|
116
|
-
if (!headers) {
|
|
117
|
-
throw new Error("no headers");
|
|
118
|
-
}
|
|
119
120
|
const objectRow = {};
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
if (headers) {
|
|
122
|
+
for (let i = 0; i < headers.length; i++) {
|
|
123
|
+
objectRow[headers[i]] = arrayRow[i];
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
for (let i = 0; i < arrayRow.length; i++) {
|
|
127
|
+
const columnName = `column-${i}`;
|
|
128
|
+
objectRow[columnName] = arrayRow[i];
|
|
129
|
+
}
|
|
122
130
|
}
|
|
123
131
|
return objectRow;
|
|
124
132
|
}
|
|
@@ -126,14 +134,25 @@ var __exports__ = (() => {
|
|
|
126
134
|
if (!objectRow) {
|
|
127
135
|
throw new Error("null row");
|
|
128
136
|
}
|
|
129
|
-
if (
|
|
130
|
-
|
|
137
|
+
if (headers) {
|
|
138
|
+
const arrayRow = new Array(headers.length);
|
|
139
|
+
for (let i = 0; i < headers.length; i++) {
|
|
140
|
+
arrayRow[i] = objectRow[headers[i]];
|
|
141
|
+
}
|
|
142
|
+
return arrayRow;
|
|
131
143
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
144
|
+
return Object.values(objectRow);
|
|
145
|
+
}
|
|
146
|
+
function inferHeadersFromArrayRow(arrayRow) {
|
|
147
|
+
const headers = [];
|
|
148
|
+
for (let i = 0; i < arrayRow.length; i++) {
|
|
149
|
+
const columnName = `column-${i}`;
|
|
150
|
+
headers.push(columnName);
|
|
135
151
|
}
|
|
136
|
-
return
|
|
152
|
+
return headers;
|
|
153
|
+
}
|
|
154
|
+
function inferHeadersFromObjectRow(row) {
|
|
155
|
+
return Object.keys(row);
|
|
137
156
|
}
|
|
138
157
|
|
|
139
158
|
// ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
|
|
@@ -143,11 +162,11 @@ var __exports__ = (() => {
|
|
|
143
162
|
objectRows = null;
|
|
144
163
|
arrayRows = null;
|
|
145
164
|
cursor = 0;
|
|
146
|
-
_headers =
|
|
165
|
+
_headers = null;
|
|
147
166
|
constructor(schema, options) {
|
|
148
167
|
this.options = options;
|
|
149
168
|
this.schema = schema;
|
|
150
|
-
if (
|
|
169
|
+
if (schema) {
|
|
151
170
|
this._headers = [];
|
|
152
171
|
for (const key in schema) {
|
|
153
172
|
this._headers[schema[key].index] = schema[key].name;
|
|
@@ -161,6 +180,7 @@ var __exports__ = (() => {
|
|
|
161
180
|
if (Number.isFinite(cursor)) {
|
|
162
181
|
this.cursor = cursor;
|
|
163
182
|
}
|
|
183
|
+
this._headers ||= inferHeadersFromArrayRow(row);
|
|
164
184
|
switch (this.options.shape) {
|
|
165
185
|
case "object-row-table":
|
|
166
186
|
const rowObject = convertToObjectRow(row, this._headers);
|
|
@@ -177,6 +197,7 @@ var __exports__ = (() => {
|
|
|
177
197
|
if (Number.isFinite(cursor)) {
|
|
178
198
|
this.cursor = cursor;
|
|
179
199
|
}
|
|
200
|
+
this._headers ||= inferHeadersFromObjectRow(row);
|
|
180
201
|
switch (this.options.shape) {
|
|
181
202
|
case "array-row-table":
|
|
182
203
|
const rowArray = convertToArrayRow(row, this._headers);
|
|
@@ -286,7 +307,7 @@ var __exports__ = (() => {
|
|
|
286
307
|
|
|
287
308
|
// ../schema/src/lib/table/batches/table-batch-builder.ts
|
|
288
309
|
var DEFAULT_OPTIONS = {
|
|
289
|
-
shape:
|
|
310
|
+
shape: void 0,
|
|
290
311
|
batchSize: "auto",
|
|
291
312
|
batchDebounceMs: 0,
|
|
292
313
|
limit: 0,
|
|
@@ -398,8 +419,6 @@ var __exports__ = (() => {
|
|
|
398
419
|
}
|
|
399
420
|
_getTableBatchType() {
|
|
400
421
|
switch (this.options.shape) {
|
|
401
|
-
case "row-table":
|
|
402
|
-
return BaseTableBatchAggregator;
|
|
403
422
|
case "array-row-table":
|
|
404
423
|
case "object-row-table":
|
|
405
424
|
return RowTableBatchAggregator;
|
|
@@ -411,7 +430,7 @@ var __exports__ = (() => {
|
|
|
411
430
|
}
|
|
412
431
|
return TableBatchBuilder.ArrowBatch;
|
|
413
432
|
default:
|
|
414
|
-
|
|
433
|
+
return BaseTableBatchAggregator;
|
|
415
434
|
}
|
|
416
435
|
}
|
|
417
436
|
};
|
|
@@ -12427,243 +12446,513 @@ return true;`);
|
|
|
12427
12446
|
}
|
|
12428
12447
|
return {
|
|
12429
12448
|
shape: "columnar-table",
|
|
12449
|
+
schema: table.schema,
|
|
12430
12450
|
data: columnarTable
|
|
12431
12451
|
};
|
|
12432
12452
|
}
|
|
12433
12453
|
|
|
12434
|
-
// src/
|
|
12435
|
-
function
|
|
12436
|
-
|
|
12437
|
-
|
|
12438
|
-
|
|
12439
|
-
data: apacheArrowTable
|
|
12454
|
+
// src/schema/convert-arrow-schema.ts
|
|
12455
|
+
function serializeArrowSchema(arrowSchema) {
|
|
12456
|
+
return {
|
|
12457
|
+
fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
|
|
12458
|
+
metadata: serializeArrowMetadata(arrowSchema.metadata)
|
|
12440
12459
|
};
|
|
12441
|
-
const shape = options?.shape || "arrow-table";
|
|
12442
|
-
switch (shape) {
|
|
12443
|
-
case "arrow-table":
|
|
12444
|
-
return arrowTable;
|
|
12445
|
-
case "columnar-table":
|
|
12446
|
-
return convertArrowToColumnarTable(arrowTable);
|
|
12447
|
-
case "object-row-table":
|
|
12448
|
-
let columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
12449
|
-
return convertTable(columnarTable, "object-row-table");
|
|
12450
|
-
case "array-row-table":
|
|
12451
|
-
columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
12452
|
-
return convertTable(columnarTable, "array-row-table");
|
|
12453
|
-
default:
|
|
12454
|
-
throw new Error(shape);
|
|
12455
|
-
}
|
|
12456
|
-
}
|
|
12457
|
-
|
|
12458
|
-
// src/parsers/parse-arrow-in-batches.ts
|
|
12459
|
-
function parseArrowInBatches(asyncIterator) {
|
|
12460
|
-
async function* makeArrowAsyncIterator() {
|
|
12461
|
-
const readers = RecordBatchReader.readAll(asyncIterator);
|
|
12462
|
-
for await (const reader of readers) {
|
|
12463
|
-
for await (const recordBatch of reader) {
|
|
12464
|
-
const arrowTabledBatch = {
|
|
12465
|
-
shape: "arrow-table",
|
|
12466
|
-
batchType: "data",
|
|
12467
|
-
data: new Table([recordBatch]),
|
|
12468
|
-
length: recordBatch.data.length
|
|
12469
|
-
};
|
|
12470
|
-
yield arrowTabledBatch;
|
|
12471
|
-
}
|
|
12472
|
-
break;
|
|
12473
|
-
}
|
|
12474
|
-
}
|
|
12475
|
-
return makeArrowAsyncIterator();
|
|
12476
|
-
}
|
|
12477
|
-
|
|
12478
|
-
// src/arrow-loader.ts
|
|
12479
|
-
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
12480
|
-
var ArrowWorkerLoader = {
|
|
12481
|
-
name: "Apache Arrow",
|
|
12482
|
-
id: "arrow",
|
|
12483
|
-
module: "arrow",
|
|
12484
|
-
version: VERSION,
|
|
12485
|
-
category: "table",
|
|
12486
|
-
extensions: ["arrow", "feather"],
|
|
12487
|
-
mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
|
|
12488
|
-
binary: true,
|
|
12489
|
-
tests: ["ARROW"],
|
|
12490
|
-
options: {
|
|
12491
|
-
arrow: {
|
|
12492
|
-
shape: "columnar-table"
|
|
12493
|
-
}
|
|
12494
|
-
}
|
|
12495
|
-
};
|
|
12496
|
-
var ArrowLoader = {
|
|
12497
|
-
...ArrowWorkerLoader,
|
|
12498
|
-
parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),
|
|
12499
|
-
parseSync: (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),
|
|
12500
|
-
parseInBatches: parseArrowInBatches
|
|
12501
|
-
};
|
|
12502
|
-
|
|
12503
|
-
// src/lib/encode-arrow.ts
|
|
12504
|
-
function encodeArrowSync(data) {
|
|
12505
|
-
const vectors = {};
|
|
12506
|
-
for (const arrayData of data) {
|
|
12507
|
-
const arrayVector = createVector(arrayData.array, arrayData.type);
|
|
12508
|
-
vectors[arrayData.name] = arrayVector;
|
|
12509
|
-
}
|
|
12510
|
-
const table = new Table(vectors);
|
|
12511
|
-
const arrowBuffer = tableToIPC(table);
|
|
12512
|
-
return arrowBuffer;
|
|
12513
|
-
}
|
|
12514
|
-
function createVector(array, type) {
|
|
12515
|
-
switch (type) {
|
|
12516
|
-
case VECTOR_TYPES.DATE:
|
|
12517
|
-
return vectorFromArray(array);
|
|
12518
|
-
case VECTOR_TYPES.FLOAT:
|
|
12519
|
-
default:
|
|
12520
|
-
return vectorFromArray(array);
|
|
12521
|
-
}
|
|
12522
|
-
}
|
|
12523
|
-
|
|
12524
|
-
// src/arrow-writer.ts
|
|
12525
|
-
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
12526
|
-
var ArrowWriter = {
|
|
12527
|
-
name: "Apache Arrow",
|
|
12528
|
-
id: "arrow",
|
|
12529
|
-
module: "arrow",
|
|
12530
|
-
version: VERSION2,
|
|
12531
|
-
extensions: ["arrow", "feather"],
|
|
12532
|
-
mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
|
|
12533
|
-
binary: true,
|
|
12534
|
-
options: {},
|
|
12535
|
-
encode: async function encodeArrow(data, options) {
|
|
12536
|
-
return encodeArrowSync(data);
|
|
12537
|
-
},
|
|
12538
|
-
encodeSync(data, options) {
|
|
12539
|
-
return encodeArrowSync(data);
|
|
12540
|
-
}
|
|
12541
|
-
};
|
|
12542
|
-
|
|
12543
|
-
// ../gis/src/lib/geo/geoarrow-metadata.ts
|
|
12544
|
-
var GEOARROW_ENCODINGS = ["geoarrow.multipolygon", "geoarrow.polygon", "geoarrow.multilinestring", "geoarrow.linestring", "geoarrow.multipoint", "geoarrow.point", "geoarrow.wkb", "geoarrow.wkt"];
|
|
12545
|
-
var GEOARROW_COLUMN_METADATA_ENCODING = "ARROW:extension:name";
|
|
12546
|
-
var GEOARROW_COLUMN_METADATA_METADATA = "ARROW:extension:metadata";
|
|
12547
|
-
function getGeometryColumnsFromSchema(schema) {
|
|
12548
|
-
const geometryColumns = {};
|
|
12549
|
-
for (const field of schema.fields) {
|
|
12550
|
-
const metadata = getGeometryMetadataForField(field);
|
|
12551
|
-
if (metadata) {
|
|
12552
|
-
geometryColumns[field.name] = metadata;
|
|
12553
|
-
}
|
|
12554
|
-
}
|
|
12555
|
-
return geometryColumns;
|
|
12556
|
-
}
|
|
12557
|
-
function getGeometryMetadataForField(field) {
|
|
12558
|
-
let metadata = null;
|
|
12559
|
-
const columnMetadata = field.metadata?.[GEOARROW_COLUMN_METADATA_METADATA];
|
|
12560
|
-
if (columnMetadata) {
|
|
12561
|
-
try {
|
|
12562
|
-
metadata = JSON.parse(columnMetadata);
|
|
12563
|
-
} catch (error) {
|
|
12564
|
-
console.warn("Failed to parse GeoArrow metadata", error);
|
|
12565
|
-
}
|
|
12566
|
-
}
|
|
12567
|
-
let geoEncoding = field.metadata?.[GEOARROW_COLUMN_METADATA_ENCODING];
|
|
12568
|
-
if (geoEncoding) {
|
|
12569
|
-
geoEncoding = geoEncoding.toLowerCase();
|
|
12570
|
-
if (!GEOARROW_ENCODINGS.includes(geoEncoding)) {
|
|
12571
|
-
console.warn(`Invalid GeoArrow encoding: ${geoEncoding}`);
|
|
12572
|
-
} else {
|
|
12573
|
-
metadata = metadata || {};
|
|
12574
|
-
metadata.encoding = geoEncoding;
|
|
12575
|
-
}
|
|
12576
|
-
}
|
|
12577
|
-
return metadata || null;
|
|
12578
12460
|
}
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
function _typeof(obj) {
|
|
12582
|
-
"@babel/helpers - typeof";
|
|
12583
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
12584
|
-
return typeof obj2;
|
|
12585
|
-
} : function(obj2) {
|
|
12586
|
-
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
12587
|
-
}, _typeof(obj);
|
|
12461
|
+
function deserializeArrowSchema(schema) {
|
|
12462
|
+
return new Schema2(schema.fields.map((field) => deserializeArrowField(field)), deserializeArrowMetadata(schema.metadata));
|
|
12588
12463
|
}
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
function _toPrimitive(input, hint) {
|
|
12592
|
-
if (_typeof(input) !== "object" || input === null)
|
|
12593
|
-
return input;
|
|
12594
|
-
var prim = input[Symbol.toPrimitive];
|
|
12595
|
-
if (prim !== void 0) {
|
|
12596
|
-
var res = prim.call(input, hint || "default");
|
|
12597
|
-
if (_typeof(res) !== "object")
|
|
12598
|
-
return res;
|
|
12599
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
12600
|
-
}
|
|
12601
|
-
return (hint === "string" ? String : Number)(input);
|
|
12464
|
+
function serializeArrowMetadata(arrowMetadata) {
|
|
12465
|
+
return Object.fromEntries(arrowMetadata);
|
|
12602
12466
|
}
|
|
12603
|
-
|
|
12604
|
-
|
|
12605
|
-
function _toPropertyKey(arg) {
|
|
12606
|
-
var key = _toPrimitive(arg, "string");
|
|
12607
|
-
return _typeof(key) === "symbol" ? key : String(key);
|
|
12467
|
+
function deserializeArrowMetadata(metadata) {
|
|
12468
|
+
return metadata ? new Map(Object.entries(metadata)) : /* @__PURE__ */ new Map();
|
|
12608
12469
|
}
|
|
12609
|
-
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
12613
|
-
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
enumerable: true,
|
|
12617
|
-
configurable: true,
|
|
12618
|
-
writable: true
|
|
12619
|
-
});
|
|
12620
|
-
} else {
|
|
12621
|
-
obj[key] = value;
|
|
12622
|
-
}
|
|
12623
|
-
return obj;
|
|
12470
|
+
function serializeArrowField(field) {
|
|
12471
|
+
return {
|
|
12472
|
+
name: field.name,
|
|
12473
|
+
type: serializeArrowType(field.type),
|
|
12474
|
+
nullable: field.nullable,
|
|
12475
|
+
metadata: serializeArrowMetadata(field.metadata)
|
|
12476
|
+
};
|
|
12624
12477
|
}
|
|
12625
|
-
|
|
12626
|
-
|
|
12627
|
-
var DimIndex = {
|
|
12628
|
-
x: 0,
|
|
12629
|
-
y: 1,
|
|
12630
|
-
z: 2
|
|
12631
|
-
};
|
|
12632
|
-
function getPolygonSignedArea(points, options = {}) {
|
|
12633
|
-
const {
|
|
12634
|
-
start = 0,
|
|
12635
|
-
end = points.length,
|
|
12636
|
-
plane = "xy"
|
|
12637
|
-
} = options;
|
|
12638
|
-
const dim = options.size || 2;
|
|
12639
|
-
let area2 = 0;
|
|
12640
|
-
const i0 = DimIndex[plane[0]];
|
|
12641
|
-
const i1 = DimIndex[plane[1]];
|
|
12642
|
-
for (let i = start, j = end - dim; i < end; i += dim) {
|
|
12643
|
-
area2 += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
|
|
12644
|
-
j = i;
|
|
12645
|
-
}
|
|
12646
|
-
return area2 / 2;
|
|
12478
|
+
function deserializeArrowField(field) {
|
|
12479
|
+
return new Field2(field.name, deserializeArrowType(field.type), field.nullable, deserializeArrowMetadata(field.metadata));
|
|
12647
12480
|
}
|
|
12648
|
-
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
|
|
12661
|
-
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12481
|
+
function serializeArrowType(arrowType) {
|
|
12482
|
+
switch (arrowType.constructor) {
|
|
12483
|
+
case Null:
|
|
12484
|
+
return "null";
|
|
12485
|
+
case Binary:
|
|
12486
|
+
return "binary";
|
|
12487
|
+
case Bool:
|
|
12488
|
+
return "bool";
|
|
12489
|
+
case Int_:
|
|
12490
|
+
const intType = arrowType;
|
|
12491
|
+
return `${intType.isSigned ? "u" : ""}int${intType.bitWidth}`;
|
|
12492
|
+
case Int8:
|
|
12493
|
+
return "int8";
|
|
12494
|
+
case Int16:
|
|
12495
|
+
return "int16";
|
|
12496
|
+
case Int32:
|
|
12497
|
+
return "int32";
|
|
12498
|
+
case Int64:
|
|
12499
|
+
return "int64";
|
|
12500
|
+
case Uint8:
|
|
12501
|
+
return "uint8";
|
|
12502
|
+
case Uint16:
|
|
12503
|
+
return "uint16";
|
|
12504
|
+
case Uint32:
|
|
12505
|
+
return "uint32";
|
|
12506
|
+
case Uint64:
|
|
12507
|
+
return "uint64";
|
|
12508
|
+
case Float:
|
|
12509
|
+
const precision = arrowType.precision;
|
|
12510
|
+
switch (precision) {
|
|
12511
|
+
case Precision.HALF:
|
|
12512
|
+
return "float16";
|
|
12513
|
+
case Precision.SINGLE:
|
|
12514
|
+
return "float32";
|
|
12515
|
+
case Precision.DOUBLE:
|
|
12516
|
+
return "float64";
|
|
12517
|
+
default:
|
|
12518
|
+
return "float16";
|
|
12519
|
+
}
|
|
12520
|
+
case Float16:
|
|
12521
|
+
return "float16";
|
|
12522
|
+
case Float32:
|
|
12523
|
+
return "float32";
|
|
12524
|
+
case Float64:
|
|
12525
|
+
return "float64";
|
|
12526
|
+
case Utf8:
|
|
12527
|
+
return "utf8";
|
|
12528
|
+
case Decimal:
|
|
12529
|
+
const decimal = arrowType;
|
|
12530
|
+
return {
|
|
12531
|
+
type: "decimal",
|
|
12532
|
+
bitWidth: decimal.bitWidth,
|
|
12533
|
+
precision: decimal.precision,
|
|
12534
|
+
scale: decimal.scale
|
|
12535
|
+
};
|
|
12536
|
+
case Date_:
|
|
12537
|
+
const dateUnit = arrowType.unit;
|
|
12538
|
+
return dateUnit === DateUnit.DAY ? "date-day" : "date-millisecond";
|
|
12539
|
+
case DateDay:
|
|
12540
|
+
return "date-day";
|
|
12541
|
+
case DateMillisecond:
|
|
12542
|
+
return "date-millisecond";
|
|
12543
|
+
case Time_:
|
|
12544
|
+
const timeUnit = arrowType.unit;
|
|
12545
|
+
switch (timeUnit) {
|
|
12546
|
+
case TimeUnit.SECOND:
|
|
12547
|
+
return "time-second";
|
|
12548
|
+
case TimeUnit.MILLISECOND:
|
|
12549
|
+
return "time-millisecond";
|
|
12550
|
+
case TimeUnit.MICROSECOND:
|
|
12551
|
+
return "time-microsecond";
|
|
12552
|
+
case TimeUnit.NANOSECOND:
|
|
12553
|
+
return "time-nanosecond";
|
|
12554
|
+
default:
|
|
12555
|
+
return "time-second";
|
|
12556
|
+
}
|
|
12557
|
+
case TimeMillisecond:
|
|
12558
|
+
return "time-millisecond";
|
|
12559
|
+
case TimeSecond:
|
|
12560
|
+
return "time-second";
|
|
12561
|
+
case TimeMicrosecond:
|
|
12562
|
+
return "time-microsecond";
|
|
12563
|
+
case TimeNanosecond:
|
|
12564
|
+
return "time-nanosecond";
|
|
12565
|
+
case Timestamp_:
|
|
12566
|
+
const timeStampUnit = arrowType.unit;
|
|
12567
|
+
switch (timeStampUnit) {
|
|
12568
|
+
case TimeUnit.SECOND:
|
|
12569
|
+
return "timestamp-second";
|
|
12570
|
+
case TimeUnit.MILLISECOND:
|
|
12571
|
+
return "timestamp-millisecond";
|
|
12572
|
+
case TimeUnit.MICROSECOND:
|
|
12573
|
+
return "timestamp-microsecond";
|
|
12574
|
+
case TimeUnit.NANOSECOND:
|
|
12575
|
+
return "timestamp-nanosecond";
|
|
12576
|
+
default:
|
|
12577
|
+
return "timestamp-second";
|
|
12578
|
+
}
|
|
12579
|
+
case TimestampSecond:
|
|
12580
|
+
return "timestamp-second";
|
|
12581
|
+
case TimestampMillisecond:
|
|
12582
|
+
return "timestamp-millisecond";
|
|
12583
|
+
case TimestampMicrosecond:
|
|
12584
|
+
return "timestamp-microsecond";
|
|
12585
|
+
case TimestampNanosecond:
|
|
12586
|
+
return "timestamp-nanosecond";
|
|
12587
|
+
case Interval_:
|
|
12588
|
+
const intervalUnit = arrowType.unit;
|
|
12589
|
+
switch (intervalUnit) {
|
|
12590
|
+
case IntervalUnit.DAY_TIME:
|
|
12591
|
+
return "interval-daytime";
|
|
12592
|
+
case IntervalUnit.YEAR_MONTH:
|
|
12593
|
+
return "interval-yearmonth";
|
|
12594
|
+
default:
|
|
12595
|
+
return "interval-daytime";
|
|
12596
|
+
}
|
|
12597
|
+
case IntervalDayTime:
|
|
12598
|
+
return "interval-daytime";
|
|
12599
|
+
case IntervalYearMonth:
|
|
12600
|
+
return "interval-yearmonth";
|
|
12601
|
+
case Map_:
|
|
12602
|
+
const mapType = arrowType;
|
|
12603
|
+
return {
|
|
12604
|
+
type: "map",
|
|
12605
|
+
keysSorted: mapType.keysSorted,
|
|
12606
|
+
children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
12607
|
+
};
|
|
12608
|
+
case List:
|
|
12609
|
+
const listType = arrowType;
|
|
12610
|
+
const listField = listType.valueField;
|
|
12611
|
+
return {
|
|
12612
|
+
type: "list",
|
|
12613
|
+
children: [serializeArrowField(listField)]
|
|
12614
|
+
};
|
|
12615
|
+
case FixedSizeList:
|
|
12616
|
+
const fixedSizeList = arrowType;
|
|
12617
|
+
return {
|
|
12618
|
+
type: "fixed-size-list",
|
|
12619
|
+
listSize: fixedSizeList.listSize,
|
|
12620
|
+
children: [serializeArrowField(fixedSizeList.children[0])]
|
|
12621
|
+
};
|
|
12622
|
+
case Struct:
|
|
12623
|
+
const structType = arrowType;
|
|
12624
|
+
return {
|
|
12625
|
+
type: "struct",
|
|
12626
|
+
children: structType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
12627
|
+
};
|
|
12628
|
+
default:
|
|
12629
|
+
throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
|
|
12630
|
+
}
|
|
12631
|
+
}
|
|
12632
|
+
function deserializeArrowType(dataType) {
|
|
12633
|
+
if (typeof dataType === "object") {
|
|
12634
|
+
switch (dataType.type) {
|
|
12635
|
+
case "decimal":
|
|
12636
|
+
return new Decimal(dataType.precision, dataType.scale, dataType.bitWidth);
|
|
12637
|
+
case "map":
|
|
12638
|
+
let children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
12639
|
+
return new Map_(children, dataType.keysSorted);
|
|
12640
|
+
case "list":
|
|
12641
|
+
const field = deserializeArrowField(dataType.children[0]);
|
|
12642
|
+
return new List(field);
|
|
12643
|
+
case "fixed-size-list":
|
|
12644
|
+
const child = deserializeArrowField(dataType.children[0]);
|
|
12645
|
+
return new FixedSizeList(dataType.listSize, child);
|
|
12646
|
+
case "struct":
|
|
12647
|
+
children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
12648
|
+
return new Struct(children);
|
|
12649
|
+
default:
|
|
12650
|
+
throw new Error("array type not supported");
|
|
12651
|
+
}
|
|
12652
|
+
}
|
|
12653
|
+
switch (dataType) {
|
|
12654
|
+
case "null":
|
|
12655
|
+
return new Null();
|
|
12656
|
+
case "binary":
|
|
12657
|
+
return new Binary();
|
|
12658
|
+
case "bool":
|
|
12659
|
+
return new Bool();
|
|
12660
|
+
case "int8":
|
|
12661
|
+
return new Int8();
|
|
12662
|
+
case "int16":
|
|
12663
|
+
return new Int16();
|
|
12664
|
+
case "int32":
|
|
12665
|
+
return new Int32();
|
|
12666
|
+
case "int64":
|
|
12667
|
+
return new Int64();
|
|
12668
|
+
case "uint8":
|
|
12669
|
+
return new Uint8();
|
|
12670
|
+
case "uint16":
|
|
12671
|
+
return new Uint16();
|
|
12672
|
+
case "uint32":
|
|
12673
|
+
return new Uint32();
|
|
12674
|
+
case "uint64":
|
|
12675
|
+
return new Uint64();
|
|
12676
|
+
case "float16":
|
|
12677
|
+
return new Float16();
|
|
12678
|
+
case "float32":
|
|
12679
|
+
return new Float32();
|
|
12680
|
+
case "float64":
|
|
12681
|
+
return new Float64();
|
|
12682
|
+
case "utf8":
|
|
12683
|
+
return new Utf8();
|
|
12684
|
+
case "date-day":
|
|
12685
|
+
return new DateDay();
|
|
12686
|
+
case "date-millisecond":
|
|
12687
|
+
return new DateMillisecond();
|
|
12688
|
+
case "time-second":
|
|
12689
|
+
return new TimeSecond();
|
|
12690
|
+
case "time-millisecond":
|
|
12691
|
+
return new TimeMillisecond();
|
|
12692
|
+
case "time-microsecond":
|
|
12693
|
+
return new TimeMicrosecond();
|
|
12694
|
+
case "time-nanosecond":
|
|
12695
|
+
return new TimeNanosecond();
|
|
12696
|
+
case "timestamp-second":
|
|
12697
|
+
return new TimestampSecond();
|
|
12698
|
+
case "timestamp-millisecond":
|
|
12699
|
+
return new TimestampMillisecond();
|
|
12700
|
+
case "timestamp-microsecond":
|
|
12701
|
+
return new TimestampMicrosecond();
|
|
12702
|
+
case "timestamp-nanosecond":
|
|
12703
|
+
return new TimestampNanosecond();
|
|
12704
|
+
case "interval-daytime":
|
|
12705
|
+
return new IntervalDayTime();
|
|
12706
|
+
case "interval-yearmonth":
|
|
12707
|
+
return new IntervalYearMonth();
|
|
12708
|
+
default:
|
|
12709
|
+
throw new Error("array type not supported");
|
|
12710
|
+
}
|
|
12711
|
+
}
|
|
12712
|
+
|
|
12713
|
+
// src/parsers/parse-arrow-sync.ts
|
|
12714
|
+
function parseArrowSync(arrayBuffer, options) {
|
|
12715
|
+
const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
|
|
12716
|
+
const arrowTable = {
|
|
12717
|
+
shape: "arrow-table",
|
|
12718
|
+
schema: serializeArrowSchema(apacheArrowTable.schema),
|
|
12719
|
+
data: apacheArrowTable
|
|
12720
|
+
};
|
|
12721
|
+
const shape = options?.shape || "arrow-table";
|
|
12722
|
+
switch (shape) {
|
|
12723
|
+
case "arrow-table":
|
|
12724
|
+
return arrowTable;
|
|
12725
|
+
case "columnar-table":
|
|
12726
|
+
return convertArrowToColumnarTable(arrowTable);
|
|
12727
|
+
case "object-row-table":
|
|
12728
|
+
let columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
12729
|
+
return convertTable(columnarTable, "object-row-table");
|
|
12730
|
+
case "array-row-table":
|
|
12731
|
+
columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
12732
|
+
return convertTable(columnarTable, "array-row-table");
|
|
12733
|
+
default:
|
|
12734
|
+
throw new Error(shape);
|
|
12735
|
+
}
|
|
12736
|
+
}
|
|
12737
|
+
|
|
12738
|
+
// src/parsers/parse-arrow-in-batches.ts
|
|
12739
|
+
function parseArrowInBatches(asyncIterator, options) {
|
|
12740
|
+
async function* makeArrowAsyncIterator() {
|
|
12741
|
+
const readers = RecordBatchReader.readAll(asyncIterator);
|
|
12742
|
+
for await (const reader of readers) {
|
|
12743
|
+
for await (const recordBatch of reader) {
|
|
12744
|
+
if (options?.arrow?.batchDebounceMs !== void 0 && options?.arrow?.batchDebounceMs > 0) {
|
|
12745
|
+
await new Promise((resolve) => setTimeout(resolve, options.arrow?.batchDebounceMs || 0));
|
|
12746
|
+
}
|
|
12747
|
+
const arrowTabledBatch = {
|
|
12748
|
+
shape: "arrow-table",
|
|
12749
|
+
batchType: "data",
|
|
12750
|
+
data: new Table([recordBatch]),
|
|
12751
|
+
length: recordBatch.data.length
|
|
12752
|
+
};
|
|
12753
|
+
yield arrowTabledBatch;
|
|
12754
|
+
}
|
|
12755
|
+
break;
|
|
12756
|
+
}
|
|
12757
|
+
}
|
|
12758
|
+
return makeArrowAsyncIterator();
|
|
12759
|
+
}
|
|
12760
|
+
|
|
12761
|
+
// src/arrow-loader.ts
|
|
12762
|
+
var VERSION = true ? "4.1.0-alpha.10" : "latest";
|
|
12763
|
+
var ArrowWorkerLoader = {
|
|
12764
|
+
name: "Apache Arrow",
|
|
12765
|
+
id: "arrow",
|
|
12766
|
+
module: "arrow",
|
|
12767
|
+
version: VERSION,
|
|
12768
|
+
category: "table",
|
|
12769
|
+
extensions: ["arrow", "feather"],
|
|
12770
|
+
mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
|
|
12771
|
+
binary: true,
|
|
12772
|
+
tests: ["ARROW"],
|
|
12773
|
+
options: {
|
|
12774
|
+
arrow: {
|
|
12775
|
+
shape: "columnar-table"
|
|
12776
|
+
}
|
|
12777
|
+
}
|
|
12778
|
+
};
|
|
12779
|
+
var ArrowLoader = {
|
|
12780
|
+
...ArrowWorkerLoader,
|
|
12781
|
+
parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),
|
|
12782
|
+
parseSync: (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),
|
|
12783
|
+
parseInBatches: parseArrowInBatches
|
|
12784
|
+
};
|
|
12785
|
+
|
|
12786
|
+
// src/lib/encode-arrow.ts
|
|
12787
|
+
function encodeArrowSync(data) {
|
|
12788
|
+
const vectors = {};
|
|
12789
|
+
for (const arrayData of data) {
|
|
12790
|
+
const arrayVector = createVector(arrayData.array, arrayData.type);
|
|
12791
|
+
vectors[arrayData.name] = arrayVector;
|
|
12792
|
+
}
|
|
12793
|
+
const table = new Table(vectors);
|
|
12794
|
+
const arrowBuffer = tableToIPC(table);
|
|
12795
|
+
return arrowBuffer;
|
|
12796
|
+
}
|
|
12797
|
+
function createVector(array, type) {
|
|
12798
|
+
switch (type) {
|
|
12799
|
+
case VECTOR_TYPES.DATE:
|
|
12800
|
+
return vectorFromArray(array);
|
|
12801
|
+
case VECTOR_TYPES.FLOAT:
|
|
12802
|
+
default:
|
|
12803
|
+
return vectorFromArray(array);
|
|
12804
|
+
}
|
|
12805
|
+
}
|
|
12806
|
+
|
|
12807
|
+
// src/arrow-writer.ts
|
|
12808
|
+
var VERSION2 = true ? "4.1.0-alpha.10" : "latest";
|
|
12809
|
+
var ArrowWriter = {
|
|
12810
|
+
name: "Apache Arrow",
|
|
12811
|
+
id: "arrow",
|
|
12812
|
+
module: "arrow",
|
|
12813
|
+
version: VERSION2,
|
|
12814
|
+
extensions: ["arrow", "feather"],
|
|
12815
|
+
mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
|
|
12816
|
+
binary: true,
|
|
12817
|
+
options: {},
|
|
12818
|
+
encode: async function encodeArrow(data, options) {
|
|
12819
|
+
return encodeArrowSync(data);
|
|
12820
|
+
},
|
|
12821
|
+
encodeSync(data, options) {
|
|
12822
|
+
return encodeArrowSync(data);
|
|
12823
|
+
}
|
|
12824
|
+
};
|
|
12825
|
+
|
|
12826
|
+
// ../gis/src/lib/geo/geoarrow-metadata.ts
|
|
12827
|
+
var GEOARROW_ENCODINGS = ["geoarrow.multipolygon", "geoarrow.polygon", "geoarrow.multilinestring", "geoarrow.linestring", "geoarrow.multipoint", "geoarrow.point", "geoarrow.wkb", "geoarrow.wkt"];
|
|
12828
|
+
var GEOARROW_COLUMN_METADATA_ENCODING = "ARROW:extension:name";
|
|
12829
|
+
var GEOARROW_COLUMN_METADATA_METADATA = "ARROW:extension:metadata";
|
|
12830
|
+
function getGeometryColumnsFromSchema(schema) {
|
|
12831
|
+
const geometryColumns = {};
|
|
12832
|
+
for (const field of schema.fields) {
|
|
12833
|
+
const metadata = getGeometryMetadataForField(field);
|
|
12834
|
+
if (metadata) {
|
|
12835
|
+
geometryColumns[field.name] = metadata;
|
|
12836
|
+
}
|
|
12837
|
+
}
|
|
12838
|
+
return geometryColumns;
|
|
12839
|
+
}
|
|
12840
|
+
function getGeometryMetadataForField(field) {
|
|
12841
|
+
let metadata = null;
|
|
12842
|
+
let geoEncoding = field.metadata?.[GEOARROW_COLUMN_METADATA_ENCODING];
|
|
12843
|
+
if (geoEncoding) {
|
|
12844
|
+
geoEncoding = geoEncoding.toLowerCase();
|
|
12845
|
+
if (geoEncoding === "wkb") {
|
|
12846
|
+
geoEncoding = "geoarrow.wkb";
|
|
12847
|
+
}
|
|
12848
|
+
if (geoEncoding === "wkt") {
|
|
12849
|
+
geoEncoding = "geoarrow.wkt";
|
|
12850
|
+
}
|
|
12851
|
+
if (!GEOARROW_ENCODINGS.includes(geoEncoding)) {
|
|
12852
|
+
console.warn(`Invalid GeoArrow encoding: ${geoEncoding}`);
|
|
12853
|
+
} else {
|
|
12854
|
+
metadata = metadata || {};
|
|
12855
|
+
metadata.encoding = geoEncoding;
|
|
12856
|
+
}
|
|
12857
|
+
}
|
|
12858
|
+
const columnMetadata = field.metadata?.[GEOARROW_COLUMN_METADATA_METADATA];
|
|
12859
|
+
if (columnMetadata) {
|
|
12860
|
+
try {
|
|
12861
|
+
metadata = JSON.parse(columnMetadata);
|
|
12862
|
+
} catch (error) {
|
|
12863
|
+
console.warn("Failed to parse GeoArrow metadata", error);
|
|
12864
|
+
}
|
|
12865
|
+
}
|
|
12866
|
+
return metadata || null;
|
|
12867
|
+
}
|
|
12868
|
+
|
|
12869
|
+
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
12870
|
+
function _typeof(obj) {
|
|
12871
|
+
"@babel/helpers - typeof";
|
|
12872
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
12873
|
+
return typeof obj2;
|
|
12874
|
+
} : function(obj2) {
|
|
12875
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
12876
|
+
}, _typeof(obj);
|
|
12877
|
+
}
|
|
12878
|
+
|
|
12879
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
|
|
12880
|
+
function _toPrimitive(input, hint) {
|
|
12881
|
+
if (_typeof(input) !== "object" || input === null)
|
|
12882
|
+
return input;
|
|
12883
|
+
var prim = input[Symbol.toPrimitive];
|
|
12884
|
+
if (prim !== void 0) {
|
|
12885
|
+
var res = prim.call(input, hint || "default");
|
|
12886
|
+
if (_typeof(res) !== "object")
|
|
12887
|
+
return res;
|
|
12888
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
12889
|
+
}
|
|
12890
|
+
return (hint === "string" ? String : Number)(input);
|
|
12891
|
+
}
|
|
12892
|
+
|
|
12893
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
|
|
12894
|
+
function _toPropertyKey(arg) {
|
|
12895
|
+
var key = _toPrimitive(arg, "string");
|
|
12896
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
12897
|
+
}
|
|
12898
|
+
|
|
12899
|
+
// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
12900
|
+
function _defineProperty(obj, key, value) {
|
|
12901
|
+
key = _toPropertyKey(key);
|
|
12902
|
+
if (key in obj) {
|
|
12903
|
+
Object.defineProperty(obj, key, {
|
|
12904
|
+
value,
|
|
12905
|
+
enumerable: true,
|
|
12906
|
+
configurable: true,
|
|
12907
|
+
writable: true
|
|
12908
|
+
});
|
|
12909
|
+
} else {
|
|
12910
|
+
obj[key] = value;
|
|
12911
|
+
}
|
|
12912
|
+
return obj;
|
|
12913
|
+
}
|
|
12914
|
+
|
|
12915
|
+
// ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
|
|
12916
|
+
var DimIndex = {
|
|
12917
|
+
x: 0,
|
|
12918
|
+
y: 1,
|
|
12919
|
+
z: 2
|
|
12920
|
+
};
|
|
12921
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
12922
|
+
const {
|
|
12923
|
+
start = 0,
|
|
12924
|
+
end = points.length,
|
|
12925
|
+
plane = "xy"
|
|
12926
|
+
} = options;
|
|
12927
|
+
const dim = options.size || 2;
|
|
12928
|
+
let area2 = 0;
|
|
12929
|
+
const i0 = DimIndex[plane[0]];
|
|
12930
|
+
const i1 = DimIndex[plane[1]];
|
|
12931
|
+
for (let i = start, j = end - dim; i < end; i += dim) {
|
|
12932
|
+
area2 += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
|
|
12933
|
+
j = i;
|
|
12934
|
+
}
|
|
12935
|
+
return area2 / 2;
|
|
12936
|
+
}
|
|
12937
|
+
|
|
12938
|
+
// ../../node_modules/@math.gl/polygon/dist/earcut.js
|
|
12939
|
+
function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
|
|
12940
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
12941
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
12942
|
+
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
|
|
12943
|
+
const triangles = [];
|
|
12944
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
12945
|
+
return triangles;
|
|
12946
|
+
let invSize;
|
|
12947
|
+
let maxX;
|
|
12948
|
+
let maxY;
|
|
12949
|
+
let minX;
|
|
12950
|
+
let minY;
|
|
12951
|
+
let x;
|
|
12952
|
+
let y;
|
|
12953
|
+
if (hasHoles)
|
|
12954
|
+
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
|
|
12955
|
+
if (positions.length > 80 * dim) {
|
|
12667
12956
|
minX = maxX = positions[0];
|
|
12668
12957
|
minY = maxY = positions[1];
|
|
12669
12958
|
for (let i = dim; i < outerLen; i += dim) {
|
|
@@ -13136,329 +13425,175 @@ return true;`);
|
|
|
13136
13425
|
}
|
|
13137
13426
|
};
|
|
13138
13427
|
|
|
13139
|
-
// src/
|
|
13140
|
-
function
|
|
13141
|
-
|
|
13142
|
-
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
|
|
13147
|
-
|
|
13148
|
-
|
|
13149
|
-
|
|
13150
|
-
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
|
|
13154
|
-
|
|
13428
|
+
// ../gis/src/lib/binary-features/binary-to-geojson.ts
|
|
13429
|
+
function binaryToGeometry(data, startIndex, endIndex) {
|
|
13430
|
+
switch (data.type) {
|
|
13431
|
+
case "Point":
|
|
13432
|
+
return pointToGeoJson(data, startIndex, endIndex);
|
|
13433
|
+
case "LineString":
|
|
13434
|
+
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
13435
|
+
case "Polygon":
|
|
13436
|
+
return polygonToGeoJson(data, startIndex, endIndex);
|
|
13437
|
+
default:
|
|
13438
|
+
const unexpectedInput = data;
|
|
13439
|
+
throw new Error(`Unsupported geometry type: ${unexpectedInput?.type}`);
|
|
13440
|
+
}
|
|
13441
|
+
}
|
|
13442
|
+
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
13443
|
+
const {
|
|
13444
|
+
positions
|
|
13445
|
+
} = data;
|
|
13446
|
+
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
13447
|
+
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
13448
|
+
const multi = polygonIndices.length > 2;
|
|
13449
|
+
if (!multi) {
|
|
13450
|
+
const coordinates2 = [];
|
|
13451
|
+
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
13452
|
+
const startRingIndex = primitivePolygonIndices[i];
|
|
13453
|
+
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
13454
|
+
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
13455
|
+
coordinates2.push(ringCoordinates);
|
|
13155
13456
|
}
|
|
13457
|
+
return {
|
|
13458
|
+
type: "Polygon",
|
|
13459
|
+
coordinates: coordinates2
|
|
13460
|
+
};
|
|
13461
|
+
}
|
|
13462
|
+
const coordinates = [];
|
|
13463
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
13464
|
+
const startPolygonIndex = polygonIndices[i];
|
|
13465
|
+
const endPolygonIndex = polygonIndices[i + 1];
|
|
13466
|
+
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
13467
|
+
coordinates.push(polygonCoordinates);
|
|
13156
13468
|
}
|
|
13157
13469
|
return {
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
features
|
|
13470
|
+
type: "MultiPolygon",
|
|
13471
|
+
coordinates
|
|
13161
13472
|
};
|
|
13162
13473
|
}
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13474
|
+
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
13475
|
+
const {
|
|
13476
|
+
positions
|
|
13477
|
+
} = data;
|
|
13478
|
+
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
13479
|
+
const multi = pathIndices.length > 2;
|
|
13480
|
+
if (!multi) {
|
|
13481
|
+
const coordinates2 = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
13482
|
+
return {
|
|
13483
|
+
type: "LineString",
|
|
13484
|
+
coordinates: coordinates2
|
|
13485
|
+
};
|
|
13174
13486
|
}
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
return parseArrowInBatches(asyncIterator);
|
|
13180
|
-
}
|
|
13181
|
-
|
|
13182
|
-
// src/geoarrow-loader.ts
|
|
13183
|
-
var GeoArrowWorkerLoader = {
|
|
13184
|
-
...ArrowWorkerLoader,
|
|
13185
|
-
options: {
|
|
13186
|
-
arrow: {
|
|
13187
|
-
shape: "arrow-table"
|
|
13188
|
-
}
|
|
13487
|
+
const coordinates = [];
|
|
13488
|
+
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
13489
|
+
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
13490
|
+
coordinates.push(ringCoordinates);
|
|
13189
13491
|
}
|
|
13190
|
-
};
|
|
13191
|
-
var GeoArrowLoader = {
|
|
13192
|
-
...ArrowWorkerLoader,
|
|
13193
|
-
options: {
|
|
13194
|
-
arrow: {
|
|
13195
|
-
shape: "arrow-table"
|
|
13196
|
-
}
|
|
13197
|
-
},
|
|
13198
|
-
parse: async (arraybuffer, options) => parseGeoArrowSync(arraybuffer, options?.arrow),
|
|
13199
|
-
parseSync: (arraybuffer, options) => parseGeoArrowSync(arraybuffer, options?.arrow),
|
|
13200
|
-
parseInBatches: parseGeoArrowInBatches
|
|
13201
|
-
};
|
|
13202
|
-
|
|
13203
|
-
// src/schema/convert-arrow-schema.ts
|
|
13204
|
-
function serializeArrowSchema(arrowSchema) {
|
|
13205
13492
|
return {
|
|
13206
|
-
|
|
13207
|
-
|
|
13493
|
+
type: "MultiLineString",
|
|
13494
|
+
coordinates
|
|
13208
13495
|
};
|
|
13209
13496
|
}
|
|
13210
|
-
function
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
|
|
13216
|
-
|
|
13217
|
-
|
|
13218
|
-
|
|
13219
|
-
|
|
13220
|
-
|
|
13221
|
-
|
|
13222
|
-
|
|
13223
|
-
|
|
13224
|
-
|
|
13497
|
+
function pointToGeoJson(data, startIndex, endIndex) {
|
|
13498
|
+
const {
|
|
13499
|
+
positions
|
|
13500
|
+
} = data;
|
|
13501
|
+
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
13502
|
+
const multi = coordinates.length > 1;
|
|
13503
|
+
if (multi) {
|
|
13504
|
+
return {
|
|
13505
|
+
type: "MultiPoint",
|
|
13506
|
+
coordinates
|
|
13507
|
+
};
|
|
13508
|
+
}
|
|
13509
|
+
return {
|
|
13510
|
+
type: "Point",
|
|
13511
|
+
coordinates: coordinates[0]
|
|
13225
13512
|
};
|
|
13226
13513
|
}
|
|
13227
|
-
function
|
|
13228
|
-
|
|
13229
|
-
|
|
13230
|
-
|
|
13231
|
-
|
|
13232
|
-
|
|
13233
|
-
|
|
13234
|
-
|
|
13235
|
-
|
|
13236
|
-
|
|
13237
|
-
return "bool";
|
|
13238
|
-
case Int_:
|
|
13239
|
-
const intType = arrowType;
|
|
13240
|
-
return `${intType.isSigned ? "u" : ""}int${intType.bitWidth}`;
|
|
13241
|
-
case Int8:
|
|
13242
|
-
return "int8";
|
|
13243
|
-
case Int16:
|
|
13244
|
-
return "int16";
|
|
13245
|
-
case Int32:
|
|
13246
|
-
return "int32";
|
|
13247
|
-
case Int64:
|
|
13248
|
-
return "int64";
|
|
13249
|
-
case Uint8:
|
|
13250
|
-
return "uint8";
|
|
13251
|
-
case Uint16:
|
|
13252
|
-
return "uint16";
|
|
13253
|
-
case Uint32:
|
|
13254
|
-
return "uint32";
|
|
13255
|
-
case Uint64:
|
|
13256
|
-
return "uint64";
|
|
13257
|
-
case Float:
|
|
13258
|
-
const precision = arrowType.precision;
|
|
13259
|
-
switch (precision) {
|
|
13260
|
-
case Precision.HALF:
|
|
13261
|
-
return "float16";
|
|
13262
|
-
case Precision.SINGLE:
|
|
13263
|
-
return "float32";
|
|
13264
|
-
case Precision.DOUBLE:
|
|
13265
|
-
return "float64";
|
|
13266
|
-
default:
|
|
13267
|
-
return "float16";
|
|
13268
|
-
}
|
|
13269
|
-
case Float16:
|
|
13270
|
-
return "float16";
|
|
13271
|
-
case Float32:
|
|
13272
|
-
return "float32";
|
|
13273
|
-
case Float64:
|
|
13274
|
-
return "float64";
|
|
13275
|
-
case Utf8:
|
|
13276
|
-
return "utf8";
|
|
13277
|
-
case Decimal:
|
|
13278
|
-
const decimal = arrowType;
|
|
13279
|
-
return {
|
|
13280
|
-
type: "decimal",
|
|
13281
|
-
bitWidth: decimal.bitWidth,
|
|
13282
|
-
precision: decimal.precision,
|
|
13283
|
-
scale: decimal.scale
|
|
13284
|
-
};
|
|
13285
|
-
case Date_:
|
|
13286
|
-
const dateUnit = arrowType.unit;
|
|
13287
|
-
return dateUnit === DateUnit.DAY ? "date-day" : "date-millisecond";
|
|
13288
|
-
case DateDay:
|
|
13289
|
-
return "date-day";
|
|
13290
|
-
case DateMillisecond:
|
|
13291
|
-
return "date-millisecond";
|
|
13292
|
-
case Time_:
|
|
13293
|
-
const timeUnit = arrowType.unit;
|
|
13294
|
-
switch (timeUnit) {
|
|
13295
|
-
case TimeUnit.SECOND:
|
|
13296
|
-
return "time-second";
|
|
13297
|
-
case TimeUnit.MILLISECOND:
|
|
13298
|
-
return "time-millisecond";
|
|
13299
|
-
case TimeUnit.MICROSECOND:
|
|
13300
|
-
return "time-microsecond";
|
|
13301
|
-
case TimeUnit.NANOSECOND:
|
|
13302
|
-
return "time-nanosecond";
|
|
13303
|
-
default:
|
|
13304
|
-
return "time-second";
|
|
13305
|
-
}
|
|
13306
|
-
case TimeMillisecond:
|
|
13307
|
-
return "time-millisecond";
|
|
13308
|
-
case TimeSecond:
|
|
13309
|
-
return "time-second";
|
|
13310
|
-
case TimeMicrosecond:
|
|
13311
|
-
return "time-microsecond";
|
|
13312
|
-
case TimeNanosecond:
|
|
13313
|
-
return "time-nanosecond";
|
|
13314
|
-
case Timestamp_:
|
|
13315
|
-
const timeStampUnit = arrowType.unit;
|
|
13316
|
-
switch (timeStampUnit) {
|
|
13317
|
-
case TimeUnit.SECOND:
|
|
13318
|
-
return "timestamp-second";
|
|
13319
|
-
case TimeUnit.MILLISECOND:
|
|
13320
|
-
return "timestamp-millisecond";
|
|
13321
|
-
case TimeUnit.MICROSECOND:
|
|
13322
|
-
return "timestamp-microsecond";
|
|
13323
|
-
case TimeUnit.NANOSECOND:
|
|
13324
|
-
return "timestamp-nanosecond";
|
|
13325
|
-
default:
|
|
13326
|
-
return "timestamp-second";
|
|
13327
|
-
}
|
|
13328
|
-
case TimestampSecond:
|
|
13329
|
-
return "timestamp-second";
|
|
13330
|
-
case TimestampMillisecond:
|
|
13331
|
-
return "timestamp-millisecond";
|
|
13332
|
-
case TimestampMicrosecond:
|
|
13333
|
-
return "timestamp-microsecond";
|
|
13334
|
-
case TimestampNanosecond:
|
|
13335
|
-
return "timestamp-nanosecond";
|
|
13336
|
-
case Interval_:
|
|
13337
|
-
const intervalUnit = arrowType.unit;
|
|
13338
|
-
switch (intervalUnit) {
|
|
13339
|
-
case IntervalUnit.DAY_TIME:
|
|
13340
|
-
return "interval-daytime";
|
|
13341
|
-
case IntervalUnit.YEAR_MONTH:
|
|
13342
|
-
return "interval-yearmonth";
|
|
13343
|
-
default:
|
|
13344
|
-
return "interval-daytime";
|
|
13345
|
-
}
|
|
13346
|
-
case IntervalDayTime:
|
|
13347
|
-
return "interval-daytime";
|
|
13348
|
-
case IntervalYearMonth:
|
|
13349
|
-
return "interval-yearmonth";
|
|
13350
|
-
case Map_:
|
|
13351
|
-
const mapType = arrowType;
|
|
13352
|
-
return {
|
|
13353
|
-
type: "map",
|
|
13354
|
-
keysSorted: mapType.keysSorted,
|
|
13355
|
-
children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
13356
|
-
};
|
|
13357
|
-
case List:
|
|
13358
|
-
const listType = arrowType;
|
|
13359
|
-
const listField = listType.valueField;
|
|
13360
|
-
return {
|
|
13361
|
-
type: "list",
|
|
13362
|
-
children: [serializeArrowField(listField)]
|
|
13363
|
-
};
|
|
13364
|
-
case FixedSizeList:
|
|
13365
|
-
const fixedSizeList = arrowType;
|
|
13366
|
-
return {
|
|
13367
|
-
type: "fixed-size-list",
|
|
13368
|
-
listSize: fixedSizeList.listSize,
|
|
13369
|
-
children: [serializeArrowField(fixedSizeList.children[0])]
|
|
13370
|
-
};
|
|
13371
|
-
case Struct:
|
|
13372
|
-
const structType = arrowType;
|
|
13373
|
-
return {
|
|
13374
|
-
type: "struct",
|
|
13375
|
-
children: structType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
13376
|
-
};
|
|
13377
|
-
default:
|
|
13378
|
-
throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
|
|
13514
|
+
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
13515
|
+
startIndex = startIndex || 0;
|
|
13516
|
+
endIndex = endIndex || positions.value.length / positions.size;
|
|
13517
|
+
const ringCoordinates = [];
|
|
13518
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
13519
|
+
const coord = Array();
|
|
13520
|
+
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
13521
|
+
coord.push(Number(positions.value[k]));
|
|
13522
|
+
}
|
|
13523
|
+
ringCoordinates.push(coord);
|
|
13379
13524
|
}
|
|
13525
|
+
return ringCoordinates;
|
|
13380
13526
|
}
|
|
13381
|
-
|
|
13382
|
-
|
|
13383
|
-
|
|
13384
|
-
|
|
13385
|
-
|
|
13386
|
-
|
|
13387
|
-
|
|
13388
|
-
|
|
13389
|
-
|
|
13390
|
-
|
|
13391
|
-
|
|
13392
|
-
|
|
13393
|
-
|
|
13394
|
-
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
|
|
13399
|
-
|
|
13527
|
+
|
|
13528
|
+
// src/tables/convert-arrow-to-geojson-table.ts
|
|
13529
|
+
function convertArrowToGeoJSONTable(table) {
|
|
13530
|
+
const arrowTable = table.data;
|
|
13531
|
+
const schema = serializeArrowSchema(arrowTable.schema);
|
|
13532
|
+
const geometryColumns = getGeometryColumnsFromSchema(schema);
|
|
13533
|
+
const encoding = geometryColumns.geometry.encoding;
|
|
13534
|
+
const features = [];
|
|
13535
|
+
const propertyColumnNames = arrowTable.schema.fields.map((field) => field.name).filter((name) => !(name in geometryColumns));
|
|
13536
|
+
const propertiesTable = arrowTable.select(propertyColumnNames);
|
|
13537
|
+
const arrowGeometryColumn = arrowTable.getChild("geometry");
|
|
13538
|
+
for (let row = 0; row < arrowTable.numRows; row++) {
|
|
13539
|
+
const arrowGeometry = arrowGeometryColumn?.get(row);
|
|
13540
|
+
const feature = parseGeometryFromArrow(arrowGeometry, encoding);
|
|
13541
|
+
if (feature) {
|
|
13542
|
+
const properties = propertiesTable.get(row)?.toJSON() || {};
|
|
13543
|
+
features.push({
|
|
13544
|
+
type: "Feature",
|
|
13545
|
+
geometry: feature,
|
|
13546
|
+
properties
|
|
13547
|
+
});
|
|
13400
13548
|
}
|
|
13401
13549
|
}
|
|
13402
|
-
|
|
13403
|
-
|
|
13404
|
-
|
|
13405
|
-
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
13411
|
-
|
|
13412
|
-
|
|
13413
|
-
|
|
13414
|
-
|
|
13415
|
-
|
|
13416
|
-
|
|
13417
|
-
|
|
13418
|
-
return new Uint8();
|
|
13419
|
-
case "uint16":
|
|
13420
|
-
return new Uint16();
|
|
13421
|
-
case "uint32":
|
|
13422
|
-
return new Uint32();
|
|
13423
|
-
case "uint64":
|
|
13424
|
-
return new Uint64();
|
|
13425
|
-
case "float16":
|
|
13426
|
-
return new Float16();
|
|
13427
|
-
case "float32":
|
|
13428
|
-
return new Float32();
|
|
13429
|
-
case "float64":
|
|
13430
|
-
return new Float64();
|
|
13431
|
-
case "utf8":
|
|
13432
|
-
return new Utf8();
|
|
13433
|
-
case "date-day":
|
|
13434
|
-
return new DateDay();
|
|
13435
|
-
case "date-millisecond":
|
|
13436
|
-
return new DateMillisecond();
|
|
13437
|
-
case "time-second":
|
|
13438
|
-
return new TimeSecond();
|
|
13439
|
-
case "time-millisecond":
|
|
13440
|
-
return new TimeMillisecond();
|
|
13441
|
-
case "time-microsecond":
|
|
13442
|
-
return new TimeMicrosecond();
|
|
13443
|
-
case "time-nanosecond":
|
|
13444
|
-
return new TimeNanosecond();
|
|
13445
|
-
case "timestamp-second":
|
|
13446
|
-
return new TimestampSecond();
|
|
13447
|
-
case "timestamp-millisecond":
|
|
13448
|
-
return new TimestampMillisecond();
|
|
13449
|
-
case "timestamp-microsecond":
|
|
13450
|
-
return new TimestampMicrosecond();
|
|
13451
|
-
case "timestamp-nanosecond":
|
|
13452
|
-
return new TimestampNanosecond();
|
|
13453
|
-
case "interval-daytime":
|
|
13454
|
-
return new IntervalDayTime();
|
|
13455
|
-
case "interval-yearmonth":
|
|
13456
|
-
return new IntervalYearMonth();
|
|
13550
|
+
return {
|
|
13551
|
+
shape: "geojson-table",
|
|
13552
|
+
type: "FeatureCollection",
|
|
13553
|
+
schema: table.schema,
|
|
13554
|
+
features
|
|
13555
|
+
};
|
|
13556
|
+
}
|
|
13557
|
+
|
|
13558
|
+
// src/parsers/parse-geoarrow-sync.ts
|
|
13559
|
+
function parseGeoArrowSync(arrayBuffer, options) {
|
|
13560
|
+
const table = parseArrowSync(arrayBuffer, {
|
|
13561
|
+
shape: "arrow-table"
|
|
13562
|
+
});
|
|
13563
|
+
switch (options?.shape) {
|
|
13564
|
+
case "geojson-table":
|
|
13565
|
+
return convertArrowToGeoJSONTable(table);
|
|
13457
13566
|
default:
|
|
13458
|
-
|
|
13567
|
+
return table;
|
|
13459
13568
|
}
|
|
13460
13569
|
}
|
|
13461
13570
|
|
|
13571
|
+
// src/parsers/parse-geoarrow-in-batches.ts
|
|
13572
|
+
function parseGeoArrowInBatches(asyncIterator) {
|
|
13573
|
+
return parseArrowInBatches(asyncIterator);
|
|
13574
|
+
}
|
|
13575
|
+
|
|
13576
|
+
// src/geoarrow-loader.ts
|
|
13577
|
+
var GeoArrowWorkerLoader = {
|
|
13578
|
+
...ArrowWorkerLoader,
|
|
13579
|
+
options: {
|
|
13580
|
+
arrow: {
|
|
13581
|
+
shape: "arrow-table"
|
|
13582
|
+
}
|
|
13583
|
+
}
|
|
13584
|
+
};
|
|
13585
|
+
var GeoArrowLoader = {
|
|
13586
|
+
...ArrowWorkerLoader,
|
|
13587
|
+
options: {
|
|
13588
|
+
arrow: {
|
|
13589
|
+
shape: "arrow-table"
|
|
13590
|
+
}
|
|
13591
|
+
},
|
|
13592
|
+
parse: async (arraybuffer, options) => parseGeoArrowSync(arraybuffer, options?.arrow),
|
|
13593
|
+
parseSync: (arraybuffer, options) => parseGeoArrowSync(arraybuffer, options?.arrow),
|
|
13594
|
+
parseInBatches: parseGeoArrowInBatches
|
|
13595
|
+
};
|
|
13596
|
+
|
|
13462
13597
|
// src/geoarrow/get-arrow-bounds.ts
|
|
13463
13598
|
function updateBoundsFromGeoArrowSamples(flatCoords, nDim, bounds, sampleSize = 100) {
|
|
13464
13599
|
const numberOfFeatures = flatCoords.length / nDim;
|
|
@@ -13484,31 +13619,39 @@ return true;`);
|
|
|
13484
13619
|
}
|
|
13485
13620
|
|
|
13486
13621
|
// src/geoarrow/convert-geoarrow-to-binary-geometry.ts
|
|
13487
|
-
var
|
|
13488
|
-
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
|
|
13497
|
-
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
|
|
13501
|
-
|
|
13502
|
-
|
|
13622
|
+
var BinaryGeometryType = function(BinaryGeometryType2) {
|
|
13623
|
+
BinaryGeometryType2["points"] = "points";
|
|
13624
|
+
BinaryGeometryType2["lines"] = "lines";
|
|
13625
|
+
BinaryGeometryType2["polygons"] = "polygons";
|
|
13626
|
+
return BinaryGeometryType2;
|
|
13627
|
+
}(BinaryGeometryType || {});
|
|
13628
|
+
function getBinaryGeometryTemplate() {
|
|
13629
|
+
return {
|
|
13630
|
+
globalFeatureIds: {
|
|
13631
|
+
value: new Uint32Array(0),
|
|
13632
|
+
size: 1
|
|
13633
|
+
},
|
|
13634
|
+
positions: {
|
|
13635
|
+
value: new Float32Array(0),
|
|
13636
|
+
size: 2
|
|
13637
|
+
},
|
|
13638
|
+
properties: [],
|
|
13639
|
+
numericProps: {},
|
|
13640
|
+
featureIds: {
|
|
13641
|
+
value: new Uint32Array(0),
|
|
13642
|
+
size: 1
|
|
13643
|
+
}
|
|
13644
|
+
};
|
|
13645
|
+
}
|
|
13503
13646
|
function getBinaryGeometriesFromArrow(geoColumn, geoEncoding, options) {
|
|
13504
13647
|
const featureTypes = {
|
|
13505
13648
|
polygon: geoEncoding === "geoarrow.multipolygon" || geoEncoding === "geoarrow.polygon",
|
|
13506
13649
|
point: geoEncoding === "geoarrow.multipoint" || geoEncoding === "geoarrow.point",
|
|
13507
13650
|
line: geoEncoding === "geoarrow.multilinestring" || geoEncoding === "geoarrow.linestring"
|
|
13508
13651
|
};
|
|
13509
|
-
const chunks = options?.chunkIndex ? [geoColumn.data[options?.chunkIndex]] : geoColumn.data;
|
|
13652
|
+
const chunks = options?.chunkIndex !== void 0 && options?.chunkIndex >= 0 ? [geoColumn.data[options?.chunkIndex]] : geoColumn.data;
|
|
13510
13653
|
let bounds = [Infinity, Infinity, -Infinity, -Infinity];
|
|
13511
|
-
let globalFeatureIdOffset = 0;
|
|
13654
|
+
let globalFeatureIdOffset = options?.chunkOffset || 0;
|
|
13512
13655
|
const binaryGeometries = [];
|
|
13513
13656
|
chunks.forEach((chunk) => {
|
|
13514
13657
|
const {
|
|
@@ -13517,7 +13660,7 @@ return true;`);
|
|
|
13517
13660
|
nDim,
|
|
13518
13661
|
geomOffset,
|
|
13519
13662
|
triangles
|
|
13520
|
-
} = getBinaryGeometriesFromChunk(chunk, geoEncoding);
|
|
13663
|
+
} = getBinaryGeometriesFromChunk(chunk, geoEncoding, options);
|
|
13521
13664
|
const globalFeatureIds = new Uint32Array(featureIds.length);
|
|
13522
13665
|
for (let i = 0; i < featureIds.length; i++) {
|
|
13523
13666
|
globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
|
|
@@ -13544,12 +13687,12 @@ return true;`);
|
|
|
13544
13687
|
shape: "binary-feature-collection",
|
|
13545
13688
|
points: {
|
|
13546
13689
|
type: "Point",
|
|
13547
|
-
...
|
|
13690
|
+
...getBinaryGeometryTemplate(),
|
|
13548
13691
|
...featureTypes.point ? binaryContent : {}
|
|
13549
13692
|
},
|
|
13550
13693
|
lines: {
|
|
13551
13694
|
type: "LineString",
|
|
13552
|
-
...
|
|
13695
|
+
...getBinaryGeometryTemplate(),
|
|
13553
13696
|
...featureTypes.line ? binaryContent : {},
|
|
13554
13697
|
pathIndices: {
|
|
13555
13698
|
value: featureTypes.line ? geomOffset : new Uint16Array(0),
|
|
@@ -13558,7 +13701,7 @@ return true;`);
|
|
|
13558
13701
|
},
|
|
13559
13702
|
polygons: {
|
|
13560
13703
|
type: "Polygon",
|
|
13561
|
-
...
|
|
13704
|
+
...getBinaryGeometryTemplate(),
|
|
13562
13705
|
...featureTypes.polygon ? binaryContent : {},
|
|
13563
13706
|
polygonIndices: {
|
|
13564
13707
|
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
@@ -13582,7 +13725,7 @@ return true;`);
|
|
|
13582
13725
|
binaryGeometries,
|
|
13583
13726
|
bounds,
|
|
13584
13727
|
featureTypes,
|
|
13585
|
-
...options?.
|
|
13728
|
+
...options?.calculateMeanCenters ? {
|
|
13586
13729
|
meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries)
|
|
13587
13730
|
} : {}
|
|
13588
13731
|
};
|
|
@@ -13592,18 +13735,18 @@ return true;`);
|
|
|
13592
13735
|
binaryGeometries.forEach((binaryGeometry) => {
|
|
13593
13736
|
let binaryGeometryType = null;
|
|
13594
13737
|
if (binaryGeometry.points && binaryGeometry.points.positions.value.length > 0) {
|
|
13595
|
-
binaryGeometryType =
|
|
13738
|
+
binaryGeometryType = BinaryGeometryType.points;
|
|
13596
13739
|
} else if (binaryGeometry.lines && binaryGeometry.lines.positions.value.length > 0) {
|
|
13597
|
-
binaryGeometryType =
|
|
13740
|
+
binaryGeometryType = BinaryGeometryType.lines;
|
|
13598
13741
|
} else if (binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0) {
|
|
13599
|
-
binaryGeometryType =
|
|
13742
|
+
binaryGeometryType = BinaryGeometryType.polygons;
|
|
13600
13743
|
}
|
|
13601
13744
|
const binaryContent = binaryGeometryType ? binaryGeometry[binaryGeometryType] : null;
|
|
13602
13745
|
if (binaryContent && binaryGeometryType !== null) {
|
|
13603
13746
|
const featureIds = binaryContent.featureIds.value;
|
|
13604
13747
|
const flatCoordinateArray = binaryContent.positions.value;
|
|
13605
13748
|
const nDim = binaryContent.positions.size;
|
|
13606
|
-
const primitivePolygonIndices = binaryContent.primitivePolygonIndices?.value;
|
|
13749
|
+
const primitivePolygonIndices = binaryContent.type === "Polygon" ? binaryContent.primitivePolygonIndices?.value : void 0;
|
|
13607
13750
|
const meanCenters = getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, binaryGeometryType, primitivePolygonIndices);
|
|
13608
13751
|
meanCenters.forEach((center) => {
|
|
13609
13752
|
globalMeanCenters.push(center);
|
|
@@ -13616,19 +13759,23 @@ return true;`);
|
|
|
13616
13759
|
const meanCenters = [];
|
|
13617
13760
|
const vertexCount = flatCoordinateArray.length;
|
|
13618
13761
|
let vertexIndex = 0;
|
|
13762
|
+
let coordIdx = 0;
|
|
13763
|
+
let primitiveIdx = 0;
|
|
13619
13764
|
while (vertexIndex < vertexCount) {
|
|
13620
13765
|
const featureId = featureIds[vertexIndex / nDim];
|
|
13621
13766
|
const center = [0, 0];
|
|
13622
13767
|
let vertexCountInFeature = 0;
|
|
13623
|
-
while (vertexIndex < vertexCount && featureIds[
|
|
13624
|
-
if (geometryType ===
|
|
13768
|
+
while (vertexIndex < vertexCount && featureIds[coordIdx] === featureId) {
|
|
13769
|
+
if (geometryType === BinaryGeometryType.polygons && primitivePolygonIndices?.[primitiveIdx] === coordIdx) {
|
|
13625
13770
|
vertexIndex += nDim;
|
|
13771
|
+
primitiveIdx++;
|
|
13626
13772
|
} else {
|
|
13627
13773
|
center[0] += flatCoordinateArray[vertexIndex];
|
|
13628
13774
|
center[1] += flatCoordinateArray[vertexIndex + 1];
|
|
13629
13775
|
vertexIndex += nDim;
|
|
13630
13776
|
vertexCountInFeature++;
|
|
13631
13777
|
}
|
|
13778
|
+
coordIdx += 1;
|
|
13632
13779
|
}
|
|
13633
13780
|
center[0] /= vertexCountInFeature;
|
|
13634
13781
|
center[1] /= vertexCountInFeature;
|
|
@@ -13636,7 +13783,7 @@ return true;`);
|
|
|
13636
13783
|
}
|
|
13637
13784
|
return meanCenters;
|
|
13638
13785
|
}
|
|
13639
|
-
function getBinaryGeometriesFromChunk(chunk, geoEncoding) {
|
|
13786
|
+
function getBinaryGeometriesFromChunk(chunk, geoEncoding, options) {
|
|
13640
13787
|
switch (geoEncoding) {
|
|
13641
13788
|
case "geoarrow.point":
|
|
13642
13789
|
case "geoarrow.multipoint":
|
|
@@ -13646,37 +13793,44 @@ return true;`);
|
|
|
13646
13793
|
return getBinaryLinesFromChunk(chunk, geoEncoding);
|
|
13647
13794
|
case "geoarrow.polygon":
|
|
13648
13795
|
case "geoarrow.multipolygon":
|
|
13649
|
-
return getBinaryPolygonsFromChunk(chunk, geoEncoding);
|
|
13796
|
+
return getBinaryPolygonsFromChunk(chunk, geoEncoding, options);
|
|
13650
13797
|
default:
|
|
13651
13798
|
throw Error("invalid geoarrow encoding");
|
|
13652
13799
|
}
|
|
13653
13800
|
}
|
|
13654
13801
|
function getTriangleIndices(polygonIndices, primitivePolygonIndices, flatCoordinateArray, nDim) {
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13802
|
+
try {
|
|
13803
|
+
let primitiveIndex = 0;
|
|
13804
|
+
const triangles = [];
|
|
13805
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
13806
|
+
const startIdx = polygonIndices[i];
|
|
13807
|
+
const endIdx = polygonIndices[i + 1];
|
|
13808
|
+
const slicedFlatCoords = flatCoordinateArray.subarray(startIdx * nDim, endIdx * nDim);
|
|
13809
|
+
const holeIndices = [];
|
|
13810
|
+
while (primitivePolygonIndices[primitiveIndex] < endIdx) {
|
|
13811
|
+
if (primitivePolygonIndices[primitiveIndex] > startIdx) {
|
|
13812
|
+
holeIndices.push(primitivePolygonIndices[primitiveIndex] - startIdx);
|
|
13813
|
+
}
|
|
13814
|
+
primitiveIndex++;
|
|
13815
|
+
}
|
|
13816
|
+
const triangleIndices = earcut(slicedFlatCoords, holeIndices.length > 0 ? holeIndices : void 0, nDim);
|
|
13817
|
+
if (triangleIndices.length === 0) {
|
|
13818
|
+
throw Error("earcut failed e.g. invalid polygon");
|
|
13819
|
+
}
|
|
13820
|
+
for (let j = 0; j < triangleIndices.length; j++) {
|
|
13821
|
+
triangles.push(triangleIndices[j] + startIdx);
|
|
13665
13822
|
}
|
|
13666
|
-
primitiveIndex++;
|
|
13667
13823
|
}
|
|
13668
|
-
const
|
|
13669
|
-
for (let
|
|
13670
|
-
|
|
13824
|
+
const trianglesUint32 = new Uint32Array(triangles.length);
|
|
13825
|
+
for (let i = 0; i < triangles.length; i++) {
|
|
13826
|
+
trianglesUint32[i] = triangles[i];
|
|
13671
13827
|
}
|
|
13828
|
+
return trianglesUint32;
|
|
13829
|
+
} catch (error) {
|
|
13830
|
+
return null;
|
|
13672
13831
|
}
|
|
13673
|
-
const trianglesUint32 = new Uint32Array(triangles.length);
|
|
13674
|
-
for (let i = 0; i < triangles.length; i++) {
|
|
13675
|
-
trianglesUint32[i] = triangles[i];
|
|
13676
|
-
}
|
|
13677
|
-
return trianglesUint32;
|
|
13678
13832
|
}
|
|
13679
|
-
function getBinaryPolygonsFromChunk(chunk, geoEncoding) {
|
|
13833
|
+
function getBinaryPolygonsFromChunk(chunk, geoEncoding, options) {
|
|
13680
13834
|
const isMultiPolygon = geoEncoding === "geoarrow.multipolygon";
|
|
13681
13835
|
const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
|
|
13682
13836
|
const polygonOffset = polygonData.valueOffsets;
|
|
@@ -13700,14 +13854,16 @@ return true;`);
|
|
|
13700
13854
|
featureIds[j] = i;
|
|
13701
13855
|
}
|
|
13702
13856
|
}
|
|
13703
|
-
const triangles = getTriangleIndices(geometryIndicies, geomOffset, flatCoordinateArray, nDim);
|
|
13857
|
+
const triangles = options?.triangulate ? getTriangleIndices(geometryIndicies, geomOffset, flatCoordinateArray, nDim) : null;
|
|
13704
13858
|
return {
|
|
13705
13859
|
featureIds,
|
|
13706
|
-
flatCoordinateArray,
|
|
13707
13860
|
nDim,
|
|
13861
|
+
flatCoordinateArray,
|
|
13708
13862
|
geomOffset,
|
|
13709
13863
|
geometryIndicies,
|
|
13710
|
-
triangles
|
|
13864
|
+
...options?.triangulate && triangles ? {
|
|
13865
|
+
triangles
|
|
13866
|
+
} : {}
|
|
13711
13867
|
};
|
|
13712
13868
|
}
|
|
13713
13869
|
function getBinaryLinesFromChunk(chunk, geoEncoding) {
|
|
@@ -13780,46 +13936,706 @@ return true;`);
|
|
|
13780
13936
|
};
|
|
13781
13937
|
}
|
|
13782
13938
|
|
|
13783
|
-
// src/
|
|
13784
|
-
|
|
13785
|
-
|
|
13786
|
-
|
|
13787
|
-
|
|
13939
|
+
// ../wkt/src/lib/utils/version.ts
|
|
13940
|
+
var VERSION3 = true ? "4.1.0-alpha.10" : "latest";
|
|
13941
|
+
|
|
13942
|
+
// ../wkt/src/lib/parse-wkt.ts
|
|
13943
|
+
var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
|
|
13944
|
+
var tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
|
|
13945
|
+
var WKT_MAGIC_STRINGS = ["POINT(", "LINESTRING(", "POLYGON(", "MULTIPOINT(", "MULTILINESTRING(", "MULTIPOLYGON(", "GEOMETRYCOLLECTION("];
|
|
13946
|
+
function isWKT(input) {
|
|
13947
|
+
return WKT_MAGIC_STRINGS.some((magicString) => input.startsWith(magicString));
|
|
13948
|
+
}
|
|
13949
|
+
function parseWKT(input, options) {
|
|
13950
|
+
return parseWKTToGeometry(input, options);
|
|
13951
|
+
}
|
|
13952
|
+
function parseWKTToGeometry(input, options) {
|
|
13953
|
+
const parts = input.split(";");
|
|
13954
|
+
let _ = parts.pop();
|
|
13955
|
+
const srid = (parts.shift() || "").split("=").pop();
|
|
13956
|
+
const state = {
|
|
13957
|
+
parts,
|
|
13958
|
+
_,
|
|
13959
|
+
i: 0
|
|
13960
|
+
};
|
|
13961
|
+
const geometry = parseGeometry(state);
|
|
13962
|
+
return options?.wkt?.crs ? addCRS(geometry, srid) : geometry;
|
|
13963
|
+
}
|
|
13964
|
+
function parseGeometry(state) {
|
|
13965
|
+
return parsePoint(state) || parseLineString(state) || parsePolygon(state) || parseMultiPoint(state) || parseMultiLineString(state) || parseMultiPolygon(state) || parseGeometryCollection(state);
|
|
13966
|
+
}
|
|
13967
|
+
function addCRS(obj, srid) {
|
|
13968
|
+
if (obj && srid?.match(/\d+/)) {
|
|
13969
|
+
const crs = {
|
|
13970
|
+
type: "name",
|
|
13971
|
+
properties: {
|
|
13972
|
+
name: "urn:ogc:def:crs:EPSG::" + srid
|
|
13973
|
+
}
|
|
13974
|
+
};
|
|
13975
|
+
obj.crs = crs;
|
|
13976
|
+
}
|
|
13977
|
+
return obj;
|
|
13978
|
+
}
|
|
13979
|
+
function parsePoint(state) {
|
|
13980
|
+
if (!$(/^(POINT(\sz)?)/i, state)) {
|
|
13981
|
+
return null;
|
|
13982
|
+
}
|
|
13983
|
+
white(state);
|
|
13984
|
+
if (!$(/^(\()/, state)) {
|
|
13985
|
+
return null;
|
|
13986
|
+
}
|
|
13987
|
+
const c = coords(state);
|
|
13988
|
+
if (!c) {
|
|
13989
|
+
return null;
|
|
13990
|
+
}
|
|
13991
|
+
white(state);
|
|
13992
|
+
if (!$(/^(\))/, state)) {
|
|
13993
|
+
return null;
|
|
13994
|
+
}
|
|
13995
|
+
return {
|
|
13996
|
+
type: "Point",
|
|
13997
|
+
coordinates: c[0]
|
|
13998
|
+
};
|
|
13999
|
+
}
|
|
14000
|
+
function parseMultiPoint(state) {
|
|
14001
|
+
if (!$(/^(MULTIPOINT)/i, state)) {
|
|
14002
|
+
return null;
|
|
14003
|
+
}
|
|
14004
|
+
white(state);
|
|
14005
|
+
const newCoordsFormat = state._?.substring(state._?.indexOf("(") + 1, state._.length - 1).replace(/\(/g, "").replace(/\)/g, "");
|
|
14006
|
+
state._ = "MULTIPOINT (" + newCoordsFormat + ")";
|
|
14007
|
+
const c = multicoords(state);
|
|
14008
|
+
if (!c) {
|
|
14009
|
+
return null;
|
|
14010
|
+
}
|
|
14011
|
+
white(state);
|
|
14012
|
+
return {
|
|
14013
|
+
type: "MultiPoint",
|
|
14014
|
+
coordinates: c
|
|
14015
|
+
};
|
|
14016
|
+
}
|
|
14017
|
+
function parseLineString(state) {
|
|
14018
|
+
if (!$(/^(LINESTRING(\sz)?)/i, state)) {
|
|
14019
|
+
return null;
|
|
14020
|
+
}
|
|
14021
|
+
white(state);
|
|
14022
|
+
if (!$(/^(\()/, state)) {
|
|
14023
|
+
return null;
|
|
14024
|
+
}
|
|
14025
|
+
const c = coords(state);
|
|
14026
|
+
if (!c) {
|
|
14027
|
+
return null;
|
|
14028
|
+
}
|
|
14029
|
+
if (!$(/^(\))/, state)) {
|
|
14030
|
+
return null;
|
|
14031
|
+
}
|
|
14032
|
+
return {
|
|
14033
|
+
type: "LineString",
|
|
14034
|
+
coordinates: c
|
|
14035
|
+
};
|
|
14036
|
+
}
|
|
14037
|
+
function parseMultiLineString(state) {
|
|
14038
|
+
if (!$(/^(MULTILINESTRING)/i, state))
|
|
14039
|
+
return null;
|
|
14040
|
+
white(state);
|
|
14041
|
+
const c = multicoords(state);
|
|
14042
|
+
if (!c) {
|
|
14043
|
+
return null;
|
|
14044
|
+
}
|
|
14045
|
+
white(state);
|
|
14046
|
+
return {
|
|
14047
|
+
type: "MultiLineString",
|
|
14048
|
+
coordinates: c
|
|
14049
|
+
};
|
|
14050
|
+
}
|
|
14051
|
+
function parsePolygon(state) {
|
|
14052
|
+
if (!$(/^(POLYGON(\sz)?)/i, state)) {
|
|
14053
|
+
return null;
|
|
14054
|
+
}
|
|
14055
|
+
white(state);
|
|
14056
|
+
const c = multicoords(state);
|
|
14057
|
+
if (!c) {
|
|
14058
|
+
return null;
|
|
14059
|
+
}
|
|
14060
|
+
return {
|
|
14061
|
+
type: "Polygon",
|
|
14062
|
+
coordinates: c
|
|
14063
|
+
};
|
|
14064
|
+
}
|
|
14065
|
+
function parseMultiPolygon(state) {
|
|
14066
|
+
if (!$(/^(MULTIPOLYGON)/i, state)) {
|
|
14067
|
+
return null;
|
|
14068
|
+
}
|
|
14069
|
+
white(state);
|
|
14070
|
+
const c = multicoords(state);
|
|
14071
|
+
if (!c) {
|
|
14072
|
+
return null;
|
|
14073
|
+
}
|
|
14074
|
+
return {
|
|
14075
|
+
type: "MultiPolygon",
|
|
14076
|
+
coordinates: c
|
|
14077
|
+
};
|
|
14078
|
+
}
|
|
14079
|
+
function parseGeometryCollection(state) {
|
|
14080
|
+
const geometries = [];
|
|
14081
|
+
let geometry;
|
|
14082
|
+
if (!$(/^(GEOMETRYCOLLECTION)/i, state)) {
|
|
14083
|
+
return null;
|
|
14084
|
+
}
|
|
14085
|
+
white(state);
|
|
14086
|
+
if (!$(/^(\()/, state)) {
|
|
14087
|
+
return null;
|
|
14088
|
+
}
|
|
14089
|
+
while (geometry = parseGeometry(state)) {
|
|
14090
|
+
geometries.push(geometry);
|
|
14091
|
+
white(state);
|
|
14092
|
+
$(/^(,)/, state);
|
|
14093
|
+
white(state);
|
|
14094
|
+
}
|
|
14095
|
+
if (!$(/^(\))/, state)) {
|
|
14096
|
+
return null;
|
|
14097
|
+
}
|
|
14098
|
+
return {
|
|
14099
|
+
type: "GeometryCollection",
|
|
14100
|
+
geometries
|
|
14101
|
+
};
|
|
14102
|
+
}
|
|
14103
|
+
function multicoords(state) {
|
|
14104
|
+
white(state);
|
|
14105
|
+
let depth = 0;
|
|
14106
|
+
const rings = [];
|
|
14107
|
+
const stack = [rings];
|
|
14108
|
+
let pointer = rings;
|
|
14109
|
+
let elem;
|
|
14110
|
+
while (elem = $(/^(\()/, state) || $(/^(\))/, state) || $(/^(,)/, state) || $(tuples, state)) {
|
|
14111
|
+
if (elem === "(") {
|
|
14112
|
+
stack.push(pointer);
|
|
14113
|
+
pointer = [];
|
|
14114
|
+
stack[stack.length - 1].push(pointer);
|
|
14115
|
+
depth++;
|
|
14116
|
+
} else if (elem === ")") {
|
|
14117
|
+
if (pointer.length === 0)
|
|
14118
|
+
return null;
|
|
14119
|
+
pointer = stack.pop();
|
|
14120
|
+
if (!pointer)
|
|
14121
|
+
return null;
|
|
14122
|
+
depth--;
|
|
14123
|
+
if (depth === 0)
|
|
14124
|
+
break;
|
|
14125
|
+
} else if (elem === ",") {
|
|
14126
|
+
pointer = [];
|
|
14127
|
+
stack[stack.length - 1].push(pointer);
|
|
14128
|
+
} else if (!elem.split(/\s/g).some(isNaN)) {
|
|
14129
|
+
Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
|
|
14130
|
+
} else {
|
|
14131
|
+
return null;
|
|
14132
|
+
}
|
|
14133
|
+
white(state);
|
|
14134
|
+
}
|
|
14135
|
+
if (depth !== 0)
|
|
14136
|
+
return null;
|
|
14137
|
+
return rings;
|
|
14138
|
+
}
|
|
14139
|
+
function coords(state) {
|
|
14140
|
+
const list = [];
|
|
14141
|
+
let item;
|
|
14142
|
+
let pt;
|
|
14143
|
+
while (pt = $(tuples, state) || $(/^(,)/, state)) {
|
|
14144
|
+
if (pt === ",") {
|
|
14145
|
+
list.push(item);
|
|
14146
|
+
item = [];
|
|
14147
|
+
} else if (!pt.split(/\s/g).some(isNaN)) {
|
|
14148
|
+
if (!item)
|
|
14149
|
+
item = [];
|
|
14150
|
+
Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
|
|
14151
|
+
}
|
|
14152
|
+
white(state);
|
|
14153
|
+
}
|
|
14154
|
+
if (item)
|
|
14155
|
+
list.push(item);
|
|
14156
|
+
else
|
|
14157
|
+
return null;
|
|
14158
|
+
return list.length ? list : null;
|
|
14159
|
+
}
|
|
14160
|
+
function $(regexp, state) {
|
|
14161
|
+
const match = state._?.substring(state.i).match(regexp);
|
|
14162
|
+
if (!match)
|
|
14163
|
+
return null;
|
|
14164
|
+
else {
|
|
14165
|
+
state.i += match[0].length;
|
|
14166
|
+
return match[0];
|
|
14167
|
+
}
|
|
14168
|
+
}
|
|
14169
|
+
function white(state) {
|
|
14170
|
+
$(/^\s*/, state);
|
|
14171
|
+
}
|
|
14172
|
+
|
|
14173
|
+
// ../wkt/src/wkt-loader.ts
|
|
14174
|
+
var WKTWorkerLoader = {
|
|
14175
|
+
name: "WKT (Well-Known Text)",
|
|
14176
|
+
id: "wkt",
|
|
14177
|
+
module: "wkt",
|
|
14178
|
+
version: VERSION3,
|
|
14179
|
+
worker: true,
|
|
14180
|
+
extensions: ["wkt"],
|
|
14181
|
+
mimeTypes: ["text/plain"],
|
|
14182
|
+
category: "geometry",
|
|
14183
|
+
text: true,
|
|
14184
|
+
tests: WKT_MAGIC_STRINGS,
|
|
14185
|
+
testText: isWKT,
|
|
14186
|
+
options: {
|
|
14187
|
+
wkt: {
|
|
14188
|
+
shape: "geojson-geometry",
|
|
14189
|
+
crs: true
|
|
14190
|
+
}
|
|
14191
|
+
}
|
|
14192
|
+
};
|
|
14193
|
+
var WKTLoader = {
|
|
14194
|
+
...WKTWorkerLoader,
|
|
14195
|
+
parse: async (arrayBuffer, options) => parseWKT(new TextDecoder().decode(arrayBuffer), options),
|
|
14196
|
+
parseTextSync: parseWKT
|
|
14197
|
+
};
|
|
14198
|
+
|
|
14199
|
+
// ../wkt/src/lib/parse-wkb-header.ts
|
|
14200
|
+
var EWKB_FLAG_Z = 2147483648;
|
|
14201
|
+
var EWKB_FLAG_M = 1073741824;
|
|
14202
|
+
var EWKB_FLAG_SRID = 536870912;
|
|
14203
|
+
var MAX_SRID = 1e4;
|
|
14204
|
+
var WKBGeometryType = function(WKBGeometryType2) {
|
|
14205
|
+
WKBGeometryType2[WKBGeometryType2["Point"] = 1] = "Point";
|
|
14206
|
+
WKBGeometryType2[WKBGeometryType2["LineString"] = 2] = "LineString";
|
|
14207
|
+
WKBGeometryType2[WKBGeometryType2["Polygon"] = 3] = "Polygon";
|
|
14208
|
+
WKBGeometryType2[WKBGeometryType2["MultiPoint"] = 4] = "MultiPoint";
|
|
14209
|
+
WKBGeometryType2[WKBGeometryType2["MultiLineString"] = 5] = "MultiLineString";
|
|
14210
|
+
WKBGeometryType2[WKBGeometryType2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
14211
|
+
WKBGeometryType2[WKBGeometryType2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
14212
|
+
return WKBGeometryType2;
|
|
14213
|
+
}({});
|
|
14214
|
+
function isWKB(arrayBuffer) {
|
|
14215
|
+
const dataView = new DataView(arrayBuffer);
|
|
14216
|
+
let byteOffset = 0;
|
|
14217
|
+
const endianness = dataView.getUint8(byteOffset);
|
|
14218
|
+
byteOffset += 1;
|
|
14219
|
+
if (endianness > 1) {
|
|
14220
|
+
return false;
|
|
14221
|
+
}
|
|
14222
|
+
const littleEndian = endianness === 1;
|
|
14223
|
+
const geometry = dataView.getUint32(byteOffset, littleEndian);
|
|
14224
|
+
byteOffset += 4;
|
|
14225
|
+
const geometryType = geometry & 7;
|
|
14226
|
+
if (geometryType === 0 || geometryType > 7) {
|
|
14227
|
+
return false;
|
|
14228
|
+
}
|
|
14229
|
+
const geometryFlags = geometry - geometryType;
|
|
14230
|
+
if (geometryFlags === 0 || geometryFlags === 1e3 || geometryFlags === 2e3 || geometryFlags === 3e3) {
|
|
14231
|
+
return true;
|
|
14232
|
+
}
|
|
14233
|
+
if ((geometryFlags & ~(EWKB_FLAG_Z | EWKB_FLAG_M | EWKB_FLAG_SRID)) !== 0) {
|
|
14234
|
+
return false;
|
|
14235
|
+
}
|
|
14236
|
+
if (geometryFlags & EWKB_FLAG_SRID) {
|
|
14237
|
+
const srid = dataView.getUint32(byteOffset, littleEndian);
|
|
14238
|
+
byteOffset += 4;
|
|
14239
|
+
if (srid > MAX_SRID) {
|
|
14240
|
+
return false;
|
|
14241
|
+
}
|
|
14242
|
+
}
|
|
14243
|
+
return true;
|
|
14244
|
+
}
|
|
14245
|
+
function parseWKBHeader(dataView, target) {
|
|
14246
|
+
const wkbHeader = Object.assign(target || {}, {
|
|
14247
|
+
type: "wkb",
|
|
14248
|
+
geometryType: 1,
|
|
14249
|
+
dimensions: 2,
|
|
14250
|
+
coordinates: "xy",
|
|
14251
|
+
littleEndian: true,
|
|
14252
|
+
byteOffset: 0
|
|
14253
|
+
});
|
|
14254
|
+
wkbHeader.littleEndian = dataView.getUint8(wkbHeader.byteOffset) === 1;
|
|
14255
|
+
wkbHeader.byteOffset++;
|
|
14256
|
+
const geometryCode = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
14257
|
+
wkbHeader.byteOffset += 4;
|
|
14258
|
+
wkbHeader.geometryType = geometryCode & 7;
|
|
14259
|
+
const isoType = (geometryCode - wkbHeader.geometryType) / 1e3;
|
|
14260
|
+
switch (isoType) {
|
|
14261
|
+
case 0:
|
|
14262
|
+
break;
|
|
14263
|
+
case 1:
|
|
14264
|
+
wkbHeader.type = "iso-wkb";
|
|
14265
|
+
wkbHeader.dimensions = 3;
|
|
14266
|
+
wkbHeader.coordinates = "xyz";
|
|
14267
|
+
break;
|
|
14268
|
+
case 2:
|
|
14269
|
+
wkbHeader.type = "iso-wkb";
|
|
14270
|
+
wkbHeader.dimensions = 3;
|
|
14271
|
+
wkbHeader.coordinates = "xym";
|
|
14272
|
+
break;
|
|
14273
|
+
case 3:
|
|
14274
|
+
wkbHeader.type = "iso-wkb";
|
|
14275
|
+
wkbHeader.dimensions = 4;
|
|
14276
|
+
wkbHeader.coordinates = "xyzm";
|
|
14277
|
+
break;
|
|
14278
|
+
default:
|
|
14279
|
+
throw new Error(`WKB: Unsupported iso-wkb type: ${isoType}`);
|
|
14280
|
+
}
|
|
14281
|
+
const ewkbZ = geometryCode & EWKB_FLAG_Z;
|
|
14282
|
+
const ewkbM = geometryCode & EWKB_FLAG_M;
|
|
14283
|
+
const ewkbSRID = geometryCode & EWKB_FLAG_SRID;
|
|
14284
|
+
if (ewkbZ && ewkbM) {
|
|
14285
|
+
wkbHeader.type = "ewkb";
|
|
14286
|
+
wkbHeader.dimensions = 4;
|
|
14287
|
+
wkbHeader.coordinates = "xyzm";
|
|
14288
|
+
} else if (ewkbZ) {
|
|
14289
|
+
wkbHeader.type = "ewkb";
|
|
14290
|
+
wkbHeader.dimensions = 3;
|
|
14291
|
+
wkbHeader.coordinates = "xyz";
|
|
14292
|
+
} else if (ewkbM) {
|
|
14293
|
+
wkbHeader.type = "ewkb";
|
|
14294
|
+
wkbHeader.dimensions = 3;
|
|
14295
|
+
wkbHeader.coordinates = "xym";
|
|
14296
|
+
}
|
|
14297
|
+
if (ewkbSRID) {
|
|
14298
|
+
wkbHeader.type = "ewkb";
|
|
14299
|
+
wkbHeader.srid = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
14300
|
+
wkbHeader.byteOffset += 4;
|
|
14301
|
+
}
|
|
14302
|
+
return wkbHeader;
|
|
14303
|
+
}
|
|
14304
|
+
|
|
14305
|
+
// ../wkt/src/lib/parse-wkb.ts
|
|
14306
|
+
function parseWKB(arrayBuffer, options) {
|
|
14307
|
+
const binaryGeometry = parseWKBToBinary(arrayBuffer, options);
|
|
14308
|
+
const shape = options?.wkb?.shape || "binary-geometry";
|
|
14309
|
+
switch (shape) {
|
|
14310
|
+
case "binary-geometry":
|
|
14311
|
+
return binaryGeometry;
|
|
14312
|
+
case "geojson-geometry":
|
|
14313
|
+
return binaryToGeometry(binaryGeometry);
|
|
14314
|
+
case "geometry":
|
|
14315
|
+
console.error('WKBLoader: "geometry" shape is deprecated, use "binary-geometry" instead');
|
|
14316
|
+
return binaryToGeometry(binaryGeometry);
|
|
14317
|
+
default:
|
|
14318
|
+
throw new Error(shape);
|
|
14319
|
+
}
|
|
14320
|
+
}
|
|
14321
|
+
function parseWKBToBinary(arrayBuffer, options) {
|
|
14322
|
+
const dataView = new DataView(arrayBuffer);
|
|
14323
|
+
const wkbHeader = parseWKBHeader(dataView);
|
|
14324
|
+
const {
|
|
14325
|
+
geometryType,
|
|
14326
|
+
dimensions,
|
|
14327
|
+
littleEndian
|
|
14328
|
+
} = wkbHeader;
|
|
14329
|
+
const offset = wkbHeader.byteOffset;
|
|
14330
|
+
switch (geometryType) {
|
|
14331
|
+
case WKBGeometryType.Point:
|
|
14332
|
+
const point = parsePoint2(dataView, offset, dimensions, littleEndian);
|
|
14333
|
+
return point.geometry;
|
|
14334
|
+
case WKBGeometryType.LineString:
|
|
14335
|
+
const line = parseLineString2(dataView, offset, dimensions, littleEndian);
|
|
14336
|
+
return line.geometry;
|
|
14337
|
+
case WKBGeometryType.Polygon:
|
|
14338
|
+
const polygon = parsePolygon2(dataView, offset, dimensions, littleEndian);
|
|
14339
|
+
return polygon.geometry;
|
|
14340
|
+
case WKBGeometryType.MultiPoint:
|
|
14341
|
+
const multiPoint = parseMultiPoint2(dataView, offset, dimensions, littleEndian);
|
|
14342
|
+
multiPoint.type = "Point";
|
|
14343
|
+
return multiPoint;
|
|
14344
|
+
case WKBGeometryType.MultiLineString:
|
|
14345
|
+
const multiLine = parseMultiLineString2(dataView, offset, dimensions, littleEndian);
|
|
14346
|
+
multiLine.type = "LineString";
|
|
14347
|
+
return multiLine;
|
|
14348
|
+
case WKBGeometryType.MultiPolygon:
|
|
14349
|
+
const multiPolygon = parseMultiPolygon2(dataView, offset, dimensions, littleEndian);
|
|
14350
|
+
multiPolygon.type = "Polygon";
|
|
14351
|
+
return multiPolygon;
|
|
14352
|
+
default:
|
|
14353
|
+
throw new Error(`WKB: Unsupported geometry type: ${geometryType}`);
|
|
14354
|
+
}
|
|
14355
|
+
}
|
|
14356
|
+
function parsePoint2(dataView, offset, dimension, littleEndian) {
|
|
14357
|
+
const positions = new Float64Array(dimension);
|
|
14358
|
+
for (let i = 0; i < dimension; i++) {
|
|
14359
|
+
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
14360
|
+
offset += 8;
|
|
14361
|
+
}
|
|
14362
|
+
return {
|
|
14363
|
+
geometry: {
|
|
14364
|
+
type: "Point",
|
|
14365
|
+
positions: {
|
|
14366
|
+
value: positions,
|
|
14367
|
+
size: dimension
|
|
14368
|
+
}
|
|
14369
|
+
},
|
|
14370
|
+
offset
|
|
14371
|
+
};
|
|
14372
|
+
}
|
|
14373
|
+
function parseLineString2(dataView, offset, dimension, littleEndian) {
|
|
14374
|
+
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
14375
|
+
offset += 4;
|
|
14376
|
+
const positions = new Float64Array(nPoints * dimension);
|
|
14377
|
+
for (let i = 0; i < nPoints * dimension; i++) {
|
|
14378
|
+
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
14379
|
+
offset += 8;
|
|
14380
|
+
}
|
|
14381
|
+
const pathIndices = [0];
|
|
14382
|
+
if (nPoints > 0) {
|
|
14383
|
+
pathIndices.push(nPoints);
|
|
14384
|
+
}
|
|
14385
|
+
return {
|
|
14386
|
+
geometry: {
|
|
14387
|
+
type: "LineString",
|
|
14388
|
+
positions: {
|
|
14389
|
+
value: positions,
|
|
14390
|
+
size: dimension
|
|
14391
|
+
},
|
|
14392
|
+
pathIndices: {
|
|
14393
|
+
value: new Uint16Array(pathIndices),
|
|
14394
|
+
size: 1
|
|
14395
|
+
}
|
|
14396
|
+
},
|
|
14397
|
+
offset
|
|
14398
|
+
};
|
|
14399
|
+
}
|
|
14400
|
+
var cumulativeSum = (sum2) => (value) => sum2 += value;
|
|
14401
|
+
function parsePolygon2(dataView, offset, dimension, littleEndian) {
|
|
14402
|
+
const nRings = dataView.getUint32(offset, littleEndian);
|
|
14403
|
+
offset += 4;
|
|
14404
|
+
const rings = [];
|
|
14405
|
+
for (let i = 0; i < nRings; i++) {
|
|
14406
|
+
const parsed = parseLineString2(dataView, offset, dimension, littleEndian);
|
|
14407
|
+
const {
|
|
14408
|
+
positions
|
|
14409
|
+
} = parsed.geometry;
|
|
14410
|
+
offset = parsed.offset;
|
|
14411
|
+
rings.push(positions.value);
|
|
14412
|
+
}
|
|
14413
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(rings).buffer);
|
|
14414
|
+
const polygonIndices = [0];
|
|
14415
|
+
if (concatenatedPositions.length > 0) {
|
|
14416
|
+
polygonIndices.push(concatenatedPositions.length / dimension);
|
|
14417
|
+
}
|
|
14418
|
+
const primitivePolygonIndices = rings.map((l) => l.length / dimension).map(cumulativeSum(0));
|
|
14419
|
+
primitivePolygonIndices.unshift(0);
|
|
14420
|
+
return {
|
|
14421
|
+
geometry: {
|
|
14422
|
+
type: "Polygon",
|
|
14423
|
+
positions: {
|
|
14424
|
+
value: concatenatedPositions,
|
|
14425
|
+
size: dimension
|
|
14426
|
+
},
|
|
14427
|
+
polygonIndices: {
|
|
14428
|
+
value: new Uint16Array(polygonIndices),
|
|
14429
|
+
size: 1
|
|
14430
|
+
},
|
|
14431
|
+
primitivePolygonIndices: {
|
|
14432
|
+
value: new Uint16Array(primitivePolygonIndices),
|
|
14433
|
+
size: 1
|
|
14434
|
+
}
|
|
14435
|
+
},
|
|
14436
|
+
offset
|
|
14437
|
+
};
|
|
14438
|
+
}
|
|
14439
|
+
function parseMultiPoint2(dataView, offset, dimension, littleEndian) {
|
|
14440
|
+
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
14441
|
+
offset += 4;
|
|
14442
|
+
const binaryPointGeometries = [];
|
|
14443
|
+
for (let i = 0; i < nPoints; i++) {
|
|
14444
|
+
const littleEndianPoint = dataView.getUint8(offset) === 1;
|
|
14445
|
+
offset++;
|
|
14446
|
+
if (dataView.getUint32(offset, littleEndianPoint) % 1e3 !== 1) {
|
|
14447
|
+
throw new Error("WKB: Inner geometries of MultiPoint not of type Point");
|
|
14448
|
+
}
|
|
14449
|
+
offset += 4;
|
|
14450
|
+
const parsed = parsePoint2(dataView, offset, dimension, littleEndianPoint);
|
|
14451
|
+
offset = parsed.offset;
|
|
14452
|
+
binaryPointGeometries.push(parsed.geometry);
|
|
14453
|
+
}
|
|
14454
|
+
return concatenateBinaryPointGeometries(binaryPointGeometries, dimension);
|
|
14455
|
+
}
|
|
14456
|
+
function parseMultiLineString2(dataView, offset, dimension, littleEndian) {
|
|
14457
|
+
const nLines = dataView.getUint32(offset, littleEndian);
|
|
14458
|
+
offset += 4;
|
|
14459
|
+
const binaryLineGeometries = [];
|
|
14460
|
+
for (let i = 0; i < nLines; i++) {
|
|
14461
|
+
const littleEndianLine = dataView.getUint8(offset) === 1;
|
|
14462
|
+
offset++;
|
|
14463
|
+
if (dataView.getUint32(offset, littleEndianLine) % 1e3 !== 2) {
|
|
14464
|
+
throw new Error("WKB: Inner geometries of MultiLineString not of type LineString");
|
|
14465
|
+
}
|
|
14466
|
+
offset += 4;
|
|
14467
|
+
const parsed = parseLineString2(dataView, offset, dimension, littleEndianLine);
|
|
14468
|
+
offset = parsed.offset;
|
|
14469
|
+
binaryLineGeometries.push(parsed.geometry);
|
|
14470
|
+
}
|
|
14471
|
+
return concatenateBinaryLineGeometries(binaryLineGeometries, dimension);
|
|
14472
|
+
}
|
|
14473
|
+
function parseMultiPolygon2(dataView, offset, dimension, littleEndian) {
|
|
14474
|
+
const nPolygons = dataView.getUint32(offset, littleEndian);
|
|
14475
|
+
offset += 4;
|
|
14476
|
+
const binaryPolygonGeometries = [];
|
|
14477
|
+
for (let i = 0; i < nPolygons; i++) {
|
|
14478
|
+
const littleEndianPolygon = dataView.getUint8(offset) === 1;
|
|
14479
|
+
offset++;
|
|
14480
|
+
if (dataView.getUint32(offset, littleEndianPolygon) % 1e3 !== 3) {
|
|
14481
|
+
throw new Error("WKB: Inner geometries of MultiPolygon not of type Polygon");
|
|
14482
|
+
}
|
|
14483
|
+
offset += 4;
|
|
14484
|
+
const parsed = parsePolygon2(dataView, offset, dimension, littleEndianPolygon);
|
|
14485
|
+
offset = parsed.offset;
|
|
14486
|
+
binaryPolygonGeometries.push(parsed.geometry);
|
|
14487
|
+
}
|
|
14488
|
+
return concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension);
|
|
14489
|
+
}
|
|
14490
|
+
function concatenateBinaryPointGeometries(binaryPointGeometries, dimension) {
|
|
14491
|
+
const positions = binaryPointGeometries.map((geometry) => geometry.positions.value);
|
|
14492
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
|
|
14493
|
+
return {
|
|
14494
|
+
type: "Point",
|
|
14495
|
+
positions: {
|
|
14496
|
+
value: concatenatedPositions,
|
|
14497
|
+
size: dimension
|
|
14498
|
+
}
|
|
14499
|
+
};
|
|
14500
|
+
}
|
|
14501
|
+
function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
|
|
14502
|
+
const lines = binaryLineGeometries.map((geometry) => geometry.positions.value);
|
|
14503
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
|
|
14504
|
+
const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
|
|
14505
|
+
pathIndices.unshift(0);
|
|
14506
|
+
return {
|
|
14507
|
+
type: "LineString",
|
|
14508
|
+
positions: {
|
|
14509
|
+
value: concatenatedPositions,
|
|
14510
|
+
size: dimension
|
|
14511
|
+
},
|
|
14512
|
+
pathIndices: {
|
|
14513
|
+
value: new Uint16Array(pathIndices),
|
|
14514
|
+
size: 1
|
|
14515
|
+
}
|
|
14516
|
+
};
|
|
14517
|
+
}
|
|
14518
|
+
function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
|
|
14519
|
+
const polygons = [];
|
|
14520
|
+
const primitivePolygons = [];
|
|
14521
|
+
for (const binaryPolygon of binaryPolygonGeometries) {
|
|
14522
|
+
const {
|
|
14523
|
+
positions,
|
|
14524
|
+
primitivePolygonIndices: primitivePolygonIndices2
|
|
14525
|
+
} = binaryPolygon;
|
|
14526
|
+
polygons.push(positions.value);
|
|
14527
|
+
primitivePolygons.push(primitivePolygonIndices2.value);
|
|
14528
|
+
}
|
|
14529
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
|
|
14530
|
+
const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
|
|
14531
|
+
polygonIndices.unshift(0);
|
|
14532
|
+
const primitivePolygonIndices = [0];
|
|
14533
|
+
for (const primitivePolygon of primitivePolygons) {
|
|
14534
|
+
primitivePolygonIndices.push(...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
|
|
14535
|
+
}
|
|
14536
|
+
return {
|
|
14537
|
+
type: "Polygon",
|
|
14538
|
+
positions: {
|
|
14539
|
+
value: concatenatedPositions,
|
|
14540
|
+
size: dimension
|
|
14541
|
+
},
|
|
14542
|
+
polygonIndices: {
|
|
14543
|
+
value: new Uint16Array(polygonIndices),
|
|
14544
|
+
size: 1
|
|
14545
|
+
},
|
|
14546
|
+
primitivePolygonIndices: {
|
|
14547
|
+
value: new Uint16Array(primitivePolygonIndices),
|
|
14548
|
+
size: 1
|
|
14549
|
+
}
|
|
14550
|
+
};
|
|
14551
|
+
}
|
|
14552
|
+
function concatTypedArrays(arrays) {
|
|
14553
|
+
let byteLength = 0;
|
|
14554
|
+
for (let i = 0; i < arrays.length; ++i) {
|
|
14555
|
+
byteLength += arrays[i].byteLength;
|
|
14556
|
+
}
|
|
14557
|
+
const buffer = new Uint8Array(byteLength);
|
|
14558
|
+
let byteOffset = 0;
|
|
14559
|
+
for (let i = 0; i < arrays.length; ++i) {
|
|
14560
|
+
const data = new Uint8Array(arrays[i].buffer);
|
|
14561
|
+
byteLength = data.length;
|
|
14562
|
+
for (let j = 0; j < byteLength; ++j) {
|
|
14563
|
+
buffer[byteOffset++] = data[j];
|
|
14564
|
+
}
|
|
14565
|
+
}
|
|
14566
|
+
return buffer;
|
|
14567
|
+
}
|
|
14568
|
+
|
|
14569
|
+
// ../wkt/src/wkb-loader.ts
|
|
14570
|
+
var WKBWorkerLoader = {
|
|
14571
|
+
name: "WKB",
|
|
14572
|
+
id: "wkb",
|
|
14573
|
+
module: "wkt",
|
|
14574
|
+
version: VERSION3,
|
|
14575
|
+
worker: true,
|
|
14576
|
+
category: "geometry",
|
|
14577
|
+
extensions: ["wkb"],
|
|
14578
|
+
mimeTypes: [],
|
|
14579
|
+
tests: [isWKB],
|
|
14580
|
+
options: {
|
|
14581
|
+
wkb: {
|
|
14582
|
+
shape: "binary-geometry"
|
|
14583
|
+
}
|
|
14584
|
+
}
|
|
14585
|
+
};
|
|
14586
|
+
var WKBLoader = {
|
|
14587
|
+
...WKBWorkerLoader,
|
|
14588
|
+
parse: async (arrayBuffer) => parseWKB(arrayBuffer),
|
|
14589
|
+
parseSync: parseWKB
|
|
14590
|
+
};
|
|
14591
|
+
|
|
14592
|
+
// src/geoarrow/convert-geoarrow-to-geojson-geometry.ts
|
|
14593
|
+
function parseGeometryFromArrow(arrowCellValue, encoding) {
|
|
14594
|
+
encoding = encoding?.toLowerCase();
|
|
14595
|
+
if (!encoding || !arrowCellValue) {
|
|
13788
14596
|
return null;
|
|
13789
14597
|
}
|
|
13790
14598
|
let geometry;
|
|
13791
14599
|
switch (encoding) {
|
|
13792
14600
|
case "geoarrow.multipolygon":
|
|
13793
|
-
geometry = arrowMultiPolygonToFeature(
|
|
14601
|
+
geometry = arrowMultiPolygonToFeature(arrowCellValue);
|
|
13794
14602
|
break;
|
|
13795
14603
|
case "geoarrow.polygon":
|
|
13796
|
-
geometry = arrowPolygonToFeature(
|
|
14604
|
+
geometry = arrowPolygonToFeature(arrowCellValue);
|
|
13797
14605
|
break;
|
|
13798
14606
|
case "geoarrow.multipoint":
|
|
13799
|
-
geometry = arrowMultiPointToFeature(
|
|
14607
|
+
geometry = arrowMultiPointToFeature(arrowCellValue);
|
|
13800
14608
|
break;
|
|
13801
14609
|
case "geoarrow.point":
|
|
13802
|
-
geometry = arrowPointToFeature(
|
|
14610
|
+
geometry = arrowPointToFeature(arrowCellValue);
|
|
13803
14611
|
break;
|
|
13804
14612
|
case "geoarrow.multilinestring":
|
|
13805
|
-
geometry = arrowMultiLineStringToFeature(
|
|
14613
|
+
geometry = arrowMultiLineStringToFeature(arrowCellValue);
|
|
13806
14614
|
break;
|
|
13807
14615
|
case "geoarrow.linestring":
|
|
13808
|
-
geometry = arrowLineStringToFeature(
|
|
14616
|
+
geometry = arrowLineStringToFeature(arrowCellValue);
|
|
13809
14617
|
break;
|
|
13810
14618
|
case "geoarrow.wkb":
|
|
13811
|
-
|
|
14619
|
+
geometry = arrowWKBToFeature(arrowCellValue);
|
|
14620
|
+
break;
|
|
13812
14621
|
case "geoarrow.wkt":
|
|
13813
|
-
|
|
14622
|
+
geometry = arrowWKTToFeature(arrowCellValue);
|
|
14623
|
+
break;
|
|
13814
14624
|
default: {
|
|
13815
14625
|
throw Error(`GeoArrow encoding not supported ${encoding}`);
|
|
13816
14626
|
}
|
|
13817
14627
|
}
|
|
13818
|
-
return
|
|
13819
|
-
|
|
13820
|
-
|
|
13821
|
-
|
|
13822
|
-
|
|
14628
|
+
return geometry;
|
|
14629
|
+
}
|
|
14630
|
+
function arrowWKBToFeature(arrowCellValue) {
|
|
14631
|
+
const arrayBuffer = arrowCellValue.buffer.slice(arrowCellValue.byteOffset, arrowCellValue.byteOffset + arrowCellValue.byteLength);
|
|
14632
|
+
const binaryGeometry = WKBLoader.parseSync?.(arrayBuffer);
|
|
14633
|
+
const geometry = binaryToGeometry(binaryGeometry);
|
|
14634
|
+
return geometry;
|
|
14635
|
+
}
|
|
14636
|
+
function arrowWKTToFeature(arrowCellValue) {
|
|
14637
|
+
const string = arrowCellValue;
|
|
14638
|
+
return WKTLoader.parseTextSync?.(string);
|
|
13823
14639
|
}
|
|
13824
14640
|
function arrowMultiPolygonToFeature(arrowMultiPolygon) {
|
|
13825
14641
|
const multiPolygon = [];
|
|
@@ -13851,8 +14667,8 @@ return true;`);
|
|
|
13851
14667
|
const ring = [];
|
|
13852
14668
|
for (let j = 0; arrowRing && j < arrowRing.length; j++) {
|
|
13853
14669
|
const arrowCoord = arrowRing.get(j);
|
|
13854
|
-
const
|
|
13855
|
-
ring.push(
|
|
14670
|
+
const coords2 = Array.from(arrowCoord);
|
|
14671
|
+
ring.push(coords2);
|
|
13856
14672
|
}
|
|
13857
14673
|
polygon.push(ring);
|
|
13858
14674
|
}
|
|
@@ -13871,19 +14687,17 @@ return true;`);
|
|
|
13871
14687
|
multiPoint.push(coord);
|
|
13872
14688
|
}
|
|
13873
14689
|
}
|
|
13874
|
-
|
|
14690
|
+
return {
|
|
13875
14691
|
type: "MultiPoint",
|
|
13876
14692
|
coordinates: multiPoint
|
|
13877
14693
|
};
|
|
13878
|
-
return geometry;
|
|
13879
14694
|
}
|
|
13880
14695
|
function arrowPointToFeature(arrowPoint) {
|
|
13881
14696
|
const point = Array.from(arrowPoint);
|
|
13882
|
-
|
|
14697
|
+
return {
|
|
13883
14698
|
type: "Point",
|
|
13884
14699
|
coordinates: point
|
|
13885
14700
|
};
|
|
13886
|
-
return geometry;
|
|
13887
14701
|
}
|
|
13888
14702
|
function arrowMultiLineStringToFeature(arrowMultiLineString) {
|
|
13889
14703
|
const multiLineString = [];
|
|
@@ -13893,32 +14707,64 @@ return true;`);
|
|
|
13893
14707
|
for (let j = 0; arrowLineString && j < arrowLineString.length; j++) {
|
|
13894
14708
|
const arrowCoord = arrowLineString.get(j);
|
|
13895
14709
|
if (arrowCoord) {
|
|
13896
|
-
const
|
|
13897
|
-
lineString.push(
|
|
14710
|
+
const coords2 = Array.from(arrowCoord);
|
|
14711
|
+
lineString.push(coords2);
|
|
13898
14712
|
}
|
|
13899
14713
|
}
|
|
13900
14714
|
multiLineString.push(lineString);
|
|
13901
14715
|
}
|
|
13902
|
-
|
|
14716
|
+
return {
|
|
13903
14717
|
type: "MultiLineString",
|
|
13904
14718
|
coordinates: multiLineString
|
|
13905
14719
|
};
|
|
13906
|
-
return geometry;
|
|
13907
14720
|
}
|
|
13908
14721
|
function arrowLineStringToFeature(arrowLineString) {
|
|
13909
14722
|
const lineString = [];
|
|
13910
14723
|
for (let i = 0; arrowLineString && i < arrowLineString.length; i++) {
|
|
13911
14724
|
const arrowCoord = arrowLineString.get(i);
|
|
13912
14725
|
if (arrowCoord) {
|
|
13913
|
-
const
|
|
13914
|
-
lineString.push(
|
|
14726
|
+
const coords2 = Array.from(arrowCoord);
|
|
14727
|
+
lineString.push(coords2);
|
|
13915
14728
|
}
|
|
13916
14729
|
}
|
|
13917
|
-
|
|
14730
|
+
return {
|
|
13918
14731
|
type: "LineString",
|
|
13919
14732
|
coordinates: lineString
|
|
13920
14733
|
};
|
|
13921
|
-
|
|
14734
|
+
}
|
|
14735
|
+
|
|
14736
|
+
// src/workers/hard-clone.ts
|
|
14737
|
+
function hardClone(data, force = false) {
|
|
14738
|
+
if ("data" in data) {
|
|
14739
|
+
return new Vector(data.data.map((data2) => hardClone(data2, force)));
|
|
14740
|
+
}
|
|
14741
|
+
const clonedChildren = [];
|
|
14742
|
+
for (const childData of data.children) {
|
|
14743
|
+
clonedChildren.push(hardClone(childData, force));
|
|
14744
|
+
}
|
|
14745
|
+
let clonedDictionary;
|
|
14746
|
+
if (data.dictionary !== void 0) {
|
|
14747
|
+
clonedDictionary = hardClone(data.dictionary, force);
|
|
14748
|
+
}
|
|
14749
|
+
const clonedBuffers = {
|
|
14750
|
+
[BufferType.OFFSET]: cloneBuffer(data.buffers[BufferType.OFFSET], force),
|
|
14751
|
+
[BufferType.DATA]: cloneBuffer(data.buffers[BufferType.DATA], force),
|
|
14752
|
+
[BufferType.VALIDITY]: cloneBuffer(data.buffers[BufferType.VALIDITY], force),
|
|
14753
|
+
[BufferType.TYPE]: cloneBuffer(data.buffers[BufferType.TYPE], force)
|
|
14754
|
+
};
|
|
14755
|
+
return new Data(data.type, data.offset, data.length, data._nullCount, clonedBuffers, clonedChildren, clonedDictionary);
|
|
14756
|
+
}
|
|
14757
|
+
function isTypedArraySliced(arr) {
|
|
14758
|
+
return !(arr.byteOffset === 0 && arr.byteLength === arr.buffer.byteLength);
|
|
14759
|
+
}
|
|
14760
|
+
function cloneBuffer(arr, force) {
|
|
14761
|
+
if (arr === void 0) {
|
|
14762
|
+
return arr;
|
|
14763
|
+
}
|
|
14764
|
+
if (!force && !isTypedArraySliced(arr)) {
|
|
14765
|
+
return arr;
|
|
14766
|
+
}
|
|
14767
|
+
return arr.slice();
|
|
13922
14768
|
}
|
|
13923
14769
|
|
|
13924
14770
|
// ../worker-utils/src/lib/env-utils/version.ts
|
|
@@ -13926,16 +14772,16 @@ return true;`);
|
|
|
13926
14772
|
function getVersion() {
|
|
13927
14773
|
if (!globalThis._loadersgl_?.version) {
|
|
13928
14774
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
13929
|
-
if (
|
|
14775
|
+
if (false) {
|
|
13930
14776
|
console.warn("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
|
|
13931
14777
|
globalThis._loadersgl_.version = NPM_TAG;
|
|
13932
14778
|
} else {
|
|
13933
|
-
globalThis._loadersgl_.version =
|
|
14779
|
+
globalThis._loadersgl_.version = "4.1.0-alpha.10";
|
|
13934
14780
|
}
|
|
13935
14781
|
}
|
|
13936
14782
|
return globalThis._loadersgl_.version;
|
|
13937
14783
|
}
|
|
13938
|
-
var
|
|
14784
|
+
var VERSION4 = getVersion();
|
|
13939
14785
|
|
|
13940
14786
|
// ../worker-utils/src/lib/env-utils/assert.ts
|
|
13941
14787
|
function assert(condition, message) {
|
|
@@ -14377,7 +15223,7 @@ return true;`);
|
|
|
14377
15223
|
|
|
14378
15224
|
// ../worker-utils/src/lib/worker-api/get-worker-url.ts
|
|
14379
15225
|
function getWorkerName(worker) {
|
|
14380
|
-
const warning = worker.version !==
|
|
15226
|
+
const warning = worker.version !== VERSION4 ? ` (worker-utils@${VERSION4})` : "";
|
|
14381
15227
|
return `${worker.name}@${worker.version}${warning}`;
|
|
14382
15228
|
}
|
|
14383
15229
|
function getWorkerURL(worker, options = {}) {
|
|
@@ -14472,16 +15318,25 @@ return true;`);
|
|
|
14472
15318
|
}
|
|
14473
15319
|
|
|
14474
15320
|
// src/triangulate-on-worker.ts
|
|
14475
|
-
var
|
|
15321
|
+
var VERSION5 = true ? "4.1.0-alpha.10" : "latest";
|
|
14476
15322
|
var TriangulationWorker = {
|
|
14477
15323
|
id: "triangulation",
|
|
14478
15324
|
name: "Triangulate",
|
|
14479
15325
|
module: "arrow",
|
|
14480
|
-
version:
|
|
15326
|
+
version: VERSION5,
|
|
14481
15327
|
options: {}
|
|
14482
15328
|
};
|
|
14483
15329
|
function triangulateOnWorker(data, options = {}) {
|
|
14484
|
-
return processOnWorker(TriangulationWorker,
|
|
15330
|
+
return processOnWorker(TriangulationWorker, {
|
|
15331
|
+
...data,
|
|
15332
|
+
operation: "triangulate"
|
|
15333
|
+
}, options);
|
|
15334
|
+
}
|
|
15335
|
+
function parseGeoArrowOnWorker(data, options = {}) {
|
|
15336
|
+
return processOnWorker(TriangulationWorker, {
|
|
15337
|
+
...data,
|
|
15338
|
+
operation: "parse-geoarrow"
|
|
15339
|
+
}, options);
|
|
14485
15340
|
}
|
|
14486
15341
|
|
|
14487
15342
|
// src/index.ts
|