@loaders.gl/arrow 4.3.2 → 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 (77) hide show
  1. package/dist/arrow-loader.d.ts +1 -1
  2. package/dist/arrow-worker.js +638 -1292
  3. package/dist/arrow-writer.js +1 -1
  4. package/dist/dist.dev.js +2140 -3383
  5. package/dist/dist.min.js +5 -5
  6. package/dist/exports/arrow-format.d.ts +12 -0
  7. package/dist/exports/arrow-format.d.ts.map +1 -0
  8. package/dist/exports/arrow-format.js +18 -0
  9. package/dist/exports/arrow-loader.d.ts +1 -1
  10. package/dist/exports/arrow-loader.d.ts.map +1 -1
  11. package/dist/exports/arrow-loader.js +1 -1
  12. package/dist/exports/geoarrow-loader.d.ts +1 -1
  13. package/dist/exports/geoarrow-loader.d.ts.map +1 -1
  14. package/dist/geoarrow-loader.d.ts +1 -2
  15. package/dist/geoarrow-loader.d.ts.map +1 -1
  16. package/dist/geoarrow-writer.d.ts +3 -3
  17. package/dist/geoarrow-writer.d.ts.map +1 -1
  18. package/dist/geoarrow-writer.js +1 -1
  19. package/dist/index.cjs +39 -952
  20. package/dist/index.cjs.map +4 -4
  21. package/dist/index.d.ts +1 -9
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +7 -14
  24. package/dist/lib/parsers/parse-arrow.d.ts +1 -2
  25. package/dist/lib/parsers/parse-arrow.d.ts.map +1 -1
  26. package/dist/lib/parsers/parse-arrow.js +1 -1
  27. package/dist/lib/parsers/parse-geoarrow.d.ts +1 -2
  28. package/dist/lib/parsers/parse-geoarrow.d.ts.map +1 -1
  29. package/dist/lib/parsers/parse-geoarrow.js +2 -2
  30. package/dist/triangulate-on-worker.d.ts +2 -1
  31. package/dist/triangulate-on-worker.d.ts.map +1 -1
  32. package/dist/triangulate-on-worker.js +1 -1
  33. package/dist/triangulation-worker.js +212 -154
  34. package/dist/workers/triangulation-worker.js +2 -2
  35. package/package.json +10 -9
  36. package/src/exports/arrow-format.ts +21 -0
  37. package/src/exports/arrow-loader.ts +1 -1
  38. package/src/exports/geoarrow-loader.ts +1 -2
  39. package/src/geoarrow-loader.ts +6 -2
  40. package/src/geoarrow-writer.ts +1 -1
  41. package/src/index.ts +2 -42
  42. package/src/lib/parsers/parse-arrow.ts +2 -3
  43. package/src/lib/parsers/parse-geoarrow.ts +8 -4
  44. package/src/triangulate-on-worker.ts +2 -1
  45. package/src/workers/triangulation-worker.ts +3 -3
  46. package/dist/lib/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +0 -74
  47. package/dist/lib/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +0 -1
  48. package/dist/lib/geoarrow/convert-geoarrow-to-binary-geometry.js +0 -377
  49. package/dist/lib/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts +0 -13
  50. package/dist/lib/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts.map +0 -1
  51. package/dist/lib/geoarrow/convert-geoarrow-to-geojson-geometry.js +0 -176
  52. package/dist/lib/geoarrow/get-arrow-bounds.d.ts +0 -11
  53. package/dist/lib/geoarrow/get-arrow-bounds.d.ts.map +0 -1
  54. package/dist/lib/geoarrow/get-arrow-bounds.js +0 -34
  55. package/dist/lib/tables/convert-arrow-schema.d.ts +0 -23
  56. package/dist/lib/tables/convert-arrow-schema.d.ts.map +0 -1
  57. package/dist/lib/tables/convert-arrow-schema.js +0 -280
  58. package/dist/lib/tables/convert-arrow-to-table.d.ts +0 -15
  59. package/dist/lib/tables/convert-arrow-to-table.d.ts.map +0 -1
  60. package/dist/lib/tables/convert-arrow-to-table.js +0 -104
  61. package/dist/lib/tables/convert-table-to-arrow.d.ts +0 -16
  62. package/dist/lib/tables/convert-table-to-arrow.d.ts.map +0 -1
  63. package/dist/lib/tables/convert-table-to-arrow.js +0 -56
  64. package/dist/schema/arrow-table-batch.d.ts +0 -10
  65. package/dist/schema/arrow-table-batch.d.ts.map +0 -1
  66. package/dist/schema/arrow-table-batch.js +0 -67
  67. package/dist/schema/arrow-table-type.d.ts +0 -25
  68. package/dist/schema/arrow-table-type.d.ts.map +0 -1
  69. package/dist/schema/arrow-table-type.js +0 -4
  70. package/src/lib/geoarrow/convert-geoarrow-to-binary-geometry.ts +0 -494
  71. package/src/lib/geoarrow/convert-geoarrow-to-geojson-geometry.ts +0 -207
  72. package/src/lib/geoarrow/get-arrow-bounds.ts +0 -41
  73. package/src/lib/tables/convert-arrow-schema.ts +0 -301
  74. package/src/lib/tables/convert-arrow-to-table.ts +0 -144
  75. package/src/lib/tables/convert-table-to-arrow.ts +0 -72
  76. package/src/schema/arrow-table-batch.ts +0 -82
  77. package/src/schema/arrow-table-type.ts +0 -30
