@loaders.gl/arrow 4.0.0 → 4.0.2

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 (82) hide show
  1. package/dist/arrow-loader.d.ts.map +1 -1
  2. package/dist/arrow-loader.js.map +1 -1
  3. package/dist/arrow-worker.js +34 -26
  4. package/dist/arrow-writer.d.ts.map +1 -1
  5. package/dist/arrow-writer.js +6 -3
  6. package/dist/arrow-writer.js.map +1 -1
  7. package/dist/dist.dev.js +658 -6
  8. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +40 -0
  9. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -0
  10. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +189 -0
  11. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -0
  12. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts +19 -0
  13. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts.map +1 -0
  14. package/dist/geoarrow/convert-geoarrow-to-geojson.js +138 -0
  15. package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +1 -0
  16. package/dist/geoarrow/get-arrow-bounds.d.ts +11 -0
  17. package/dist/geoarrow/get-arrow-bounds.d.ts.map +1 -0
  18. package/dist/geoarrow/get-arrow-bounds.js +24 -0
  19. package/dist/geoarrow/get-arrow-bounds.js.map +1 -0
  20. package/dist/index.cjs +627 -32
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +5 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/lib/arrow-table-batch.d.ts +2 -2
  26. package/dist/lib/arrow-table-batch.d.ts.map +1 -1
  27. package/dist/lib/arrow-table-batch.js +7 -7
  28. package/dist/lib/arrow-table-batch.js.map +1 -1
  29. package/dist/lib/arrow-table.d.ts +3 -3
  30. package/dist/lib/arrow-table.d.ts.map +1 -1
  31. package/dist/lib/arrow-table.js.map +1 -1
  32. package/dist/lib/encode-arrow.js +5 -5
  33. package/dist/lib/encode-arrow.js.map +1 -1
  34. package/dist/lib/parse-arrow-in-batches.js +3 -3
  35. package/dist/lib/parse-arrow-in-batches.js.map +1 -1
  36. package/dist/lib/parse-arrow-sync.d.ts.map +1 -1
  37. package/dist/lib/parse-arrow-sync.js +3 -3
  38. package/dist/lib/parse-arrow-sync.js.map +1 -1
  39. package/dist/schema/arrow-type-utils.d.ts +3 -2
  40. package/dist/schema/arrow-type-utils.d.ts.map +1 -1
  41. package/dist/schema/arrow-type-utils.js +9 -9
  42. package/dist/schema/arrow-type-utils.js.map +1 -1
  43. package/dist/schema/convert-arrow-schema.d.ts +19 -0
  44. package/dist/schema/convert-arrow-schema.d.ts.map +1 -0
  45. package/dist/schema/convert-arrow-schema.js +232 -0
  46. package/dist/schema/convert-arrow-schema.js.map +1 -0
  47. package/dist/{lib/convert-table.d.ts → tables/convert-arrow-to-table.d.ts} +4 -4
  48. package/dist/tables/convert-arrow-to-table.d.ts.map +1 -0
  49. package/dist/{lib/convert-table.js → tables/convert-arrow-to-table.js} +1 -1
  50. package/dist/tables/convert-arrow-to-table.js.map +1 -0
  51. package/dist/{schema → tables}/convert-table-to-arrow.d.ts.map +1 -1
  52. package/dist/{schema → tables}/convert-table-to-arrow.js.map +1 -1
  53. package/dist/types.d.ts.map +1 -1
  54. package/dist/types.js.map +1 -1
  55. package/dist/workers/arrow-worker.js.map +1 -1
  56. package/package.json +5 -4
  57. package/src/arrow-loader.ts +1 -0
  58. package/src/arrow-writer.ts +7 -3
  59. package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +260 -0
  60. package/src/geoarrow/convert-geoarrow-to-geojson.ts +192 -0
  61. package/src/geoarrow/get-arrow-bounds.ts +40 -0
  62. package/src/index.ts +33 -4
  63. package/src/lib/arrow-table-batch.ts +13 -23
  64. package/src/lib/arrow-table.ts +3 -3
  65. package/src/lib/encode-arrow.ts +8 -8
  66. package/src/lib/parse-arrow-in-batches.ts +4 -4
  67. package/src/lib/parse-arrow-sync.ts +6 -3
  68. package/src/schema/arrow-type-utils.ts +11 -29
  69. package/src/schema/convert-arrow-schema.ts +265 -0
  70. package/src/{lib/convert-table.ts → tables/convert-arrow-to-table.ts} +4 -3
  71. package/src/types.ts +3 -0
  72. package/src/workers/arrow-worker.ts +3 -0
  73. package/dist/lib/convert-table.d.ts.map +0 -1
  74. package/dist/lib/convert-table.js.map +0 -1
  75. package/dist/schema/convert-schema-arrow.d.ts +0 -13
  76. package/dist/schema/convert-schema-arrow.d.ts.map +0 -1
  77. package/dist/schema/convert-schema-arrow.js +0 -158
  78. package/dist/schema/convert-schema-arrow.js.map +0 -1
  79. package/src/schema/convert-schema-arrow.ts +0 -233
  80. /package/dist/{schema → tables}/convert-table-to-arrow.d.ts +0 -0
  81. /package/dist/{schema → tables}/convert-table-to-arrow.js +0 -0
  82. /package/src/{schema → tables}/convert-table-to-arrow.ts +0 -0
