@loaders.gl/arrow 4.0.3 → 4.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) 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 +272 -537
  6. package/dist/dist.dev.js +2399 -269
  7. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +33 -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 +146 -17
  10. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
  11. package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts +13 -0
  12. package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts.map +1 -0
  13. package/dist/geoarrow/{convert-geoarrow-to-geojson.js → convert-geoarrow-to-geojson-geometry.js} +36 -25
  14. package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.js.map +1 -0
  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 +23 -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 +481 -255
  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 +28 -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 +15 -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 +39 -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 +19 -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 +887 -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 +26 -0
  77. package/dist/workers/triangulation-worker.js.map +1 -0
  78. package/package.json +20 -12
  79. package/src/arrow-loader.ts +25 -3
  80. package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +247 -23
  81. package/src/geoarrow/{convert-geoarrow-to-geojson.ts → convert-geoarrow-to-geojson-geometry.ts} +58 -44
  82. package/src/geoarrow-loader.ts +51 -0
  83. package/src/geoarrow-writer.ts +41 -0
  84. package/src/index.ts +31 -37
  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 +43 -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 +30 -0
  93. package/src/tables/convert-arrow-to-geojson-table.ts +65 -0
  94. package/src/tables/convert-columnar-to-row-table.ts +30 -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/geoarrow/convert-geoarrow-to-geojson.d.ts +0 -19
  100. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts.map +0 -1
  101. package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +0 -1
  102. package/dist/lib/parse-arrow-in-batches.d.ts.map +0 -1
  103. package/dist/lib/parse-arrow-in-batches.js.map +0 -1
  104. package/dist/lib/parse-arrow-sync.d.ts +0 -5
  105. package/dist/lib/parse-arrow-sync.d.ts.map +0 -1
  106. package/dist/lib/parse-arrow-sync.js +0 -21
  107. package/dist/lib/parse-arrow-sync.js.map +0 -1
  108. package/dist/tables/convert-arrow-to-table.d.ts +0 -21
  109. package/dist/tables/convert-arrow-to-table.d.ts.map +0 -1
  110. package/dist/tables/convert-arrow-to-table.js +0 -37
  111. package/dist/tables/convert-arrow-to-table.js.map +0 -1
  112. package/src/lib/parse-arrow-sync.ts +0 -35
  113. package/src/tables/convert-arrow-to-table.ts +0 -68
  114. /package/dist/{lib → parsers}/parse-arrow-in-batches.js +0 -0
package/dist/index.cjs CHANGED
@@ -30,120 +30,38 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- ArrowLoader: () => ArrowLoader2,
34
- ArrowWorkerLoader: () => ArrowLoader,
33
+ ArrowLoader: () => ArrowLoader,
34
+ ArrowWorkerLoader: () => ArrowWorkerLoader,
35
35
  ArrowWriter: () => ArrowWriter,
36
36
  BINARY_GEOMETRY_TEMPLATE: () => BINARY_GEOMETRY_TEMPLATE,
37
+ GeoArrowLoader: () => GeoArrowLoader,
38
+ GeoArrowWorkerLoader: () => GeoArrowWorkerLoader,
39
+ TriangulationWorker: () => TriangulationWorker,
37
40
  VECTOR_TYPES: () => VECTOR_TYPES,
41
+ convertArrowToGeoJSONTable: () => convertArrowToGeoJSONTable,
38
42
  deserializeArrowField: () => deserializeArrowField,
39
43
  deserializeArrowMetadata: () => deserializeArrowMetadata,
40
44
  deserializeArrowSchema: () => deserializeArrowSchema,
41
45
  deserializeArrowType: () => deserializeArrowType,
42
46
  getArrowType: () => getArrowType,
43
47
  getBinaryGeometriesFromArrow: () => getBinaryGeometriesFromArrow,
44
- parseGeometryFromArrow: () => parseGeometryFromArrow,
48
+ getMeanCentersFromBinaryGeometries: () => getMeanCentersFromBinaryGeometries,
49
+ getTriangleIndices: () => getTriangleIndices,
50
+ parseGeometryFromArrow: () => parseGeometryFromArrow2,
45
51
  serializeArrowField: () => serializeArrowField,
46
52
  serializeArrowMetadata: () => serializeArrowMetadata,
47
53
  serializeArrowSchema: () => serializeArrowSchema,
48
54
  serializeArrowType: () => serializeArrowType,
55
+ triangulateOnWorker: () => triangulateOnWorker,
49
56
  updateBoundsFromGeoArrowSamples: () => updateBoundsFromGeoArrowSamples
50
57
  });
51
58
  module.exports = __toCommonJS(src_exports);
52
59
  var import_schema3 = require("@loaders.gl/schema");
53
60
 
54
- // src/arrow-loader.ts
55
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
56
- var ArrowLoader = {
57
- name: "Apache Arrow",
58
- id: "arrow",
59
- module: "arrow",
60
- version: VERSION,
61
- // worker: true,
62
- category: "table",
63
- extensions: ["arrow", "feather"],
64
- mimeTypes: [
65
- "application/vnd.apache.arrow.file",
66
- "application/vnd.apache.arrow.stream",
67
- "application/octet-stream"
68
- ],
69
- binary: true,
70
- tests: ["ARROW"],
71
- options: {
72
- arrow: {
73
- shape: "columnar-table"
74
- }
75
- }
76
- };
77
-
78
- // src/lib/parse-arrow-sync.ts
61
+ // src/lib/arrow-table-batch.ts
79
62
  var import_schema = require("@loaders.gl/schema");
80
63
  var arrow = __toESM(require("apache-arrow"), 1);