@@ -1,377 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { earcut } from '@math.gl/polygon';
5
- import { updateBoundsFromGeoArrowSamples } from "./get-arrow-bounds.js";
6
- /**
7
- * Binary geometry type
8
- */
9
- var BinaryGeometryType;
10
- (function (BinaryGeometryType) {
11
- BinaryGeometryType["points"] = "points";
12
- BinaryGeometryType["lines"] = "lines";
13
- BinaryGeometryType["polygons"] = "polygons";
14
- })(BinaryGeometryType || (BinaryGeometryType = {}));
15
- /**
16
- * binary geometry template, see deck.gl BinaryGeometry
17
- */
18
- export function getBinaryGeometryTemplate() {
19
- return {
20
- globalFeatureIds: { value: new Uint32Array(0), size: 1 },
21
- positions: { value: new Float32Array(0), size: 2 },
22
- properties: [],
23
- numericProps: {},
24
- featureIds: { value: new Uint32Array(0), size: 1 }
25
- };
26
- }
27
- /**
28
- * get binary geometries from geoarrow column
29
- *
30
- * @param geoColumn the geoarrow column, e.g. arrowTable.getChildAt(geoColumnIndex)
31
- * @param geoEncoding the geo encoding of the geoarrow column, e.g. getGeoArrowEncoding(arrowTable.schema, geoColumnName)
32
- * @param options options for getting binary geometries {meanCenter: boolean}
33
- * @returns BinaryDataFromGeoArrow
34
- */
35
- export function getBinaryGeometriesFromArrow(geoColumn, geoEncoding, options) {
36
- const featureTypes = {
37
- polygon: geoEncoding === 'geoarrow.multipolygon' || geoEncoding === 'geoarrow.polygon',
38
- point: geoEncoding === 'geoarrow.multipoint' || geoEncoding === 'geoarrow.point',
39
- line: geoEncoding === 'geoarrow.multilinestring' || geoEncoding === 'geoarrow.linestring'
40
- };
41
- const chunks = options?.chunkIndex !== undefined && options?.chunkIndex >= 0
42
- ? [geoColumn.data[options?.chunkIndex]]
43
- : geoColumn.data;
44
- let bounds = [Infinity, Infinity, -Infinity, -Infinity];
45
- let globalFeatureIdOffset = options?.chunkOffset || 0;
46
- const binaryGeometries = [];
47
- chunks.forEach((chunk) => {
48
- const { featureIds, flatCoordinateArray, nDim, geomOffset, triangles } = getBinaryGeometriesFromChunk(chunk, geoEncoding, options);
49
- const globalFeatureIds = new Uint32Array(featureIds.length);
50
- for (let i = 0; i < featureIds.length; i++) {
51
- globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
52
- }
53
- const binaryContent = {
54
- globalFeatureIds: { value: globalFeatureIds, size: 1 },
55
- positions: {
56
- value: flatCoordinateArray,
57
- size: nDim
58
- },
59
- featureIds: { value: featureIds, size: 1 },
60
- // eslint-disable-next-line no-loop-func
61
- properties: [...Array(chunk.length).keys()].map((i) => ({
62
- index: i + globalFeatureIdOffset
63
- }))
64
- };
65
- // TODO: check if chunks are sequentially accessed
66
- globalFeatureIdOffset += chunk.length;
67
- // NOTE: deck.gl defines the BinaryFeatures structure must have points, lines, polygons even if they are empty
68
- binaryGeometries.push({
69
- shape: 'binary-feature-collection',
70
- points: {
71
- type: 'Point',
72
- ...getBinaryGeometryTemplate(),
73
- ...(featureTypes.point ? binaryContent : {})
74
- },
75
- lines: {
76
- type: 'LineString',
77
- ...getBinaryGeometryTemplate(),
78
- ...(featureTypes.line ? binaryContent : {}),
79
- pathIndices: { value: featureTypes.line ? geomOffset : new Uint16Array(0), size: 1 }
80
- },
81
- polygons: {
82
- type: 'Polygon',
83
- ...getBinaryGeometryTemplate(),
84
- ...(featureTypes.polygon ? binaryContent : {}),
85
- polygonIndices: {
86
- // use geomOffset as polygonIndices same as primitivePolygonIndices since we are using earcut to get triangule indices
87
- value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
88
- size: 1
89
- },
90
- primitivePolygonIndices: {
91
- value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
92
- size: 1
93
- },
94
- ...(triangles ? { triangles: { value: triangles, size: 1 } } : {})
95
- }
96
- });
97
- bounds = updateBoundsFromGeoArrowSamples(flatCoordinateArray, nDim, bounds);
98
- });
99
- return {
100
- binaryGeometries,
101
- bounds,
102
- featureTypes,
103
- ...(options?.calculateMeanCenters
104
- ? { meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries) }
105
- : {})
106
- };
107
- }
108
- /**
109
- * Get mean centers from binary geometries
110
- * @param binaryGeometries binary geometries from geoarrow column, an array of BinaryFeatureCollection
111
- * @returns mean centers of the binary geometries
112
- */
113
- export function getMeanCentersFromBinaryGeometries(binaryGeometries) {
114
- const globalMeanCenters = [];
115
- binaryGeometries.forEach((binaryGeometry) => {
116
- let binaryGeometryType = null;
117
- if (binaryGeometry.points && binaryGeometry.points.positions.value.length > 0) {
118
- binaryGeometryType = BinaryGeometryType.points;
119
- }
120
- else if (binaryGeometry.lines && binaryGeometry.lines.positions.value.length > 0) {
121
- binaryGeometryType = BinaryGeometryType.lines;
122
- }
123
- else if (binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0) {
124
- binaryGeometryType = BinaryGeometryType.polygons;
125
- }
126
- const binaryContent = binaryGeometryType ? binaryGeometry[binaryGeometryType] : null;
127
- if (binaryContent && binaryGeometryType !== null) {
128
- const featureIds = binaryContent.featureIds.value;
129
- const flatCoordinateArray = binaryContent.positions.value;
130
- const nDim = binaryContent.positions.size;
131
- const primitivePolygonIndices = binaryContent.type === 'Polygon' ? binaryContent.primitivePolygonIndices?.value : undefined;
132
- const meanCenters = getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, binaryGeometryType, primitivePolygonIndices);
133
- meanCenters.forEach((center) => {
134
- globalMeanCenters.push(center);
135
- });
136
- }
137
- });
138
- return globalMeanCenters;
139
- }
140
- /**
141
- * Get mean centers from raw coordinates and feature ids
142
- * @param featureIds Array of feature ids indexes by vertex
143
- * @param flatCoordinateArray Array of vertex, e.g. x, y or x, y, z, positions
144
- * @param nDim number of dimensions per position
145
- * @returns - mean centers of each polygon
146
- */
147
- function getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, geometryType, primitivePolygonIndices) {
148
- const meanCenters = [];
149
- const vertexCount = flatCoordinateArray.length;
150
- let vertexIndex = 0;
151
- let coordIdx = 0;
152
- let primitiveIdx = 0;
153
- while (vertexIndex < vertexCount) {
154
- const featureId = featureIds[vertexIndex / nDim];
155
- const center = [0, 0];
156
- let vertexCountInFeature = 0;
157
- while (vertexIndex < vertexCount && featureIds[coordIdx] === featureId) {
158
- if (geometryType === BinaryGeometryType.polygons &&
159
- primitivePolygonIndices?.[primitiveIdx] === coordIdx) {
160
- // skip the first point since it is the same as the last point in each ring for polygons
161
- vertexIndex += nDim;
162
- primitiveIdx++;
163
- }
164
- else {
165
- center[0] += flatCoordinateArray[vertexIndex];
166
- center[1] += flatCoordinateArray[vertexIndex + 1];
167
- vertexIndex += nDim;
168
- vertexCountInFeature++;
169
- }
170
- coordIdx += 1;
171
- }
172
- center[0] /= vertexCountInFeature;
173
- center[1] /= vertexCountInFeature;
174
- meanCenters.push(center);
175
- }
176
- return meanCenters;
177
- }
178
- /**
179
- * get binary geometries from geoarrow column
180
- * @param chunk one chunk/batch of geoarrow column
181
- * @param geoEncoding geo encoding of the geoarrow column
182
- * @param options options for getting binary geometries
183
- * @returns BinaryGeometryContent
184
- */
185
- function getBinaryGeometriesFromChunk(chunk, geoEncoding, options) {
186
- switch (geoEncoding) {
187
- case 'geoarrow.point':
188
- case 'geoarrow.multipoint':
189
- return getBinaryPointsFromChunk(chunk, geoEncoding);
190
- case 'geoarrow.linestring':
191
- case 'geoarrow.multilinestring':
192
- return getBinaryLinesFromChunk(chunk, geoEncoding);
193
- case 'geoarrow.polygon':
194
- case 'geoarrow.multipolygon':
195
- return getBinaryPolygonsFromChunk(chunk, geoEncoding, options);
196
- default:
197
- throw Error('invalid geoarrow encoding');
198
- }
199
- }
200
- /**
201
- * get triangle indices. Allows deck.gl to skip performing costly triangulation on main thread.
202
- * @param polygonIndices Indices within positions of the start of each simple Polygon
203
- * @param primitivePolygonIndices Indices within positions of the start of each primitive Polygon/ring
204
- * @param flatCoordinateArray Array of x, y or x, y, z positions
205
- * @param nDim - number of dimensions per position
206
- * @returns triangle indices or null if invalid polygon and earcut fails
207
- */
208
- export function getTriangleIndices(polygonIndices, primitivePolygonIndices, flatCoordinateArray, nDim) {
209
- try {
210
- let primitiveIndex = 0;
211
- const triangles = [];
212
- // loop polygonIndices to get triangles
213
- for (let i = 0; i < polygonIndices.length - 1; i++) {
214
- const startIdx = polygonIndices[i];
215
- const endIdx = polygonIndices[i + 1];
216
- // get subarray of flatCoordinateArray
217
- const slicedFlatCoords = flatCoordinateArray.subarray(startIdx * nDim, endIdx * nDim);
218
- // get holeIndices for earcut
219
- const holeIndices = [];
220
- while (primitivePolygonIndices[primitiveIndex] < endIdx) {
221
- if (primitivePolygonIndices[primitiveIndex] > startIdx) {
222
- holeIndices.push(primitivePolygonIndices[primitiveIndex] - startIdx);
223
- }
224
- primitiveIndex++;
225
- }
226
- // TODO check if each ring is closed
227
- const triangleIndices = earcut(slicedFlatCoords, holeIndices.length > 0 ? holeIndices : undefined, nDim);
228
- if (triangleIndices.length === 0) {
229
- throw Error('earcut failed e.g. invalid polygon');
230
- }
231
- for (let j = 0; j < triangleIndices.length; j++) {
232
- triangles.push(triangleIndices[j] + startIdx);
233
- }
234
- }
235
- // convert traingles to Uint32Array
236
- const trianglesUint32 = new Uint32Array(triangles.length);
237
- for (let i = 0; i < triangles.length; i++) {
238
- trianglesUint32[i] = triangles[i];
239
- }
240
- return trianglesUint32;
241
- }
242
- catch (error) {
243
- // if earcut fails, return null
244
- return null;
245
- }
246
- }
247
- /**
248
- * get binary polygons from geoarrow polygon column
249
- * @param chunk one chunk of geoarrow polygon column
250
- * @param geoEncoding the geo encoding of the geoarrow polygon column
251
- * @param options options for getting binary geometries
252
- * @returns BinaryGeometryContent
253
- */
254
- function getBinaryPolygonsFromChunk(chunk, geoEncoding, options) {
255
- const isMultiPolygon = geoEncoding === 'geoarrow.multipolygon';
256
- const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
257
- const polygonOffset = polygonData.valueOffsets;
258
- const partData = isMultiPolygon
259
- ? chunk.valueOffsets.map((i) => polygonOffset.at(i) || i)
260
- : chunk.valueOffsets;
261
- const ringData = polygonData.children[0];
262
- const pointData = ringData.children[0];
263
- const coordData = pointData.children[0];
264
- const nDim = pointData.stride;
265
- const geomOffset = ringData.valueOffsets;
266
- const flatCoordinateArray = coordData.values;
267
- const geometryIndicies = new Uint16Array(polygonOffset.length);
268
- for (let i = 0; i < polygonOffset.length; i++) {
269
- geometryIndicies[i] = geomOffset[polygonOffset[i]];
270
- }
271
- const numOfVertices = flatCoordinateArray.length / nDim;
272
- const featureIds = new Uint32Array(numOfVertices);
273
- for (let i = 0; i < partData.length - 1; i++) {
274
- const startIdx = geomOffset[partData[i]];
275
- const endIdx = geomOffset[partData[i + 1]];
276
- for (let j = startIdx; j < endIdx; j++) {
277
- featureIds[j] = i;
278
- }
279
- }
280
- const triangles = options?.triangulate
281
- ? getTriangleIndices(geometryIndicies, geomOffset, flatCoordinateArray, nDim)
282
- : null;
283
- return {
284
- featureIds,
285
- nDim,
286
- flatCoordinateArray,
287
- geomOffset,
288
- geometryIndicies,
289
- ...(options?.triangulate && triangles ? { triangles } : {})
290
- };
291
- }
292
- /**
293
- * get binary lines from geoarrow line column
294
- * @param chunk one chunk/batch of geoarrow column
295
- * @param geoEncoding the geo encoding of the geoarrow column
296
- * @returns BinaryGeometryContent
297
- */
298
- function getBinaryLinesFromChunk(chunk, geoEncoding) {
299
- const isMultiLineString = geoEncoding === 'geoarrow.multilinestring';
300
- const lineData = isMultiLineString ? chunk.children[0] : chunk;
301
- const pointData = lineData.children[0];
302
- const coordData = pointData.children[0];
303
- const nDim = pointData.stride;
304
- const geomOffset = lineData.valueOffsets;
305
- const flatCoordinateArray = coordData.values;
306
- // geometryIndicies is not needed for line string
307
- const geometryIndicies = new Uint16Array(0);
308
- const numOfVertices = flatCoordinateArray.length / nDim;
309
- const featureIds = new Uint32Array(numOfVertices);
310
- if (isMultiLineString) {
311
- const partData = chunk.valueOffsets;
312
- for (let i = 0; i < partData.length - 1; i++) {
313
- const startIdx = geomOffset[partData[i]];
314
- const endIdx = geomOffset[partData[i + 1]];
315
- for (let j = startIdx; j < endIdx; j++) {
316
- featureIds[j] = i;
317
- }
318
- }
319
- }
320
- else {
321
- for (let i = 0; i < chunk.length; i++) {
322
- const startIdx = geomOffset[i];
323
- const endIdx = geomOffset[i + 1];
324
- for (let j = startIdx; j < endIdx; j++) {
325
- featureIds[j] = i;
326
- }
327
- }
328
- }
329
- return {
330
- featureIds,
331
- flatCoordinateArray,
332
- nDim,
333
- geomOffset,
334
- geometryIndicies
335
- };
336
- }
337
- /**
338
- * get binary points from geoarrow point column
339
- * @param chunk one chunk/batch of geoarrow column
340
- * @param geoEncoding geo encoding of the geoarrow column
341
- * @returns BinaryGeometryContent
342
- */
343
- function getBinaryPointsFromChunk(chunk, geoEncoding) {
344
- const isMultiPoint = geoEncoding === 'geoarrow.multipoint';
345
- const pointData = isMultiPoint ? chunk.children[0] : chunk;
346
- const coordData = pointData.children[0];
347
- const nDim = pointData.stride;
348
- const flatCoordinateArray = coordData.values;
349
- // geometryIndices is not needed for point
350
- const geometryIndicies = new Uint16Array(0);
351
- // geomOffset is not needed for point
352
- const geomOffset = new Int32Array(0);
353
- const numOfVertices = flatCoordinateArray.length / nDim;
354
- const featureIds = new Uint32Array(numOfVertices);
355
- if (isMultiPoint) {
356
- const partData = chunk.valueOffsets;
357
- for (let i = 0; i < partData.length - 1; i++) {
358
- const startIdx = partData[i];
359
- const endIdx = partData[i + 1];
360
- for (let j = startIdx; j < endIdx; j++) {
361
- featureIds[j] = i;
362
- }
363
- }
364
- }
365
- else {
366
- for (let i = 0; i < chunk.length; i++) {
367
- featureIds[i] = i;
368
- }
369
- }
370
- return {
371
- featureIds,
372
- flatCoordinateArray,
373
- nDim,
374
- geomOffset,
375
- geometryIndicies
376
- };
377
- }
@@ -1,13 +0,0 @@
1
- import { Geometry } from '@loaders.gl/schema';
2
- import { type GeoArrowEncoding } from '@loaders.gl/gis';
3
- /**
4
- * parse geometry from arrow data that is returned from processArrowData()
5
- * NOTE: this function could be deduplicated with the binaryToFeature() in deck.gl,
6
- * it is currently used for deck.gl picking because currently deck.gl returns only the index of the feature
7
- *
8
- * @param data data extraced from arrow vector representing a geometry
9
- * @param encoding the geoarrow encoding of the geometry column
10
- * @returns Feature or null
11
- */
12
- export declare function parseGeometryFromArrow(arrowCellValue: any, encoding?: GeoArrowEncoding): Geometry | null;
13
- //# sourceMappingURL=convert-geoarrow-to-geojson-geometry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert-geoarrow-to-geojson-geometry.d.ts","sourceRoot":"","sources":["../../../src/lib/geoarrow/convert-geoarrow-to-geojson-geometry.ts"],"names":[],"mappings":"AAKA,OAAO,EAQL,QAAQ,EAET,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAmB,KAAK,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAGxE;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,GAAG,EACnB,QAAQ,CAAC,EAAE,gBAAgB,GAC1B,QAAQ,GAAG,IAAI,CAwCjB"}
@@ -1,176 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { binaryToGeometry } from '@loaders.gl/gis';
5
- import { WKBLoader, WKTLoader } from '@loaders.gl/wkt';
6
- /**
7
- * parse geometry from arrow data that is returned from processArrowData()
8
- * NOTE: this function could be deduplicated with the binaryToFeature() in deck.gl,
9
- * it is currently used for deck.gl picking because currently deck.gl returns only the index of the feature
10
- *
11
- * @param data data extraced from arrow vector representing a geometry
12
- * @param encoding the geoarrow encoding of the geometry column
13
- * @returns Feature or null
14
- */
15
- export function parseGeometryFromArrow(arrowCellValue, encoding) {
16
- // sanity
17
- encoding = encoding?.toLowerCase();
18
- if (!encoding || !arrowCellValue) {
19
- return null;
20
- }
21
- let geometry;
22
- switch (encoding) {
23
- case 'geoarrow.multipolygon':
24
- geometry = arrowMultiPolygonToFeature(arrowCellValue);
25
- break;
26
- case 'geoarrow.polygon':
27
- geometry = arrowPolygonToFeature(arrowCellValue);
28
- break;
29
- case 'geoarrow.multipoint':
30
- geometry = arrowMultiPointToFeature(arrowCellValue);
31
- break;
32
- case 'geoarrow.point':
33
- geometry = arrowPointToFeature(arrowCellValue);
34
- break;
35
- case 'geoarrow.multilinestring':
36
- geometry = arrowMultiLineStringToFeature(arrowCellValue);
37
- break;
38
- case 'geoarrow.linestring':
39
- geometry = arrowLineStringToFeature(arrowCellValue);
40
- break;
41
- case 'geoarrow.wkb':
42
- geometry = arrowWKBToFeature(arrowCellValue);
43
- break;
44
- case 'geoarrow.wkt':
45
- geometry = arrowWKTToFeature(arrowCellValue);
46
- break;
47
- default: {
48
- throw Error(`GeoArrow encoding not supported ${encoding}`);
49
- }
50
- }
51
- return geometry;
52
- }
53
- function arrowWKBToFeature(arrowCellValue) {
54
- // The actual WKB array buffer starts from byteOffset and ends at byteOffset + byteLength
55
- const arrayBuffer = arrowCellValue.buffer.slice(arrowCellValue.byteOffset, arrowCellValue.byteOffset + arrowCellValue.byteLength);
56
- const binaryGeometry = WKBLoader.parseSync?.(arrayBuffer);
57
- const geometry = binaryToGeometry(binaryGeometry);
58
- return geometry;
59
- }
60
- function arrowWKTToFeature(arrowCellValue) {
61
- const string = arrowCellValue;
62
- return WKTLoader.parseTextSync?.(string);
63
- }
64
- /**
65
- * convert Arrow MultiPolygon to geojson Feature
66
- */
67
- function arrowMultiPolygonToFeature(arrowMultiPolygon) {
68
- const multiPolygon = [];
69
- for (let m = 0; m < arrowMultiPolygon.length; m++) {
70
- const arrowPolygon = arrowMultiPolygon.get(m);
71
- const polygon = [];
72
- for (let i = 0; arrowPolygon && i < arrowPolygon?.length; i++) {
73
- const arrowRing = arrowPolygon?.get(i);
74
- const ring = [];
75
- for (let j = 0; arrowRing && j < arrowRing.length; j++) {
76
- const arrowCoord = arrowRing.get(j);
77
- const coord = Array.from(arrowCoord);
78
- ring.push(coord);
79
- }
80
- polygon.push(ring);
81
- }
82
- multiPolygon.push(polygon);
83
- }
84
- const geometry = {
85
- type: 'MultiPolygon',
86
- coordinates: multiPolygon
87
- };
88
- return geometry;
89
- }
90
- /**
91
- * convert Arrow Polygon to geojson Feature
92
- */
93
- function arrowPolygonToFeature(arrowPolygon) {
94
- const polygon = [];
95
- for (let i = 0; arrowPolygon && i < arrowPolygon.length; i++) {
96
- const arrowRing = arrowPolygon.get(i);
97
- const ring = [];
98
- for (let j = 0; arrowRing && j < arrowRing.length; j++) {
99
- const arrowCoord = arrowRing.get(j);
100
- const coords = Array.from(arrowCoord);
101
- ring.push(coords);
102
- }
103
- polygon.push(ring);
104
- }
105
- const geometry = {
106
- type: 'Polygon',
107
- coordinates: polygon
108
- };
109
- return geometry;
110
- }
111
- /**
112
- * convert Arrow MultiPoint to geojson MultiPoint
113
- */
114
- function arrowMultiPointToFeature(arrowMultiPoint) {
115
- const multiPoint = [];
116
- for (let i = 0; arrowMultiPoint && i < arrowMultiPoint.length; i++) {
117
- const arrowPoint = arrowMultiPoint.get(i);
118
- if (arrowPoint) {
119
- const coord = Array.from(arrowPoint);
120
- multiPoint.push(coord);
121
- }
122
- }
123
- return {
124
- type: 'MultiPoint',
125
- coordinates: multiPoint
126
- };
127
- }
128
- /**
129
- * convert Arrow Point to geojson Point
130
- */
131
- function arrowPointToFeature(arrowPoint) {
132
- const point = Array.from(arrowPoint);
133
- return {
134
- type: 'Point',
135
- coordinates: point
136
- };
137
- }
138
- /**
139
- * convert Arrow MultiLineString to geojson MultiLineString
140
- */
141
- function arrowMultiLineStringToFeature(arrowMultiLineString) {
142
- const multiLineString = [];
143
- for (let i = 0; arrowMultiLineString && i < arrowMultiLineString.length; i++) {
144
- const arrowLineString = arrowMultiLineString.get(i);
145
- const lineString = [];
146
- for (let j = 0; arrowLineString && j < arrowLineString.length; j++) {
147
- const arrowCoord = arrowLineString.get(j);
148
- if (arrowCoord) {
149
- const coords = Array.from(arrowCoord);
150
- lineString.push(coords);
151
- }
152
- }
153
- multiLineString.push(lineString);
154
- }
155
- return {
156
- type: 'MultiLineString',
157
- coordinates: multiLineString
158
- };
159
- }
160
- /**
161
- * convert Arrow LineString to geojson LineString
162
- */
163
- function arrowLineStringToFeature(arrowLineString) {
164
- const lineString = [];
165
- for (let i = 0; arrowLineString && i < arrowLineString.length; i++) {
166
- const arrowCoord = arrowLineString.get(i);
167
- if (arrowCoord) {
168
- const coords = Array.from(arrowCoord);
169
- lineString.push(coords);
170
- }
171
- }
172
- return {
173
- type: 'LineString',
174
- coordinates: lineString
175
- };
176
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Update bounds from geoarrow sample data
3
- *
4
- * @param flatCoords the flattend coordinates array from one chunk of geoarrow column
5
- * @param nDim the number of dimensions of the coordinates
6
- * @param bounds the bounds to be updated
7
- * @param sampleSize how many samples to be used to update the bounds, default is 1000 per chunk
8
- * @returns the updated bounds
9
- */
10
- export declare function updateBoundsFromGeoArrowSamples(flatCoords: Float64Array, nDim: number, bounds: [number, number, number, number], sampleSize?: number): [number, number, number, number];
11
- //# sourceMappingURL=get-arrow-bounds.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-arrow-bounds.d.ts","sourceRoot":"","sources":["../../../src/lib/geoarrow/get-arrow-bounds.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,YAAY,EACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACxC,UAAU,GAAE,MAAY,GACvB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAsBlC"}
@@ -1,34 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- /**
5
- * Update bounds from geoarrow sample data
6
- *
7
- * @param flatCoords the flattend coordinates array from one chunk of geoarrow column
8
- * @param nDim the number of dimensions of the coordinates
9
- * @param bounds the bounds to be updated
10
- * @param sampleSize how many samples to be used to update the bounds, default is 1000 per chunk
11
- * @returns the updated bounds
12
- */
13
- export function updateBoundsFromGeoArrowSamples(flatCoords, nDim, bounds, sampleSize = 100) {
14
- const numberOfFeatures = flatCoords.length / nDim;
15
- const sampleStep = Math.max(Math.floor(numberOfFeatures / sampleSize), 1);
16
- const newBounds = [...bounds];
17
- for (let i = 0; i < numberOfFeatures; i += sampleStep) {
18
- const lng = flatCoords[i * nDim];
19
- const lat = flatCoords[i * nDim + 1];
20
- if (lng < newBounds[0]) {
21
- newBounds[0] = lng;
22
- }
23
- if (lat < newBounds[1]) {
24
- newBounds[1] = lat;
25
- }
26
- if (lng > newBounds[2]) {
27
- newBounds[2] = lng;
28
- }
29
- if (lat > newBounds[3]) {
30
- newBounds[3] = lat;
31
- }
32
- }
33
- return newBounds;
34
- }
@@ -1,23 +0,0 @@
1
- import type { DataType, Field, Schema, SchemaMetadata } from '@loaders.gl/schema';
2
- import * as arrow from 'apache-arrow';
3
- /** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
4
- export declare function convertArrowToSchema(arrowSchema: arrow.Schema): Schema;
5
- /** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
6
- export declare function convertSchemaToArrow(schema: Schema): arrow.Schema;
7
- /** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
8
- export declare function serializeArrowSchema(arrowSchema: arrow.Schema): Schema;
9
- /** Convert a serialized Schema (plain data) to an Apache Arrow Schema (class instance) */
10
- export declare function deserializeArrowSchema(schema: Schema): arrow.Schema;
11
- /** Convert Apache Arrow Schema metadata (Map<string, string>) to serialized metadata (Record<string, string> */
12
- export declare function serializeArrowMetadata(arrowMetadata: Map<string, string>): SchemaMetadata;
13
- /** Convert serialized metadata (Record<string, string> to Apache Arrow Schema metadata (Map<string, string>) to */
14
- export declare function deserializeArrowMetadata(metadata?: SchemaMetadata): Map<string, string>;
15
- /** Convert Apache Arrow Field (class instance) to serialized Field (plain data) */
16
- export declare function serializeArrowField(field: arrow.Field): Field;
17
- /** Convert a serialized Field (plain data) to an Apache Arrow Field (class instance)*/
18
- export declare function deserializeArrowField(field: Field): arrow.Field;
19
- /** Converts a serializable loaders.gl data type to hydrated arrow data type */
20
- export declare function serializeArrowType(arrowType: arrow.DataType): DataType;
21
- /** Converts a serializable loaders.gl data type to hydrated arrow data type */
22
- export declare function deserializeArrowType(dataType: DataType): arrow.DataType;
23
- //# sourceMappingURL=convert-arrow-schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert-arrow-schema.d.ts","sourceRoot":"","sources":["../../../src/lib/tables/convert-arrow-schema.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAEtE;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAEjE;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAKtE;AAED,0FAA0F;AAC1F,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAKnE;AAED,gHAAgH;AAChH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,cAAc,CAEzF;AAED,mHAAmH;AACnH,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAEvF;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAO7D;AAED,uFAAuF;AACvF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,KAAK,CAO/D;AAED,+EAA+E;AAE/E,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAuJtE;AAED,+EAA+E;AAE/E,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAgFvE"}