@loaders.gl/arrow 4.0.3 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/arrow-loader.d.ts +6 -3
  2. package/dist/arrow-loader.d.ts.map +1 -1
  3. package/dist/arrow-loader.js +9 -1
  4. package/dist/arrow-loader.js.map +1 -1
  5. package/dist/arrow-worker.js +37 -537
  6. package/dist/dist.dev.js +1573 -231
  7. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +31 -1
  8. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
  9. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +123 -13
  10. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
  11. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts +2 -1
  12. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts.map +1 -1
  13. package/dist/geoarrow/convert-geoarrow-to-geojson.js +4 -0
  14. package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +1 -1
  15. package/dist/geoarrow-loader.d.ts +19 -0
  16. package/dist/geoarrow-loader.d.ts.map +1 -0
  17. package/dist/geoarrow-loader.js +24 -0
  18. package/dist/geoarrow-loader.js.map +1 -0
  19. package/dist/geoarrow-writer.d.ts +9 -0
  20. package/dist/geoarrow-writer.d.ts.map +1 -0
  21. package/dist/geoarrow-writer.js +19 -0
  22. package/dist/geoarrow-writer.js.map +1 -0
  23. package/dist/index.cjs +472 -275
  24. package/dist/index.d.ts +9 -12
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +7 -13
  27. package/dist/index.js.map +1 -1
  28. package/dist/lib/arrow-table-batch.d.ts.map +1 -1
  29. package/dist/lib/arrow-table-batch.js.map +1 -1
  30. package/dist/lib/encode-arrow.d.ts.map +1 -1
  31. package/dist/lib/encode-arrow.js.map +1 -1
  32. package/dist/lib/encode-geoarrow.d.ts +15 -0
  33. package/dist/lib/encode-geoarrow.d.ts.map +1 -0
  34. package/dist/lib/encode-geoarrow.js +22 -0
  35. package/dist/lib/encode-geoarrow.js.map +1 -0
  36. package/dist/{lib → parsers}/parse-arrow-in-batches.d.ts +1 -1
  37. package/dist/parsers/parse-arrow-in-batches.d.ts.map +1 -0
  38. package/dist/parsers/parse-arrow-in-batches.js.map +1 -0
  39. package/dist/parsers/parse-arrow-sync.d.ts +6 -0
  40. package/dist/parsers/parse-arrow-sync.d.ts.map +1 -0
  41. package/dist/parsers/parse-arrow-sync.js +26 -0
  42. package/dist/parsers/parse-arrow-sync.js.map +1 -0
  43. package/dist/parsers/parse-geoarrow-in-batches.d.ts +6 -0
  44. package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +1 -0
  45. package/dist/parsers/parse-geoarrow-in-batches.js +5 -0
  46. package/dist/parsers/parse-geoarrow-in-batches.js.map +1 -0
  47. package/dist/parsers/parse-geoarrow-sync.d.ts +6 -0
  48. package/dist/parsers/parse-geoarrow-sync.d.ts.map +1 -0
  49. package/dist/parsers/parse-geoarrow-sync.js +14 -0
  50. package/dist/parsers/parse-geoarrow-sync.js.map +1 -0
  51. package/dist/tables/convert-arrow-to-columnar-table.d.ts +8 -0
  52. package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +1 -0
  53. package/dist/tables/convert-arrow-to-columnar-table.js +14 -0
  54. package/dist/tables/convert-arrow-to-columnar-table.js.map +1 -0
  55. package/dist/tables/convert-arrow-to-geojson-table.d.ts +16 -0
  56. package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +1 -0
  57. package/dist/tables/convert-arrow-to-geojson-table.js +33 -0
  58. package/dist/tables/convert-arrow-to-geojson-table.js.map +1 -0
  59. package/dist/tables/convert-columnar-to-row-table.d.ts +7 -0
  60. package/dist/tables/convert-columnar-to-row-table.d.ts.map +1 -0
  61. package/dist/tables/convert-columnar-to-row-table.js +18 -0
  62. package/dist/tables/convert-columnar-to-row-table.js.map +1 -0
  63. package/dist/triangulate-on-worker.d.ts +36 -0
  64. package/dist/triangulate-on-worker.d.ts.map +1 -0
  65. package/dist/triangulate-on-worker.js +14 -0
  66. package/dist/triangulate-on-worker.js.map +1 -0
  67. package/dist/triangulation-worker.js +880 -0
  68. package/dist/workers/arrow-worker.js +1 -1
  69. package/dist/workers/arrow-worker.js.map +1 -1
  70. package/dist/workers/triangulation-worker-node.d.ts +2 -0
  71. package/dist/workers/triangulation-worker-node.d.ts.map +1 -0
  72. package/dist/workers/triangulation-worker-node.js +2 -0
  73. package/dist/workers/triangulation-worker-node.js.map +1 -0
  74. package/dist/workers/triangulation-worker.d.ts +2 -0
  75. package/dist/workers/triangulation-worker.d.ts.map +1 -0
  76. package/dist/workers/triangulation-worker.js +24 -0
  77. package/dist/workers/triangulation-worker.js.map +1 -0
  78. package/package.json +9 -7
  79. package/src/arrow-loader.ts +25 -3
  80. package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +209 -20
  81. package/src/geoarrow/convert-geoarrow-to-geojson.ts +6 -2
  82. package/src/geoarrow-loader.ts +55 -0
  83. package/src/geoarrow-writer.ts +41 -0
  84. package/src/index.ts +30 -36
  85. package/src/lib/arrow-table-batch.ts +3 -0
  86. package/src/lib/encode-arrow.ts +3 -0
  87. package/src/lib/encode-geoarrow.ts +45 -0
  88. package/src/{lib → parsers}/parse-arrow-in-batches.ts +4 -2
  89. package/src/parsers/parse-arrow-sync.ts +38 -0
  90. package/src/parsers/parse-geoarrow-in-batches.ts +15 -0
  91. package/src/parsers/parse-geoarrow-sync.ts +22 -0
  92. package/src/tables/convert-arrow-to-columnar-table.ts +29 -0
  93. package/src/tables/convert-arrow-to-geojson-table.ts +54 -0
  94. package/src/tables/convert-columnar-to-row-table.ts +29 -0
  95. package/src/triangulate-on-worker.ts +47 -0
  96. package/src/workers/arrow-worker.ts +1 -1
  97. package/src/workers/triangulation-worker-node.ts +4 -0
  98. package/src/workers/triangulation-worker.ts +39 -0
  99. package/dist/lib/parse-arrow-in-batches.d.ts.map +0 -1
  100. package/dist/lib/parse-arrow-in-batches.js.map +0 -1
  101. package/dist/lib/parse-arrow-sync.d.ts +0 -5
  102. package/dist/lib/parse-arrow-sync.d.ts.map +0 -1
  103. package/dist/lib/parse-arrow-sync.js +0 -21
  104. package/dist/lib/parse-arrow-sync.js.map +0 -1
  105. package/dist/tables/convert-arrow-to-table.d.ts +0 -21
  106. package/dist/tables/convert-arrow-to-table.d.ts.map +0 -1
  107. package/dist/tables/convert-arrow-to-table.js +0 -37
  108. package/dist/tables/convert-arrow-to-table.js.map +0 -1
  109. package/src/lib/parse-arrow-sync.ts +0 -35
  110. package/src/tables/convert-arrow-to-table.ts +0 -68
  111. /package/dist/{lib → parsers}/parse-arrow-in-batches.js +0 -0
