@loaders.gl/arrow 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-loader.d.ts.map +1 -1
- package/dist/arrow-loader.js.map +1 -1
- package/dist/arrow-worker.js +2 -2
- package/dist/arrow-writer.d.ts.map +1 -1
- package/dist/arrow-writer.js.map +1 -1
- package/dist/dist.dev.js +650 -2
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +24 -0
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -0
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +190 -0
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -0
- package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts +19 -0
- package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts.map +1 -0
- package/dist/geoarrow/convert-geoarrow-to-geojson.js +138 -0
- package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +1 -0
- package/dist/geoarrow/get-arrow-bounds.d.ts +11 -0
- package/dist/geoarrow/get-arrow-bounds.d.ts.map +1 -0
- package/dist/geoarrow/get-arrow-bounds.js +24 -0
- package/dist/geoarrow/get-arrow-bounds.js.map +1 -0
- package/dist/index.cjs +589 -7
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/parse-arrow-sync.d.ts.map +1 -1
- package/dist/lib/parse-arrow-sync.js +1 -1
- package/dist/lib/parse-arrow-sync.js.map +1 -1
- package/dist/schema/arrow-type-utils.d.ts +1 -0
- package/dist/schema/arrow-type-utils.d.ts.map +1 -1
- package/dist/schema/arrow-type-utils.js.map +1 -1
- package/dist/schema/{convert-schema-arrow.d.ts → convert-arrow-schema.d.ts} +7 -1
- package/dist/schema/convert-arrow-schema.d.ts.map +1 -0
- package/dist/schema/{convert-schema-arrow.js → convert-arrow-schema.js} +78 -4
- package/dist/schema/convert-arrow-schema.js.map +1 -0
- package/dist/{lib/convert-table.d.ts → tables/convert-arrow-to-table.d.ts} +2 -2
- package/dist/tables/convert-arrow-to-table.d.ts.map +1 -0
- package/dist/{lib/convert-table.js → tables/convert-arrow-to-table.js} +1 -1
- package/dist/tables/convert-arrow-to-table.js.map +1 -0
- package/dist/{schema → tables}/convert-table-to-arrow.d.ts.map +1 -1
- package/dist/{schema → tables}/convert-table-to-arrow.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/workers/arrow-worker.js.map +1 -1
- package/package.json +5 -4
- package/src/arrow-loader.ts +1 -0
- package/src/arrow-writer.ts +1 -0
- package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +262 -0
- package/src/geoarrow/convert-geoarrow-to-geojson.ts +192 -0
- package/src/geoarrow/get-arrow-bounds.ts +41 -0
- package/src/index.ts +28 -4
- package/src/lib/parse-arrow-sync.ts +4 -1
- package/src/schema/arrow-type-utils.ts +1 -0
- package/src/schema/{convert-schema-arrow.ts → convert-arrow-schema.ts} +97 -21
- package/src/{lib/convert-table.ts → tables/convert-arrow-to-table.ts} +2 -1
- package/src/types.ts +3 -0
- package/src/workers/arrow-worker.ts +3 -0
- package/dist/lib/convert-table.d.ts.map +0 -1
- package/dist/lib/convert-table.js.map +0 -1
- package/dist/schema/convert-schema-arrow.d.ts.map +0 -1
- package/dist/schema/convert-schema-arrow.js.map +0 -1
- /package/dist/{schema → tables}/convert-table-to-arrow.d.ts +0 -0
- /package/dist/{schema → tables}/convert-table-to-arrow.js +0 -0
- /package/src/{schema → tables}/convert-table-to-arrow.ts +0 -0
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,17 @@ __export(src_exports, {
|
|
|
24
24
|
ArrowWorkerLoader: () => ArrowLoader,
|
|
25
25
|
ArrowWriter: () => ArrowWriter,
|
|
26
26
|
VECTOR_TYPES: () => VECTOR_TYPES,
|
|
27
|
-
|
|
27
|
+
deserializeArrowField: () => deserializeArrowField,
|
|
28
|
+
deserializeArrowMetadata: () => deserializeArrowMetadata,
|
|
29
|
+
deserializeArrowSchema: () => deserializeArrowSchema,
|
|
30
|
+
deserializeArrowType: () => deserializeArrowType,
|
|
31
|
+
getArrowType: () => getArrowType,
|
|
32
|
+
getBinaryGeometriesFromArrow: () => getBinaryGeometriesFromArrow,
|
|
33
|
+
parseGeometryFromArrow: () => parseGeometryFromArrow,
|
|
34
|
+
serializeArrowField: () => serializeArrowField,
|
|
35
|
+
serializeArrowMetadata: () => serializeArrowMetadata,
|
|
36
|
+
serializeArrowSchema: () => serializeArrowSchema,
|
|
37
|
+
serializeArrowType: () => serializeArrowType
|
|
28
38
|
});
|
|
29
39
|
module.exports = __toCommonJS(src_exports);
|
|
30
40
|
var import_schema3 = require("@loaders.gl/schema");
|
|
@@ -57,7 +67,7 @@ var ArrowLoader = {
|
|
|
57
67
|
var import_schema = require("@loaders.gl/schema");
|
|
58
68
|
var import_apache_arrow = require("apache-arrow");
|
|
59
69
|
|
|
60
|
-
// src/
|
|
70
|
+
// src/tables/convert-arrow-to-table.ts
|
|
61
71
|
function convertApacheArrowToArrowTable(arrowTable) {
|
|
62
72
|
return {
|
|
63
73
|
shape: "arrow-table",
|
|
@@ -203,6 +213,247 @@ function getArrowType(array) {
|
|
|
203
213
|
}
|
|
204
214
|
}
|
|
205
215
|
|
|
216
|
+
// src/schema/convert-arrow-schema.ts
|
|
217
|
+
var import_apache_arrow5 = require("apache-arrow");
|
|
218
|
+
function serializeArrowSchema(arrowSchema) {
|
|
219
|
+
return {
|
|
220
|
+
fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
|
|
221
|
+
metadata: serializeArrowMetadata(arrowSchema.metadata)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function deserializeArrowSchema(schema) {
|
|
225
|
+
return new import_apache_arrow5.Schema(
|
|
226
|
+
schema.fields.map((field) => deserializeArrowField(field)),
|
|
227
|
+
deserializeArrowMetadata(schema.metadata)
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
function serializeArrowMetadata(arrowMetadata) {
|
|
231
|
+
return Object.fromEntries(arrowMetadata);
|
|
232
|
+
}
|
|
233
|
+
function deserializeArrowMetadata(metadata) {
|
|
234
|
+
return metadata ? new Map(Object.entries(metadata)) : /* @__PURE__ */ new Map();
|
|
235
|
+
}
|
|
236
|
+
function serializeArrowField(field) {
|
|
237
|
+
return {
|
|
238
|
+
name: field.name,
|
|
239
|
+
type: serializeArrowType(field.type),
|
|
240
|
+
nullable: field.nullable,
|
|
241
|
+
metadata: serializeArrowMetadata(field.metadata)
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function deserializeArrowField(field) {
|
|
245
|
+
return new import_apache_arrow5.Field(
|
|
246
|
+
field.name,
|
|
247
|
+
deserializeArrowType(field.type),
|
|
248
|
+
field.nullable,
|
|
249
|
+
deserializeArrowMetadata(field.metadata)
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
function serializeArrowType(arrowType) {
|
|
253
|
+
switch (arrowType.constructor) {
|
|
254
|
+
case import_apache_arrow5.Null:
|
|
255
|
+
return "null";
|
|
256
|
+
case import_apache_arrow5.Binary:
|
|
257
|
+
return "binary";
|
|
258
|
+
case import_apache_arrow5.Bool:
|
|
259
|
+
return "bool";
|
|
260
|
+
case import_apache_arrow5.Int:
|
|
261
|
+
const intType = arrowType;
|
|
262
|
+
return `${intType.isSigned ? "u" : ""}int${intType.bitWidth}`;
|
|
263
|
+
case import_apache_arrow5.Int8:
|
|
264
|
+
return "int8";
|
|
265
|
+
case import_apache_arrow5.Int16:
|
|
266
|
+
return "int16";
|
|
267
|
+
case import_apache_arrow5.Int32:
|
|
268
|
+
return "int32";
|
|
269
|
+
case import_apache_arrow5.Int64:
|
|
270
|
+
return "int64";
|
|
271
|
+
case import_apache_arrow5.Uint8:
|
|
272
|
+
return "uint8";
|
|
273
|
+
case import_apache_arrow5.Uint16:
|
|
274
|
+
return "uint16";
|
|
275
|
+
case import_apache_arrow5.Uint32:
|
|
276
|
+
return "uint32";
|
|
277
|
+
case import_apache_arrow5.Uint64:
|
|
278
|
+
return "uint64";
|
|
279
|
+
case import_apache_arrow5.Float:
|
|
280
|
+
const precision = arrowType.precision;
|
|
281
|
+
switch (precision) {
|
|
282
|
+
case import_apache_arrow5.Precision.HALF:
|
|
283
|
+
return "float16";
|
|
284
|
+
case import_apache_arrow5.Precision.SINGLE:
|
|
285
|
+
return "float32";
|
|
286
|
+
case import_apache_arrow5.Precision.DOUBLE:
|
|
287
|
+
return "float64";
|
|
288
|
+
default:
|
|
289
|
+
return "float16";
|
|
290
|
+
}
|
|
291
|
+
case import_apache_arrow5.Float16:
|
|
292
|
+
return "float16";
|
|
293
|
+
case import_apache_arrow5.Float32:
|
|
294
|
+
return "float32";
|
|
295
|
+
case import_apache_arrow5.Float64:
|
|
296
|
+
return "float64";
|
|
297
|
+
case import_apache_arrow5.Utf8:
|
|
298
|
+
return "utf8";
|
|
299
|
+
case Date:
|
|
300
|
+
const dateUnit = arrowType.unit;
|
|
301
|
+
return dateUnit === import_apache_arrow5.DateUnit.DAY ? "date-day" : "date-millisecond";
|
|
302
|
+
case import_apache_arrow5.DateDay:
|
|
303
|
+
return "date-day";
|
|
304
|
+
case import_apache_arrow5.DateMillisecond:
|
|
305
|
+
return "date-millisecond";
|
|
306
|
+
case import_apache_arrow5.Time:
|
|
307
|
+
const timeUnit = arrowType.unit;
|
|
308
|
+
switch (timeUnit) {
|
|
309
|
+
case import_apache_arrow5.TimeUnit.SECOND:
|
|
310
|
+
return "time-second";
|
|
311
|
+
case import_apache_arrow5.TimeUnit.MILLISECOND:
|
|
312
|
+
return "time-millisecond";
|
|
313
|
+
case import_apache_arrow5.TimeUnit.MICROSECOND:
|
|
314
|
+
return "time-microsecond";
|
|
315
|
+
case import_apache_arrow5.TimeUnit.NANOSECOND:
|
|
316
|
+
return "time-nanosecond";
|
|
317
|
+
default:
|
|
318
|
+
return "time-second";
|
|
319
|
+
}
|
|
320
|
+
case import_apache_arrow5.TimeMillisecond:
|
|
321
|
+
return "time-millisecond";
|
|
322
|
+
case import_apache_arrow5.TimeSecond:
|
|
323
|
+
return "time-second";
|
|
324
|
+
case import_apache_arrow5.TimeMicrosecond:
|
|
325
|
+
return "time-microsecond";
|
|
326
|
+
case import_apache_arrow5.TimeNanosecond:
|
|
327
|
+
return "time-nanosecond";
|
|
328
|
+
case import_apache_arrow5.Timestamp:
|
|
329
|
+
const timeStampUnit = arrowType.unit;
|
|
330
|
+
switch (timeStampUnit) {
|
|
331
|
+
case import_apache_arrow5.TimeUnit.SECOND:
|
|
332
|
+
return "timestamp-second";
|
|
333
|
+
case import_apache_arrow5.TimeUnit.MILLISECOND:
|
|
334
|
+
return "timestamp-millisecond";
|
|
335
|
+
case import_apache_arrow5.TimeUnit.MICROSECOND:
|
|
336
|
+
return "timestamp-microsecond";
|
|
337
|
+
case import_apache_arrow5.TimeUnit.NANOSECOND:
|
|
338
|
+
return "timestamp-nanosecond";
|
|
339
|
+
default:
|
|
340
|
+
return "timestamp-second";
|
|
341
|
+
}
|
|
342
|
+
case import_apache_arrow5.TimestampSecond:
|
|
343
|
+
return "timestamp-second";
|
|
344
|
+
case import_apache_arrow5.TimestampMillisecond:
|
|
345
|
+
return "timestamp-millisecond";
|
|
346
|
+
case import_apache_arrow5.TimestampMicrosecond:
|
|
347
|
+
return "timestamp-microsecond";
|
|
348
|
+
case import_apache_arrow5.TimestampNanosecond:
|
|
349
|
+
return "timestamp-nanosecond";
|
|
350
|
+
case import_apache_arrow5.Interval:
|
|
351
|
+
const intervalUnit = arrowType.unit;
|
|
352
|
+
switch (intervalUnit) {
|
|
353
|
+
case import_apache_arrow5.IntervalUnit.DAY_TIME:
|
|
354
|
+
return "interval-daytime";
|
|
355
|
+
case import_apache_arrow5.IntervalUnit.YEAR_MONTH:
|
|
356
|
+
return "interval-yearmonth";
|
|
357
|
+
default:
|
|
358
|
+
return "interval-daytime";
|
|
359
|
+
}
|
|
360
|
+
case import_apache_arrow5.IntervalDayTime:
|
|
361
|
+
return "interval-daytime";
|
|
362
|
+
case import_apache_arrow5.IntervalYearMonth:
|
|
363
|
+
return "interval-yearmonth";
|
|
364
|
+
case import_apache_arrow5.List:
|
|
365
|
+
const listType = arrowType;
|
|
366
|
+
const listField = listType.valueField;
|
|
367
|
+
return {
|
|
368
|
+
type: "list",
|
|
369
|
+
children: [serializeArrowField(listField)]
|
|
370
|
+
};
|
|
371
|
+
case import_apache_arrow5.FixedSizeList:
|
|
372
|
+
return {
|
|
373
|
+
type: "fixed-size-list",
|
|
374
|
+
listSize: arrowType.listSize,
|
|
375
|
+
children: [serializeArrowField(arrowType.children[0])]
|
|
376
|
+
};
|
|
377
|
+
default:
|
|
378
|
+
throw new Error("array type not supported");
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function deserializeArrowType(dataType) {
|
|
382
|
+
if (typeof dataType === "object") {
|
|
383
|
+
switch (dataType.type) {
|
|
384
|
+
case "list":
|
|
385
|
+
const field = deserializeArrowField(dataType.children[0]);
|
|
386
|
+
return new import_apache_arrow5.List(field);
|
|
387
|
+
case "fixed-size-list":
|
|
388
|
+
const child = deserializeArrowField(dataType.children[0]);
|
|
389
|
+
return new import_apache_arrow5.FixedSizeList(dataType.listSize, child);
|
|
390
|
+
case "struct":
|
|
391
|
+
const children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
392
|
+
return new import_apache_arrow5.Struct(children);
|
|
393
|
+
default:
|
|
394
|
+
throw new Error("array type not supported");
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
switch (dataType) {
|
|
398
|
+
case "null":
|
|
399
|
+
return new import_apache_arrow5.Null();
|
|
400
|
+
case "binary":
|
|
401
|
+
return new import_apache_arrow5.Binary();
|
|
402
|
+
case "bool":
|
|
403
|
+
return new import_apache_arrow5.Bool();
|
|
404
|
+
case "int8":
|
|
405
|
+
return new import_apache_arrow5.Int8();
|
|
406
|
+
case "int16":
|
|
407
|
+
return new import_apache_arrow5.Int16();
|
|
408
|
+
case "int32":
|
|
409
|
+
return new import_apache_arrow5.Int32();
|
|
410
|
+
case "int64":
|
|
411
|
+
return new import_apache_arrow5.Int64();
|
|
412
|
+
case "uint8":
|
|
413
|
+
return new import_apache_arrow5.Uint8();
|
|
414
|
+
case "uint16":
|
|
415
|
+
return new import_apache_arrow5.Uint16();
|
|
416
|
+
case "uint32":
|
|
417
|
+
return new import_apache_arrow5.Uint32();
|
|
418
|
+
case "uint64":
|
|
419
|
+
return new import_apache_arrow5.Uint64();
|
|
420
|
+
case "float16":
|
|
421
|
+
return new import_apache_arrow5.Float16();
|
|
422
|
+
case "float32":
|
|
423
|
+
return new import_apache_arrow5.Float32();
|
|
424
|
+
case "float64":
|
|
425
|
+
return new import_apache_arrow5.Float64();
|
|
426
|
+
case "utf8":
|
|
427
|
+
return new import_apache_arrow5.Utf8();
|
|
428
|
+
case "date-day":
|
|
429
|
+
return new import_apache_arrow5.DateDay();
|
|
430
|
+
case "date-millisecond":
|
|
431
|
+
return new import_apache_arrow5.DateMillisecond();
|
|
432
|
+
case "time-second":
|
|
433
|
+
return new import_apache_arrow5.TimeSecond();
|
|
434
|
+
case "time-millisecond":
|
|
435
|
+
return new import_apache_arrow5.TimeMillisecond();
|
|
436
|
+
case "time-microsecond":
|
|
437
|
+
return new import_apache_arrow5.TimeMicrosecond();
|
|
438
|
+
case "time-nanosecond":
|
|
439
|
+
return new import_apache_arrow5.TimeNanosecond();
|
|
440
|
+
case "timestamp-second":
|
|
441
|
+
return new import_apache_arrow5.TimestampSecond();
|
|
442
|
+
case "timestamp-millisecond":
|
|
443
|
+
return new import_apache_arrow5.TimestampMillisecond();
|
|
444
|
+
case "timestamp-microsecond":
|
|
445
|
+
return new import_apache_arrow5.TimestampMicrosecond();
|
|
446
|
+
case "timestamp-nanosecond":
|
|
447
|
+
return new import_apache_arrow5.TimestampNanosecond();
|
|
448
|
+
case "interval-daytime":
|
|
449
|
+
return new import_apache_arrow5.IntervalDayTime();
|
|
450
|
+
case "interval-yearmonth":
|
|
451
|
+
return new import_apache_arrow5.IntervalYearMonth();
|
|
452
|
+
default:
|
|
453
|
+
throw new Error("array type not supported");
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
206
457
|
// src/types.ts
|
|
207
458
|
var VECTOR_TYPES = /* @__PURE__ */ ((VECTOR_TYPES2) => {
|
|
208
459
|
VECTOR_TYPES2[VECTOR_TYPES2["FLOAT"] = 0] = "FLOAT";
|
|
@@ -211,24 +462,24 @@ var VECTOR_TYPES = /* @__PURE__ */ ((VECTOR_TYPES2) => {
|
|
|
211
462
|
})(VECTOR_TYPES || {});
|
|
212
463
|
|
|
213
464
|
// src/lib/encode-arrow.ts
|
|
214
|
-
var
|
|
465
|
+
var import_apache_arrow6 = require("apache-arrow");
|
|
215
466
|
function encodeArrowSync(data) {
|
|
216
467
|
const vectors = {};
|
|
217
468
|
for (const arrayData of data) {
|
|
218
469
|
const arrayVector = createVector(arrayData.array, arrayData.type);
|
|
219
470
|
vectors[arrayData.name] = arrayVector;
|
|
220
471
|
}
|
|
221
|
-
const table = new
|
|
222
|
-
const arrowBuffer = (0,
|
|
472
|
+
const table = new import_apache_arrow6.Table(vectors);
|
|
473
|
+
const arrowBuffer = (0, import_apache_arrow6.tableToIPC)(table);
|
|
223
474
|
return arrowBuffer;
|
|
224
475
|
}
|
|
225
476
|
function createVector(array, type) {
|
|
226
477
|
switch (type) {
|
|
227
478
|
case 1 /* DATE */:
|
|
228
|
-
return (0,
|
|
479
|
+
return (0, import_apache_arrow6.vectorFromArray)(array);
|
|
229
480
|
case 0 /* FLOAT */:
|
|
230
481
|
default:
|
|
231
|
-
return (0,
|
|
482
|
+
return (0, import_apache_arrow6.vectorFromArray)(array);
|
|
232
483
|
}
|
|
233
484
|
}
|
|
234
485
|
|
|
@@ -252,6 +503,337 @@ var ArrowWriter = {
|
|
|
252
503
|
options: {}
|
|
253
504
|
};
|
|
254
505
|
|
|
506
|
+
// src/geoarrow/get-arrow-bounds.ts
|
|
507
|
+
function updateBoundsFromGeoArrowSamples(flatCoords, nDim, bounds, sampleSize = 100) {
|
|
508
|
+
const numberOfFeatures = flatCoords.length / nDim;
|
|
509
|
+
const sampleStep = Math.max(Math.floor(numberOfFeatures / sampleSize), 1);
|
|
510
|
+
const newBounds = [...bounds];
|
|
511
|
+
for (let i = 0; i < numberOfFeatures; i += sampleStep) {
|
|
512
|
+
const lng = flatCoords[i * nDim];
|
|
513
|
+
const lat = flatCoords[i * nDim + 1];
|
|
514
|
+
if (lng < bounds[0]) {
|
|
515
|
+
newBounds[0] = lng;
|
|
516
|
+
}
|
|
517
|
+
if (lat < newBounds[1]) {
|
|
518
|
+
newBounds[1] = lat;
|
|
519
|
+
}
|
|
520
|
+
if (lng > newBounds[2]) {
|
|
521
|
+
newBounds[2] = lng;
|
|
522
|
+
}
|
|
523
|
+
if (lat > newBounds[3]) {
|
|
524
|
+
newBounds[3] = lat;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return newBounds;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// src/geoarrow/convert-geoarrow-to-binary-geometry.ts
|
|
531
|
+
var BINARY_GEOMETRY_TEMPLATE = {
|
|
532
|
+
globalFeatureIds: { value: new Uint32Array(0), size: 1 },
|
|
533
|
+
positions: { value: new Float32Array(0), size: 2 },
|
|
534
|
+
properties: [],
|
|
535
|
+
numericProps: {},
|
|
536
|
+
featureIds: { value: new Uint32Array(0), size: 1 }
|
|
537
|
+
};
|
|
538
|
+
function getBinaryGeometriesFromArrow(geoColumn, geoEncoding) {
|
|
539
|
+
const featureTypes = {
|
|
540
|
+
polygon: geoEncoding === "geoarrow.multipolygon" || geoEncoding === "geoarrow.polygon",
|
|
541
|
+
point: geoEncoding === "geoarrow.multipoint" || geoEncoding === "geoarrow.point",
|
|
542
|
+
line: geoEncoding === "geoarrow.multilinestring" || geoEncoding === "geoarrow.linestring"
|
|
543
|
+
};
|
|
544
|
+
const chunks = geoColumn.data;
|
|
545
|
+
const bounds = [Infinity, Infinity, -Infinity, -Infinity];
|
|
546
|
+
let globalFeatureIdOffset = 0;
|
|
547
|
+
const binaryGeometries = [];
|
|
548
|
+
for (let c = 0; c < chunks.length; c++) {
|
|
549
|
+
const geometries = chunks[c];
|
|
550
|
+
const { featureIds, flatCoordinateArray, nDim, geomOffset } = getBinaryGeometriesFromChunk(
|
|
551
|
+
geometries,
|
|
552
|
+
geoEncoding
|
|
553
|
+
);
|
|
554
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
555
|
+
const globalFeatureIds = new Uint32Array(numOfVertices);
|
|
556
|
+
for (let i = 0; i < numOfVertices; i++) {
|
|
557
|
+
globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
|
|
558
|
+
}
|
|
559
|
+
const binaryContent = {
|
|
560
|
+
globalFeatureIds: { value: globalFeatureIds, size: 1 },
|
|
561
|
+
positions: {
|
|
562
|
+
value: flatCoordinateArray,
|
|
563
|
+
size: nDim
|
|
564
|
+
},
|
|
565
|
+
featureIds: { value: featureIds, size: 1 },
|
|
566
|
+
// eslint-disable-next-line no-loop-func
|
|
567
|
+
properties: [...Array(geometries.length).keys()].map((i) => ({
|
|
568
|
+
index: i + globalFeatureIdOffset
|
|
569
|
+
}))
|
|
570
|
+
};
|
|
571
|
+
globalFeatureIdOffset += geometries.length;
|
|
572
|
+
binaryGeometries.push({
|
|
573
|
+
shape: "binary-feature-collection",
|
|
574
|
+
points: {
|
|
575
|
+
type: "Point",
|
|
576
|
+
...BINARY_GEOMETRY_TEMPLATE,
|
|
577
|
+
...featureTypes.point ? binaryContent : {}
|
|
578
|
+
},
|
|
579
|
+
lines: {
|
|
580
|
+
type: "LineString",
|
|
581
|
+
...BINARY_GEOMETRY_TEMPLATE,
|
|
582
|
+
...featureTypes.line ? binaryContent : {},
|
|
583
|
+
pathIndices: { value: featureTypes.line ? geomOffset : new Uint16Array(0), size: 1 }
|
|
584
|
+
},
|
|
585
|
+
polygons: {
|
|
586
|
+
type: "Polygon",
|
|
587
|
+
...BINARY_GEOMETRY_TEMPLATE,
|
|
588
|
+
...featureTypes.polygon ? binaryContent : {},
|
|
589
|
+
polygonIndices: {
|
|
590
|
+
// TODO why deck.gl's tessellatePolygon performance is not good when using geometryIndicies
|
|
591
|
+
// even when there is no hole in any polygon
|
|
592
|
+
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
593
|
+
size: 1
|
|
594
|
+
},
|
|
595
|
+
primitivePolygonIndices: {
|
|
596
|
+
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
597
|
+
size: 1
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
updateBoundsFromGeoArrowSamples(flatCoordinateArray, nDim, bounds);
|
|
602
|
+
}
|
|
603
|
+
return { binaryGeometries, bounds, featureTypes };
|
|
604
|
+
}
|
|
605
|
+
function getBinaryGeometriesFromChunk(chunk, geoEncoding) {
|
|
606
|
+
switch (geoEncoding) {
|
|
607
|
+
case "geoarrow.point":
|
|
608
|
+
case "geoarrow.multipoint":
|
|
609
|
+
return getBinaryPointsFromChunk(chunk, geoEncoding);
|
|
610
|
+
case "geoarrow.linestring":
|
|
611
|
+
case "geoarrow.multilinestring":
|
|
612
|
+
return getBinaryLinesFromChunk(chunk, geoEncoding);
|
|
613
|
+
case "geoarrow.polygon":
|
|
614
|
+
case "geoarrow.multipolygon":
|
|
615
|
+
return getBinaryPolygonsFromChunk(chunk, geoEncoding);
|
|
616
|
+
default:
|
|
617
|
+
throw Error("invalid geoarrow encoding");
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
function getBinaryPolygonsFromChunk(chunk, geoEncoding) {
|
|
621
|
+
const isMultiPolygon = geoEncoding === "geoarrow.multipolygon";
|
|
622
|
+
const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
|
|
623
|
+
const ringData = polygonData.children[0];
|
|
624
|
+
const pointData = ringData.children[0];
|
|
625
|
+
const coordData = pointData.children[0];
|
|
626
|
+
const nDim = pointData.stride;
|
|
627
|
+
const geomOffset = ringData.valueOffsets;
|
|
628
|
+
const flatCoordinateArray = coordData.values;
|
|
629
|
+
const geometryIndicies = new Uint16Array(chunk.length + 1);
|
|
630
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
631
|
+
geometryIndicies[i] = geomOffset[chunk.valueOffsets[i]];
|
|
632
|
+
}
|
|
633
|
+
geometryIndicies[chunk.length] = flatCoordinateArray.length / nDim;
|
|
634
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
635
|
+
const featureIds = new Uint32Array(numOfVertices);
|
|
636
|
+
for (let i = 0; i < chunk.length - 1; i++) {
|
|
637
|
+
const startIdx = geomOffset[chunk.valueOffsets[i]];
|
|
638
|
+
const endIdx = geomOffset[chunk.valueOffsets[i + 1]];
|
|
639
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
640
|
+
featureIds[j] = i;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return {
|
|
644
|
+
featureIds,
|
|
645
|
+
flatCoordinateArray,
|
|
646
|
+
nDim,
|
|
647
|
+
geomOffset,
|
|
648
|
+
geometryIndicies
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
function getBinaryLinesFromChunk(chunk, geoEncoding) {
|
|
652
|
+
const isMultiLineString = geoEncoding === "geoarrow.multilinestring";
|
|
653
|
+
const lineData = isMultiLineString ? chunk.children[0] : chunk;
|
|
654
|
+
const pointData = lineData.children[0];
|
|
655
|
+
const coordData = pointData.children[0];
|
|
656
|
+
const nDim = pointData.stride;
|
|
657
|
+
const geomOffset = lineData.valueOffsets;
|
|
658
|
+
const flatCoordinateArray = coordData.values;
|
|
659
|
+
const geometryIndicies = new Uint16Array(0);
|
|
660
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
661
|
+
const featureIds = new Uint32Array(numOfVertices);
|
|
662
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
663
|
+
const startIdx = geomOffset[i];
|
|
664
|
+
const endIdx = geomOffset[i + 1];
|
|
665
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
666
|
+
featureIds[j] = i;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return {
|
|
670
|
+
featureIds,
|
|
671
|
+
flatCoordinateArray,
|
|
672
|
+
nDim,
|
|
673
|
+
geomOffset,
|
|
674
|
+
geometryIndicies
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function getBinaryPointsFromChunk(chunk, geoEncoding) {
|
|
678
|
+
const isMultiPoint = geoEncoding === "geoarrow.multipoint";
|
|
679
|
+
const pointData = isMultiPoint ? chunk.children[0] : chunk;
|
|
680
|
+
const coordData = pointData.children[0];
|
|
681
|
+
const nDim = pointData.stride;
|
|
682
|
+
const flatCoordinateArray = coordData.values;
|
|
683
|
+
const geometryIndicies = new Uint16Array(0);
|
|
684
|
+
const geomOffset = new Int32Array(0);
|
|
685
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
686
|
+
const featureIds = new Uint32Array(numOfVertices);
|
|
687
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
688
|
+
featureIds[i] = i;
|
|
689
|
+
}
|
|
690
|
+
return {
|
|
691
|
+
featureIds,
|
|
692
|
+
flatCoordinateArray,
|
|
693
|
+
nDim,
|
|
694
|
+
geomOffset,
|
|
695
|
+
geometryIndicies
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// src/geoarrow/convert-geoarrow-to-geojson.ts
|
|
700
|
+
function parseGeometryFromArrow(rawData) {
|
|
701
|
+
var _a;
|
|
702
|
+
const encoding = (_a = rawData.encoding) == null ? void 0 : _a.toLowerCase();
|
|
703
|
+
const data = rawData.data;
|
|
704
|
+
if (!encoding || !data) {
|
|
705
|
+
return null;
|
|
706
|
+
}
|
|
707
|
+
let geometry;
|
|
708
|
+
switch (encoding) {
|
|
709
|
+
case "geoarrow.multipolygon":
|
|
710
|
+
geometry = arrowMultiPolygonToFeature(data);
|
|
711
|
+
break;
|
|
712
|
+
case "geoarrow.polygon":
|
|
713
|
+
geometry = arrowPolygonToFeature(data);
|
|
714
|
+
break;
|
|
715
|
+
case "geoarrow.multipoint":
|
|
716
|
+
geometry = arrowMultiPointToFeature(data);
|
|
717
|
+
break;
|
|
718
|
+
case "geoarrow.point":
|
|
719
|
+
geometry = arrowPointToFeature(data);
|
|
720
|
+
break;
|
|
721
|
+
case "geoarrow.multilinestring":
|
|
722
|
+
geometry = arrowMultiLineStringToFeature(data);
|
|
723
|
+
break;
|
|
724
|
+
case "geoarrow.linestring":
|
|
725
|
+
geometry = arrowLineStringToFeature(data);
|
|
726
|
+
break;
|
|
727
|
+
default: {
|
|
728
|
+
throw Error(`GeoArrow encoding not supported ${encoding}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return {
|
|
732
|
+
type: "Feature",
|
|
733
|
+
geometry,
|
|
734
|
+
properties: {}
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
function arrowMultiPolygonToFeature(arrowMultiPolygon) {
|
|
738
|
+
const multiPolygon = [];
|
|
739
|
+
for (let m = 0; m < arrowMultiPolygon.length; m++) {
|
|
740
|
+
const arrowPolygon = arrowMultiPolygon.get(m);
|
|
741
|
+
const polygon = [];
|
|
742
|
+
for (let i = 0; arrowPolygon && i < (arrowPolygon == null ? void 0 : arrowPolygon.length); i++) {
|
|
743
|
+
const arrowRing = arrowPolygon == null ? void 0 : arrowPolygon.get(i);
|
|
744
|
+
const ring = [];
|
|
745
|
+
for (let j = 0; arrowRing && j < arrowRing.length; j++) {
|
|
746
|
+
const arrowCoord = arrowRing.get(j);
|
|
747
|
+
const coord = Array.from(arrowCoord);
|
|
748
|
+
ring.push(coord);
|
|
749
|
+
}
|
|
750
|
+
polygon.push(ring);
|
|
751
|
+
}
|
|
752
|
+
multiPolygon.push(polygon);
|
|
753
|
+
}
|
|
754
|
+
const geometry = {
|
|
755
|
+
type: "MultiPolygon",
|
|
756
|
+
coordinates: multiPolygon
|
|
757
|
+
};
|
|
758
|
+
return geometry;
|
|
759
|
+
}
|
|
760
|
+
function arrowPolygonToFeature(arrowPolygon) {
|
|
761
|
+
const polygon = [];
|
|
762
|
+
for (let i = 0; arrowPolygon && i < arrowPolygon.length; i++) {
|
|
763
|
+
const arrowRing = arrowPolygon.get(i);
|
|
764
|
+
const ring = [];
|
|
765
|
+
for (let j = 0; arrowRing && j < arrowRing.length; j++) {
|
|
766
|
+
const arrowCoord = arrowRing.get(j);
|
|
767
|
+
const coords = Array.from(arrowCoord);
|
|
768
|
+
ring.push(coords);
|
|
769
|
+
}
|
|
770
|
+
polygon.push(ring);
|
|
771
|
+
}
|
|
772
|
+
const geometry = {
|
|
773
|
+
type: "Polygon",
|
|
774
|
+
coordinates: polygon
|
|
775
|
+
};
|
|
776
|
+
return geometry;
|
|
777
|
+
}
|
|
778
|
+
function arrowMultiPointToFeature(arrowMultiPoint) {
|
|
779
|
+
const multiPoint = [];
|
|
780
|
+
for (let i = 0; arrowMultiPoint && i < arrowMultiPoint.length; i++) {
|
|
781
|
+
const arrowPoint = arrowMultiPoint.get(i);
|
|
782
|
+
if (arrowPoint) {
|
|
783
|
+
const coord = Array.from(arrowPoint);
|
|
784
|
+
multiPoint.push(coord);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const geometry = {
|
|
788
|
+
type: "MultiPoint",
|
|
789
|
+
coordinates: multiPoint
|
|
790
|
+
};
|
|
791
|
+
return geometry;
|
|
792
|
+
}
|
|
793
|
+
function arrowPointToFeature(arrowPoint) {
|
|
794
|
+
const point = Array.from(arrowPoint);
|
|
795
|
+
const geometry = {
|
|
796
|
+
type: "Point",
|
|
797
|
+
coordinates: point
|
|
798
|
+
};
|
|
799
|
+
return geometry;
|
|
800
|
+
}
|
|
801
|
+
function arrowMultiLineStringToFeature(arrowMultiLineString) {
|
|
802
|
+
const multiLineString = [];
|
|
803
|
+
for (let i = 0; arrowMultiLineString && i < arrowMultiLineString.length; i++) {
|
|
804
|
+
const arrowLineString = arrowMultiLineString.get(i);
|
|
805
|
+
const lineString = [];
|
|
806
|
+
for (let j = 0; arrowLineString && j < arrowLineString.length; j++) {
|
|
807
|
+
const arrowCoord = arrowLineString.get(j);
|
|
808
|
+
if (arrowCoord) {
|
|
809
|
+
const coords = Array.from(arrowCoord);
|
|
810
|
+
lineString.push(coords);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
multiLineString.push(lineString);
|
|
814
|
+
}
|
|
815
|
+
const geometry = {
|
|
816
|
+
type: "MultiLineString",
|
|
817
|
+
coordinates: multiLineString
|
|
818
|
+
};
|
|
819
|
+
return geometry;
|
|
820
|
+
}
|
|
821
|
+
function arrowLineStringToFeature(arrowLineString) {
|
|
822
|
+
const lineString = [];
|
|
823
|
+
for (let i = 0; arrowLineString && i < arrowLineString.length; i++) {
|
|
824
|
+
const arrowCoord = arrowLineString.get(i);
|
|
825
|
+
if (arrowCoord) {
|
|
826
|
+
const coords = Array.from(arrowCoord);
|
|
827
|
+
lineString.push(coords);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
const geometry = {
|
|
831
|
+
type: "LineString",
|
|
832
|
+
coordinates: lineString
|
|
833
|
+
};
|
|
834
|
+
return geometry;
|
|
835
|
+
}
|
|
836
|
+
|
|
255
837
|
// src/index.ts
|
|
256
838
|
import_schema3.TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
257
839
|
var ArrowLoader2 = {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { ArrowTableBatch, ColumnarTable, ObjectRowTable } from '@loaders.gl
|
|
|
4
4
|
import type { ArrowTable } from './lib/arrow-table';
|
|
5
5
|
import { ArrowLoader as ArrowWorkerLoader } from './arrow-loader';
|
|
6
6
|
export { getArrowType } from './schema/arrow-type-utils';
|
|
7
|
+
export { serializeArrowSchema, deserializeArrowSchema, serializeArrowMetadata, deserializeArrowMetadata, serializeArrowField, deserializeArrowField, serializeArrowType, deserializeArrowType } from './schema/convert-arrow-schema';
|
|
7
8
|
export type { ArrowTable, ArrowTableBatch } from './lib/arrow-table';
|
|
8
9
|
export { VECTOR_TYPES } from './types';
|
|
9
10
|
export { ArrowWriter } from './arrow-writer';
|
|
@@ -11,4 +12,8 @@ export type { ArrowLoaderOptions };
|
|
|
11
12
|
export { ArrowWorkerLoader };
|
|
12
13
|
/** ArrowJS table loader */
|
|
13
14
|
export declare const ArrowLoader: LoaderWithParser<ArrowTable | ColumnarTable | ObjectRowTable, ArrowTableBatch, ArrowLoaderOptions>;
|
|
15
|
+
export type { GeoArrowEncoding } from '@loaders.gl/gis';
|
|
16
|
+
export type { BinaryDataFromGeoArrow } from './geoarrow/convert-geoarrow-to-binary-geometry';
|
|
17
|
+
export { getBinaryGeometriesFromArrow } from './geoarrow/convert-geoarrow-to-binary-geometry';
|
|
18
|
+
export { parseGeometryFromArrow } from './geoarrow/convert-geoarrow-to-geojson';
|
|
14
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAC,eAAe,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAWhE,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAIvD,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AAGvC,YAAY,EAAC,UAAU,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AAIrC,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAI3C,YAAY,EAAC,kBAAkB,EAAC,CAAC;AACjC,OAAO,EAAC,iBAAiB,EAAC,CAAC;AAE3B,2BAA2B;AAC3B,eAAO,MAAM,WAAW,EAAE,gBAAgB,CACxC,UAAU,GAAG,aAAa,GAAG,cAAc,EAC3C,eAAe,EACf,kBAAkB,CAOnB,CAAC;AAGF,YAAY,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAItD,YAAY,EAAC,sBAAsB,EAAC,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAC,4BAA4B,EAAC,MAAM,gDAAgD,CAAC;AAE5F,OAAO,EAAC,sBAAsB,EAAC,MAAM,wCAAwC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,9 @@ import { ArrowLoader as ArrowWorkerLoader } from "./arrow-loader.js";
|
|
|
3
3
|
import parseSync from "./lib/parse-arrow-sync.js";
|
|
4
4
|
import { parseArrowInBatches } from "./lib/parse-arrow-in-batches.js";
|
|
5
5
|
import { ArrowTableBatchAggregator } from "./lib/arrow-table-batch.js";
|
|
6
|
-
export { getArrowType } from "./schema/arrow-type-utils.js";
|
|
7
6
|
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
7
|
+
export { getArrowType } from "./schema/arrow-type-utils.js";
|
|
8
|
+
export { serializeArrowSchema, deserializeArrowSchema, serializeArrowMetadata, deserializeArrowMetadata, serializeArrowField, deserializeArrowField, serializeArrowType, deserializeArrowType } from "./schema/convert-arrow-schema.js";
|
|
8
9
|
export { VECTOR_TYPES } from "./types.js";
|
|
9
10
|
export { ArrowWriter } from "./arrow-writer.js";
|
|
10
11
|
export { ArrowWorkerLoader };
|
|
@@ -14,4 +15,6 @@ export const ArrowLoader = {
|
|
|
14
15
|
parseSync,
|
|
15
16
|
parseInBatches: parseArrowInBatches
|
|
16
17
|
};
|
|
18
|
+
export { getBinaryGeometriesFromArrow } from "./geoarrow/convert-geoarrow-to-binary-geometry.js";
|
|
19
|
+
export { parseGeometryFromArrow } from "./geoarrow/convert-geoarrow-to-geojson.js";
|
|
17
20
|
//# sourceMappingURL=index.js.map
|