81
-
82
- // src/tables/convert-arrow-to-table.ts
83
- function convertApacheArrowToArrowTable(arrowTable) {
84
- return {
85
- shape: "arrow-table",
86
- data: arrowTable
87
- };
88
- }
89
- function convertArrowToColumnarTable(table) {
90
- const arrowTable = table.data;
91
- const columnarTable = {};
92
- for (const field of arrowTable.schema.fields) {
93
- const arrowColumn = arrowTable.getChild(field.name);
94
- const values = arrowColumn == null ? void 0 : arrowColumn.toArray();
95
- columnarTable[field.name] = values;
96
- }
97
- return {
98
- shape: "columnar-table",
99
- data: columnarTable
100
- };
101
- }
102
-
103
- // src/lib/parse-arrow-sync.ts
104
- function parseArrowSync(arrayBuffer, options) {
105
- var _a;
106
- const apacheArrowTable = arrow.tableFromIPC([new Uint8Array(arrayBuffer)]);
107
- const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
108
- const shape = ((_a = options == null ? void 0 : options.arrow) == null ? void 0 : _a.shape) || "arrow-table";
109
- switch (shape) {
110
- case "arrow-table":
111
- return arrowTable;
112
- case "columnar-table":
113
- return convertArrowToColumnarTable(arrowTable);
114
- case "object-row-table":
115
- const columnarTable = convertArrowToColumnarTable(arrowTable);
116
- return (0, import_schema.convertTable)(columnarTable, "object-row-table");
117
- default:
118
- throw new Error(shape);
119
- }
120
- }
121
-
122
- // src/lib/parse-arrow-in-batches.ts
123
- var arrow2 = __toESM(require("apache-arrow"), 1);
124
- function parseArrowInBatches(asyncIterator) {
125
- async function* makeArrowAsyncIterator() {
126
- const readers = arrow2.RecordBatchReader.readAll(asyncIterator);
127
- for await (const reader of readers) {
128
- for await (const recordBatch of reader) {
129
- const arrowTabledBatch = {
130
- shape: "arrow-table",
131
- batchType: "data",
132
- data: new arrow2.Table([recordBatch]),
133
- length: recordBatch.data.length
134
- };
135
- yield arrowTabledBatch;
136
- }
137
- break;
138
- }
139
- }
140
- return makeArrowAsyncIterator();
141
- }
142
-
143
- // src/lib/arrow-table-batch.ts
144
- var import_schema2 = require("@loaders.gl/schema");
145
- var arrow3 = __toESM(require("apache-arrow"), 1);
146
- var ArrowTableBatchAggregator = class extends import_schema2.ColumnarTableBatchAggregator {
64
+ var ArrowTableBatchAggregator = class extends import_schema.ColumnarTableBatchAggregator {
147
65
  constructor(schema, options) {
148
66
  super(schema, options);
149
67
  this.arrowSchema = null;
@@ -153,17 +71,17 @@ var ArrowTableBatchAggregator = class extends import_schema2.ColumnarTableBatchA
153
71
  if (batch) {
154
72
  this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);
155
73
  const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);
156
- const recordBatch = new arrow3.RecordBatch(
74
+ const recordBatch = new arrow.RecordBatch(
157
75
  this.arrowSchema,
158
- arrow3.makeData({
159
- type: new arrow3.Struct(this.arrowSchema.fields),
76
+ arrow.makeData({
77
+ type: new arrow.Struct(this.arrowSchema.fields),
160
78
  children: arrowVectors.map(({ data }) => data[0])
161
79
  })
162
80
  );
163
81
  return {
164
82
  shape: "arrow-table",
165
83
  batchType: "data",
166
- data: new arrow3.Table([recordBatch]),
84
+ data: new arrow.Table([recordBatch]),
167
85
  length: batch.length
168
86
  };
169
87
  }
@@ -176,21 +94,21 @@ function getArrowSchema(schema) {
176
94
  const field = schema[key];
177
95
  if (field.type === Float32Array) {
178
96
  const metadata = /* @__PURE__ */ new Map();
179
- const arrowField = new arrow3.Field(field.name, new arrow3.Float32(), field.nullable, metadata);
97
+ const arrowField = new arrow.Field(field.name, new arrow.Float32(), field.nullable, metadata);
180
98
  arrowFields.push(arrowField);
181
99
  }
182
100
  }
183
101
  if (arrowFields.length === 0) {
184
102
  throw new Error("No arrow convertible fields");
185
103
  }
186
- return new arrow3.Schema(arrowFields);
104
+ return new arrow.Schema(arrowFields);
187
105
  }
188
106
  function getArrowVectors(arrowSchema, data) {
189
107
  const arrowVectors = [];
190
108
  for (const field of arrowSchema.fields) {
191
109
  const vector = data[field.name];
192
110
  if (vector instanceof Float32Array) {
193
- const arrowVector = arrow3.makeVector(vector);
111
+ const arrowVector = arrow.makeVector(vector);
194
112
  arrowVectors.push(arrowVector);
195
113
  }
196
114
  }
@@ -201,32 +119,59 @@ function getArrowVectors(arrowSchema, data) {
201
119
  }
202
120
 
203
121
  // src/schema/arrow-type-utils.ts
204
- var arrow4 = __toESM(require("apache-arrow"), 1);
122
+ var arrow2 = __toESM(require("apache-arrow"), 1);
205
123
  function getArrowType(array) {
206
124
  switch (array.constructor) {
207
125
  case Int8Array:
208
- return new arrow4.Int8();
126
+ return new arrow2.Int8();
209
127
  case Uint8Array:
210
- return new arrow4.Uint8();
128
+ return new arrow2.Uint8();
211
129
  case Int16Array:
212
- return new arrow4.Int16();
130
+ return new arrow2.Int16();
213
131
  case Uint16Array:
214
- return new arrow4.Uint16();
132
+ return new arrow2.Uint16();
215
133
  case Int32Array:
216
- return new arrow4.Int32();
134
+ return new arrow2.Int32();
217
135
  case Uint32Array:
218
- return new arrow4.Uint32();
136
+ return new arrow2.Uint32();
219
137
  case Float32Array:
220
- return new arrow4.Float32();
138
+ return new arrow2.Float32();
221
139
  case Float64Array:
222
- return new arrow4.Float64();
140
+ return new arrow2.Float64();
223
141
  default:
224
142
  throw new Error("array type not supported");
225
143
  }
226
144
  }
227
145
 
146
+ // src/types.ts
147
+ var VECTOR_TYPES = /* @__PURE__ */ ((VECTOR_TYPES2) => {
148
+ VECTOR_TYPES2[VECTOR_TYPES2["FLOAT"] = 0] = "FLOAT";
149
+ VECTOR_TYPES2[VECTOR_TYPES2["DATE"] = 1] = "DATE";
150
+ return VECTOR_TYPES2;
151
+ })(VECTOR_TYPES || {});
152
+
153
+ // src/parsers/parse-arrow-sync.ts
154
+ var import_schema2 = require("@loaders.gl/schema");
155
+ var arrow4 = __toESM(require("apache-arrow"), 1);
156
+
157
+ // src/tables/convert-arrow-to-columnar-table.ts
158
+ function convertArrowToColumnarTable(table) {
159
+ const arrowTable = table.data;
160
+ const columnarTable = {};
161
+ for (const field of arrowTable.schema.fields) {
162
+ const arrowColumn = arrowTable.getChild(field.name);
163
+ const values = arrowColumn == null ? void 0 : arrowColumn.toArray();
164
+ columnarTable[field.name] = values;
165
+ }
166
+ return {
167
+ shape: "columnar-table",
168
+ schema: table.schema,
169
+ data: columnarTable
170
+ };
171
+ }
172
+
228
173
  // src/schema/convert-arrow-schema.ts
229
- var arrow5 = __toESM(require("apache-arrow"), 1);
174
+ var arrow3 = __toESM(require("apache-arrow"), 1);
230
175
  function serializeArrowSchema(arrowSchema) {
231
176
  return {
232
177
  fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
@@ -234,7 +179,7 @@ function serializeArrowSchema(arrowSchema) {
234
179
  };
235
180
  }
236
181
  function deserializeArrowSchema(schema) {
237
- return new arrow5.Schema(
182
+ return new arrow3.Schema(
238
183
  schema.fields.map((field) => deserializeArrowField(field)),
239
184
  deserializeArrowMetadata(schema.metadata)
240
185
  );
@@ -254,7 +199,7 @@ function serializeArrowField(field) {
254
199
  };
255
200
  }
256
201
  function deserializeArrowField(field) {
257
- return new arrow5.Field(
202
+ return new arrow3.Field(
258
203
  field.name,
259
204
  deserializeArrowType(field.type),
260
205
  field.nullable,
@@ -263,52 +208,52 @@ function deserializeArrowField(field) {
263
208
  }
264
209
  function serializeArrowType(arrowType) {
265
210
  switch (arrowType.constructor) {
266
- case arrow5.Null:
211
+ case arrow3.Null:
267
212
  return "null";
268
- case arrow5.Binary:
213
+ case arrow3.Binary:
269
214
  return "binary";
270
- case arrow5.Bool:
215
+ case arrow3.Bool:
271
216
  return "bool";
272
- case arrow5.Int:
217
+ case arrow3.Int:
273
218
  const intType = arrowType;
274
219
  return `${intType.isSigned ? "u" : ""}int${intType.bitWidth}`;
275
- case arrow5.Int8:
220
+ case arrow3.Int8:
276
221
  return "int8";
277
- case arrow5.Int16:
222
+ case arrow3.Int16:
278
223
  return "int16";
279
- case arrow5.Int32:
224
+ case arrow3.Int32:
280
225
  return "int32";
281
- case arrow5.Int64:
226
+ case arrow3.Int64:
282
227
  return "int64";
283
- case arrow5.Uint8:
228
+ case arrow3.Uint8:
284
229
  return "uint8";
285
- case arrow5.Uint16:
230
+ case arrow3.Uint16:
286
231
  return "uint16";
287
- case arrow5.Uint32:
232
+ case arrow3.Uint32:
288
233
  return "uint32";
289
- case arrow5.Uint64:
234
+ case arrow3.Uint64:
290
235
  return "uint64";
291
- case arrow5.Float:
236
+ case arrow3.Float:
292
237
  const precision = arrowType.precision;
293
238
  switch (precision) {
294
- case arrow5.Precision.HALF:
239
+ case arrow3.Precision.HALF:
295
240
  return "float16";
296
- case arrow5.Precision.SINGLE:
241
+ case arrow3.Precision.SINGLE:
297
242
  return "float32";
298
- case arrow5.Precision.DOUBLE:
243
+ case arrow3.Precision.DOUBLE:
299
244
  return "float64";
300
245
  default:
301
246
  return "float16";
302
247
  }
303
- case arrow5.Float16:
248
+ case arrow3.Float16:
304
249
  return "float16";
305
- case arrow5.Float32:
250
+ case arrow3.Float32:
306
251
  return "float32";
307
- case arrow5.Float64:
252
+ case arrow3.Float64:
308
253
  return "float64";
309
- case arrow5.Utf8:
254
+ case arrow3.Utf8:
310
255
  return "utf8";
311
- case arrow5.Decimal:
256
+ case arrow3.Decimal:
312
257
  const decimal = arrowType;
313
258
  return {
314
259
  type: "decimal",
@@ -316,93 +261,93 @@ function serializeArrowType(arrowType) {
316
261
  precision: decimal.precision,
317
262
  scale: decimal.scale
318
263
  };
319
- case arrow5.Date_:
264
+ case arrow3.Date_:
320
265
  const dateUnit = arrowType.unit;
321
- return dateUnit === arrow5.DateUnit.DAY ? "date-day" : "date-millisecond";
322
- case arrow5.DateDay:
266
+ return dateUnit === arrow3.DateUnit.DAY ? "date-day" : "date-millisecond";
267
+ case arrow3.DateDay:
323
268
  return "date-day";
324
- case arrow5.DateMillisecond:
269
+ case arrow3.DateMillisecond:
325
270
  return "date-millisecond";
326
- case arrow5.Time:
271
+ case arrow3.Time:
327
272
  const timeUnit = arrowType.unit;
328
273
  switch (timeUnit) {
329
- case arrow5.TimeUnit.SECOND:
274
+ case arrow3.TimeUnit.SECOND:
330
275
  return "time-second";
331
- case arrow5.TimeUnit.MILLISECOND:
276
+ case arrow3.TimeUnit.MILLISECOND:
332
277
  return "time-millisecond";
333
- case arrow5.TimeUnit.MICROSECOND:
278
+ case arrow3.TimeUnit.MICROSECOND:
334
279
  return "time-microsecond";
335
- case arrow5.TimeUnit.NANOSECOND:
280
+ case arrow3.TimeUnit.NANOSECOND:
336
281
  return "time-nanosecond";
337
282
  default:
338
283
  return "time-second";
339
284
  }
340
- case arrow5.TimeMillisecond:
285
+ case arrow3.TimeMillisecond:
341
286
  return "time-millisecond";
342
- case arrow5.TimeSecond:
287
+ case arrow3.TimeSecond:
343
288
  return "time-second";
344
- case arrow5.TimeMicrosecond:
289
+ case arrow3.TimeMicrosecond:
345
290
  return "time-microsecond";
346
- case arrow5.TimeNanosecond:
291
+ case arrow3.TimeNanosecond:
347
292
  return "time-nanosecond";
348
- case arrow5.Timestamp:
293
+ case arrow3.Timestamp:
349
294
  const timeStampUnit = arrowType.unit;
350
295
  switch (timeStampUnit) {
351
- case arrow5.TimeUnit.SECOND:
296
+ case arrow3.TimeUnit.SECOND:
352
297
  return "timestamp-second";
353
- case arrow5.TimeUnit.MILLISECOND:
298
+ case arrow3.TimeUnit.MILLISECOND:
354
299
  return "timestamp-millisecond";
355
- case arrow5.TimeUnit.MICROSECOND:
300
+ case arrow3.TimeUnit.MICROSECOND:
356
301
  return "timestamp-microsecond";
357
- case arrow5.TimeUnit.NANOSECOND:
302
+ case arrow3.TimeUnit.NANOSECOND:
358
303
  return "timestamp-nanosecond";
359
304
  default:
360
305
  return "timestamp-second";
361
306
  }
362
- case arrow5.TimestampSecond:
307
+ case arrow3.TimestampSecond:
363
308
  return "timestamp-second";
364
- case arrow5.TimestampMillisecond:
309
+ case arrow3.TimestampMillisecond:
365
310
  return "timestamp-millisecond";
366
- case arrow5.TimestampMicrosecond:
311
+ case arrow3.TimestampMicrosecond:
367
312
  return "timestamp-microsecond";
368
- case arrow5.TimestampNanosecond:
313
+ case arrow3.TimestampNanosecond:
369
314
  return "timestamp-nanosecond";
370
- case arrow5.Interval:
315
+ case arrow3.Interval:
371
316
  const intervalUnit = arrowType.unit;
372
317
  switch (intervalUnit) {
373
- case arrow5.IntervalUnit.DAY_TIME:
318
+ case arrow3.IntervalUnit.DAY_TIME:
374
319
  return "interval-daytime";
375
- case arrow5.IntervalUnit.YEAR_MONTH:
320
+ case arrow3.IntervalUnit.YEAR_MONTH:
376
321
  return "interval-yearmonth";
377
322
  default:
378
323
  return "interval-daytime";
379
324
  }
380
- case arrow5.IntervalDayTime:
325
+ case arrow3.IntervalDayTime:
381
326
  return "interval-daytime";
382
- case arrow5.IntervalYearMonth:
327
+ case arrow3.IntervalYearMonth:
383
328
  return "interval-yearmonth";
384
- case arrow5.Map_:
329
+ case arrow3.Map_:
385
330
  const mapType = arrowType;
386
331
  return {
387
332
  type: "map",
388
333
  keysSorted: mapType.keysSorted,
389
334
  children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
390
335
  };
391
- case arrow5.List:
336
+ case arrow3.List:
392
337
  const listType = arrowType;
393
338
  const listField = listType.valueField;
394
339
  return {
395
340
  type: "list",
396
341
  children: [serializeArrowField(listField)]
397
342
  };
398
- case arrow5.FixedSizeList:
343
+ case arrow3.FixedSizeList:
399
344
  const fixedSizeList = arrowType;
400
345
  return {
401
346
  type: "fixed-size-list",
402
347
  listSize: fixedSizeList.listSize,
403
348
  children: [serializeArrowField(fixedSizeList.children[0])]
404
349
  };
405
- case arrow5.Struct:
350
+ case arrow3.Struct:
406
351
  const structType = arrowType;
407
352
  return {
408
353
  type: "struct",
@@ -416,89 +361,158 @@ function deserializeArrowType(dataType) {
416
361
  if (typeof dataType === "object") {
417
362
  switch (dataType.type) {
418
363
  case "decimal":
419
- return new arrow5.Decimal(dataType.precision, dataType.scale, dataType.bitWidth);
364
+ return new arrow3.Decimal(dataType.precision, dataType.scale, dataType.bitWidth);
420
365
  case "map":
421
366
  let children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
422
- return new arrow5.Map_(children, dataType.keysSorted);
367
+ return new arrow3.Map_(children, dataType.keysSorted);
423
368
  case "list":
424
369
  const field = deserializeArrowField(dataType.children[0]);
425
- return new arrow5.List(field);
370
+ return new arrow3.List(field);
426
371
  case "fixed-size-list":
427
372
  const child = deserializeArrowField(dataType.children[0]);
428
- return new arrow5.FixedSizeList(dataType.listSize, child);
373
+ return new arrow3.FixedSizeList(dataType.listSize, child);
429
374
  case "struct":
430
375
  children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
431
- return new arrow5.Struct(children);
376
+ return new arrow3.Struct(children);
432
377
  default:
433
378
  throw new Error("array type not supported");
434
379
  }
435
380
  }
436
381
  switch (dataType) {
437
382
  case "null":
438
- return new arrow5.Null();
383
+ return new arrow3.Null();
439
384
  case "binary":
440
- return new arrow5.Binary();
385
+ return new arrow3.Binary();
441
386
  case "bool":
442
- return new arrow5.Bool();
387
+ return new arrow3.Bool();
443
388
  case "int8":
444
- return new arrow5.Int8();
389
+ return new arrow3.Int8();
445
390
  case "int16":
446
- return new arrow5.Int16();
391
+ return new arrow3.Int16();
447
392
  case "int32":
448
- return new arrow5.Int32();
393
+ return new arrow3.Int32();
449
394
  case "int64":
450
- return new arrow5.Int64();
395
+ return new arrow3.Int64();
451
396
  case "uint8":
452
- return new arrow5.Uint8();
397
+ return new arrow3.Uint8();
453
398
  case "uint16":
454
- return new arrow5.Uint16();
399
+ return new arrow3.Uint16();
455
400
  case "uint32":
456
- return new arrow5.Uint32();
401
+ return new arrow3.Uint32();
457
402
  case "uint64":
458
- return new arrow5.Uint64();
403
+ return new arrow3.Uint64();
459
404
  case "float16":
460
- return new arrow5.Float16();
405
+ return new arrow3.Float16();
461
406
  case "float32":
462
- return new arrow5.Float32();
407
+ return new arrow3.Float32();
463
408
  case "float64":
464
- return new arrow5.Float64();
409
+ return new arrow3.Float64();
465
410
  case "utf8":
466
- return new arrow5.Utf8();
411
+ return new arrow3.Utf8();
467
412
  case "date-day":
468
- return new arrow5.DateDay();
413
+ return new arrow3.DateDay();
469
414
  case "date-millisecond":
470
- return new arrow5.DateMillisecond();
415
+ return new arrow3.DateMillisecond();
471
416
  case "time-second":
472
- return new arrow5.TimeSecond();
417
+ return new arrow3.TimeSecond();
473
418
  case "time-millisecond":
474
- return new arrow5.TimeMillisecond();
419
+ return new arrow3.TimeMillisecond();
475
420
  case "time-microsecond":
476
- return new arrow5.TimeMicrosecond();
421
+ return new arrow3.TimeMicrosecond();
477
422
  case "time-nanosecond":
478
- return new arrow5.TimeNanosecond();
423
+ return new arrow3.TimeNanosecond();
479
424
  case "timestamp-second":
480
- return new arrow5.TimestampSecond();
425
+ return new arrow3.TimestampSecond();
481
426
  case "timestamp-millisecond":
482
- return new arrow5.TimestampMillisecond();
427
+ return new arrow3.TimestampMillisecond();
483
428
  case "timestamp-microsecond":
484
- return new arrow5.TimestampMicrosecond();
429
+ return new arrow3.TimestampMicrosecond();
485
430
  case "timestamp-nanosecond":
486
- return new arrow5.TimestampNanosecond();
431
+ return new arrow3.TimestampNanosecond();
487
432
  case "interval-daytime":
488
- return new arrow5.IntervalDayTime();
433
+ return new arrow3.IntervalDayTime();
489
434
  case "interval-yearmonth":
490
- return new arrow5.IntervalYearMonth();
435
+ return new arrow3.IntervalYearMonth();
491
436
  default:
492
437
  throw new Error("array type not supported");
493
438
  }
494
439
  }
495
440
 
496
- // src/types.ts
497
- var VECTOR_TYPES = /* @__PURE__ */ ((VECTOR_TYPES2) => {
498
- VECTOR_TYPES2[VECTOR_TYPES2["FLOAT"] = 0] = "FLOAT";
499
- VECTOR_TYPES2[VECTOR_TYPES2["DATE"] = 1] = "DATE";
500
- return VECTOR_TYPES2;
501
- })(VECTOR_TYPES || {});
441
+ // src/parsers/parse-arrow-sync.ts
442
+ function parseArrowSync(arrayBuffer, options) {
443
+ const apacheArrowTable = arrow4.tableFromIPC([new Uint8Array(arrayBuffer)]);
444
+ const arrowTable = {
445
+ shape: "arrow-table",
446
+ schema: serializeArrowSchema(apacheArrowTable.schema),
447
+ data: apacheArrowTable
448
+ };
449
+ const shape = (options == null ? void 0 : options.shape) || "arrow-table";
450
+ switch (shape) {
451
+ case "arrow-table":
452
+ return arrowTable;
453
+ case "columnar-table":
454
+ return convertArrowToColumnarTable(arrowTable);
455
+ case "object-row-table":
456
+ let columnarTable = convertArrowToColumnarTable(arrowTable);
457
+ return (0, import_schema2.convertTable)(columnarTable, "object-row-table");
458
+ case "array-row-table":
459
+ columnarTable = convertArrowToColumnarTable(arrowTable);
460
+ return (0, import_schema2.convertTable)(columnarTable, "array-row-table");
461
+ default:
462
+ throw new Error(shape);
463
+ }
464
+ }
465
+
466
+ // src/parsers/parse-arrow-in-batches.ts
467
+ var arrow5 = __toESM(require("apache-arrow"), 1);
468
+ function parseArrowInBatches(asyncIterator) {
469
+ async function* makeArrowAsyncIterator() {
470
+ const readers = arrow5.RecordBatchReader.readAll(asyncIterator);
471
+ for await (const reader of readers) {
472
+ for await (const recordBatch of reader) {
473
+ const arrowTabledBatch = {
474
+ shape: "arrow-table",
475
+ batchType: "data",
476
+ data: new arrow5.Table([recordBatch]),
477
+ length: recordBatch.data.length
478
+ };
479
+ yield arrowTabledBatch;
480
+ }
481
+ break;
482
+ }
483
+ }
484
+ return makeArrowAsyncIterator();
485
+ }
486
+
487
+ // src/arrow-loader.ts
488
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
489
+ var ArrowWorkerLoader = {
490
+ name: "Apache Arrow",
491
+ id: "arrow",
492
+ module: "arrow",
493
+ version: VERSION,
494
+ // worker: true,
495
+ category: "table",
496
+ extensions: ["arrow", "feather"],
497
+ mimeTypes: [
498
+ "application/vnd.apache.arrow.file",
499
+ "application/vnd.apache.arrow.stream",
500
+ "application/octet-stream"
501
+ ],
502
+ binary: true,
503
+ tests: ["ARROW"],
504
+ options: {
505
+ arrow: {
506
+ shape: "columnar-table"
507
+ }
508
+ }
509
+ };
510
+ var ArrowLoader = {
511
+ ...ArrowWorkerLoader,
512
+ parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options == null ? void 0 : options.arrow),
513
+ parseSync: (arraybuffer, options) => parseArrowSync(arraybuffer, options == null ? void 0 : options.arrow),
514
+ parseInBatches: parseArrowInBatches
515
+ };
502
516
 
503
517
  // src/lib/encode-arrow.ts
504
518
  var arrow6 = __toESM(require("apache-arrow"), 1);
@@ -545,6 +559,75 @@ var ArrowWriter = {
545
559
  }
546
560
  };
547
561
 
562
+ // src/tables/convert-arrow-to-geojson-table.ts
563
+ var import_arrow = require("@loaders.gl/arrow");
564
+ var import_gis = require("@loaders.gl/gis");
565
+ function convertArrowToGeoJSONTable(table) {
566
+ var _a;
567
+ const arrowTable = table.data;
568
+ const schema = (0, import_arrow.serializeArrowSchema)(arrowTable.schema);
569
+ const geometryColumns = (0, import_gis.getGeometryColumnsFromSchema)(schema);
570
+ const encoding = geometryColumns.geometry.encoding;
571
+ const features = [];
572
+ const propertyColumnNames = arrowTable.schema.fields.map((field) => field.name).filter((name) => !(name in geometryColumns));
573
+ const propertiesTable = arrowTable.select(propertyColumnNames);
574
+ const arrowGeometryColumn = arrowTable.getChild("geometry");
575
+ for (let row = 0; row < arrowTable.numRows; row++) {
576
+ const arrowGeometry = arrowGeometryColumn == null ? void 0 : arrowGeometryColumn.get(row);
577
+ const feature = (0, import_arrow.parseGeometryFromArrow)(arrowGeometry, encoding);
578
+ if (feature) {
579
+ const properties = ((_a = propertiesTable.get(row)) == null ? void 0 : _a.toJSON()) || {};
580
+ features.push({ type: "Feature", geometry: feature, properties });
581
+ }
582
+ }
583
+ return {
584
+ shape: "geojson-table",
585
+ type: "FeatureCollection",
586
+ schema: table.schema,
587
+ features
588
+ };
589
+ }
590
+
591
+ // src/parsers/parse-geoarrow-sync.ts
592
+ function parseGeoArrowSync(arrayBuffer, options) {
593
+ const table = parseArrowSync(arrayBuffer, { shape: "arrow-table" });
594
+ switch (options == null ? void 0 : options.shape) {
595
+ case "geojson-table":
596
+ return convertArrowToGeoJSONTable(table);
597
+ default:
598
+ return table;
599
+ }
600
+ }
601
+
602
+ // src/parsers/parse-geoarrow-in-batches.ts
603
+ function parseGeoArrowInBatches(asyncIterator) {
604
+ return parseArrowInBatches(asyncIterator);
605
+ }
606
+
607
+ // src/geoarrow-loader.ts
608
+ var GeoArrowWorkerLoader = {
609
+ ...ArrowWorkerLoader,
610
+ options: {
611
+ arrow: {
612
+ shape: "arrow-table"
613
+ }
614
+ }
615
+ };
616
+ var GeoArrowLoader = {
617
+ ...ArrowWorkerLoader,
618
+ options: {
619
+ arrow: {
620
+ shape: "arrow-table"
621
+ }
622
+ },
623
+ parse: async (arraybuffer, options) => parseGeoArrowSync(arraybuffer, options == null ? void 0 : options.arrow),
624
+ parseSync: (arraybuffer, options) => parseGeoArrowSync(arraybuffer, options == null ? void 0 : options.arrow),
625
+ parseInBatches: parseGeoArrowInBatches
626
+ };
627
+
628
+ // src/geoarrow/convert-geoarrow-to-binary-geometry.ts
629
+ var import_polygon = require("@math.gl/polygon");
630
+
548
631
  // src/geoarrow/get-arrow-bounds.ts
549
632
  function updateBoundsFromGeoArrowSamples(flatCoords, nDim, bounds, sampleSize = 100) {
550
633
  const numberOfFeatures = flatCoords.length / nDim;
@@ -577,21 +660,18 @@ var BINARY_GEOMETRY_TEMPLATE = {
577
660
  numericProps: {},
578
661
  featureIds: { value: new Uint32Array(0), size: 1 }
579
662
  };
580
- function getBinaryGeometriesFromArrow(geoColumn, geoEncoding) {
663
+ function getBinaryGeometriesFromArrow(geoColumn, geoEncoding, options) {
581
664
  const featureTypes = {
582
665
  polygon: geoEncoding === "geoarrow.multipolygon" || geoEncoding === "geoarrow.polygon",
583
666
  point: geoEncoding === "geoarrow.multipoint" || geoEncoding === "geoarrow.point",
584
667
  line: geoEncoding === "geoarrow.multilinestring" || geoEncoding === "geoarrow.linestring"
585
668
  };
586
- const chunks = geoColumn.data;
669
+ const chunks = (options == null ? void 0 : options.chunkIndex) ? [geoColumn.data[options == null ? void 0 : options.chunkIndex]] : geoColumn.data;
587
670
  let bounds = [Infinity, Infinity, -Infinity, -Infinity];
588
671
  let globalFeatureIdOffset = 0;
589
672
  const binaryGeometries = [];
590
673
  chunks.forEach((chunk) => {
591
- const { featureIds, flatCoordinateArray, nDim, geomOffset } = getBinaryGeometriesFromChunk(
592
- chunk,
593
- geoEncoding
594
- );
674
+ const { featureIds, flatCoordinateArray, nDim, geomOffset, triangles } = getBinaryGeometriesFromChunk(chunk, geoEncoding, options);
595
675
  const globalFeatureIds = new Uint32Array(featureIds.length);
596
676
  for (let i = 0; i < featureIds.length; i++) {
597
677
  globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
@@ -626,22 +706,87 @@ function getBinaryGeometriesFromArrow(geoColumn, geoEncoding) {
626
706
  ...BINARY_GEOMETRY_TEMPLATE,
627
707
  ...featureTypes.polygon ? binaryContent : {},
628
708
  polygonIndices: {
629
- // TODO why deck.gl's tessellatePolygon performance is not good when using geometryIndicies
630
- // even when there is no hole in any polygon
709
+ // use geomOffset as polygonIndices same as primitivePolygonIndices since we are using earcut to get triangule indices
631
710
  value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
632
711
  size: 1
633
712
  },
634
713
  primitivePolygonIndices: {
635
714
  value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
636
715
  size: 1
637
- }
716
+ },
717
+ ...triangles ? { triangles: { value: triangles, size: 1 } } : {}
638
718
  }
639
719
  });
640
720
  bounds = updateBoundsFromGeoArrowSamples(flatCoordinateArray, nDim, bounds);
641
721
  });
642
- return { binaryGeometries, bounds, featureTypes };
722
+ return {
723
+ binaryGeometries,
724
+ bounds,
725
+ featureTypes,
726
+ ...(options == null ? void 0 : options.calculateMeanCenters) ? { meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries) } : {}
727
+ };
728
+ }
729
+ function getMeanCentersFromBinaryGeometries(binaryGeometries) {
730
+ const globalMeanCenters = [];
731
+ binaryGeometries.forEach((binaryGeometry) => {
732
+ var _a;
733
+ let binaryGeometryType = null;
734
+ if (binaryGeometry.points && binaryGeometry.points.positions.value.length > 0) {
735
+ binaryGeometryType = "points" /* points */;
736
+ } else if (binaryGeometry.lines && binaryGeometry.lines.positions.value.length > 0) {
737
+ binaryGeometryType = "lines" /* lines */;
738
+ } else if (binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0) {
739
+ binaryGeometryType = "polygons" /* polygons */;
740
+ }
741
+ const binaryContent = binaryGeometryType ? binaryGeometry[binaryGeometryType] : null;
742
+ if (binaryContent && binaryGeometryType !== null) {
743
+ const featureIds = binaryContent.featureIds.value;
744
+ const flatCoordinateArray = binaryContent.positions.value;
745
+ const nDim = binaryContent.positions.size;
746
+ const primitivePolygonIndices = binaryContent.type === "Polygon" ? (_a = binaryContent.primitivePolygonIndices) == null ? void 0 : _a.value : void 0;
747
+ const meanCenters = getMeanCentersFromGeometry(
748
+ featureIds,
749
+ flatCoordinateArray,
750
+ nDim,
751
+ binaryGeometryType,
752
+ primitivePolygonIndices
753
+ );
754
+ meanCenters.forEach((center) => {
755
+ globalMeanCenters.push(center);
756
+ });
757
+ }
758
+ });
759
+ return globalMeanCenters;
760
+ }
761
+ function getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, geometryType, primitivePolygonIndices) {
762
+ const meanCenters = [];
763
+ const vertexCount = flatCoordinateArray.length;
764
+ let vertexIndex = 0;
765
+ let coordIdx = 0;
766
+ let primitiveIdx = 0;
767
+ while (vertexIndex < vertexCount) {
768
+ const featureId = featureIds[vertexIndex / nDim];
769
+ const center = [0, 0];
770
+ let vertexCountInFeature = 0;
771
+ while (vertexIndex < vertexCount && featureIds[coordIdx] === featureId) {
772
+ if (geometryType === "polygons" /* polygons */ && (primitivePolygonIndices == null ? void 0 : primitivePolygonIndices[primitiveIdx]) === coordIdx) {
773
+ vertexIndex += nDim;
774
+ primitiveIdx++;
775
+ } else {
776
+ center[0] += flatCoordinateArray[vertexIndex];
777
+ center[1] += flatCoordinateArray[vertexIndex + 1];
778
+ vertexIndex += nDim;
779
+ vertexCountInFeature++;
780
+ }
781
+ coordIdx += 1;
782
+ }
783
+ center[0] /= vertexCountInFeature;
784
+ center[1] /= vertexCountInFeature;
785
+ meanCenters.push(center);
786
+ }
787
+ return meanCenters;
643
788
  }
644
- function getBinaryGeometriesFromChunk(chunk, geoEncoding) {
789
+ function getBinaryGeometriesFromChunk(chunk, geoEncoding, options) {
645
790
  switch (geoEncoding) {
646
791
  case "geoarrow.point":
647
792
  case "geoarrow.multipoint":
@@ -651,12 +796,48 @@ function getBinaryGeometriesFromChunk(chunk, geoEncoding) {
651
796
  return getBinaryLinesFromChunk(chunk, geoEncoding);
652
797
  case "geoarrow.polygon":
653
798
  case "geoarrow.multipolygon":
654
- return getBinaryPolygonsFromChunk(chunk, geoEncoding);
799
+ return getBinaryPolygonsFromChunk(chunk, geoEncoding, options);
655
800
  default:
656
801
  throw Error("invalid geoarrow encoding");
657
802
  }
658
803
  }
659
- function getBinaryPolygonsFromChunk(chunk, geoEncoding) {
804
+ function getTriangleIndices(polygonIndices, primitivePolygonIndices, flatCoordinateArray, nDim) {
805
+ try {
806
+ let primitiveIndex = 0;
807
+ const triangles = [];
808
+ for (let i = 0; i < polygonIndices.length - 1; i++) {
809
+ const startIdx = polygonIndices[i];
810
+ const endIdx = polygonIndices[i + 1];
811
+ const slicedFlatCoords = flatCoordinateArray.subarray(startIdx * nDim, endIdx * nDim);
812
+ const holeIndices = [];
813
+ while (primitivePolygonIndices[primitiveIndex] < endIdx) {
814
+ if (primitivePolygonIndices[primitiveIndex] > startIdx) {
815
+ holeIndices.push(primitivePolygonIndices[primitiveIndex] - startIdx);
816
+ }
817
+ primitiveIndex++;
818
+ }
819
+ const triangleIndices = (0, import_polygon.earcut)(
820
+ slicedFlatCoords,
821
+ holeIndices.length > 0 ? holeIndices : void 0,
822
+ nDim
823
+ );
824
+ if (triangleIndices.length === 0) {
825
+ throw Error("can not tesselate invalid polygon");
826
+ }
827
+ for (let j = 0; j < triangleIndices.length; j++) {
828
+ triangles.push(triangleIndices[j] + startIdx);
829
+ }
830
+ }
831
+ const trianglesUint32 = new Uint32Array(triangles.length);
832
+ for (let i = 0; i < triangles.length; i++) {
833
+ trianglesUint32[i] = triangles[i];
834
+ }
835
+ return trianglesUint32;
836
+ } catch (error) {
837
+ return null;
838
+ }
839
+ }
840
+ function getBinaryPolygonsFromChunk(chunk, geoEncoding, options) {
660
841
  const isMultiPolygon = geoEncoding === "geoarrow.multipolygon";
661
842
  const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
662
843
  const polygonOffset = polygonData.valueOffsets;
@@ -680,12 +861,14 @@ function getBinaryPolygonsFromChunk(chunk, geoEncoding) {
680
861
  featureIds[j] = i;
681
862
  }
682
863
  }
864
+ const triangles = (options == null ? void 0 : options.triangulate) ? getTriangleIndices(geometryIndicies, geomOffset, flatCoordinateArray, nDim) : null;
683
865
  return {
684
866
  featureIds,
685
867
  flatCoordinateArray,
686
868
  nDim,
687
869
  geomOffset,
688
- geometryIndicies
870
+ geometryIndicies,
871
+ ...(options == null ? void 0 : options.triangulate) && triangles ? { triangles } : {}
689
872
  };
690
873
  }
691
874
  function getBinaryLinesFromChunk(chunk, geoEncoding) {
@@ -699,11 +882,22 @@ function getBinaryLinesFromChunk(chunk, geoEncoding) {
699
882
  const geometryIndicies = new Uint16Array(0);
700
883
  const numOfVertices = flatCoordinateArray.length / nDim;
701
884
  const featureIds = new Uint32Array(numOfVertices);
702
- for (let i = 0; i < chunk.length; i++) {
703
- const startIdx = geomOffset[i];
704
- const endIdx = geomOffset[i + 1];
705
- for (let j = startIdx; j < endIdx; j++) {
706
- featureIds[j] = i;
885
+ if (isMultiLineString) {
886
+ const partData = chunk.valueOffsets;
887
+ for (let i = 0; i < partData.length - 1; i++) {
888
+ const startIdx = geomOffset[partData[i]];
889
+ const endIdx = geomOffset[partData[i + 1]];
890
+ for (let j = startIdx; j < endIdx; j++) {
891
+ featureIds[j] = i;
892
+ }
893
+ }
894
+ } else {
895
+ for (let i = 0; i < chunk.length; i++) {
896
+ const startIdx = geomOffset[i];
897
+ const endIdx = geomOffset[i + 1];
898
+ for (let j = startIdx; j < endIdx; j++) {
899
+ featureIds[j] = i;
900
+ }
707
901
  }
708
902
  }
709
903
  return {
@@ -724,8 +918,19 @@ function getBinaryPointsFromChunk(chunk, geoEncoding) {
724
918
  const geomOffset = new Int32Array(0);
725
919
  const numOfVertices = flatCoordinateArray.length / nDim;
726
920
  const featureIds = new Uint32Array(numOfVertices);
727
- for (let i = 0; i < chunk.length; i++) {
728
- featureIds[i] = i;
921
+ if (isMultiPoint) {
922
+ const partData = chunk.valueOffsets;
923
+ for (let i = 0; i < partData.length - 1; i++) {
924
+ const startIdx = partData[i];
925
+ const endIdx = partData[i + 1];
926
+ for (let j = startIdx; j < endIdx; j++) {
927
+ featureIds[j] = i;
928
+ }
929
+ }
930
+ } else {
931
+ for (let i = 0; i < chunk.length; i++) {
932
+ featureIds[i] = i;
933
+ }
729
934
  }
730
935
  return {
731
936
  featureIds,
@@ -736,43 +941,60 @@ function getBinaryPointsFromChunk(chunk, geoEncoding) {
736
941
  };
737
942
  }
738
943
 
739
- // src/geoarrow/convert-geoarrow-to-geojson.ts
740
- function parseGeometryFromArrow(rawData) {
741
- var _a;
742
- const encoding = (_a = rawData.encoding) == null ? void 0 : _a.toLowerCase();
743
- const data = rawData.data;
744
- if (!encoding || !data) {
944
+ // src/geoarrow/convert-geoarrow-to-geojson-geometry.ts
945
+ var import_gis2 = require("@loaders.gl/gis");
946
+ var import_wkt = require("@loaders.gl/wkt");
947
+ function parseGeometryFromArrow2(arrowCellValue, encoding) {
948
+ encoding = encoding == null ? void 0 : encoding.toLowerCase();
949
+ if (!encoding || !arrowCellValue) {
745
950
  return null;
746
951
  }
747
952
  let geometry;
748
953
  switch (encoding) {
749
954
  case "geoarrow.multipolygon":
750
- geometry = arrowMultiPolygonToFeature(data);
955
+ geometry = arrowMultiPolygonToFeature(arrowCellValue);
751
956
  break;
752
957
  case "geoarrow.polygon":
753
- geometry = arrowPolygonToFeature(data);
958
+ geometry = arrowPolygonToFeature(arrowCellValue);
754
959
  break;
755
960
  case "geoarrow.multipoint":
756
- geometry = arrowMultiPointToFeature(data);
961
+ geometry = arrowMultiPointToFeature(arrowCellValue);
757
962
  break;
758
963
  case "geoarrow.point":
759
- geometry = arrowPointToFeature(data);
964
+ geometry = arrowPointToFeature(arrowCellValue);
760
965
  break;
761
966
  case "geoarrow.multilinestring":
762
- geometry = arrowMultiLineStringToFeature(data);
967
+ geometry = arrowMultiLineStringToFeature(arrowCellValue);
763
968
  break;
764
969
  case "geoarrow.linestring":
765
- geometry = arrowLineStringToFeature(data);
970
+ geometry = arrowLineStringToFeature(arrowCellValue);
971
+ break;
972
+ case "geoarrow.wkb":
973
+ geometry = arrowWKBToFeature(arrowCellValue);
974
+ break;
975
+ case "geoarrow.wkt":
976
+ geometry = arrowWKTToFeature(arrowCellValue);
766
977
  break;
767
978
  default: {
768
979
  throw Error(`GeoArrow encoding not supported ${encoding}`);
769
980
  }
770
981
  }
771
- return {
772
- type: "Feature",
773
- geometry,
774
- properties: {}
775
- };
982
+ return geometry;
983
+ }
984
+ function arrowWKBToFeature(arrowCellValue) {
985
+ var _a, _b;
986
+ const arrayBuffer = arrowCellValue.buffer.slice(
987
+ arrowCellValue.byteOffset,
988
+ arrowCellValue.byteOffset + arrowCellValue.byteLength
989
+ );
990
+ const binaryGeometry = (_b = (_a = import_wkt.WKBLoader).parseSync) == null ? void 0 : _b.call(_a, arrayBuffer);
991
+ const geometry = (0, import_gis2.binaryToGeometry)(binaryGeometry);
992
+ return geometry;
993
+ }
994
+ function arrowWKTToFeature(arrowCellValue) {
995
+ var _a, _b;
996
+ const string = arrowCellValue;
997
+ return (_b = (_a = import_wkt.WKTLoader).parseTextSync) == null ? void 0 : _b.call(_a, string);
776
998
  }
777
999
  function arrowMultiPolygonToFeature(arrowMultiPolygon) {
778
1000
  const multiPolygon = [];
@@ -824,19 +1046,17 @@ function arrowMultiPointToFeature(arrowMultiPoint) {
824
1046
  multiPoint.push(coord);
825
1047
  }
826
1048
  }
827
- const geometry = {
1049
+ return {
828
1050
  type: "MultiPoint",
829
1051
  coordinates: multiPoint
830
1052
  };
831
- return geometry;
832
1053
  }
833
1054
  function arrowPointToFeature(arrowPoint) {
834
1055
  const point = Array.from(arrowPoint);
835
- const geometry = {
1056
+ return {
836
1057
  type: "Point",
837
1058
  coordinates: point
838
1059
  };
839
- return geometry;
840
1060
  }
841
1061
  function arrowMultiLineStringToFeature(arrowMultiLineString) {
842
1062
  const multiLineString = [];
@@ -852,11 +1072,10 @@ function arrowMultiLineStringToFeature(arrowMultiLineString) {
852
1072
  }
853
1073
  multiLineString.push(lineString);
854
1074
  }
855
- const geometry = {
1075
+ return {
856
1076
  type: "MultiLineString",
857
1077
  coordinates: multiLineString
858
1078
  };
859
- return geometry;
860
1079
  }
861
1080
  function arrowLineStringToFeature(arrowLineString) {
862
1081
  const lineString = [];
@@ -867,18 +1086,25 @@ function arrowLineStringToFeature(arrowLineString) {
867
1086
  lineString.push(coords);
868
1087
  }
869
1088
  }
870
- const geometry = {
1089
+ return {
871
1090
  type: "LineString",
872
1091
  coordinates: lineString
873
1092
  };
874
- return geometry;
1093
+ }
1094
+
1095
+ // src/triangulate-on-worker.ts
1096
+ var import_worker_utils = require("@loaders.gl/worker-utils");
1097
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1098
+ var TriangulationWorker = {
1099
+ id: "triangulation",
1100
+ name: "Triangulate",
1101
+ module: "arrow",
1102
+ version: VERSION3,
1103
+ options: {}
1104
+ };
1105
+ function triangulateOnWorker(data, options = {}) {
1106
+ return (0, import_worker_utils.processOnWorker)(TriangulationWorker, data, options);
875
1107
  }
876
1108
 
877
1109
  // src/index.ts
878
1110
  import_schema3.TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
879
- var ArrowLoader2 = {
880
- ...ArrowLoader,
881
- parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options),
882
- parseSync: parseArrowSync,
883
- parseInBatches: parseArrowInBatches
884
- };