package/dist/dist.dev.js CHANGED
@@ -27,22 +27,29 @@ var __exports__ = (() => {
27
27
  // src/index.ts
28
28
  var src_exports = {};
29
29
  __export(src_exports, {
30
- ArrowLoader: () => ArrowLoader2,
31
- ArrowWorkerLoader: () => ArrowLoader,
30
+ ArrowLoader: () => ArrowLoader,
31
+ ArrowWorkerLoader: () => ArrowWorkerLoader,
32
32
  ArrowWriter: () => ArrowWriter,
33
33
  BINARY_GEOMETRY_TEMPLATE: () => BINARY_GEOMETRY_TEMPLATE,
34
+ GeoArrowLoader: () => GeoArrowLoader,
35
+ GeoArrowWorkerLoader: () => GeoArrowWorkerLoader,
36
+ TriangulationWorker: () => TriangulationWorker,
34
37
  VECTOR_TYPES: () => VECTOR_TYPES,
38
+ convertArrowToGeoJSONTable: () => convertArrowToGeoJSONTable,
35
39
  deserializeArrowField: () => deserializeArrowField,
36
40
  deserializeArrowMetadata: () => deserializeArrowMetadata,
37
41
  deserializeArrowSchema: () => deserializeArrowSchema,
38
42
  deserializeArrowType: () => deserializeArrowType,
39
43
  getArrowType: () => getArrowType,
40
44
  getBinaryGeometriesFromArrow: () => getBinaryGeometriesFromArrow,
45
+ getMeanCentersFromBinaryGeometries: () => getMeanCentersFromBinaryGeometries,
46
+ getTriangleIndices: () => getTriangleIndices,
41
47
  parseGeometryFromArrow: () => parseGeometryFromArrow,
42
48
  serializeArrowField: () => serializeArrowField,
43
49
  serializeArrowMetadata: () => serializeArrowMetadata,
44
50
  serializeArrowSchema: () => serializeArrowSchema,
45
51
  serializeArrowType: () => serializeArrowType,
52
+ triangulateOnWorker: () => triangulateOnWorker,
46
53
  updateBoundsFromGeoArrowSamples: () => updateBoundsFromGeoArrowSamples
47
54
  });
48
55
 
@@ -456,10 +463,10 @@ var __exports__ = (() => {
456
463
  }
457
464
  return columnIndex;
458
465
  }
459
- function getTableRowAsObject(table, rowIndex, target, copy) {
466
+ function getTableRowAsObject(table, rowIndex, target, copy2) {
460
467
  switch (table.shape) {
461
468
  case "object-row-table":
462
- return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
469
+ return copy2 ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
463
470
  case "array-row-table":
464
471
  if (table.schema) {
465
472
  const objectRow2 = target || {};
@@ -505,10 +512,10 @@ var __exports__ = (() => {
505
512
  throw new Error("shape");
506
513
  }
507
514
  }
508
- function getTableRowAsArray(table, rowIndex, target, copy) {
515
+ function getTableRowAsArray(table, rowIndex, target, copy2) {
509
516
  switch (table.shape) {
510
517
  case "array-row-table":
511
- return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
518
+ return copy2 ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
512
519
  case "object-row-table":
513
520
  if (table.schema) {
514
521
  const arrayRow2 = target || [];
@@ -792,25 +799,6 @@ var __exports__ = (() => {
792
799
  };
793
800
  }
794
801
 
795
- // src/arrow-loader.ts
796
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
797
- var ArrowLoader = {
798
- name: "Apache Arrow",
799
- id: "arrow",
800
- module: "arrow",
801
- version: VERSION,
802
- category: "table",
803
- extensions: ["arrow", "feather"],
804
- mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
805
- binary: true,
806
- tests: ["ARROW"],
807
- options: {
808
- arrow: {
809
- shape: "columnar-table"
810
- }
811
- }
812
- };
813
-
814
802
  // ../../node_modules/tslib/tslib.es6.mjs
815
803
  function __rest(s, e) {
816
804
  var t = {};
@@ -2796,21 +2784,21 @@ var __exports__ = (() => {
2796
2784
  function uint16ToFloat64(h) {
2797
2785
  const expo = (h & 31744) >> 10;
2798
2786
  const sigf = (h & 1023) / 1024;
2799
- const sign = Math.pow(-1, (h & 32768) >> 15);
2787
+ const sign2 = Math.pow(-1, (h & 32768) >> 15);
2800
2788
  switch (expo) {
2801
2789
  case 31:
2802
- return sign * (sigf ? Number.NaN : 1 / 0);
2790
+ return sign2 * (sigf ? Number.NaN : 1 / 0);
2803
2791
  case 0:
2804
- return sign * (sigf ? 6103515625e-14 * sigf : 0);
2792
+ return sign2 * (sigf ? 6103515625e-14 * sigf : 0);
2805
2793
  }
2806
- return sign * Math.pow(2, expo - 15) * (1 + sigf);
2794
+ return sign2 * Math.pow(2, expo - 15) * (1 + sigf);
2807
2795
  }
2808
2796
  function float64ToUint16(d) {
2809
2797
  if (d !== d) {
2810
2798
  return 32256;
2811
2799
  }
2812
2800
  f64[0] = d;
2813
- const sign = (u32[1] & 2147483648) >> 16 & 65535;
2801
+ const sign2 = (u32[1] & 2147483648) >> 16 & 65535;
2814
2802
  let expo = u32[1] & 2146435072, sigf = 0;
2815
2803
  if (expo >= 1089470464) {
2816
2804
  if (u32[0] > 0) {
@@ -2827,7 +2815,7 @@ var __exports__ = (() => {
2827
2815
  expo = expo - 1056964608 >> 10;
2828
2816
  sigf = (u32[1] & 1048575) + 512 >> 10;
2829
2817
  }
2830
- return sign | expo | sigf & 65535;
2818
+ return sign2 | expo | sigf & 65535;
2831
2819
  }
2832
2820
 
2833
2821
  // ../../node_modules/apache-arrow/visitor/set.mjs
@@ -11592,8 +11580,8 @@ return true;`);
11592
11580
  return new JSONVectorLoader(body, header.nodes, header.buffers, this.dictionaries).visitMany(types);
11593
11581
  }
11594
11582
  };
11595
- function shouldAutoDestroy(self, options) {
11596
- return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self["autoDestroy"];
11583
+ function shouldAutoDestroy(self2, options) {
11584
+ return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self2["autoDestroy"];
11597
11585
  }
11598
11586
  function* readAllSync(source) {
11599
11587
  const reader = RecordBatchReader.from(source);
@@ -12340,65 +12328,6 @@ return true;`);
12340
12328
  RecordBatchFileWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12341
12329
  RecordBatchStreamWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12342
12330
 
12343
- // src/tables/convert-arrow-to-table.ts
12344
- function convertApacheArrowToArrowTable(arrowTable) {
12345
- return {
12346
- shape: "arrow-table",
12347
- data: arrowTable
12348
- };
12349
- }
12350
- function convertArrowToColumnarTable(table) {
12351
- const arrowTable = table.data;
12352
- const columnarTable = {};
12353
- for (const field of arrowTable.schema.fields) {
12354
- const arrowColumn = arrowTable.getChild(field.name);
12355
- const values = arrowColumn?.toArray();
12356
- columnarTable[field.name] = values;
12357
- }
12358
- return {
12359
- shape: "columnar-table",
12360
- data: columnarTable
12361
- };
12362
- }
12363
-
12364
- // src/lib/parse-arrow-sync.ts
12365
- function parseArrowSync(arrayBuffer, options) {
12366
- const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
12367
- const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
12368
- const shape = options?.arrow?.shape || "arrow-table";
12369
- switch (shape) {
12370
- case "arrow-table":
12371
- return arrowTable;
12372
- case "columnar-table":
12373
- return convertArrowToColumnarTable(arrowTable);
12374
- case "object-row-table":
12375
- const columnarTable = convertArrowToColumnarTable(arrowTable);
12376
- return convertTable(columnarTable, "object-row-table");
12377
- default:
12378
- throw new Error(shape);
12379
- }
12380
- }
12381
-
12382
- // src/lib/parse-arrow-in-batches.ts
12383
- function parseArrowInBatches(asyncIterator) {
12384
- async function* makeArrowAsyncIterator() {
12385
- const readers = RecordBatchReader.readAll(asyncIterator);
12386
- for await (const reader of readers) {
12387
- for await (const recordBatch of reader) {
12388
- const arrowTabledBatch = {
12389
- shape: "arrow-table",
12390
- batchType: "data",
12391
- data: new Table([recordBatch]),
12392
- length: recordBatch.data.length
12393
- };
12394
- yield arrowTabledBatch;
12395
- }
12396
- break;
12397
- }
12398
- }
12399
- return makeArrowAsyncIterator();
12400
- }
12401
-
12402
12331
  // src/lib/arrow-table-batch.ts
12403
12332
  var ArrowTableBatchAggregator = class extends ColumnarTableBatchAggregator {
12404
12333
  constructor(schema, options) {
@@ -12480,87 +12409,878 @@ return true;`);
12480
12409
  }
12481
12410
  }
12482
12411
 
12483
- // src/schema/convert-arrow-schema.ts
12484
- function serializeArrowSchema(arrowSchema) {
12412
+ // src/types.ts
12413
+ var VECTOR_TYPES = function(VECTOR_TYPES2) {
12414
+ VECTOR_TYPES2[VECTOR_TYPES2["FLOAT"] = 0] = "FLOAT";
12415
+ VECTOR_TYPES2[VECTOR_TYPES2["DATE"] = 1] = "DATE";
12416
+ return VECTOR_TYPES2;
12417
+ }({});
12418
+
12419
+ // src/tables/convert-arrow-to-columnar-table.ts
12420
+ function convertArrowToColumnarTable(table) {
12421
+ const arrowTable = table.data;
12422
+ const columnarTable = {};
12423
+ for (const field of arrowTable.schema.fields) {
12424
+ const arrowColumn = arrowTable.getChild(field.name);
12425
+ const values = arrowColumn?.toArray();
12426
+ columnarTable[field.name] = values;
12427
+ }
12485
12428
  return {
12486
- fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
12487
- metadata: serializeArrowMetadata(arrowSchema.metadata)
12429
+ shape: "columnar-table",
12430
+ data: columnarTable
12488
12431
  };
12489
12432
  }
12490
- function deserializeArrowSchema(schema) {
12491
- return new Schema2(schema.fields.map((field) => deserializeArrowField(field)), deserializeArrowMetadata(schema.metadata));
12433
+
12434
+ // src/parsers/parse-arrow-sync.ts
12435
+ function parseArrowSync(arrayBuffer, options) {
12436
+ const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
12437
+ const arrowTable = {
12438
+ shape: "arrow-table",
12439
+ data: apacheArrowTable
12440
+ };
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
+ }
12492
12456
  }
12493
- function serializeArrowMetadata(arrowMetadata) {
12494
- return Object.fromEntries(arrowMetadata);
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();
12495
12476
  }
12496
- function deserializeArrowMetadata(metadata) {
12497
- return metadata ? new Map(Object.entries(metadata)) : /* @__PURE__ */ new Map();
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;
12498
12513
  }
12499
- function serializeArrowField(field) {
12500
- return {
12501
- name: field.name,
12502
- type: serializeArrowType(field.type),
12503
- nullable: field.nullable,
12504
- metadata: serializeArrowMetadata(field.metadata)
12505
- };
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
+ }
12506
12522
  }
12507
- function deserializeArrowField(field) {
12508
- return new Field2(field.name, deserializeArrowType(field.type), field.nullable, deserializeArrowMetadata(field.metadata));
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;
12509
12556
  }
12510
- function serializeArrowType(arrowType) {
12511
- switch (arrowType.constructor) {
12512
- case Null:
12513
- return "null";
12514
- case Binary:
12515
- return "binary";
12516
- case Bool:
12517
- return "bool";
12518
- case Int_:
12519
- const intType = arrowType;
12520
- return `${intType.isSigned ? "u" : ""}int${intType.bitWidth}`;
12521
- case Int8:
12522
- return "int8";
12523
- case Int16:
12524
- return "int16";
12525
- case Int32:
12526
- return "int32";
12527
- case Int64:
12528
- return "int64";
12529
- case Uint8:
12530
- return "uint8";
12531
- case Uint16:
12532
- return "uint16";
12533
- case Uint32:
12534
- return "uint32";
12535
- case Uint64:
12536
- return "uint64";
12537
- case Float:
12538
- const precision = arrowType.precision;
12539
- switch (precision) {
12540
- case Precision.HALF:
12541
- return "float16";
12542
- case Precision.SINGLE:
12543
- return "float32";
12544
- case Precision.DOUBLE:
12545
- return "float64";
12546
- default:
12547
- return "float16";
12548
- }
12549
- case Float16:
12550
- return "float16";
12551
- case Float32:
12552
- return "float32";
12553
- case Float64:
12554
- return "float64";
12555
- case Utf8:
12556
- return "utf8";
12557
- case Decimal:
12558
- const decimal = arrowType;
12559
- return {
12560
- type: "decimal",
12561
- bitWidth: decimal.bitWidth,
12562
- precision: decimal.precision,
12563
- scale: decimal.scale
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
+ }
12579
+
12580
+ // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
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);
12588
+ }
12589
+
12590
+ // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
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);
12602
+ }
12603
+
12604
+ // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
12605
+ function _toPropertyKey(arg) {
12606
+ var key = _toPrimitive(arg, "string");
12607
+ return _typeof(key) === "symbol" ? key : String(key);
12608
+ }
12609
+
12610
+ // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
12611
+ function _defineProperty(obj, key, value) {
12612
+ key = _toPropertyKey(key);
12613
+ if (key in obj) {
12614
+ Object.defineProperty(obj, key, {
12615
+ value,
12616
+ enumerable: true,
12617
+ configurable: true,
12618
+ writable: true
12619
+ });
12620
+ } else {
12621
+ obj[key] = value;
12622
+ }
12623
+ return obj;
12624
+ }
12625
+
12626
+ // ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
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;
12647
+ }
12648
+
12649
+ // ../../node_modules/@math.gl/polygon/dist/earcut.js
12650
+ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
12651
+ const hasHoles = holeIndices && holeIndices.length;
12652
+ const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
12653
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
12654
+ const triangles = [];
12655
+ if (!outerNode || outerNode.next === outerNode.prev)
12656
+ return triangles;
12657
+ let invSize;
12658
+ let maxX;
12659
+ let maxY;
12660
+ let minX;
12661
+ let minY;
12662
+ let x;
12663
+ let y;
12664
+ if (hasHoles)
12665
+ outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
12666
+ if (positions.length > 80 * dim) {
12667
+ minX = maxX = positions[0];
12668
+ minY = maxY = positions[1];
12669
+ for (let i = dim; i < outerLen; i += dim) {
12670
+ x = positions[i];
12671
+ y = positions[i + 1];
12672
+ if (x < minX)
12673
+ minX = x;
12674
+ if (y < minY)
12675
+ minY = y;
12676
+ if (x > maxX)
12677
+ maxX = x;
12678
+ if (y > maxY)
12679
+ maxY = y;
12680
+ }
12681
+ invSize = Math.max(maxX - minX, maxY - minY);
12682
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
12683
+ }
12684
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
12685
+ return triangles;
12686
+ }
12687
+ function linkedList(data, start, end, dim, clockwise, area2, plane) {
12688
+ let i;
12689
+ let last;
12690
+ if (area2 === void 0) {
12691
+ area2 = getPolygonSignedArea(data, {
12692
+ start,
12693
+ end,
12694
+ size: dim,
12695
+ plane
12696
+ });
12697
+ }
12698
+ let i0 = DimIndex[plane[0]];
12699
+ let i1 = DimIndex[plane[1]];
12700
+ if (clockwise === area2 < 0) {
12701
+ for (i = start; i < end; i += dim)
12702
+ last = insertNode(i, data[i + i0], data[i + i1], last);
12703
+ } else {
12704
+ for (i = end - dim; i >= start; i -= dim)
12705
+ last = insertNode(i, data[i + i0], data[i + i1], last);
12706
+ }
12707
+ if (last && equals(last, last.next)) {
12708
+ removeNode(last);
12709
+ last = last.next;
12710
+ }
12711
+ return last;
12712
+ }
12713
+ function filterPoints(start, end) {
12714
+ if (!start)
12715
+ return start;
12716
+ if (!end)
12717
+ end = start;
12718
+ let p = start;
12719
+ let again;
12720
+ do {
12721
+ again = false;
12722
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
12723
+ removeNode(p);
12724
+ p = end = p.prev;
12725
+ if (p === p.next)
12726
+ break;
12727
+ again = true;
12728
+ } else {
12729
+ p = p.next;
12730
+ }
12731
+ } while (again || p !== end);
12732
+ return end;
12733
+ }
12734
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
12735
+ if (!ear)
12736
+ return;
12737
+ if (!pass && invSize)
12738
+ indexCurve(ear, minX, minY, invSize);
12739
+ let stop = ear;
12740
+ let prev;
12741
+ let next;
12742
+ while (ear.prev !== ear.next) {
12743
+ prev = ear.prev;
12744
+ next = ear.next;
12745
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
12746
+ triangles.push(prev.i / dim | 0);
12747
+ triangles.push(ear.i / dim | 0);
12748
+ triangles.push(next.i / dim | 0);
12749
+ removeNode(ear);
12750
+ ear = next.next;
12751
+ stop = next.next;
12752
+ continue;
12753
+ }
12754
+ ear = next;
12755
+ if (ear === stop) {
12756
+ if (!pass) {
12757
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
12758
+ } else if (pass === 1) {
12759
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
12760
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
12761
+ } else if (pass === 2) {
12762
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
12763
+ }
12764
+ break;
12765
+ }
12766
+ }
12767
+ }
12768
+ function isEar(ear) {
12769
+ const a = ear.prev;
12770
+ const b = ear;
12771
+ const c = ear.next;
12772
+ if (area(a, b, c) >= 0)
12773
+ return false;
12774
+ const ax = a.x;
12775
+ const bx = b.x;
12776
+ const cx = c.x;
12777
+ const ay = a.y;
12778
+ const by = b.y;
12779
+ const cy = c.y;
12780
+ const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
12781
+ const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
12782
+ const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
12783
+ const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
12784
+ let p = c.next;
12785
+ while (p !== a) {
12786
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
12787
+ return false;
12788
+ p = p.next;
12789
+ }
12790
+ return true;
12791
+ }
12792
+ function isEarHashed(ear, minX, minY, invSize) {
12793
+ const a = ear.prev;
12794
+ const b = ear;
12795
+ const c = ear.next;
12796
+ if (area(a, b, c) >= 0)
12797
+ return false;
12798
+ const ax = a.x;
12799
+ const bx = b.x;
12800
+ const cx = c.x;
12801
+ const ay = a.y;
12802
+ const by = b.y;
12803
+ const cy = c.y;
12804
+ const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
12805
+ const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
12806
+ const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
12807
+ const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
12808
+ const minZ = zOrder(x0, y0, minX, minY, invSize);
12809
+ const maxZ = zOrder(x1, y1, minX, minY, invSize);
12810
+ let p = ear.prevZ;
12811
+ let n = ear.nextZ;
12812
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
12813
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
12814
+ return false;
12815
+ p = p.prevZ;
12816
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
12817
+ return false;
12818
+ n = n.nextZ;
12819
+ }
12820
+ while (p && p.z >= minZ) {
12821
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
12822
+ return false;
12823
+ p = p.prevZ;
12824
+ }
12825
+ while (n && n.z <= maxZ) {
12826
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
12827
+ return false;
12828
+ n = n.nextZ;
12829
+ }
12830
+ return true;
12831
+ }
12832
+ function cureLocalIntersections(start, triangles, dim) {
12833
+ let p = start;
12834
+ do {
12835
+ const a = p.prev;
12836
+ const b = p.next.next;
12837
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
12838
+ triangles.push(a.i / dim | 0);
12839
+ triangles.push(p.i / dim | 0);
12840
+ triangles.push(b.i / dim | 0);
12841
+ removeNode(p);
12842
+ removeNode(p.next);
12843
+ p = start = b;
12844
+ }
12845
+ p = p.next;
12846
+ } while (p !== start);
12847
+ return filterPoints(p);
12848
+ }
12849
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
12850
+ let a = start;
12851
+ do {
12852
+ let b = a.next.next;
12853
+ while (b !== a.prev) {
12854
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
12855
+ let c = splitPolygon(a, b);
12856
+ a = filterPoints(a, a.next);
12857
+ c = filterPoints(c, c.next);
12858
+ earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
12859
+ earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
12860
+ return;
12861
+ }
12862
+ b = b.next;
12863
+ }
12864
+ a = a.next;
12865
+ } while (a !== start);
12866
+ }
12867
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
12868
+ const queue = [];
12869
+ let i;
12870
+ let len;
12871
+ let start;
12872
+ let end;
12873
+ let list;
12874
+ for (i = 0, len = holeIndices.length; i < len; i++) {
12875
+ start = holeIndices[i] * dim;
12876
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
12877
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
12878
+ if (list === list.next)
12879
+ list.steiner = true;
12880
+ queue.push(getLeftmost(list));
12881
+ }
12882
+ queue.sort(compareX);
12883
+ for (i = 0; i < queue.length; i++) {
12884
+ outerNode = eliminateHole(queue[i], outerNode);
12885
+ }
12886
+ return outerNode;
12887
+ }
12888
+ function compareX(a, b) {
12889
+ return a.x - b.x;
12890
+ }
12891
+ function eliminateHole(hole, outerNode) {
12892
+ const bridge = findHoleBridge(hole, outerNode);
12893
+ if (!bridge) {
12894
+ return outerNode;
12895
+ }
12896
+ const bridgeReverse = splitPolygon(bridge, hole);
12897
+ filterPoints(bridgeReverse, bridgeReverse.next);
12898
+ return filterPoints(bridge, bridge.next);
12899
+ }
12900
+ function findHoleBridge(hole, outerNode) {
12901
+ let p = outerNode;
12902
+ const hx = hole.x;
12903
+ const hy = hole.y;
12904
+ let qx = -Infinity;
12905
+ let m;
12906
+ do {
12907
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
12908
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
12909
+ if (x <= hx && x > qx) {
12910
+ qx = x;
12911
+ m = p.x < p.next.x ? p : p.next;
12912
+ if (x === hx)
12913
+ return m;
12914
+ }
12915
+ }
12916
+ p = p.next;
12917
+ } while (p !== outerNode);
12918
+ if (!m)
12919
+ return null;
12920
+ const stop = m;
12921
+ const mx = m.x;
12922
+ const my = m.y;
12923
+ let tanMin = Infinity;
12924
+ let tan;
12925
+ p = m;
12926
+ do {
12927
+ if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
12928
+ tan = Math.abs(hy - p.y) / (hx - p.x);
12929
+ if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
12930
+ m = p;
12931
+ tanMin = tan;
12932
+ }
12933
+ }
12934
+ p = p.next;
12935
+ } while (p !== stop);
12936
+ return m;
12937
+ }
12938
+ function sectorContainsSector(m, p) {
12939
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
12940
+ }
12941
+ function indexCurve(start, minX, minY, invSize) {
12942
+ let p = start;
12943
+ do {
12944
+ if (p.z === 0)
12945
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
12946
+ p.prevZ = p.prev;
12947
+ p.nextZ = p.next;
12948
+ p = p.next;
12949
+ } while (p !== start);
12950
+ p.prevZ.nextZ = null;
12951
+ p.prevZ = null;
12952
+ sortLinked(p);
12953
+ }
12954
+ function sortLinked(list) {
12955
+ let e;
12956
+ let i;
12957
+ let inSize = 1;
12958
+ let numMerges;
12959
+ let p;
12960
+ let pSize;
12961
+ let q;
12962
+ let qSize;
12963
+ let tail;
12964
+ do {
12965
+ p = list;
12966
+ list = null;
12967
+ tail = null;
12968
+ numMerges = 0;
12969
+ while (p) {
12970
+ numMerges++;
12971
+ q = p;
12972
+ pSize = 0;
12973
+ for (i = 0; i < inSize; i++) {
12974
+ pSize++;
12975
+ q = q.nextZ;
12976
+ if (!q)
12977
+ break;
12978
+ }
12979
+ qSize = inSize;
12980
+ while (pSize > 0 || qSize > 0 && q) {
12981
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
12982
+ e = p;
12983
+ p = p.nextZ;
12984
+ pSize--;
12985
+ } else {
12986
+ e = q;
12987
+ q = q.nextZ;
12988
+ qSize--;
12989
+ }
12990
+ if (tail)
12991
+ tail.nextZ = e;
12992
+ else
12993
+ list = e;
12994
+ e.prevZ = tail;
12995
+ tail = e;
12996
+ }
12997
+ p = q;
12998
+ }
12999
+ tail.nextZ = null;
13000
+ inSize *= 2;
13001
+ } while (numMerges > 1);
13002
+ return list;
13003
+ }
13004
+ function zOrder(x, y, minX, minY, invSize) {
13005
+ x = (x - minX) * invSize | 0;
13006
+ y = (y - minY) * invSize | 0;
13007
+ x = (x | x << 8) & 16711935;
13008
+ x = (x | x << 4) & 252645135;
13009
+ x = (x | x << 2) & 858993459;
13010
+ x = (x | x << 1) & 1431655765;
13011
+ y = (y | y << 8) & 16711935;
13012
+ y = (y | y << 4) & 252645135;
13013
+ y = (y | y << 2) & 858993459;
13014
+ y = (y | y << 1) & 1431655765;
13015
+ return x | y << 1;
13016
+ }
13017
+ function getLeftmost(start) {
13018
+ let p = start;
13019
+ let leftmost = start;
13020
+ do {
13021
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
13022
+ leftmost = p;
13023
+ p = p.next;
13024
+ } while (p !== start);
13025
+ return leftmost;
13026
+ }
13027
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
13028
+ return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
13029
+ }
13030
+ function isValidDiagonal(a, b) {
13031
+ return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
13032
+ }
13033
+ function area(p, q, r) {
13034
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
13035
+ }
13036
+ function equals(p1, p2) {
13037
+ return p1.x === p2.x && p1.y === p2.y;
13038
+ }
13039
+ function intersects(p1, q1, p2, q2) {
13040
+ const o1 = sign(area(p1, q1, p2));
13041
+ const o2 = sign(area(p1, q1, q2));
13042
+ const o3 = sign(area(p2, q2, p1));
13043
+ const o4 = sign(area(p2, q2, q1));
13044
+ if (o1 !== o2 && o3 !== o4)
13045
+ return true;
13046
+ if (o1 === 0 && onSegment(p1, p2, q1))
13047
+ return true;
13048
+ if (o2 === 0 && onSegment(p1, q2, q1))
13049
+ return true;
13050
+ if (o3 === 0 && onSegment(p2, p1, q2))
13051
+ return true;
13052
+ if (o4 === 0 && onSegment(p2, q1, q2))
13053
+ return true;
13054
+ return false;
13055
+ }
13056
+ function onSegment(p, q, r) {
13057
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
13058
+ }
13059
+ function sign(num) {
13060
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
13061
+ }
13062
+ function intersectsPolygon(a, b) {
13063
+ let p = a;
13064
+ do {
13065
+ if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
13066
+ return true;
13067
+ p = p.next;
13068
+ } while (p !== a);
13069
+ return false;
13070
+ }
13071
+ function locallyInside(a, b) {
13072
+ return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
13073
+ }
13074
+ function middleInside(a, b) {
13075
+ let p = a;
13076
+ let inside = false;
13077
+ const px = (a.x + b.x) / 2;
13078
+ const py = (a.y + b.y) / 2;
13079
+ do {
13080
+ if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
13081
+ inside = !inside;
13082
+ p = p.next;
13083
+ } while (p !== a);
13084
+ return inside;
13085
+ }
13086
+ function splitPolygon(a, b) {
13087
+ const a2 = new Vertex(a.i, a.x, a.y);
13088
+ const b2 = new Vertex(b.i, b.x, b.y);
13089
+ const an = a.next;
13090
+ const bp = b.prev;
13091
+ a.next = b;
13092
+ b.prev = a;
13093
+ a2.next = an;
13094
+ an.prev = a2;
13095
+ b2.next = a2;
13096
+ a2.prev = b2;
13097
+ bp.next = b2;
13098
+ b2.prev = bp;
13099
+ return b2;
13100
+ }
13101
+ function insertNode(i, x, y, last) {
13102
+ const p = new Vertex(i, x, y);
13103
+ if (!last) {
13104
+ p.prev = p;
13105
+ p.next = p;
13106
+ } else {
13107
+ p.next = last.next;
13108
+ p.prev = last;
13109
+ last.next.prev = p;
13110
+ last.next = p;
13111
+ }
13112
+ return p;
13113
+ }
13114
+ function removeNode(p) {
13115
+ p.next.prev = p.prev;
13116
+ p.prev.next = p.next;
13117
+ if (p.prevZ)
13118
+ p.prevZ.nextZ = p.nextZ;
13119
+ if (p.nextZ)
13120
+ p.nextZ.prevZ = p.prevZ;
13121
+ }
13122
+ var Vertex = class {
13123
+ constructor(i, x, y) {
13124
+ _defineProperty(this, "i", void 0);
13125
+ _defineProperty(this, "x", void 0);
13126
+ _defineProperty(this, "y", void 0);
13127
+ _defineProperty(this, "prev", null);
13128
+ _defineProperty(this, "next", null);
13129
+ _defineProperty(this, "z", 0);
13130
+ _defineProperty(this, "prevZ", null);
13131
+ _defineProperty(this, "nextZ", null);
13132
+ _defineProperty(this, "steiner", false);
13133
+ this.i = i;
13134
+ this.x = x;
13135
+ this.y = y;
13136
+ }
13137
+ };
13138
+
13139
+ // src/tables/convert-arrow-to-geojson-table.ts
13140
+ function convertArrowToGeoJSONTable(table) {
13141
+ const arrowTable = table.data;
13142
+ const schema = serializeArrowSchema(arrowTable.schema);
13143
+ const geometryColumns = getGeometryColumnsFromSchema(schema);
13144
+ const encoding = geometryColumns.geometry.encoding;
13145
+ const features = [];
13146
+ for (let row = 0; row < arrowTable.numRows; row++) {
13147
+ const arrowGeometry = arrowTable.getChild("geometry")?.get(row);
13148
+ const arrowGeometryObject = {
13149
+ encoding,
13150
+ data: arrowGeometry
13151
+ };
13152
+ const feature = parseGeometryFromArrow(arrowGeometryObject);
13153
+ if (feature) {
13154
+ features.push(feature);
13155
+ }
13156
+ }
13157
+ return {
13158
+ shape: "geojson-table",
13159
+ type: "FeatureCollection",
13160
+ features
13161
+ };
13162
+ }
13163
+
13164
+ // src/parsers/parse-geoarrow-sync.ts
13165
+ function parseGeoArrowSync(arrayBuffer, options) {
13166
+ const table = parseArrowSync(arrayBuffer, {
13167
+ shape: "arrow-table"
13168
+ });
13169
+ switch (options?.shape) {
13170
+ case "geojson-table":
13171
+ return convertArrowToGeoJSONTable(table);
13172
+ default:
13173
+ return table;
13174
+ }
13175
+ }
13176
+
13177
+ // src/parsers/parse-geoarrow-in-batches.ts
13178
+ function parseGeoArrowInBatches(asyncIterator) {
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
+ }
13189
+ }
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
+ return {
13206
+ fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
13207
+ metadata: serializeArrowMetadata(arrowSchema.metadata)
13208
+ };
13209
+ }
13210
+ function deserializeArrowSchema(schema) {
13211
+ return new Schema2(schema.fields.map((field) => deserializeArrowField(field)), deserializeArrowMetadata(schema.metadata));
13212
+ }
13213
+ function serializeArrowMetadata(arrowMetadata) {
13214
+ return Object.fromEntries(arrowMetadata);
13215
+ }
13216
+ function deserializeArrowMetadata(metadata) {
13217
+ return metadata ? new Map(Object.entries(metadata)) : /* @__PURE__ */ new Map();
13218
+ }
13219
+ function serializeArrowField(field) {
13220
+ return {
13221
+ name: field.name,
13222
+ type: serializeArrowType(field.type),
13223
+ nullable: field.nullable,
13224
+ metadata: serializeArrowMetadata(field.metadata)
13225
+ };
13226
+ }
13227
+ function deserializeArrowField(field) {
13228
+ return new Field2(field.name, deserializeArrowType(field.type), field.nullable, deserializeArrowMetadata(field.metadata));
13229
+ }
13230
+ function serializeArrowType(arrowType) {
13231
+ switch (arrowType.constructor) {
13232
+ case Null:
13233
+ return "null";
13234
+ case Binary:
13235
+ return "binary";
13236
+ case Bool:
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
12564
13284
  };
12565
13285
  case Date_:
12566
13286
  const dateUnit = arrowType.unit;
@@ -12739,53 +13459,6 @@ return true;`);
12739
13459
  }
12740
13460
  }
12741
13461
 
12742
- // src/types.ts
12743
- var VECTOR_TYPES = function(VECTOR_TYPES2) {
12744
- VECTOR_TYPES2[VECTOR_TYPES2["FLOAT"] = 0] = "FLOAT";
12745
- VECTOR_TYPES2[VECTOR_TYPES2["DATE"] = 1] = "DATE";
12746
- return VECTOR_TYPES2;
12747
- }({});
12748
-
12749
- // src/lib/encode-arrow.ts
12750
- function encodeArrowSync(data) {
12751
- const vectors = {};
12752
- for (const arrayData of data) {
12753
- const arrayVector = createVector(arrayData.array, arrayData.type);
12754
- vectors[arrayData.name] = arrayVector;
12755
- }
12756
- const table = new Table(vectors);
12757
- const arrowBuffer = tableToIPC(table);
12758
- return arrowBuffer;
12759
- }
12760
- function createVector(array, type) {
12761
- switch (type) {
12762
- case VECTOR_TYPES.DATE:
12763
- return vectorFromArray(array);
12764
- case VECTOR_TYPES.FLOAT:
12765
- default:
12766
- return vectorFromArray(array);
12767
- }
12768
- }
12769
-
12770
- // src/arrow-writer.ts
12771
- var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
12772
- var ArrowWriter = {
12773
- name: "Apache Arrow",
12774
- id: "arrow",
12775
- module: "arrow",
12776
- version: VERSION2,
12777
- extensions: ["arrow", "feather"],
12778
- mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
12779
- binary: true,
12780
- options: {},
12781
- encode: async function encodeArrow(data, options) {
12782
- return encodeArrowSync(data);
12783
- },
12784
- encodeSync(data, options) {
12785
- return encodeArrowSync(data);
12786
- }
12787
- };
12788
-
12789
13462
  // src/geoarrow/get-arrow-bounds.ts
12790
13463
  function updateBoundsFromGeoArrowSamples(flatCoords, nDim, bounds, sampleSize = 100) {
12791
13464
  const numberOfFeatures = flatCoords.length / nDim;
@@ -12827,13 +13500,13 @@ return true;`);
12827
13500
  size: 1
12828
13501
  }
12829
13502
  };
12830
- function getBinaryGeometriesFromArrow(geoColumn, geoEncoding) {
13503
+ function getBinaryGeometriesFromArrow(geoColumn, geoEncoding, options) {
12831
13504
  const featureTypes = {
12832
13505
  polygon: geoEncoding === "geoarrow.multipolygon" || geoEncoding === "geoarrow.polygon",
12833
13506
  point: geoEncoding === "geoarrow.multipoint" || geoEncoding === "geoarrow.point",
12834
13507
  line: geoEncoding === "geoarrow.multilinestring" || geoEncoding === "geoarrow.linestring"
12835
13508
  };
12836
- const chunks = geoColumn.data;
13509
+ const chunks = options?.chunkIndex ? [geoColumn.data[options?.chunkIndex]] : geoColumn.data;
12837
13510
  let bounds = [Infinity, Infinity, -Infinity, -Infinity];
12838
13511
  let globalFeatureIdOffset = 0;
12839
13512
  const binaryGeometries = [];
@@ -12842,7 +13515,8 @@ return true;`);
12842
13515
  featureIds,
12843
13516
  flatCoordinateArray,
12844
13517
  nDim,
12845
- geomOffset
13518
+ geomOffset,
13519
+ triangles
12846
13520
  } = getBinaryGeometriesFromChunk(chunk, geoEncoding);
12847
13521
  const globalFeatureIds = new Uint32Array(featureIds.length);
12848
13522
  for (let i = 0; i < featureIds.length; i++) {
@@ -12893,7 +13567,13 @@ return true;`);
12893
13567
  primitivePolygonIndices: {
12894
13568
  value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
12895
13569
  size: 1
12896
- }
13570
+ },
13571
+ ...triangles ? {
13572
+ triangles: {
13573
+ value: triangles,
13574
+ size: 1
13575
+ }
13576
+ } : {}
12897
13577
  }
12898
13578
  });
12899
13579
  bounds = updateBoundsFromGeoArrowSamples(flatCoordinateArray, nDim, bounds);
@@ -12901,9 +13581,61 @@ return true;`);
12901
13581
  return {
12902
13582
  binaryGeometries,
12903
13583
  bounds,
12904
- featureTypes
13584
+ featureTypes,
13585
+ ...options?.meanCenter ? {
13586
+ meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries)
13587
+ } : {}
12905
13588
  };
12906
13589
  }
13590
+ function getMeanCentersFromBinaryGeometries(binaryGeometries) {
13591
+ const globalMeanCenters = [];
13592
+ binaryGeometries.forEach((binaryGeometry) => {
13593
+ let binaryGeometryType = null;
13594
+ if (binaryGeometry.points && binaryGeometry.points.positions.value.length > 0) {
13595
+ binaryGeometryType = "points";
13596
+ } else if (binaryGeometry.lines && binaryGeometry.lines.positions.value.length > 0) {
13597
+ binaryGeometryType = "lines";
13598
+ } else if (binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0) {
13599
+ binaryGeometryType = "polygons";
13600
+ }
13601
+ const binaryContent = binaryGeometryType ? binaryGeometry[binaryGeometryType] : null;
13602
+ if (binaryContent && binaryGeometryType !== null) {
13603
+ const featureIds = binaryContent.featureIds.value;
13604
+ const flatCoordinateArray = binaryContent.positions.value;
13605
+ const nDim = binaryContent.positions.size;
13606
+ const primitivePolygonIndices = binaryContent.primitivePolygonIndices?.value;
13607
+ const meanCenters = getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, binaryGeometryType, primitivePolygonIndices);
13608
+ meanCenters.forEach((center) => {
13609
+ globalMeanCenters.push(center);
13610
+ });
13611
+ }
13612
+ });
13613
+ return globalMeanCenters;
13614
+ }
13615
+ function getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, geometryType, primitivePolygonIndices) {
13616
+ const meanCenters = [];
13617
+ const vertexCount = flatCoordinateArray.length;
13618
+ let vertexIndex = 0;
13619
+ while (vertexIndex < vertexCount) {
13620
+ const featureId = featureIds[vertexIndex / nDim];
13621
+ const center = [0, 0];
13622
+ let vertexCountInFeature = 0;
13623
+ while (vertexIndex < vertexCount && featureIds[vertexIndex / nDim] === featureId) {
13624
+ if (geometryType === "polygons" && primitivePolygonIndices && primitivePolygonIndices.indexOf(vertexIndex / nDim) >= 0) {
13625
+ vertexIndex += nDim;
13626
+ } else {
13627
+ center[0] += flatCoordinateArray[vertexIndex];
13628
+ center[1] += flatCoordinateArray[vertexIndex + 1];
13629
+ vertexIndex += nDim;
13630
+ vertexCountInFeature++;
13631
+ }
13632
+ }
13633
+ center[0] /= vertexCountInFeature;
13634
+ center[1] /= vertexCountInFeature;
13635
+ meanCenters.push(center);
13636
+ }
13637
+ return meanCenters;
13638
+ }
12907
13639
  function getBinaryGeometriesFromChunk(chunk, geoEncoding) {
12908
13640
  switch (geoEncoding) {
12909
13641
  case "geoarrow.point":
@@ -12919,6 +13651,31 @@ return true;`);
12919
13651
  throw Error("invalid geoarrow encoding");
12920
13652
  }
12921
13653
  }
13654
+ function getTriangleIndices(polygonIndices, primitivePolygonIndices, flatCoordinateArray, nDim) {
13655
+ let primitiveIndex = 0;
13656
+ const triangles = [];
13657
+ for (let i = 0; i < polygonIndices.length - 1; i++) {
13658
+ const startIdx = polygonIndices[i];
13659
+ const endIdx = polygonIndices[i + 1];
13660
+ const slicedFlatCoords = flatCoordinateArray.subarray(startIdx * nDim, endIdx * nDim);
13661
+ const holeIndices = [];
13662
+ while (primitivePolygonIndices[primitiveIndex] < endIdx) {
13663
+ if (primitivePolygonIndices[primitiveIndex] > startIdx) {
13664
+ holeIndices.push(primitivePolygonIndices[primitiveIndex] - startIdx);
13665
+ }
13666
+ primitiveIndex++;
13667
+ }
13668
+ const triangleIndices = earcut(slicedFlatCoords, holeIndices.length > 0 ? holeIndices : void 0, nDim);
13669
+ for (let j = 0; j < triangleIndices.length; j++) {
13670
+ triangles.push(triangleIndices[j] + startIdx);
13671
+ }
13672
+ }
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
+ }
12922
13679
  function getBinaryPolygonsFromChunk(chunk, geoEncoding) {
12923
13680
  const isMultiPolygon = geoEncoding === "geoarrow.multipolygon";
12924
13681
  const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
@@ -12943,12 +13700,14 @@ return true;`);
12943
13700
  featureIds[j] = i;
12944
13701
  }
12945
13702
  }
13703
+ const triangles = getTriangleIndices(geometryIndicies, geomOffset, flatCoordinateArray, nDim);
12946
13704
  return {
12947
13705
  featureIds,
12948
13706
  flatCoordinateArray,
12949
13707
  nDim,
12950
13708
  geomOffset,
12951
- geometryIndicies
13709
+ geometryIndicies,
13710
+ triangles
12952
13711
  };
12953
13712
  }
12954
13713
  function getBinaryLinesFromChunk(chunk, geoEncoding) {
@@ -12962,11 +13721,22 @@ return true;`);
12962
13721
  const geometryIndicies = new Uint16Array(0);
12963
13722
  const numOfVertices = flatCoordinateArray.length / nDim;
12964
13723
  const featureIds = new Uint32Array(numOfVertices);
12965
- for (let i = 0; i < chunk.length; i++) {
12966
- const startIdx = geomOffset[i];
12967
- const endIdx = geomOffset[i + 1];
12968
- for (let j = startIdx; j < endIdx; j++) {
12969
- featureIds[j] = i;
13724
+ if (isMultiLineString) {
13725
+ const partData = chunk.valueOffsets;
13726
+ for (let i = 0; i < partData.length - 1; i++) {
13727
+ const startIdx = geomOffset[partData[i]];
13728
+ const endIdx = geomOffset[partData[i + 1]];
13729
+ for (let j = startIdx; j < endIdx; j++) {
13730
+ featureIds[j] = i;
13731
+ }
13732
+ }
13733
+ } else {
13734
+ for (let i = 0; i < chunk.length; i++) {
13735
+ const startIdx = geomOffset[i];
13736
+ const endIdx = geomOffset[i + 1];
13737
+ for (let j = startIdx; j < endIdx; j++) {
13738
+ featureIds[j] = i;
13739
+ }
12970
13740
  }
12971
13741
  }
12972
13742
  return {
@@ -12987,8 +13757,19 @@ return true;`);
12987
13757
  const geomOffset = new Int32Array(0);
12988
13758
  const numOfVertices = flatCoordinateArray.length / nDim;
12989
13759
  const featureIds = new Uint32Array(numOfVertices);
12990
- for (let i = 0; i < chunk.length; i++) {
12991
- featureIds[i] = i;
13760
+ if (isMultiPoint) {
13761
+ const partData = chunk.valueOffsets;
13762
+ for (let i = 0; i < partData.length - 1; i++) {
13763
+ const startIdx = partData[i];
13764
+ const endIdx = partData[i + 1];
13765
+ for (let j = startIdx; j < endIdx; j++) {
13766
+ featureIds[j] = i;
13767
+ }
13768
+ }
13769
+ } else {
13770
+ for (let i = 0; i < chunk.length; i++) {
13771
+ featureIds[i] = i;
13772
+ }
12992
13773
  }
12993
13774
  return {
12994
13775
  featureIds,
@@ -13026,6 +13807,10 @@ return true;`);
13026
13807
  case "geoarrow.linestring":
13027
13808
  geometry = arrowLineStringToFeature(data);
13028
13809
  break;
13810
+ case "geoarrow.wkb":
13811
+ throw Error(`GeoArrow encoding not supported ${encoding}`);
13812
+ case "geoarrow.wkt":
13813
+ throw Error(`GeoArrow encoding not supported ${encoding}`);
13029
13814
  default: {
13030
13815
  throw Error(`GeoArrow encoding not supported ${encoding}`);
13031
13816
  }
@@ -13136,14 +13921,571 @@ return true;`);
13136
13921
  return geometry;
13137
13922
  }
13138
13923
 
13924
+ // ../worker-utils/src/lib/env-utils/version.ts
13925
+ var NPM_TAG = "latest";
13926
+ function getVersion() {
13927
+ if (!globalThis._loadersgl_?.version) {
13928
+ globalThis._loadersgl_ = globalThis._loadersgl_ || {};
13929
+ if (typeof __VERSION__ === "undefined") {
13930
+ console.warn("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
13931
+ globalThis._loadersgl_.version = NPM_TAG;
13932
+ } else {
13933
+ globalThis._loadersgl_.version = __VERSION__;
13934
+ }
13935
+ }
13936
+ return globalThis._loadersgl_.version;
13937
+ }
13938
+ var VERSION3 = getVersion();
13939
+
13940
+ // ../worker-utils/src/lib/env-utils/assert.ts
13941
+ function assert(condition, message) {
13942
+ if (!condition) {
13943
+ throw new Error(message || "loaders.gl assertion failed.");
13944
+ }
13945
+ }
13946
+
13947
+ // ../worker-utils/src/lib/env-utils/globals.ts
13948
+ var globals = {
13949
+ self: typeof self !== "undefined" && self,
13950
+ window: typeof window !== "undefined" && window,
13951
+ global: typeof global !== "undefined" && global,
13952
+ document: typeof document !== "undefined" && document
13953
+ };
13954
+ var self_ = globals.self || globals.window || globals.global || {};
13955
+ var window_ = globals.window || globals.self || globals.global || {};
13956
+ var global_ = globals.global || globals.self || globals.window || {};
13957
+ var document_ = globals.document || {};
13958
+ var isBrowser = typeof process !== "object" || String(process) !== "[object process]" || process.browser;
13959
+ var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
13960
+ var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
13961
+ var nodeVersion = matches && parseFloat(matches[1]) || 0;
13962
+
13963
+ // ../worker-utils/src/lib/worker-farm/worker-job.ts
13964
+ var WorkerJob = class {
13965
+ isRunning = true;
13966
+ _resolve = () => {
13967
+ };
13968
+ _reject = () => {
13969
+ };
13970
+ constructor(jobName, workerThread) {
13971
+ this.name = jobName;
13972
+ this.workerThread = workerThread;
13973
+ this.result = new Promise((resolve, reject) => {
13974
+ this._resolve = resolve;
13975
+ this._reject = reject;
13976
+ });
13977
+ }
13978
+ postMessage(type, payload) {
13979
+ this.workerThread.postMessage({
13980
+ source: "loaders.gl",
13981
+ type,
13982
+ payload
13983
+ });
13984
+ }
13985
+ done(value) {
13986
+ assert(this.isRunning);
13987
+ this.isRunning = false;
13988
+ this._resolve(value);
13989
+ }
13990
+ error(error) {
13991
+ assert(this.isRunning);
13992
+ this.isRunning = false;
13993
+ this._reject(error);
13994
+ }
13995
+ };
13996
+
13997
+ // ../worker-utils/src/lib/node/worker_threads-browser.ts
13998
+ var NodeWorker = class {
13999
+ terminate() {
14000
+ }
14001
+ };
14002
+
14003
+ // ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
14004
+ var workerURLCache = /* @__PURE__ */ new Map();
14005
+ function getLoadableWorkerURL(props) {
14006
+ assert(props.source && !props.url || !props.source && props.url);
14007
+ let workerURL = workerURLCache.get(props.source || props.url);
14008
+ if (!workerURL) {
14009
+ if (props.url) {
14010
+ workerURL = getLoadableWorkerURLFromURL(props.url);
14011
+ workerURLCache.set(props.url, workerURL);
14012
+ }
14013
+ if (props.source) {
14014
+ workerURL = getLoadableWorkerURLFromSource(props.source);
14015
+ workerURLCache.set(props.source, workerURL);
14016
+ }
14017
+ }
14018
+ assert(workerURL);
14019
+ return workerURL;
14020
+ }
14021
+ function getLoadableWorkerURLFromURL(url) {
14022
+ if (!url.startsWith("http")) {
14023
+ return url;
14024
+ }
14025
+ const workerSource = buildScriptSource(url);
14026
+ return getLoadableWorkerURLFromSource(workerSource);
14027
+ }
14028
+ function getLoadableWorkerURLFromSource(workerSource) {
14029
+ const blob = new Blob([workerSource], {
14030
+ type: "application/javascript"
14031
+ });
14032
+ return URL.createObjectURL(blob);
14033
+ }
14034
+ function buildScriptSource(workerUrl) {
14035
+ return `try {
14036
+ importScripts('${workerUrl}');
14037
+ } catch (error) {
14038
+ console.error(error);
14039
+ throw error;
14040
+ }`;
14041
+ }
14042
+
14043
+ // ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
14044
+ function getTransferList(object, recursive = true, transfers) {
14045
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
14046
+ if (!object) {
14047
+ } else if (isTransferable(object)) {
14048
+ transfersSet.add(object);
14049
+ } else if (isTransferable(object.buffer)) {
14050
+ transfersSet.add(object.buffer);
14051
+ } else if (ArrayBuffer.isView(object)) {
14052
+ } else if (recursive && typeof object === "object") {
14053
+ for (const key in object) {
14054
+ getTransferList(object[key], recursive, transfersSet);
14055
+ }
14056
+ }
14057
+ return transfers === void 0 ? Array.from(transfersSet) : [];
14058
+ }
14059
+ function isTransferable(object) {
14060
+ if (!object) {
14061
+ return false;
14062
+ }
14063
+ if (object instanceof ArrayBuffer) {
14064
+ return true;
14065
+ }
14066
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
14067
+ return true;
14068
+ }
14069
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
14070
+ return true;
14071
+ }
14072
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
14073
+ return true;
14074
+ }
14075
+ return false;
14076
+ }
14077
+ function getTransferListForWriter(object) {
14078
+ if (object === null) {
14079
+ return {};
14080
+ }
14081
+ const clone = Object.assign({}, object);
14082
+ Object.keys(clone).forEach((key) => {
14083
+ if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
14084
+ clone[key] = getTransferListForWriter(object[key]);
14085
+ } else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
14086
+ clone[key] = {};
14087
+ } else {
14088
+ clone[key] = object[key];
14089
+ }
14090
+ });
14091
+ return clone;
14092
+ }
14093
+
14094
+ // ../worker-utils/src/lib/worker-farm/worker-thread.ts
14095
+ var NOOP = () => {
14096
+ };
14097
+ var WorkerThread = class {
14098
+ terminated = false;
14099
+ _loadableURL = "";
14100
+ static isSupported() {
14101
+ return typeof Worker !== "undefined" && isBrowser || typeof NodeWorker !== "undefined" && !isBrowser;
14102
+ }
14103
+ constructor(props) {
14104
+ const {
14105
+ name,
14106
+ source,
14107
+ url
14108
+ } = props;
14109
+ assert(source || url);
14110
+ this.name = name;
14111
+ this.source = source;
14112
+ this.url = url;
14113
+ this.onMessage = NOOP;
14114
+ this.onError = (error) => console.log(error);
14115
+ this.worker = isBrowser ? this._createBrowserWorker() : this._createNodeWorker();
14116
+ }
14117
+ destroy() {
14118
+ this.onMessage = NOOP;
14119
+ this.onError = NOOP;
14120
+ this.worker.terminate();
14121
+ this.terminated = true;
14122
+ }
14123
+ get isRunning() {
14124
+ return Boolean(this.onMessage);
14125
+ }
14126
+ postMessage(data, transferList) {
14127
+ transferList = transferList || getTransferList(data);
14128
+ this.worker.postMessage(data, transferList);
14129
+ }
14130
+ _getErrorFromErrorEvent(event) {
14131
+ let message = "Failed to load ";
14132
+ message += `worker ${this.name} from ${this.url}. `;
14133
+ if (event.message) {
14134
+ message += `${event.message} in `;
14135
+ }
14136
+ if (event.lineno) {
14137
+ message += `:${event.lineno}:${event.colno}`;
14138
+ }
14139
+ return new Error(message);
14140
+ }
14141
+ _createBrowserWorker() {
14142
+ this._loadableURL = getLoadableWorkerURL({
14143
+ source: this.source,
14144
+ url: this.url
14145
+ });
14146
+ const worker = new Worker(this._loadableURL, {
14147
+ name: this.name
14148
+ });
14149
+ worker.onmessage = (event) => {
14150
+ if (!event.data) {
14151
+ this.onError(new Error("No data received"));
14152
+ } else {
14153
+ this.onMessage(event.data);
14154
+ }
14155
+ };
14156
+ worker.onerror = (error) => {
14157
+ this.onError(this._getErrorFromErrorEvent(error));
14158
+ this.terminated = true;
14159
+ };
14160
+ worker.onmessageerror = (event) => console.error(event);
14161
+ return worker;
14162
+ }
14163
+ _createNodeWorker() {
14164
+ let worker;
14165
+ if (this.url) {
14166
+ const absolute = this.url.includes(":/") || this.url.startsWith("/");
14167
+ const url = absolute ? this.url : `./${this.url}`;
14168
+ worker = new NodeWorker(url, {
14169
+ eval: false
14170
+ });
14171
+ } else if (this.source) {
14172
+ worker = new NodeWorker(this.source, {
14173
+ eval: true
14174
+ });
14175
+ } else {
14176
+ throw new Error("no worker");
14177
+ }
14178
+ worker.on("message", (data) => {
14179
+ this.onMessage(data);
14180
+ });
14181
+ worker.on("error", (error) => {
14182
+ this.onError(error);
14183
+ });
14184
+ worker.on("exit", (code) => {
14185
+ });
14186
+ return worker;
14187
+ }
14188
+ };
14189
+
14190
+ // ../worker-utils/src/lib/worker-farm/worker-pool.ts
14191
+ var WorkerPool = class {
14192
+ name = "unnamed";
14193
+ maxConcurrency = 1;
14194
+ maxMobileConcurrency = 1;
14195
+ onDebug = () => {
14196
+ };
14197
+ reuseWorkers = true;
14198
+ props = {};
14199
+ jobQueue = [];
14200
+ idleQueue = [];
14201
+ count = 0;
14202
+ isDestroyed = false;
14203
+ static isSupported() {
14204
+ return WorkerThread.isSupported();
14205
+ }
14206
+ constructor(props) {
14207
+ this.source = props.source;
14208
+ this.url = props.url;
14209
+ this.setProps(props);
14210
+ }
14211
+ destroy() {
14212
+ this.idleQueue.forEach((worker) => worker.destroy());
14213
+ this.isDestroyed = true;
14214
+ }
14215
+ setProps(props) {
14216
+ this.props = {
14217
+ ...this.props,
14218
+ ...props
14219
+ };
14220
+ if (props.name !== void 0) {
14221
+ this.name = props.name;
14222
+ }
14223
+ if (props.maxConcurrency !== void 0) {
14224
+ this.maxConcurrency = props.maxConcurrency;
14225
+ }
14226
+ if (props.maxMobileConcurrency !== void 0) {
14227
+ this.maxMobileConcurrency = props.maxMobileConcurrency;
14228
+ }
14229
+ if (props.reuseWorkers !== void 0) {
14230
+ this.reuseWorkers = props.reuseWorkers;
14231
+ }
14232
+ if (props.onDebug !== void 0) {
14233
+ this.onDebug = props.onDebug;
14234
+ }
14235
+ }
14236
+ async startJob(name, onMessage2 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
14237
+ const startPromise = new Promise((onStart) => {
14238
+ this.jobQueue.push({
14239
+ name,
14240
+ onMessage: onMessage2,
14241
+ onError,
14242
+ onStart
14243
+ });
14244
+ return this;
14245
+ });
14246
+ this._startQueuedJob();
14247
+ return await startPromise;
14248
+ }
14249
+ async _startQueuedJob() {
14250
+ if (!this.jobQueue.length) {
14251
+ return;
14252
+ }
14253
+ const workerThread = this._getAvailableWorker();
14254
+ if (!workerThread) {
14255
+ return;
14256
+ }
14257
+ const queuedJob = this.jobQueue.shift();
14258
+ if (queuedJob) {
14259
+ this.onDebug({
14260
+ message: "Starting job",
14261
+ name: queuedJob.name,
14262
+ workerThread,
14263
+ backlog: this.jobQueue.length
14264
+ });
14265
+ const job = new WorkerJob(queuedJob.name, workerThread);
14266
+ workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);
14267
+ workerThread.onError = (error) => queuedJob.onError(job, error);
14268
+ queuedJob.onStart(job);
14269
+ try {
14270
+ await job.result;
14271
+ } catch (error) {
14272
+ console.error(`Worker exception: ${error}`);
14273
+ } finally {
14274
+ this.returnWorkerToQueue(workerThread);
14275
+ }
14276
+ }
14277
+ }
14278
+ returnWorkerToQueue(worker) {
14279
+ const shouldDestroyWorker = !isBrowser || this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency();
14280
+ if (shouldDestroyWorker) {
14281
+ worker.destroy();
14282
+ this.count--;
14283
+ } else {
14284
+ this.idleQueue.push(worker);
14285
+ }
14286
+ if (!this.isDestroyed) {
14287
+ this._startQueuedJob();
14288
+ }
14289
+ }
14290
+ _getAvailableWorker() {
14291
+ if (this.idleQueue.length > 0) {
14292
+ return this.idleQueue.shift() || null;
14293
+ }
14294
+ if (this.count < this._getMaxConcurrency()) {
14295
+ this.count++;
14296
+ const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
14297
+ return new WorkerThread({
14298
+ name,
14299
+ source: this.source,
14300
+ url: this.url
14301
+ });
14302
+ }
14303
+ return null;
14304
+ }
14305
+ _getMaxConcurrency() {
14306
+ return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
14307
+ }
14308
+ };
14309
+
14310
+ // ../worker-utils/src/lib/worker-farm/worker-farm.ts
14311
+ var DEFAULT_PROPS = {
14312
+ maxConcurrency: 3,
14313
+ maxMobileConcurrency: 1,
14314
+ reuseWorkers: true,
14315
+ onDebug: () => {
14316
+ }
14317
+ };
14318
+ var WorkerFarm = class {
14319
+ workerPools = /* @__PURE__ */ new Map();
14320
+ static isSupported() {
14321
+ return WorkerThread.isSupported();
14322
+ }
14323
+ static getWorkerFarm(props = {}) {
14324
+ WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({});
14325
+ WorkerFarm._workerFarm.setProps(props);
14326
+ return WorkerFarm._workerFarm;
14327
+ }
14328
+ constructor(props) {
14329
+ this.props = {
14330
+ ...DEFAULT_PROPS
14331
+ };
14332
+ this.setProps(props);
14333
+ this.workerPools = /* @__PURE__ */ new Map();
14334
+ }
14335
+ destroy() {
14336
+ for (const workerPool of this.workerPools.values()) {
14337
+ workerPool.destroy();
14338
+ }
14339
+ this.workerPools = /* @__PURE__ */ new Map();
14340
+ }
14341
+ setProps(props) {
14342
+ this.props = {
14343
+ ...this.props,
14344
+ ...props
14345
+ };
14346
+ for (const workerPool of this.workerPools.values()) {
14347
+ workerPool.setProps(this._getWorkerPoolProps());
14348
+ }
14349
+ }
14350
+ getWorkerPool(options) {
14351
+ const {
14352
+ name,
14353
+ source,
14354
+ url
14355
+ } = options;
14356
+ let workerPool = this.workerPools.get(name);
14357
+ if (!workerPool) {
14358
+ workerPool = new WorkerPool({
14359
+ name,
14360
+ source,
14361
+ url
14362
+ });
14363
+ workerPool.setProps(this._getWorkerPoolProps());
14364
+ this.workerPools.set(name, workerPool);
14365
+ }
14366
+ return workerPool;
14367
+ }
14368
+ _getWorkerPoolProps() {
14369
+ return {
14370
+ maxConcurrency: this.props.maxConcurrency,
14371
+ maxMobileConcurrency: this.props.maxMobileConcurrency,
14372
+ reuseWorkers: this.props.reuseWorkers,
14373
+ onDebug: this.props.onDebug
14374
+ };
14375
+ }
14376
+ };
14377
+
14378
+ // ../worker-utils/src/lib/worker-api/get-worker-url.ts
14379
+ function getWorkerName(worker) {
14380
+ const warning = worker.version !== VERSION3 ? ` (worker-utils@${VERSION3})` : "";
14381
+ return `${worker.name}@${worker.version}${warning}`;
14382
+ }
14383
+ function getWorkerURL(worker, options = {}) {
14384
+ const workerOptions = options[worker.id] || {};
14385
+ const workerFile = isBrowser ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`;
14386
+ let url = workerOptions.workerUrl;
14387
+ if (!url && worker.id === "compression") {
14388
+ url = options.workerUrl;
14389
+ }
14390
+ if (options._workerType === "test") {
14391
+ if (isBrowser) {
14392
+ url = `modules/${worker.module}/dist/${workerFile}`;
14393
+ } else {
14394
+ url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`;
14395
+ }
14396
+ }
14397
+ if (!url) {
14398
+ let version = worker.version;
14399
+ if (version === "latest") {
14400
+ version = NPM_TAG;
14401
+ }
14402
+ const versionTag = version ? `@${version}` : "";
14403
+ url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
14404
+ }
14405
+ assert(url);
14406
+ return url;
14407
+ }
14408
+
14409
+ // ../worker-utils/src/lib/worker-api/process-on-worker.ts
14410
+ async function processOnWorker(worker, data, options = {}, context = {}) {
14411
+ const name = getWorkerName(worker);
14412
+ const workerFarm = WorkerFarm.getWorkerFarm(options);
14413
+ const {
14414
+ source
14415
+ } = options;
14416
+ const workerPoolProps = {
14417
+ name,
14418
+ source
14419
+ };
14420
+ if (!source) {
14421
+ workerPoolProps.url = getWorkerURL(worker, options);
14422
+ }
14423
+ const workerPool = workerFarm.getWorkerPool(workerPoolProps);
14424
+ const jobName = options.jobName || worker.name;
14425
+ const job = await workerPool.startJob(jobName, onMessage.bind(null, context));
14426
+ const transferableOptions = getTransferListForWriter(options);
14427
+ job.postMessage("process", {
14428
+ input: data,
14429
+ options: transferableOptions
14430
+ });
14431
+ const result = await job.result;
14432
+ return result.result;
14433
+ }
14434
+ async function onMessage(context, job, type, payload) {
14435
+ switch (type) {
14436
+ case "done":
14437
+ job.done(payload);
14438
+ break;
14439
+ case "error":
14440
+ job.error(new Error(payload.error));
14441
+ break;
14442
+ case "process":
14443
+ const {
14444
+ id,
14445
+ input,
14446
+ options
14447
+ } = payload;
14448
+ try {
14449
+ if (!context.process) {
14450
+ job.postMessage("error", {
14451
+ id,
14452
+ error: "Worker not set up to process on main thread"
14453
+ });
14454
+ return;
14455
+ }
14456
+ const result = await context.process(input, options);
14457
+ job.postMessage("done", {
14458
+ id,
14459
+ result
14460
+ });
14461
+ } catch (error) {
14462
+ const message = error instanceof Error ? error.message : "unknown error";
14463
+ job.postMessage("error", {
14464
+ id,
14465
+ error: message
14466
+ });
14467
+ }
14468
+ break;
14469
+ default:
14470
+ console.warn(`process-on-worker: unknown message ${type}`);
14471
+ }
14472
+ }
14473
+
14474
+ // src/triangulate-on-worker.ts
14475
+ var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
14476
+ var TriangulationWorker = {
14477
+ id: "triangulation",
14478
+ name: "Triangulate",
14479
+ module: "arrow",
14480
+ version: VERSION4,
14481
+ options: {}
14482
+ };
14483
+ function triangulateOnWorker(data, options = {}) {
14484
+ return processOnWorker(TriangulationWorker, data, options);
14485
+ }
14486
+
13139
14487
  // src/index.ts
13140
14488
  TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
13141
- var ArrowLoader2 = {
13142
- ...ArrowLoader,
13143
- parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options),
13144
- parseSync: parseArrowSync,
13145
- parseInBatches: parseArrowInBatches
13146
- };
13147
14489
  return __toCommonJS(src_exports);
13148
14490
  })();
13149
14491
  return __exports__;