package/dist/dist.dev.js CHANGED
@@ -30,8 +30,20 @@ var __exports__ = (() => {
30
30
  ArrowLoader: () => ArrowLoader2,
31
31
  ArrowWorkerLoader: () => ArrowLoader,
32
32
  ArrowWriter: () => ArrowWriter,
33
+ BINARY_GEOMETRY_TEMPLATE: () => BINARY_GEOMETRY_TEMPLATE,
33
34
  VECTOR_TYPES: () => VECTOR_TYPES,
34
- getArrowType: () => getArrowType
35
+ deserializeArrowField: () => deserializeArrowField,
36
+ deserializeArrowMetadata: () => deserializeArrowMetadata,
37
+ deserializeArrowSchema: () => deserializeArrowSchema,
38
+ deserializeArrowType: () => deserializeArrowType,
39
+ getArrowType: () => getArrowType,
40
+ getBinaryGeometriesFromArrow: () => getBinaryGeometriesFromArrow,
41
+ parseGeometryFromArrow: () => parseGeometryFromArrow,
42
+ serializeArrowField: () => serializeArrowField,
43
+ serializeArrowMetadata: () => serializeArrowMetadata,
44
+ serializeArrowSchema: () => serializeArrowSchema,
45
+ serializeArrowType: () => serializeArrowType,
46
+ updateBoundsFromGeoArrowSamples: () => updateBoundsFromGeoArrowSamples
35
47
  });
36
48
 
37
49
  // ../schema/src/lib/table/batches/base-table-batch-aggregator.ts
@@ -719,7 +731,7 @@ var __exports__ = (() => {
719
731
  }
720
732
  }
