@loaders.gl/geoarrow 4.4.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +41 -0
  2. package/README.md +7 -0
  3. package/dist/geo-column/geo-column-info.d.ts +20 -0
  4. package/dist/geo-column/geo-column-info.d.ts.map +1 -0
  5. package/dist/geo-column/geo-column-info.js +74 -0
  6. package/dist/geo-column/geo-column.d.ts +61 -0
  7. package/dist/geo-column/geo-column.d.ts.map +1 -0
  8. package/dist/geo-column/geo-column.js +4 -0
  9. package/dist/geoarrow-functions.d.ts +131 -0
  10. package/dist/geoarrow-functions.d.ts.map +1 -0
  11. package/dist/geoarrow-functions.js +218 -0
  12. package/dist/geoarrow-types.d.ts +49 -0
  13. package/dist/geoarrow-types.d.ts.map +1 -0
  14. package/dist/geoarrow-types.js +4 -0
  15. package/dist/get-arrow-bounds.d.ts +11 -0
  16. package/dist/get-arrow-bounds.d.ts.map +1 -0
  17. package/dist/get-arrow-bounds.js +34 -0
  18. package/dist/get-geoarrow-geometry-info.d.ts +30 -0
  19. package/dist/get-geoarrow-geometry-info.d.ts.map +1 -0
  20. package/dist/get-geoarrow-geometry-info.js +124 -0
  21. package/dist/index.cjs +430 -0
  22. package/dist/index.cjs.map +7 -0
  23. package/dist/index.d.ts +11 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +12 -0
  26. package/dist/mesharrow/arrow-fixed-size-list-utils.d.ts +11 -0
  27. package/dist/mesharrow/arrow-fixed-size-list-utils.d.ts.map +1 -0
  28. package/dist/mesharrow/arrow-fixed-size-list-utils.js +39 -0
  29. package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.d.ts +11 -0
  30. package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.d.ts.map +1 -0
  31. package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.js +31 -0
  32. package/dist/mesharrow/get-bounding-box.d.ts +5 -0
  33. package/dist/mesharrow/get-bounding-box.d.ts.map +1 -0
  34. package/dist/mesharrow/get-bounding-box.js +33 -0
  35. package/dist/mesharrow/get-deck-binary-data.d.ts +13 -0
  36. package/dist/mesharrow/get-deck-binary-data.d.ts.map +1 -0
  37. package/dist/mesharrow/get-deck-binary-data.js +24 -0
  38. package/dist/mesharrow/mesh-accessors.d.ts +8 -0
  39. package/dist/mesharrow/mesh-accessors.d.ts.map +1 -0
  40. package/dist/mesharrow/mesh-accessors.js +18 -0
  41. package/dist/metadata/geoarrow-metadata.d.ts +27 -0
  42. package/dist/metadata/geoarrow-metadata.d.ts.map +1 -0
  43. package/dist/metadata/geoarrow-metadata.js +71 -0
  44. package/dist/metadata/geoparquet-metadata-schema.d.ts +79 -0
  45. package/dist/metadata/geoparquet-metadata-schema.d.ts.map +1 -0
  46. package/dist/metadata/geoparquet-metadata-schema.js +69 -0
  47. package/dist/metadata/geoparquet-metadata.d.ts +45 -0
  48. package/dist/metadata/geoparquet-metadata.d.ts.map +1 -0
  49. package/dist/metadata/geoparquet-metadata.js +131 -0
  50. package/dist/metadata/metadata-utils.d.ts +21 -0
  51. package/dist/metadata/metadata-utils.d.ts.map +1 -0
  52. package/dist/metadata/metadata-utils.js +14 -0
  53. package/package.json +63 -0
  54. package/src/geo-column/geo-column-info.ts +114 -0
  55. package/src/geo-column/geo-column.ts +85 -0
  56. package/src/geoarrow-functions.ts +258 -0
  57. package/src/geoarrow-types.ts +72 -0
  58. package/src/get-arrow-bounds.ts +41 -0
  59. package/src/get-geo-column-from-geoarrow.ts.disabled +251 -0
  60. package/src/get-geoarrow-geometry-info.ts +172 -0
  61. package/src/index.ts +57 -0
  62. package/src/mesharrow/arrow-fixed-size-list-utils.ts +62 -0
  63. package/src/mesharrow/arrow-list-of-fixed-size-list-utils.ts +47 -0
  64. package/src/mesharrow/get-bounding-box.ts +39 -0
  65. package/src/mesharrow/get-deck-binary-data.ts +43 -0
  66. package/src/mesharrow/mesh-accessors.ts +27 -0
  67. package/src/metadata/geoarrow-metadata.ts +102 -0
  68. package/src/metadata/geoparquet-metadata-schema.ts +71 -0
  69. package/src/metadata/geoparquet-metadata.ts +195 -0
  70. package/src/metadata/metadata-utils.ts +32 -0
