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