721
733
  function makeArrowTable(table) {
722
- const _makeArrowTable = globalThis.__luma?._makeArrowTable;
734
+ const _makeArrowTable = globalThis.__loaders?._makeArrowTable;
723
735
  if (!_makeArrowTable) {
724
736
  throw new Error("");
725
737
  }
@@ -2105,6 +2117,11 @@ var __exports__ = (() => {
2105
2117
  proto.ArrayType = Int32Array;
2106
2118
  return proto[Symbol.toStringTag] = "Date";
2107
2119
  })(Date_.prototype);
2120
+ var DateDay = class extends Date_ {
2121
+ constructor() {
2122
+ super(DateUnit.DAY);
2123
+ }
2124
+ };
2108
2125
  var DateMillisecond = class extends Date_ {
2109
2126
  constructor() {
2110
2127
  super(DateUnit.MILLISECOND);
@@ -2138,6 +2155,26 @@ var __exports__ = (() => {
2138
2155
  proto.bitWidth = null;
2139
2156
  return proto[Symbol.toStringTag] = "Time";
2140
2157
  })(Time_.prototype);
2158
+ var TimeSecond = class extends Time_ {
2159
+ constructor() {
2160
+ super(TimeUnit.SECOND, 32);
2161
+ }
2162
+ };
2163
+ var TimeMillisecond = class extends Time_ {
2164
+ constructor() {
2165
+ super(TimeUnit.MILLISECOND, 32);
2166
+ }
2167
+ };
2168
+ var TimeMicrosecond = class extends Time_ {
2169
+ constructor() {
2170
+ super(TimeUnit.MICROSECOND, 64);
2171
+ }
2172
+ };
2173
+ var TimeNanosecond = class extends Time_ {
2174
+ constructor() {
2175
+ super(TimeUnit.NANOSECOND, 64);
2176
+ }
2177
+ };
2141
2178
  var Timestamp_ = class extends DataType {
2142
2179
  constructor(unit, timezone) {
2143
2180
  super();
@@ -2158,6 +2195,26 @@ var __exports__ = (() => {
2158
2195
  proto.ArrayType = Int32Array;
2159
2196
  return proto[Symbol.toStringTag] = "Timestamp";
2160
2197
  })(Timestamp_.prototype);
2198
+ var TimestampSecond = class extends Timestamp_ {
2199
+ constructor(timezone) {
2200
+ super(TimeUnit.SECOND, timezone);
2201
+ }
2202
+ };
2203
+ var TimestampMillisecond = class extends Timestamp_ {
2204
+ constructor(timezone) {
2205
+ super(TimeUnit.MILLISECOND, timezone);
2206
+ }
2207
+ };
2208
+ var TimestampMicrosecond = class extends Timestamp_ {
2209
+ constructor(timezone) {
2210
+ super(TimeUnit.MICROSECOND, timezone);
2211
+ }
2212
+ };
2213
+ var TimestampNanosecond = class extends Timestamp_ {
2214
+ constructor(timezone) {
2215
+ super(TimeUnit.NANOSECOND, timezone);
2216
+ }
2217
+ };
2161
2218
  var Interval_ = class extends DataType {
2162
2219
  constructor(unit) {
2163
2220
  super();
@@ -2176,6 +2233,16 @@ var __exports__ = (() => {
2176
2233
  proto.ArrayType = Int32Array;
2177
2234
  return proto[Symbol.toStringTag] = "Interval";
2178
2235
  })(Interval_.prototype);
2236
+ var IntervalDayTime = class extends Interval_ {
2237
+ constructor() {
2238
+ super(IntervalUnit.DAY_TIME);
2239
+ }
2240
+ };
2241
+ var IntervalYearMonth = class extends Interval_ {
2242
+ constructor() {
2243
+ super(IntervalUnit.YEAR_MONTH);
2244
+ }
2245
+ };
2179
2246
  var List = class extends DataType {
2180
2247
  constructor(child) {
2181
2248
  super();
@@ -12273,7 +12340,7 @@ return true;`);
12273
12340
  RecordBatchFileWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12274
12341
  RecordBatchStreamWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12275
12342
 
12276
- // src/lib/convert-table.ts
12343
+ // src/tables/convert-arrow-to-table.ts
12277
12344
  function convertApacheArrowToArrowTable(arrowTable) {
12278
12345
  return {
12279
12346
  shape: "arrow-table",
@@ -12413,6 +12480,238 @@ return true;`);
12413
12480
  }
12414
12481
  }
12415
12482
 
12483
+ // src/schema/convert-arrow-schema.ts
12484
+ function serializeArrowSchema(arrowSchema) {
12485
+ return {
12486
+ fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
12487
+ metadata: serializeArrowMetadata(arrowSchema.metadata)
12488
+ };
12489
+ }
12490
+ function deserializeArrowSchema(schema) {
12491
+ return new Schema2(schema.fields.map((field) => deserializeArrowField(field)), deserializeArrowMetadata(schema.metadata));
12492
+ }
12493
+ function serializeArrowMetadata(arrowMetadata) {
12494
+ return Object.fromEntries(arrowMetadata);
12495
+ }
12496
+ function deserializeArrowMetadata(metadata) {
12497
+ return metadata ? new Map(Object.entries(metadata)) : /* @__PURE__ */ new Map();
12498
+ }
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
+ };
12506
+ }
12507
+ function deserializeArrowField(field) {
12508
+ return new Field2(field.name, deserializeArrowType(field.type), field.nullable, deserializeArrowMetadata(field.metadata));
12509
+ }
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 Date:
12558
+ const dateUnit = arrowType.unit;
12559
+ return dateUnit === DateUnit.DAY ? "date-day" : "date-millisecond";
12560
+ case DateDay:
12561
+ return "date-day";
12562
+ case DateMillisecond:
12563
+ return "date-millisecond";
12564
+ case Time_:
12565
+ const timeUnit = arrowType.unit;
12566
+ switch (timeUnit) {
12567
+ case TimeUnit.SECOND:
12568
+ return "time-second";
12569
+ case TimeUnit.MILLISECOND:
12570
+ return "time-millisecond";
12571
+ case TimeUnit.MICROSECOND:
12572
+ return "time-microsecond";
12573
+ case TimeUnit.NANOSECOND:
12574
+ return "time-nanosecond";
12575
+ default:
12576
+ return "time-second";
12577
+ }
12578
+ case TimeMillisecond:
12579
+ return "time-millisecond";
12580
+ case TimeSecond:
12581
+ return "time-second";
12582
+ case TimeMicrosecond:
12583
+ return "time-microsecond";
12584
+ case TimeNanosecond:
12585
+ return "time-nanosecond";
12586
+ case Timestamp_:
12587
+ const timeStampUnit = arrowType.unit;
12588
+ switch (timeStampUnit) {
12589
+ case TimeUnit.SECOND:
12590
+ return "timestamp-second";
12591
+ case TimeUnit.MILLISECOND:
12592
+ return "timestamp-millisecond";
12593
+ case TimeUnit.MICROSECOND:
12594
+ return "timestamp-microsecond";
12595
+ case TimeUnit.NANOSECOND:
12596
+ return "timestamp-nanosecond";
12597
+ default:
12598
+ return "timestamp-second";
12599
+ }
12600
+ case TimestampSecond:
12601
+ return "timestamp-second";
12602
+ case TimestampMillisecond:
12603
+ return "timestamp-millisecond";
12604
+ case TimestampMicrosecond:
12605
+ return "timestamp-microsecond";
12606
+ case TimestampNanosecond:
12607
+ return "timestamp-nanosecond";
12608
+ case Interval_:
12609
+ const intervalUnit = arrowType.unit;
12610
+ switch (intervalUnit) {
12611
+ case IntervalUnit.DAY_TIME:
12612
+ return "interval-daytime";
12613
+ case IntervalUnit.YEAR_MONTH:
12614
+ return "interval-yearmonth";
12615
+ default:
12616
+ return "interval-daytime";
12617
+ }
12618
+ case IntervalDayTime:
12619
+ return "interval-daytime";
12620
+ case IntervalYearMonth:
12621
+ return "interval-yearmonth";
12622
+ case List:
12623
+ const listType = arrowType;
12624
+ const listField = listType.valueField;
12625
+ return {
12626
+ type: "list",
12627
+ children: [serializeArrowField(listField)]
12628
+ };
12629
+ case FixedSizeList:
12630
+ return {
12631
+ type: "fixed-size-list",
12632
+ listSize: arrowType.listSize,
12633
+ children: [serializeArrowField(arrowType.children[0])]
12634
+ };
12635
+ default:
12636
+ throw new Error("array type not supported");
12637
+ }
12638
+ }
12639
+ function deserializeArrowType(dataType) {
12640
+ if (typeof dataType === "object") {
12641
+ switch (dataType.type) {
12642
+ case "list":
12643
+ const field = deserializeArrowField(dataType.children[0]);
12644
+ return new List(field);
12645
+ case "fixed-size-list":
12646
+ const child = deserializeArrowField(dataType.children[0]);
12647
+ return new FixedSizeList(dataType.listSize, child);
12648
+ case "struct":
12649
+ const children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
12650
+ return new Struct(children);
12651
+ default:
12652
+ throw new Error("array type not supported");
12653
+ }
12654
+ }
12655
+ switch (dataType) {
12656
+ case "null":
12657
+ return new Null();
12658
+ case "binary":
12659
+ return new Binary();
12660
+ case "bool":
12661
+ return new Bool();
12662
+ case "int8":
12663
+ return new Int8();
12664
+ case "int16":
12665
+ return new Int16();
12666
+ case "int32":
12667
+ return new Int32();
12668
+ case "int64":
12669
+ return new Int64();
12670
+ case "uint8":
12671
+ return new Uint8();
12672
+ case "uint16":
12673
+ return new Uint16();
12674
+ case "uint32":
12675
+ return new Uint32();
12676
+ case "uint64":
12677
+ return new Uint64();
12678
+ case "float16":
12679
+ return new Float16();
12680
+ case "float32":
12681
+ return new Float32();
12682
+ case "float64":
12683
+ return new Float64();
12684
+ case "utf8":
12685
+ return new Utf8();
12686
+ case "date-day":
12687
+ return new DateDay();
12688
+ case "date-millisecond":
12689
+ return new DateMillisecond();
12690
+ case "time-second":
12691
+ return new TimeSecond();
12692
+ case "time-millisecond":
12693
+ return new TimeMillisecond();
12694
+ case "time-microsecond":
12695
+ return new TimeMicrosecond();
12696
+ case "time-nanosecond":
12697
+ return new TimeNanosecond();
12698
+ case "timestamp-second":
12699
+ return new TimestampSecond();
12700
+ case "timestamp-millisecond":
12701
+ return new TimestampMillisecond();
12702
+ case "timestamp-microsecond":
12703
+ return new TimestampMicrosecond();
12704
+ case "timestamp-nanosecond":
12705
+ return new TimestampNanosecond();
12706
+ case "interval-daytime":
12707
+ return new IntervalDayTime();
12708
+ case "interval-yearmonth":
12709
+ return new IntervalYearMonth();
12710
+ default:
12711
+ throw new Error("array type not supported");
12712
+ }
12713
+ }
12714
+
12416
12715
  // src/types.ts
12417
12716
  var VECTOR_TYPES = function(VECTOR_TYPES2) {
12418
12717
  VECTOR_TYPES2[VECTOR_TYPES2["FLOAT"] = 0] = "FLOAT";
@@ -12450,13 +12749,366 @@ return true;`);
12450
12749
  version: VERSION2,
12451
12750
  extensions: ["arrow", "feather"],
12452
12751
  mimeTypes: ["application/vnd.apache.arrow.file", "application/vnd.apache.arrow.stream", "application/octet-stream"],
12453
- encodeSync(data, options) {
12752
+ binary: true,
12753
+ options: {},
12754
+ encode: async function encodeArrow(data, options) {
12454
12755
  return encodeArrowSync(data);
12455
12756
  },
12456
- binary: true,
12457
- options: {}
12757
+ encodeSync(data, options) {
12758
+ return encodeArrowSync(data);
12759
+ }
12458
12760
  };
12459
12761
 
12762
+ // src/geoarrow/get-arrow-bounds.ts
12763
+ function updateBoundsFromGeoArrowSamples(flatCoords, nDim, bounds, sampleSize = 100) {
12764
+ const numberOfFeatures = flatCoords.length / nDim;
12765
+ const sampleStep = Math.max(Math.floor(numberOfFeatures / sampleSize), 1);
12766
+ const newBounds = [...bounds];
12767
+ for (let i = 0; i < numberOfFeatures; i += sampleStep) {
12768
+ const lng = flatCoords[i * nDim];
12769
+ const lat = flatCoords[i * nDim + 1];
12770
+ if (lng < newBounds[0]) {
12771
+ newBounds[0] = lng;
12772
+ }
12773
+ if (lat < newBounds[1]) {
12774
+ newBounds[1] = lat;
12775
+ }
12776
+ if (lng > newBounds[2]) {
12777
+ newBounds[2] = lng;
12778
+ }
12779
+ if (lat > newBounds[3]) {
12780
+ newBounds[3] = lat;
12781
+ }
12782
+ }
12783
+ return newBounds;
12784
+ }
12785
+
12786
+ // src/geoarrow/convert-geoarrow-to-binary-geometry.ts
12787
+ var BINARY_GEOMETRY_TEMPLATE = {
12788
+ globalFeatureIds: {
12789
+ value: new Uint32Array(0),
12790
+ size: 1
12791
+ },
12792
+ positions: {
12793
+ value: new Float32Array(0),
12794
+ size: 2
12795
+ },
12796
+ properties: [],
12797
+ numericProps: {},
12798
+ featureIds: {
12799
+ value: new Uint32Array(0),
12800
+ size: 1
12801
+ }
12802
+ };
12803
+ function getBinaryGeometriesFromArrow(geoColumn, geoEncoding) {
12804
+ const featureTypes = {
12805
+ polygon: geoEncoding === "geoarrow.multipolygon" || geoEncoding === "geoarrow.polygon",
12806
+ point: geoEncoding === "geoarrow.multipoint" || geoEncoding === "geoarrow.point",
12807
+ line: geoEncoding === "geoarrow.multilinestring" || geoEncoding === "geoarrow.linestring"
12808
+ };
12809
+ const chunks = geoColumn.data;
12810
+ let bounds = [Infinity, Infinity, -Infinity, -Infinity];
12811
+ let globalFeatureIdOffset = 0;
12812
+ const binaryGeometries = [];
12813
+ chunks.forEach((chunk) => {
12814
+ const {
12815
+ featureIds,
12816
+ flatCoordinateArray,
12817
+ nDim,
12818
+ geomOffset
12819
+ } = getBinaryGeometriesFromChunk(chunk, geoEncoding);
12820
+ const numOfVertices = flatCoordinateArray.length / nDim;
12821
+ const globalFeatureIds = new Uint32Array(numOfVertices);
12822
+ for (let i = 0; i < numOfVertices; i++) {
12823
+ globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
12824
+ }
12825
+ const binaryContent = {
12826
+ globalFeatureIds: {
12827
+ value: globalFeatureIds,
12828
+ size: 1
12829
+ },
12830
+ positions: {
12831
+ value: flatCoordinateArray,
12832
+ size: nDim
12833
+ },
12834
+ featureIds: {
12835
+ value: featureIds,
12836
+ size: 1
12837
+ },
12838
+ properties: [...Array(chunk.length).keys()].map((i) => ({
12839
+ index: i + globalFeatureIdOffset
12840
+ }))
12841
+ };
12842
+ globalFeatureIdOffset += chunk.length;
12843
+ binaryGeometries.push({
12844
+ shape: "binary-feature-collection",
12845
+ points: {
12846
+ type: "Point",
12847
+ ...BINARY_GEOMETRY_TEMPLATE,
12848
+ ...featureTypes.point ? binaryContent : {}
12849
+ },
12850
+ lines: {
12851
+ type: "LineString",
12852
+ ...BINARY_GEOMETRY_TEMPLATE,
12853
+ ...featureTypes.line ? binaryContent : {},
12854
+ pathIndices: {
12855
+ value: featureTypes.line ? geomOffset : new Uint16Array(0),
12856
+ size: 1
12857
+ }
12858
+ },
12859
+ polygons: {
12860
+ type: "Polygon",
12861
+ ...BINARY_GEOMETRY_TEMPLATE,
12862
+ ...featureTypes.polygon ? binaryContent : {},
12863
+ polygonIndices: {
12864
+ value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
12865
+ size: 1
12866
+ },
12867
+ primitivePolygonIndices: {
12868
+ value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
12869
+ size: 1
12870
+ }
12871
+ }
12872
+ });
12873
+ bounds = updateBoundsFromGeoArrowSamples(flatCoordinateArray, nDim, bounds);
12874
+ });
12875
+ return {
12876
+ binaryGeometries,
12877
+ bounds,
12878
+ featureTypes
12879
+ };
12880
+ }
12881
+ function getBinaryGeometriesFromChunk(chunk, geoEncoding) {
12882
+ switch (geoEncoding) {
12883
+ case "geoarrow.point":
12884
+ case "geoarrow.multipoint":
12885
+ return getBinaryPointsFromChunk(chunk, geoEncoding);
12886
+ case "geoarrow.linestring":
12887
+ case "geoarrow.multilinestring":
12888
+ return getBinaryLinesFromChunk(chunk, geoEncoding);
12889
+ case "geoarrow.polygon":
12890
+ case "geoarrow.multipolygon":
12891
+ return getBinaryPolygonsFromChunk(chunk, geoEncoding);
12892
+ default:
12893
+ throw Error("invalid geoarrow encoding");
12894
+ }
12895
+ }
12896
+ function getBinaryPolygonsFromChunk(chunk, geoEncoding) {
12897
+ const isMultiPolygon = geoEncoding === "geoarrow.multipolygon";
12898
+ const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
12899
+ const ringData = polygonData.children[0];
12900
+ const pointData = ringData.children[0];
12901
+ const coordData = pointData.children[0];
12902
+ const nDim = pointData.stride;
12903
+ const geomOffset = ringData.valueOffsets;
12904
+ const flatCoordinateArray = coordData.values;
12905
+ const geometryIndicies = new Uint16Array(chunk.length + 1);
12906
+ for (let i = 0; i < chunk.length; i++) {
12907
+ geometryIndicies[i] = geomOffset[chunk.valueOffsets[i]];
12908
+ }
12909
+ geometryIndicies[chunk.length] = flatCoordinateArray.length / nDim;
12910
+ const numOfVertices = flatCoordinateArray.length / nDim;
12911
+ const featureIds = new Uint32Array(numOfVertices);
12912
+ for (let i = 0; i < chunk.length - 1; i++) {
12913
+ const startIdx = geomOffset[chunk.valueOffsets[i]];
12914
+ const endIdx = geomOffset[chunk.valueOffsets[i + 1]];
12915
+ for (let j = startIdx; j < endIdx; j++) {
12916
+ featureIds[j] = i;
12917
+ }
12918
+ }
12919
+ return {
12920
+ featureIds,
12921
+ flatCoordinateArray,
12922
+ nDim,
12923
+ geomOffset,
12924
+ geometryIndicies
12925
+ };
12926
+ }
12927
+ function getBinaryLinesFromChunk(chunk, geoEncoding) {
12928
+ const isMultiLineString = geoEncoding === "geoarrow.multilinestring";
12929
+ const lineData = isMultiLineString ? chunk.children[0] : chunk;
12930
+ const pointData = lineData.children[0];
12931
+ const coordData = pointData.children[0];
12932
+ const nDim = pointData.stride;
12933
+ const geomOffset = lineData.valueOffsets;
12934
+ const flatCoordinateArray = coordData.values;
12935
+ const geometryIndicies = new Uint16Array(0);
12936
+ const numOfVertices = flatCoordinateArray.length / nDim;
12937
+ const featureIds = new Uint32Array(numOfVertices);
12938
+ for (let i = 0; i < chunk.length; i++) {
12939
+ const startIdx = geomOffset[i];
12940
+ const endIdx = geomOffset[i + 1];
12941
+ for (let j = startIdx; j < endIdx; j++) {
12942
+ featureIds[j] = i;
12943
+ }
12944
+ }
12945
+ return {
12946
+ featureIds,
12947
+ flatCoordinateArray,
12948
+ nDim,
12949
+ geomOffset,
12950
+ geometryIndicies
12951
+ };
12952
+ }
12953
+ function getBinaryPointsFromChunk(chunk, geoEncoding) {
12954
+ const isMultiPoint = geoEncoding === "geoarrow.multipoint";
12955
+ const pointData = isMultiPoint ? chunk.children[0] : chunk;
12956
+ const coordData = pointData.children[0];
12957
+ const nDim = pointData.stride;
12958
+ const flatCoordinateArray = coordData.values;
12959
+ const geometryIndicies = new Uint16Array(0);
12960
+ const geomOffset = new Int32Array(0);
12961
+ const numOfVertices = flatCoordinateArray.length / nDim;
12962
+ const featureIds = new Uint32Array(numOfVertices);
12963
+ for (let i = 0; i < chunk.length; i++) {
12964
+ featureIds[i] = i;
12965
+ }
12966
+ return {
12967
+ featureIds,
12968
+ flatCoordinateArray,
12969
+ nDim,
12970
+ geomOffset,
12971
+ geometryIndicies
12972
+ };
12973
+ }
12974
+
12975
+ // src/geoarrow/convert-geoarrow-to-geojson.ts
12976
+ function parseGeometryFromArrow(rawData) {
12977
+ const encoding = rawData.encoding?.toLowerCase();
12978
+ const data = rawData.data;
12979
+ if (!encoding || !data) {
12980
+ return null;
12981
+ }
12982
+ let geometry;
12983
+ switch (encoding) {
12984
+ case "geoarrow.multipolygon":
12985
+ geometry = arrowMultiPolygonToFeature(data);
12986
+ break;
12987
+ case "geoarrow.polygon":
12988
+ geometry = arrowPolygonToFeature(data);
12989
+ break;
12990
+ case "geoarrow.multipoint":
12991
+ geometry = arrowMultiPointToFeature(data);
12992
+ break;
12993
+ case "geoarrow.point":
12994
+ geometry = arrowPointToFeature(data);
12995
+ break;
12996
+ case "geoarrow.multilinestring":
12997
+ geometry = arrowMultiLineStringToFeature(data);
12998
+ break;
12999
+ case "geoarrow.linestring":
13000
+ geometry = arrowLineStringToFeature(data);
13001
+ break;
13002
+ default: {
13003
+ throw Error(`GeoArrow encoding not supported ${encoding}`);
13004
+ }
13005
+ }
13006
+ return {
13007
+ type: "Feature",
13008
+ geometry,
13009
+ properties: {}
13010
+ };
13011
+ }
13012
+ function arrowMultiPolygonToFeature(arrowMultiPolygon) {
13013
+ const multiPolygon = [];
13014
+ for (let m = 0; m < arrowMultiPolygon.length; m++) {
13015
+ const arrowPolygon = arrowMultiPolygon.get(m);
13016
+ const polygon = [];
13017
+ for (let i = 0; arrowPolygon && i < arrowPolygon?.length; i++) {
13018
+ const arrowRing = arrowPolygon?.get(i);
13019
+ const ring = [];
13020
+ for (let j = 0; arrowRing && j < arrowRing.length; j++) {
13021
+ const arrowCoord = arrowRing.get(j);
13022
+ const coord = Array.from(arrowCoord);
13023
+ ring.push(coord);
13024
+ }
13025
+ polygon.push(ring);
13026
+ }
13027
+ multiPolygon.push(polygon);
13028
+ }
13029
+ const geometry = {
13030
+ type: "MultiPolygon",
13031
+ coordinates: multiPolygon
13032
+ };
13033
+ return geometry;
13034
+ }
13035
+ function arrowPolygonToFeature(arrowPolygon) {
13036
+ const polygon = [];
13037
+ for (let i = 0; arrowPolygon && i < arrowPolygon.length; i++) {
13038
+ const arrowRing = arrowPolygon.get(i);
13039
+ const ring = [];
13040
+ for (let j = 0; arrowRing && j < arrowRing.length; j++) {
13041
+ const arrowCoord = arrowRing.get(j);
13042
+ const coords = Array.from(arrowCoord);
13043
+ ring.push(coords);
13044
+ }
13045
+ polygon.push(ring);
13046
+ }
13047
+ const geometry = {
13048
+ type: "Polygon",
13049
+ coordinates: polygon
13050
+ };
13051
+ return geometry;
13052
+ }
13053
+ function arrowMultiPointToFeature(arrowMultiPoint) {
13054
+ const multiPoint = [];
13055
+ for (let i = 0; arrowMultiPoint && i < arrowMultiPoint.length; i++) {
13056
+ const arrowPoint = arrowMultiPoint.get(i);
13057
+ if (arrowPoint) {
13058
+ const coord = Array.from(arrowPoint);
13059
+ multiPoint.push(coord);
13060
+ }
13061
+ }
13062
+ const geometry = {
13063
+ type: "MultiPoint",
13064
+ coordinates: multiPoint
13065
+ };
13066
+ return geometry;
13067
+ }
13068
+ function arrowPointToFeature(arrowPoint) {
13069
+ const point = Array.from(arrowPoint);
13070
+ const geometry = {
13071
+ type: "Point",
13072
+ coordinates: point
13073
+ };
13074
+ return geometry;
13075
+ }
13076
+ function arrowMultiLineStringToFeature(arrowMultiLineString) {
13077
+ const multiLineString = [];
13078
+ for (let i = 0; arrowMultiLineString && i < arrowMultiLineString.length; i++) {
13079
+ const arrowLineString = arrowMultiLineString.get(i);
13080
+ const lineString = [];
13081
+ for (let j = 0; arrowLineString && j < arrowLineString.length; j++) {
13082
+ const arrowCoord = arrowLineString.get(j);
13083
+ if (arrowCoord) {
13084
+ const coords = Array.from(arrowCoord);
13085
+ lineString.push(coords);
13086
+ }
13087
+ }
13088
+ multiLineString.push(lineString);
13089
+ }
13090
+ const geometry = {
13091
+ type: "MultiLineString",
13092
+ coordinates: multiLineString
13093
+ };
13094
+ return geometry;
13095
+ }
13096
+ function arrowLineStringToFeature(arrowLineString) {
13097
+ const lineString = [];
13098
+ for (let i = 0; arrowLineString && i < arrowLineString.length; i++) {
13099
+ const arrowCoord = arrowLineString.get(i);
13100
+ if (arrowCoord) {
13101
+ const coords = Array.from(arrowCoord);
13102
+ lineString.push(coords);
13103
+ }
13104
+ }
13105
+ const geometry = {
13106
+ type: "LineString",
13107
+ coordinates: lineString
13108
+ };
13109
+ return geometry;
13110
+ }
13111
+
12460
13112
  // src/index.ts
12461
13113
  TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
12462
13114
  var ArrowLoader2 = {