@@ -0,0 +1,258 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /**
6
+ * @note Conforms to the GeoArrow memory layout
7
+ * @see https://geoarrow.org/format.html#memory-layouts
8
+ * @note this is aligned with the geoarrow-js library (MIT license)
9
+ * @see https://github.com/geoarrow/geoarrow-js/
10
+ */
11
+
12
+ import {DataType} from 'apache-arrow/type';
13
+
14
+ import type {
15
+ GeoArrowPoint,
16
+ GeoArrowLineString,
17
+ GeoArrowPolygon,
18
+ GeoArrowMultiPoint,
19
+ GeoArrowMultiLineString,
20
+ GeoArrowMultiPolygon,
21
+ GeoArrowGeometry
22
+ } from './geoarrow-types';
23
+
24
+ /** Checks whether the given Apache Arrow JS type is a Point data type */
25
+ export function isGeoArrowPoint(type: DataType): type is GeoArrowPoint {
26
+ if (DataType.isFixedSizeList(type)) {
27
+ // Check list size
28
+ if (![2, 3, 4].includes(type.listSize)) {
29
+ return false;
30
+ }
31
+
32
+ // Check child of FixedSizeList is floating type
33
+ if (!DataType.isFloat(type.children[0])) {
34
+ return false;
35
+ }
36
+
37
+ return true;
38
+ }
39
+
40
+ // TODO - support separated coordinates
41
+ // if (DataType.isStruct(type)) {
42
+ // // Check number of children
43
+ // if (![2, 3, 4].includes(type.children.length)) {
44
+ // return false;
45
+ // }
46
+
47
+ // // Check that children have correct field names
48
+ // if (!type.children.every((field) => ['x', 'y', 'z', 'm'].includes(field.name))) {
49
+ // return false;
50
+ // }
51
+
52
+ // if (!type.children.every((field) => DataType.isFloat(field))) {
53
+ // return false;
54
+ // }
55
+
56
+ // return true;
57
+ // }
58
+
59
+ return false;
60
+ }
61
+
62
+ /** Checks whether the given Apache Arrow JS type is a Point data type */
63
+ export function isGeoArrowLineString(type: DataType): type is GeoArrowLineString {
64
+ // Check the outer type is a List
65
+ if (!DataType.isList(type)) {
66
+ return false;
67
+ }
68
+
69
+ // Check the child is a point type
70
+ if (!isGeoArrowPoint(type.children[0].type)) {
71
+ return false;
72
+ }
73
+
74
+ return true;
75
+ }
76
+
77
+ /** Checks whether the given Apache Arrow JS type is a Polygon data type */
78
+ export function isGeoArrowPolygon(type: DataType): type is GeoArrowPolygon {
79
+ // Check the outer vector is a List
80
+ if (!DataType.isList(type)) {
81
+ return false;
82
+ }
83
+
84
+ // Check the child is a linestring vector
85
+ if (!isGeoArrowLineString(type.children[0].type)) {
86
+ return false;
87
+ }
88
+
89
+ return true;
90
+ }
91
+
92
+ /** Checks whether the given Apache Arrow JS type is a Polygon data type */
93
+ export function isGeoArrowMultiPoint(type: DataType): type is GeoArrowMultiPoint {
94
+ // Check the outer vector is a List
95
+ if (!DataType.isList(type)) {
96
+ return false;
97
+ }
98
+
99
+ // Check the child is a point vector
100
+ if (!isGeoArrowPoint(type.children[0].type)) {
101
+ return false;
102
+ }
103
+
104
+ return true;
105
+ }
106
+
107
+ /** Checks whether the given Apache Arrow JS type is a Polygon data type */
108
+ export function isGeoArrowMultiLineString(type: DataType): type is GeoArrowMultiLineString {
109
+ // Check the outer vector is a List
110
+ if (!DataType.isList(type)) {
111
+ return false;
112
+ }
113
+
114
+ // Check the child is a linestring vector
115
+ if (!isGeoArrowLineString(type.children[0].type)) {
116
+ return false;
117
+ }
118
+
119
+ return true;
120
+ }
121
+
122
+ /** Checks whether the given Apache Arrow JS type is a Polygon data type */
123
+ export function isGeoArrowMultiPolygon(type: DataType): type is GeoArrowMultiPolygon {
124
+ // Check the outer vector is a List
125
+ if (!DataType.isList(type)) {
126
+ return false;
127
+ }
128
+
129
+ // Check the child is a polygon vector
130
+ if (!isGeoArrowPolygon(type.children[0].type)) {
131
+ return false;
132
+ }
133
+
134
+ return true;
135
+ }
136
+
137
+ /**
138
+ * Checks if a given Arrow data type is a valid GeoArrowGeometry
139
+ * @note this is somewhat inefficient, it checks the same things multiple times
140
+ */
141
+ export function isGeoArrowGeometry(type: DataType): type is GeoArrowGeometry {
142
+ return (
143
+ isGeoArrowPoint(type) ||
144
+ isGeoArrowLineString(type) ||
145
+ isGeoArrowPolygon(type) ||
146
+ isGeoArrowMultiPoint(type) ||
147
+ isGeoArrowMultiLineString(type) ||
148
+ isGeoArrowMultiPolygon(type)
149
+ );
150
+ }
151
+
152
+ // CHILD EXTRACTION
153
+
154
+ /**
155
+ * Strongly typed accessors for children, since arrow.Data.children[] is untyped
156
+
157
+ import { Data } from "apache-arrow/data";
158
+ import { Vector } from "apache-arrow/vector";
159
+ import { Float } from "apache-arrow/type";
160
+ import {
161
+ LineStringData,
162
+ MultiLineStringData,
163
+ MultiPointData,
164
+ MultiPolygonData,
165
+ PointData,
166
+ PolygonData,
167
+ } from "./data";
168
+ import {
169
+ LineStringVector,
170
+ MultiLineStringVector,
171
+ MultiPointVector,
172
+ MultiPolygonVector,
173
+ PointVector,
174
+ PolygonVector,
175
+ } from "./vector";
176
+
177
+ export function getPointChild(input: PointData): Data<Float>;
178
+ export function getPointChild(input: PointVector): Vector<Float>;
179
+
180
+ export function getPointChild(
181
+ input: PointData | PointVector,
182
+ ): Data<Float> | Vector<Float> {
183
+ if ("data" in input) {
184
+ return input.getChildAt(0)!;
185
+ }
186
+
187
+ return input.children[0] as Data<Float>;
188
+ }
189
+
190
+ export function getLineStringChild(input: LineStringData): PointData;
191
+ export function getLineStringChild(input: LineStringVector): PointVector;
192
+
193
+ export function getLineStringChild(
194
+ input: LineStringData | LineStringVector,
195
+ ): PointData | PointVector {
196
+ if ("data" in input) {
197
+ return input.getChildAt(0)!;
198
+ }
199
+
200
+ return input.children[0] as PointData;
201
+ }
202
+
203
+ export function getPolygonChild(input: PolygonData): LineStringData;
204
+ export function getPolygonChild(input: PolygonVector): LineStringVector;
205
+
206
+ export function getPolygonChild(
207
+ input: PolygonData | PolygonVector,
208
+ ): LineStringData | LineStringVector {
209
+ if ("data" in input) {
210
+ return input.getChildAt(0)!;
211
+ }
212
+
213
+ return input.children[0] as LineStringData;
214
+ }
215
+
216
+ export function getMultiPointChild(input: MultiPointData): PointData;
217
+ export function getMultiPointChild(input: MultiPointVector): PointVector;
218
+
219
+ export function getMultiPointChild(
220
+ input: MultiPointData | MultiPointVector,
221
+ ): PointData | PointVector {
222
+ if ("data" in input) {
223
+ return input.getChildAt(0)!;
224
+ }
225
+
226
+ return input.children[0] as PointData;
227
+ }
228
+
229
+ export function getMultiLineStringChild(
230
+ input: MultiLineStringData,
231
+ ): LineStringData;
232
+ export function getMultiLineStringChild(
233
+ input: MultiLineStringVector,
234
+ ): LineStringVector;
235
+
236
+ export function getMultiLineStringChild(
237
+ input: MultiLineStringData | MultiLineStringVector,
238
+ ): LineStringData | LineStringVector {
239
+ if ("data" in input) {
240
+ return input.getChildAt(0)!;
241
+ }
242
+
243
+ return input.children[0] as LineStringData;
244
+ }
245
+
246
+ export function getMultiPolygonChild(input: MultiPolygonData): PolygonData;
247
+ export function getMultiPolygonChild(input: MultiPolygonVector): PolygonVector;
248
+
249
+ export function getMultiPolygonChild(
250
+ input: MultiPolygonData | MultiPolygonVector,
251
+ ): PolygonData | PolygonVector {
252
+ if ("data" in input) {
253
+ return input.getChildAt(0)!;
254
+ }
255
+
256
+ return input.children[0] as PolygonData;
257
+ }
258
+ */
@@ -0,0 +1,72 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /**
6
+ * @note Conforms to the GeoArrow memory layout
7
+ * @see https://geoarrow.org/format.html#memory-layouts
8
+ * @note this is aligned with the geoarrow-js library (MIT license)
9
+ * @see https://github.com/geoarrow/geoarrow-js/
10
+ */
11
+
12
+ import type {Struct, Float, List, FixedSizeList, Utf8, Binary} from 'apache-arrow/type';
13
+
14
+ export type GeoArrowWKB = Binary;
15
+ export type GeoArrowWKT = Utf8;
16
+ /**
17
+ * @note arrow.Float (not arrow.Float64) ensures that recreating a data instance with arrow.makeData type checks using the input's data type.
18
+ */
19
+
20
+ /** Interleaved GeoArrow coordinates */
21
+ export type GeoArrowCoordInterleaved = FixedSizeList<Float>;
22
+ /** Separated GeoArrow coordinates */
23
+ export type GeoArrowCoordSeparated = Struct<{x: Float; y: Float}>;
24
+
25
+ // Interleaved coords are the preferred case
26
+
27
+ export type GeoArrowCoord = GeoArrowCoordInterleaved;
28
+
29
+ /** Arrow type for GeoArrow geometry */
30
+ export type GeoArrowPoint = GeoArrowCoordInterleaved;
31
+ /** Arrow type for GeoArrow geometry */
32
+ export type GeoArrowLineString = List<GeoArrowCoordInterleaved>;
33
+ /** Arrow type for GeoArrow geometry */
34
+ export type GeoArrowPolygon = List<List<GeoArrowCoordInterleaved>>;
35
+ /** Arrow type for GeoArrow geometry */
36
+ export type GeoArrowMultiPoint = List<GeoArrowCoordInterleaved>;
37
+ /** Arrow type for GeoArrow geometry */
38
+ export type GeoArrowMultiLineString = List<List<GeoArrowCoordInterleaved>>;
39
+ /** Arrow type for GeoArrow geometry */
40
+ export type GeoArrowMultiPolygon = List<List<List<GeoArrowCoordInterleaved>>>;
41
+
42
+ /** Arrow type for GeoArrow geometry */
43
+ export type GeoArrowGeometry =
44
+ | GeoArrowPoint
45
+ | GeoArrowLineString
46
+ | GeoArrowPolygon
47
+ | GeoArrowMultiPoint
48
+ | GeoArrowMultiLineString
49
+ | GeoArrowMultiPolygon;
50
+
51
+ // Separated coords - not yet well supported
52
+ /** Arrow type for GeoArrow geometry */
53
+ export type GeoArrowPointSeparated = GeoArrowCoordSeparated;
54
+ /** Arrow type for GeoArrow geometry */
55
+ export type GeoArrowLineStringSeparated = List<GeoArrowCoordSeparated>;
56
+ /** Arrow type for GeoArrow geometry */
57
+ export type GeoArrowPolygonSeparated = List<List<GeoArrowCoordSeparated>>;
58
+ /** Arrow type for GeoArrow geometry */
59
+ export type GeoArrowMultiPointSeparated = List<GeoArrowCoordSeparated>;
60
+ /** Arrow type for GeoArrow geometry */
61
+ export type GeoArrowMultiLineStringSeparated = List<List<GeoArrowCoordSeparated>>;
62
+ /** Arrow type for GeoArrow geometry */
63
+ export type GeoArrowMultiPolygonSeparated = List<List<List<GeoArrowCoordSeparated>>>;
64
+
65
+ /** Arrow type for GeoArrow geometry */
66
+ export type GeoArrowGeometrySeparated =
67
+ | GeoArrowPointSeparated
68
+ | GeoArrowLineStringSeparated
69
+ | GeoArrowPolygonSeparated
70
+ | GeoArrowMultiPointSeparated
71
+ | GeoArrowMultiLineStringSeparated
72
+ | GeoArrowMultiPolygonSeparated;
@@ -0,0 +1,41 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /**
6
+ * Update bounds from geoarrow sample data
7
+ *
8
+ * @param flatCoords the flattend coordinates array from one chunk of geoarrow column
9
+ * @param nDim the number of dimensions of the coordinates
10
+ * @param bounds the bounds to be updated
11
+ * @param sampleSize how many samples to be used to update the bounds, default is 1000 per chunk
12
+ * @returns the updated bounds
13
+ */
14
+ export function updateBoundsFromGeoArrowSamples(
15
+ flatCoords: Float64Array,
16
+ nDim: number,
17
+ bounds: [number, number, number, number],
18
+ sampleSize: number = 100
19
+ ): [number, number, number, number] {
20
+ const numberOfFeatures = flatCoords.length / nDim;
21
+ const sampleStep = Math.max(Math.floor(numberOfFeatures / sampleSize), 1);
22
+
23
+ const newBounds: [number, number, number, number] = [...bounds];
24
+ for (let i = 0; i < numberOfFeatures; i += sampleStep) {
25
+ const lng = flatCoords[i * nDim];
26
+ const lat = flatCoords[i * nDim + 1];
27
+ if (lng < newBounds[0]) {
28
+ newBounds[0] = lng;
29
+ }
30
+ if (lat < newBounds[1]) {
31
+ newBounds[1] = lat;
32
+ }
33
+ if (lng > newBounds[2]) {
34
+ newBounds[2] = lng;
35
+ }
36
+ if (lat > newBounds[3]) {
37
+ newBounds[3] = lat;
38
+ }
39
+ }
40
+ return newBounds;
41
+ }
@@ -0,0 +1,251 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import * as arrow from 'apache-arrow';
6
+ import type {
7
+ GeoColumn,
8
+ GeoColumnData,
9
+ GeoColumnPointData,
10
+ GeoColumnLineData,
11
+ GeoColumnPolygonData
12
+ } from './geo-column/geo-column';
13
+ import {GeoArrowEncoding} from './metadata/geoarrow-metadata';
14
+
15
+ export type GetGeoColumnOptions = {
16
+ /** option to specify which chunk to get binary geometries from, for progressive rendering */
17
+ chunkIndex?: number;
18
+ /** The offset (beginning index of rows) of input chunk. Used for reconstructing globalFeatureIds in web workers */
19
+ chunkOffset?: number;
20
+ };
21
+
22
+ /**
23
+ * get binary geometries from geoarrow column
24
+ *
25
+ * @param geoColumn the geoarrow column, e.g. arrowTable.getChildAt(geoColumnIndex)
26
+ * @param geoEncoding the geo encoding of the geoarrow column, e.g. getGeoArrowEncoding(arrowTable.schema, geoColumnName)
27
+ * @param options options for getting binary geometries {meanCenter: boolean}
28
+ * @returns BinaryDataFromGeoArrow
29
+ */
30
+ export function getGeoColumnFromGeoArrowVector(
31
+ geoColumn: arrow.Vector,
32
+ geoEncoding: GeoArrowEncoding,
33
+ options?: GetGeoColumnOptions
34
+ ): GeoColumn {
35
+ const featureTypes = {
36
+ polygon: geoEncoding === 'geoarrow.multipolygon' || geoEncoding === 'geoarrow.polygon',
37
+ point: geoEncoding === 'geoarrow.multipoint' || geoEncoding === 'geoarrow.point',
38
+ line: geoEncoding === 'geoarrow.multilinestring' || geoEncoding === 'geoarrow.linestring'
39
+ };
40
+
41
+ const arrowDatas =
42
+ options?.chunkIndex !== undefined && options?.chunkIndex >= 0
43
+ ? [geoColumn.data[options?.chunkIndex]]
44
+ : geoColumn.data;
45
+
46
+ // const globalFeatureIdOffset = options?.chunkOffset || 0;
47
+
48
+ const data: GeoColumnData[] = [];
49
+
50
+ for (const arrowData of arrowDatas) {
51
+ // // const {featureIds, positions, dimension, geometryOffsets, triangles} =
52
+ // // getBinaryGeometriesFromChunk(arrowData, geoEncoding, options);
53
+
54
+ // const globalFeatureIds = new Uint32Array(featureIds.length);
55
+ // for (let i = 0; i < featureIds.length; i++) {
56
+ // globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
57
+ // }
58
+
59
+ const geoColumnData: GeoColumnData = {
60
+ shape: 'geo-column-data',
61
+ numRows: arrowData.length,
62
+ rowOffsets: new Uint32Array(0)
63
+ };
64
+
65
+ if (featureTypes.point) {
66
+ geoColumnData.points = getPointDataFromArrowData(arrowData, geoEncoding, options);
67
+ }
68
+
69
+ if (featureTypes.line) {
70
+ geoColumnData.lines = getLineDataFromArrowData(arrowData, geoEncoding, options);
71
+ }
72
+
73
+ if (featureTypes.polygon) {
74
+ geoColumnData.polygons = getPolygonDataFromArrowData(arrowData, geoEncoding, options);
75
+ }
76
+
77
+ data.push(geoColumnData);
78
+ }
79
+
80
+ return {
81
+ shape: 'geo-column',
82
+ data
83
+ };
84
+ }
85
+
86
+ /**
87
+ * get binary geometries from geoarrow column
88
+ * @param chunk one chunk/batch of geoarrow column
89
+ * @param geoEncoding geo encoding of the geoarrow column
90
+ * @param options options for getting binary geometries
91
+ * @returns BinaryGeometryContent
92
+ */
93
+ export function getGeoColumnDataFromArrowData(
94
+ data: arrow.Data,
95
+ geoEncoding: GeoArrowEncoding,
96
+ options?: GetGeoColumnOptions
97
+ ): GeoColumnPolygonData | GeoColumnLineData | GeoColumnPointData {
98
+ switch (geoEncoding) {
99
+ case 'geoarrow.point':
100
+ case 'geoarrow.multipoint':
101
+ return getPointDataFromArrowData(data, geoEncoding);
102
+ case 'geoarrow.linestring':
103
+ case 'geoarrow.multilinestring':
104
+ return getLineDataFromArrowData(data, geoEncoding);
105
+ case 'geoarrow.polygon':
106
+ case 'geoarrow.multipolygon':
107
+ return getPolygonDataFromArrowData(data, geoEncoding, options);
108
+ default:
109
+ throw Error('invalid geoarrow encoding');
110
+ }
111
+ }
112
+
113
+ /**
114
+ * get binary points from geoarrow point column
115
+ * @param chunk one chunk/batch of geoarrow column
116
+ * @param geoEncoding geo encoding of the geoarrow column
117
+ * @returns Flat geometry content
118
+ */
119
+ function getPointDataFromArrowData(chunk: arrow.Data, geoEncoding: string): GeoColumnPointData {
120
+ const isMultiPoint = geoEncoding === 'geoarrow.multipoint';
121
+
122
+ const pointData = isMultiPoint ? chunk.children[0] : chunk;
123
+ const coordData = pointData.children[0];
124
+
125
+ const positionStride = pointData.stride as 2 | 3 | 4;
126
+ const positions = coordData.values;
127
+
128
+ const positionCount = positions.length / positionStride;
129
+
130
+ return {
131
+ shape: 'geo-column-data',
132
+ type: 'Point',
133
+
134
+ rowCount: chunk.length,
135
+ rowOffsets: chunk.valueOffsets,
136
+
137
+ positionCount,
138
+ positionStride,
139
+ positions
140
+ };
141
+ }
142
+
143
+ /**
144
+ * get binary lines from geoarrow line column
145
+ * @param chunk one chunk/batch of geoarrow column
146
+ * @param geoEncoding the geo encoding of the geoarrow column
147
+ * @returns Flat geometry content
148
+ */
149
+ function getLineDataFromArrowData(
150
+ arrowData: arrow.Data,
151
+ geoEncoding: string,
152
+ options?: GetGeoColumnOptions
153
+ ): GeoColumnLineData {
154
+ const isMultiLineString = geoEncoding === 'geoarrow.multilinestring';
155
+
156
+ const lineData = isMultiLineString ? arrowData.children[0] : arrowData;
157
+ const pointData = lineData.children[0];
158
+ const coordData = pointData.children[0];
159
+
160
+ const dimension = pointData.stride as 2 | 3 | 4;
161
+ const geometryOffsets = lineData.valueOffsets;
162
+ const positions = coordData.values;
163
+
164
+ // geometryIndexes is not needed for line string
165
+ const geometryIndexes = new Uint16Array(0);
166
+
167
+ const rowCount = arrowData.length;
168
+ const vertexCount = positions.length / dimension;
169
+ const featureIds = new Uint32Array(positionCount);
170
+
171
+ return {
172
+ type: 'LineString',
173
+
174
+ rowCount: arrowData.length,
175
+ rowOffsets: geometryOffsets,
176
+
177
+ positionCount: positions.length / dimension,
178
+ positionStride: dimension,
179
+ positions
180
+ };
181
+ }
182
+
183
+ /**
184
+ * get binary polygons from geoarrow polygon column
185
+ * @param chunk one chunk of geoarrow polygon column
186
+ * @param geoEncoding the geo encoding of the geoarrow polygon column
187
+ * @param options options for getting binary geometries
188
+ * @returns BinaryGeometryContent
189
+ */
190
+ function getPolygonDataFromArrowData(
191
+ chunk: arrow.Data,
192
+ geoEncoding: string,
193
+ options?: GetGeoColumnOptions
194
+ ): GeoColumnPolygonData {
195
+ const isMultiPolygon = geoEncoding === 'geoarrow.multipolygon';
196
+
197
+ const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
198
+ const polygonOffset = polygonData.valueOffsets;
199
+ const partData = isMultiPolygon
200
+ ? chunk.valueOffsets.map((i) => polygonOffset.at(i) || i)
201
+ : chunk.valueOffsets;
202
+ const ringData = polygonData.children[0];
203
+ const pointData = ringData.children[0];
204
+ const coordData = pointData.children[0];
205
+ const dimension = pointData.stride;
206
+ const geometryOffsets = ringData.valueOffsets;
207
+ const positions = coordData.values;
208
+
209
+ const geometryIndexes = new Uint16Array(polygonOffset.length);
210
+ for (let i = 0; i < polygonOffset.length; i++) {
211
+ geometryIndexes[i] = geometryOffsets[polygonOffset[i]];
212
+ }
213
+
214
+ const positionCount = positions.length / dimension;
215
+ const featureIds = new Uint32Array(positionCount);
216
+ for (let i = 0; i < partData.length - 1; i++) {
217
+ const startIndex = geometryOffsets[partData[i]];
218
+ const endIndex = geometryOffsets[partData[i + 1]];
219
+ for (let j = startIndex; j < endIndex; j++) {
220
+ featureIds[j] = i;
221
+ }
222
+ }
223
+
224
+ return {
225
+ type: 'Polygon',
226
+ featureIds,
227
+ dimension,
228
+ positions,
229
+ geometryOffsets,
230
+ geometryIndexes
231
+ };
232
+ }
233
+
234
+ // return {
235
+ // globalFeatureIds: {value: new Uint32Array(0), size: 1},
236
+ // positions: {value: new Float32Array(0), size: 2},
237
+ // properties: [],
238
+ // numericProps: {},
239
+ // featureIds: {value: new Uint32Array(0), size: 1}
240
+ // ...(featureTypes.polygon ? binaryContent : {}),
241
+ // polygonIndices: {
242
+ // // use geometryOffsets as polygonIndices same as primitivePolygonIndices since we are using earcut to get triangule indices
243
+ // value: featureTypes.polygon ? geometryOffsets : new Uint16Array(0),
244
+ // size: 1
245
+ // },
246
+ // primitivePolygonIndices: {
247
+ // value: featureTypes.polygon ? geometryOffsets : new Uint16Array(0),
248
+ // size: 1
249
+ // }
250
+ // }
251
+ // }