@loaders.gl/arrow 4.0.3 → 4.0.5

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 (111) hide show
  1. package/dist/arrow-loader.d.ts +6 -3
  2. package/dist/arrow-loader.d.ts.map +1 -1
  3. package/dist/arrow-loader.js +9 -1
  4. package/dist/arrow-loader.js.map +1 -1
  5. package/dist/arrow-worker.js +37 -537
  6. package/dist/dist.dev.js +1573 -231
  7. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +31 -1
  8. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
  9. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +123 -13
  10. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
  11. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts +2 -1
  12. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts.map +1 -1
  13. package/dist/geoarrow/convert-geoarrow-to-geojson.js +4 -0
  14. package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +1 -1
  15. package/dist/geoarrow-loader.d.ts +19 -0
  16. package/dist/geoarrow-loader.d.ts.map +1 -0
  17. package/dist/geoarrow-loader.js +24 -0
  18. package/dist/geoarrow-loader.js.map +1 -0
  19. package/dist/geoarrow-writer.d.ts +9 -0
  20. package/dist/geoarrow-writer.d.ts.map +1 -0
  21. package/dist/geoarrow-writer.js +19 -0
  22. package/dist/geoarrow-writer.js.map +1 -0
  23. package/dist/index.cjs +472 -275
  24. package/dist/index.d.ts +9 -12
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +7 -13
  27. package/dist/index.js.map +1 -1
  28. package/dist/lib/arrow-table-batch.d.ts.map +1 -1
  29. package/dist/lib/arrow-table-batch.js.map +1 -1
  30. package/dist/lib/encode-arrow.d.ts.map +1 -1
  31. package/dist/lib/encode-arrow.js.map +1 -1
  32. package/dist/lib/encode-geoarrow.d.ts +15 -0
  33. package/dist/lib/encode-geoarrow.d.ts.map +1 -0
  34. package/dist/lib/encode-geoarrow.js +22 -0
  35. package/dist/lib/encode-geoarrow.js.map +1 -0
  36. package/dist/{lib → parsers}/parse-arrow-in-batches.d.ts +1 -1
  37. package/dist/parsers/parse-arrow-in-batches.d.ts.map +1 -0
  38. package/dist/parsers/parse-arrow-in-batches.js.map +1 -0
  39. package/dist/parsers/parse-arrow-sync.d.ts +6 -0
  40. package/dist/parsers/parse-arrow-sync.d.ts.map +1 -0
  41. package/dist/parsers/parse-arrow-sync.js +26 -0
  42. package/dist/parsers/parse-arrow-sync.js.map +1 -0
  43. package/dist/parsers/parse-geoarrow-in-batches.d.ts +6 -0
  44. package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +1 -0
  45. package/dist/parsers/parse-geoarrow-in-batches.js +5 -0
  46. package/dist/parsers/parse-geoarrow-in-batches.js.map +1 -0
  47. package/dist/parsers/parse-geoarrow-sync.d.ts +6 -0
  48. package/dist/parsers/parse-geoarrow-sync.d.ts.map +1 -0
  49. package/dist/parsers/parse-geoarrow-sync.js +14 -0
  50. package/dist/parsers/parse-geoarrow-sync.js.map +1 -0
  51. package/dist/tables/convert-arrow-to-columnar-table.d.ts +8 -0
  52. package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +1 -0
  53. package/dist/tables/convert-arrow-to-columnar-table.js +14 -0
  54. package/dist/tables/convert-arrow-to-columnar-table.js.map +1 -0
  55. package/dist/tables/convert-arrow-to-geojson-table.d.ts +16 -0
  56. package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +1 -0
  57. package/dist/tables/convert-arrow-to-geojson-table.js +33 -0
  58. package/dist/tables/convert-arrow-to-geojson-table.js.map +1 -0
  59. package/dist/tables/convert-columnar-to-row-table.d.ts +7 -0
  60. package/dist/tables/convert-columnar-to-row-table.d.ts.map +1 -0
  61. package/dist/tables/convert-columnar-to-row-table.js +18 -0
  62. package/dist/tables/convert-columnar-to-row-table.js.map +1 -0
  63. package/dist/triangulate-on-worker.d.ts +36 -0
  64. package/dist/triangulate-on-worker.d.ts.map +1 -0
  65. package/dist/triangulate-on-worker.js +14 -0
  66. package/dist/triangulate-on-worker.js.map +1 -0
  67. package/dist/triangulation-worker.js +880 -0
  68. package/dist/workers/arrow-worker.js +1 -1
  69. package/dist/workers/arrow-worker.js.map +1 -1
  70. package/dist/workers/triangulation-worker-node.d.ts +2 -0
  71. package/dist/workers/triangulation-worker-node.d.ts.map +1 -0
  72. package/dist/workers/triangulation-worker-node.js +2 -0
  73. package/dist/workers/triangulation-worker-node.js.map +1 -0
  74. package/dist/workers/triangulation-worker.d.ts +2 -0
  75. package/dist/workers/triangulation-worker.d.ts.map +1 -0
  76. package/dist/workers/triangulation-worker.js +24 -0
  77. package/dist/workers/triangulation-worker.js.map +1 -0
  78. package/package.json +9 -7
  79. package/src/arrow-loader.ts +25 -3
  80. package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +209 -20
  81. package/src/geoarrow/convert-geoarrow-to-geojson.ts +6 -2
  82. package/src/geoarrow-loader.ts +55 -0
  83. package/src/geoarrow-writer.ts +41 -0
  84. package/src/index.ts +30 -36
  85. package/src/lib/arrow-table-batch.ts +3 -0
  86. package/src/lib/encode-arrow.ts +3 -0
  87. package/src/lib/encode-geoarrow.ts +45 -0
  88. package/src/{lib → parsers}/parse-arrow-in-batches.ts +4 -2
  89. package/src/parsers/parse-arrow-sync.ts +38 -0
  90. package/src/parsers/parse-geoarrow-in-batches.ts +15 -0
  91. package/src/parsers/parse-geoarrow-sync.ts +22 -0
  92. package/src/tables/convert-arrow-to-columnar-table.ts +29 -0
  93. package/src/tables/convert-arrow-to-geojson-table.ts +54 -0
  94. package/src/tables/convert-columnar-to-row-table.ts +29 -0
  95. package/src/triangulate-on-worker.ts +47 -0
  96. package/src/workers/arrow-worker.ts +1 -1
  97. package/src/workers/triangulation-worker-node.ts +4 -0
  98. package/src/workers/triangulation-worker.ts +39 -0
  99. package/dist/lib/parse-arrow-in-batches.d.ts.map +0 -1
  100. package/dist/lib/parse-arrow-in-batches.js.map +0 -1
  101. package/dist/lib/parse-arrow-sync.d.ts +0 -5
  102. package/dist/lib/parse-arrow-sync.d.ts.map +0 -1
  103. package/dist/lib/parse-arrow-sync.js +0 -21
  104. package/dist/lib/parse-arrow-sync.js.map +0 -1
  105. package/dist/tables/convert-arrow-to-table.d.ts +0 -21
  106. package/dist/tables/convert-arrow-to-table.d.ts.map +0 -1
  107. package/dist/tables/convert-arrow-to-table.js +0 -37
  108. package/dist/tables/convert-arrow-to-table.js.map +0 -1
  109. package/src/lib/parse-arrow-sync.ts +0 -35
  110. package/src/tables/convert-arrow-to-table.ts +0 -68
  111. /package/dist/{lib → parsers}/parse-arrow-in-batches.js +0 -0
package/src/index.ts CHANGED
@@ -1,16 +1,8 @@
1
1
  // loaders.gl, MIT license
2
2
  // Copyright (c) vis.gl contributors
3
3
 
4
- import type {LoaderWithParser} from '@loaders.gl/loader-utils';
5
4
  import type {ArrowLoaderOptions} from './arrow-loader';
6
- import type {ArrowTableBatch, ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
7
- import type {ArrowTable} from './lib/arrow-table';
8
-
9
5
  import {TableBatchBuilder} from '@loaders.gl/schema';
10
- import {ArrowLoader as ArrowWorkerLoader} from './arrow-loader';
11
- import parseSync from './lib/parse-arrow-sync';
12
- import {parseArrowInBatches} from './lib/parse-arrow-in-batches';
13
-
14
6
  import {ArrowTableBatchAggregator} from './lib/arrow-table-batch';
15
7
 
16
8
  // Make the ArrowBatch type available
@@ -22,6 +14,21 @@ export {getArrowType} from './schema/arrow-type-utils';
22
14
 
23
15
  // SCHEMA
24
16
 
17
+ // Types
18
+ export type {ArrowTable, ArrowTableBatch} from './lib/arrow-table';
19
+ export {VECTOR_TYPES} from './types';
20
+
21
+ // Arrow loader / Writer
22
+
23
+ export type {ArrowLoaderOptions};
24
+ export {ArrowLoader, ArrowWorkerLoader} from './arrow-loader';
25
+
26
+ export {ArrowWriter} from './arrow-writer';
27
+
28
+ // Geoarrow loader
29
+ export {GeoArrowLoader, GeoArrowWorkerLoader} from './geoarrow-loader';
30
+
31
+ // Schema utils
25
32
  export {
26
33
  serializeArrowSchema,
27
34
  deserializeArrowSchema,
@@ -33,43 +40,30 @@ export {
33
40
  deserializeArrowType
34
41
  } from './schema/convert-arrow-schema';
35
42
 
36
- // Types
37
- export type {ArrowTable, ArrowTableBatch} from './lib/arrow-table';
38
- export {VECTOR_TYPES} from './types';
39
-
40
- // Arrow writer
41
-
42
- export {ArrowWriter} from './arrow-writer';
43
-
44
- // Arrow loader
45
-
46
- export type {ArrowLoaderOptions};
47
- export {ArrowWorkerLoader};
48
-
49
- /** ArrowJS table loader */
50
- export const ArrowLoader: LoaderWithParser<
51
- ArrowTable | ColumnarTable | ObjectRowTable,
52
- ArrowTableBatch,
53
- ArrowLoaderOptions
54
- > = {
55
- ...ArrowWorkerLoader,
56
- parse: async (arraybuffer: ArrayBuffer, options?: ArrowLoaderOptions) =>
57
- parseSync(arraybuffer, options),
58
- parseSync,
59
- parseInBatches: parseArrowInBatches
60
- };
43
+ // EXPERIMENTAL
61
44
 
62
45
  // Arrow Utils
63
46
  export type {GeoArrowEncoding} from '@loaders.gl/gis';
64
47
  // getGeometryColumnsFromArrowTable,
65
48
  // getGeoArrowEncoding
66
49
 
67
- export type {BinaryDataFromGeoArrow} from './geoarrow/convert-geoarrow-to-binary-geometry';
50
+ export type {
51
+ BinaryDataFromGeoArrow,
52
+ BinaryGeometriesFromArrowOptions
53
+ } from './geoarrow/convert-geoarrow-to-binary-geometry';
68
54
  export {
69
55
  BINARY_GEOMETRY_TEMPLATE,
70
- getBinaryGeometriesFromArrow
56
+ getBinaryGeometriesFromArrow,
57
+ getTriangleIndices,
58
+ getMeanCentersFromBinaryGeometries
71
59
  } from './geoarrow/convert-geoarrow-to-binary-geometry';
72
60
 
61
+ export {updateBoundsFromGeoArrowSamples} from './geoarrow/get-arrow-bounds';
62
+
73
63
  export {parseGeometryFromArrow} from './geoarrow/convert-geoarrow-to-geojson';
74
64
 
75
- export {updateBoundsFromGeoArrowSamples} from './geoarrow/get-arrow-bounds';
65
+ export {convertArrowToGeoJSONTable} from './tables/convert-arrow-to-geojson-table';
66
+
67
+ // EXPERIMENTAL WORKER
68
+
69
+ export {TriangulationWorker, triangulateOnWorker} from './triangulate-on-worker';
@@ -1,3 +1,6 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
1
4
  import {ColumnarTableBatchAggregator} from '@loaders.gl/schema';
2
5
  import type {ArrowTableBatch} from './arrow-table';
3
6
  import * as arrow from 'apache-arrow';
@@ -1,3 +1,6 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
1
4
  import * as arrow from 'apache-arrow';
2
5
  import {AnyArrayType, VECTOR_TYPES} from '../types';
3
6
 
@@ -0,0 +1,45 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import * as arrow from 'apache-arrow';
5
+ import {AnyArrayType, VECTOR_TYPES} from '../types';
6
+
7
+ export type ColumnarTable = {
8
+ name: string;
9
+ array: AnyArrayType;
10
+ type: number;
11
+ }[];
12
+
13
+ /**
14
+ * Encodes set of arrays into the Apache Arrow columnar format
15
+ * https://arrow.apache.org/docs/format/Columnar.html#ipc-file-format
16
+ * @param data - columns data
17
+ * @param options - the writer options
18
+ * @returns - encoded ArrayBuffer
19
+ */
20
+ export function encodeGeoArrowSync(data: ColumnarTable): ArrayBuffer {
21
+ const vectors: Record<string, arrow.Vector> = {};
22
+ for (const arrayData of data) {
23
+ const arrayVector = createVector(arrayData.array, arrayData.type);
24
+ vectors[arrayData.name] = arrayVector;
25
+ }
26
+ const table = new arrow.Table(vectors);
27
+ const arrowBuffer = arrow.tableToIPC(table);
28
+ return arrowBuffer;
29
+ }
30
+
31
+ /**
32
+ * Create Arrow arrow.Vector from given data and vector type
33
+ * @param array {import('../types').AnyArrayType} - columns data
34
+ * @param type {number} - the writer options
35
+ * @return a vector of one of vector's types defined in the Apache Arrow library
36
+ */
37
+ function createVector(array, type): arrow.Vector {
38
+ switch (type) {
39
+ case VECTOR_TYPES.DATE:
40
+ return arrow.vectorFromArray(array);
41
+ case VECTOR_TYPES.FLOAT:
42
+ default:
43
+ return arrow.vectorFromArray(array);
44
+ }
45
+ }
@@ -1,5 +1,7 @@
1
- // TODO - this import defeats the sophisticated typescript checking in ArrowJS
2
- import type {ArrowTableBatch} from './arrow-table';
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {ArrowTableBatch} from '../lib/arrow-table';
3
5
  import * as arrow from 'apache-arrow';
4
6
  // import {isIterable} from '@loaders.gl/core';
5
7
 
@@ -0,0 +1,38 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {ArrayRowTable, ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
5
+ import type {ArrowTable} from '../lib/arrow-table';
6
+ import {convertTable} from '@loaders.gl/schema';
7
+ import * as arrow from 'apache-arrow';
8
+ import {convertArrowToColumnarTable} from '../tables/convert-arrow-to-columnar-table';
9
+
10
+ // Parses arrow to a columnar table
11
+ export function parseArrowSync(
12
+ arrayBuffer,
13
+ options?: {shape?: 'arrow-table' | 'columnar-table' | 'object-row-table' | 'array-row-table'}
14
+ ): ArrowTable | ColumnarTable | ObjectRowTable | ArrayRowTable {
15
+ const apacheArrowTable = arrow.tableFromIPC([new Uint8Array(arrayBuffer)]);
16
+ const arrowTable: ArrowTable = {shape: 'arrow-table', data: apacheArrowTable};
17
+
18
+ const shape = options?.shape || 'arrow-table';
19
+ switch (shape) {
20
+ case 'arrow-table':
21
+ return arrowTable;
22
+
23
+ case 'columnar-table':
24
+ return convertArrowToColumnarTable(arrowTable);
25
+
26
+ case 'object-row-table':
27
+ let columnarTable = convertArrowToColumnarTable(arrowTable);
28
+ return convertTable(columnarTable, 'object-row-table');
29
+
30
+ case 'array-row-table':
31
+ columnarTable = convertArrowToColumnarTable(arrowTable);
32
+ return convertTable(columnarTable, 'array-row-table');
33
+
34
+ default:
35
+ // TODO
36
+ throw new Error(shape);
37
+ }
38
+ }
@@ -0,0 +1,15 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {GeoJSONTableBatch} from '@loaders.gl/schema';
5
+ import type {ArrowTableBatch} from '../lib/arrow-table';
6
+ import {parseArrowInBatches} from './parse-arrow-in-batches';
7
+
8
+ /**
9
+ */
10
+ export function parseGeoArrowInBatches(
11
+ asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>
12
+ ): AsyncIterable<ArrowTableBatch | GeoJSONTableBatch> {
13
+ // | BinaryGeometry
14
+ return parseArrowInBatches(asyncIterator);
15
+ }
@@ -0,0 +1,22 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {GeoJSONTable} from '@loaders.gl/schema';
5
+ import type {ArrowTable} from '../lib/arrow-table';
6
+ import {parseArrowSync} from './parse-arrow-sync';
7
+ import {convertArrowToGeoJSONTable} from '../tables/convert-arrow-to-geojson-table';
8
+
9
+ // Parses arrow to a columnar table
10
+ export function parseGeoArrowSync(
11
+ arrayBuffer,
12
+ options?: {shape?: 'arrow-table' | 'geojson-table' | 'binary-geometry'}
13
+ ): ArrowTable | GeoJSONTable {
14
+ // | BinaryGeometry
15
+ const table = parseArrowSync(arrayBuffer, {shape: 'arrow-table'}) as ArrowTable;
16
+ switch (options?.shape) {
17
+ case 'geojson-table':
18
+ return convertArrowToGeoJSONTable(table);
19
+ default:
20
+ return table;
21
+ }
22
+ }
@@ -0,0 +1,29 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {ColumnarTable} from '@loaders.gl/schema';
5
+ import type {ArrowTable} from '../lib/arrow-table';
6
+
7
+ /**
8
+ * Convert an Apache Arrow table to a ColumnarTable
9
+ * @note Currently does not convert schema
10
+ */
11
+ export function convertArrowToColumnarTable(table: ArrowTable): ColumnarTable {
12
+ // TODO - avoid calling `getColumn` on columns we are not interested in?
13
+ // Add options object?
14
+
15
+ const arrowTable = table.data;
16
+ const columnarTable = {};
17
+
18
+ for (const field of arrowTable.schema.fields) {
19
+ // This (is intended to) coalesce all record batches into a single typed array
20
+ const arrowColumn = arrowTable.getChild(field.name);
21
+ const values = arrowColumn?.toArray();
22
+ columnarTable[field.name] = values;
23
+ }
24
+
25
+ return {
26
+ shape: 'columnar-table',
27
+ data: columnarTable
28
+ };
29
+ }
@@ -0,0 +1,54 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {Feature, GeoJSONTable} from '@loaders.gl/schema';
5
+ import type * as arrow from 'apache-arrow';
6
+ import type {ArrowTable} from '../lib/arrow-table';
7
+ import {serializeArrowSchema, parseGeometryFromArrow} from '@loaders.gl/arrow';
8
+ import {getGeometryColumnsFromSchema} from '@loaders.gl/gis';
9
+
10
+ /**
11
+ * Wrap an apache arrow table in a loaders.gl table wrapper.
12
+ * From this additional conversions are available.
13
+ * @param arrowTable
14
+ * @returns
15
+ */
16
+ export function convertApacheArrowToArrowTable(arrowTable: arrow.Table): ArrowTable {
17
+ return {
18
+ shape: 'arrow-table',
19
+ data: arrowTable
20
+ };
21
+ }
22
+
23
+ /**
24
+ * Convert an Apache Arrow table to a GeoJSONTable
25
+ * @note Currently does not convert schema
26
+ */
27
+ export function convertArrowToGeoJSONTable(table: ArrowTable): GeoJSONTable {
28
+ const arrowTable = table.data;
29
+ const schema = serializeArrowSchema(arrowTable.schema);
30
+ const geometryColumns = getGeometryColumnsFromSchema(schema);
31
+
32
+ // get encoding from geometryColumns['geometry']
33
+ const encoding = geometryColumns.geometry.encoding;
34
+
35
+ const features: Feature[] = [];
36
+
37
+ for (let row = 0; row < arrowTable.numRows; row++) {
38
+ // get first geometry from arrow geometry column
39
+ const arrowGeometry = arrowTable.getChild('geometry')?.get(row);
40
+ const arrowGeometryObject = {encoding, data: arrowGeometry};
41
+
42
+ // parse arrow geometry to geojson feature
43
+ const feature = parseGeometryFromArrow(arrowGeometryObject);
44
+ if (feature) {
45
+ features.push(feature);
46
+ }
47
+ }
48
+
49
+ return {
50
+ shape: 'geojson-table',
51
+ type: 'FeatureCollection',
52
+ features
53
+ };
54
+ }
@@ -0,0 +1,29 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
5
+
6
+ /**
7
+ *
8
+ * @note - should be part of schema module
9
+ */
10
+ export function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable {
11
+ const tableKeys = Object.keys(columnarTable);
12
+ const tableRowsCount = columnarTable[tableKeys[0]].length;
13
+
14
+ const rowFormatTable: {}[] = [];
15
+
16
+ for (let index = 0; index < tableRowsCount; index++) {
17
+ const tableItem = {};
18
+ for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
19
+ const fieldName = tableKeys[keyIndex];
20
+ tableItem[fieldName] = columnarTable[fieldName][index];
21
+ }
22
+ rowFormatTable.push(tableItem);
23
+ }
24
+
25
+ return {
26
+ shape: 'object-row-table',
27
+ data: rowFormatTable
28
+ };
29
+ }
@@ -0,0 +1,47 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {WorkerOptions} from '@loaders.gl/worker-utils';
5
+ import {processOnWorker} from '@loaders.gl/worker-utils';
6
+
7
+ // __VERSION__ is injected by babel-plugin-version-inline
8
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
9
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
+
11
+ export type TriangulationWorkerInput = TriangulateInput | {operation: 'test'; data: any};
12
+ export type TriangulationWorkerOutput = TriangulateResult | {operation: 'test'; data: any};
13
+
14
+ /** Input data for operation: 'triangulate' */
15
+ export type TriangulateInput = {
16
+ operation: 'triangulate';
17
+ polygonIndices: Uint16Array;
18
+ primitivePolygonIndices: Int32Array;
19
+ flatCoordinateArray: Float64Array;
20
+ nDim: number;
21
+ };
22
+
23
+ /** Result type for operation: 'triangulate' */
24
+ export type TriangulateResult = TriangulateInput & {
25
+ triangleIndices: Uint32Array;
26
+ };
27
+
28
+ /**
29
+ * Worker for tessellating geometries. Normally called through triangulateOnWorker
30
+ */
31
+ export const TriangulationWorker = {
32
+ id: 'triangulation',
33
+ name: 'Triangulate',
34
+ module: 'arrow',
35
+ version: VERSION,
36
+ options: {}
37
+ };
38
+
39
+ /**
40
+ * Provide type safety
41
+ */
42
+ export function triangulateOnWorker(
43
+ data: TriangulationWorkerInput,
44
+ options: WorkerOptions = {}
45
+ ): Promise<TriangulationWorkerOutput> {
46
+ return processOnWorker(TriangulationWorker, data, options);
47
+ }
@@ -2,6 +2,6 @@
2
2
  // Copyright (c) vis.gl contributors
3
3
 
4
4
  import {createLoaderWorker} from '@loaders.gl/loader-utils';
5
- import {ArrowLoader} from '../index';
5
+ import {ArrowLoader} from '../arrow-loader';
6
6
 
7
7
  createLoaderWorker(ArrowLoader);
@@ -0,0 +1,4 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import './triangulation-worker';
@@ -0,0 +1,39 @@
1
+ // loaders.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import {createWorker} from '@loaders.gl/worker-utils';
5
+ import {getTriangleIndices} from '../geoarrow/convert-geoarrow-to-binary-geometry';
6
+ import type {
7
+ TriangulationWorkerInput,
8
+ TriangulateInput,
9
+ TriangulateResult
10
+ } from '../triangulate-on-worker';
11
+
12
+ createWorker(async (data, options = {}) => {
13
+ const input = data as TriangulationWorkerInput;
14
+ const operation = input?.operation;
15
+ switch (operation) {
16
+ case 'test':
17
+ return input;
18
+ case 'triangulate':
19
+ return triangulateBatch(data);
20
+ default:
21
+ throw new Error(
22
+ `TriangulationWorker: Unsupported operation ${operation}. Expected 'triangulate'`
23
+ );
24
+ }
25
+ });
26
+
27
+ function triangulateBatch(data: TriangulateInput): TriangulateResult {
28
+ // Parse any WKT/WKB geometries
29
+ // Build binary geometries
30
+ // Call earcut and triangulate
31
+ console.error('TriangulationWorker: tessellating batch', data);
32
+ const triangleIndices = getTriangleIndices(
33
+ data.polygonIndices,
34
+ data.primitivePolygonIndices,
35
+ data.flatCoordinateArray,
36
+ data.nDim
37
+ );
38
+ return {...data, triangleIndices};
39
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-arrow-in-batches.d.ts","sourceRoot":"","sources":["../../src/lib/parse-arrow-in-batches.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAInD;GACG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAChE,aAAa,CAAC,eAAe,CAAC,CAsChC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-arrow-in-batches.js","names":["arrow","parseArrowInBatches","asyncIterator","makeArrowAsyncIterator","readers","RecordBatchReader","readAll","reader","recordBatch","arrowTabledBatch","shape","batchType","data","Table","length"],"sources":["../../src/lib/parse-arrow-in-batches.ts"],"sourcesContent":["// TODO - this import defeats the sophisticated typescript checking in ArrowJS\nimport type {ArrowTableBatch} from './arrow-table';\nimport * as arrow from 'apache-arrow';\n// import {isIterable} from '@loaders.gl/core';\n\n/**\n */\nexport function parseArrowInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n): AsyncIterable<ArrowTableBatch> {\n // Creates the appropriate arrow.RecordBatchReader subclasses from the input\n // This will also close the underlying source in case of early termination or errors\n\n // As an optimization, return a non-async iterator\n /*\n if (isIterable(readers)) {\n function* makeArrowIterator() {\n for (const reader of readers) {\n for (const batch of reader) {\n yield processBatch(batch, reader);\n }\n break; // only processing one stream of batches\n }\n }\n const arrowIterator = makeArrowIterator();\n }\n */\n\n async function* makeArrowAsyncIterator(): AsyncIterator<ArrowTableBatch> {\n // @ts-ignore\n const readers = arrow.RecordBatchReader.readAll(asyncIterator);\n for await (const reader of readers) {\n for await (const recordBatch of reader) {\n const arrowTabledBatch: ArrowTableBatch = {\n shape: 'arrow-table',\n batchType: 'data',\n data: new arrow.Table([recordBatch]),\n length: recordBatch.data.length\n };\n // processBatch(recordBatch);\n yield arrowTabledBatch;\n }\n break; // only processing one stream of batches\n }\n }\n\n return makeArrowAsyncIterator() as any; // as AsyncIterator<ArrowTableBatch>;\n}\n\n// function processBatch(batch: RecordBatch): ArrowTableBatch {\n// const values = {};\n// batch.schema.fields.forEach(({name}, index) => {\n// values[name] = batch.getChildAt(index)?.toArray();\n// });\n// return {\n// };\n// }\n"],"mappings":"AAEA,OAAO,KAAKA,KAAK,MAAM,cAAc;AAKrC,OAAO,SAASC,mBAAmBA,CACjCC,aAAiE,EACjC;EAmBhC,gBAAgBC,sBAAsBA,CAAA,EAAmC;IAEvE,MAAMC,OAAO,GAAGJ,KAAK,CAACK,iBAAiB,CAACC,OAAO,CAACJ,aAAa,CAAC;IAC9D,WAAW,MAAMK,MAAM,IAAIH,OAAO,EAAE;MAClC,WAAW,MAAMI,WAAW,IAAID,MAAM,EAAE;QACtC,MAAME,gBAAiC,GAAG;UACxCC,KAAK,EAAE,aAAa;UACpBC,SAAS,EAAE,MAAM;UACjBC,IAAI,EAAE,IAAIZ,KAAK,CAACa,KAAK,CAAC,CAACL,WAAW,CAAC,CAAC;UACpCM,MAAM,EAAEN,WAAW,CAACI,IAAI,CAACE;QAC3B,CAAC;QAED,MAAML,gBAAgB;MACxB;MACA;IACF;EACF;EAEA,OAAON,sBAAsB,CAAC,CAAC;AACjC"}
@@ -1,5 +0,0 @@
1
- import type { ColumnarTable, ObjectRowTable } from '@loaders.gl/schema';
2
- import type { ArrowTable } from './arrow-table';
3
- import type { ArrowLoaderOptions } from '../arrow-loader';
4
- export default function parseArrowSync(arrayBuffer: any, options?: ArrowLoaderOptions): ArrowTable | ColumnarTable | ObjectRowTable;
5
- //# sourceMappingURL=parse-arrow-sync.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-arrow-sync.d.ts","sourceRoot":"","sources":["../../src/lib/parse-arrow-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAG9C,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAOxD,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,WAAW,KAAA,EACX,OAAO,CAAC,EAAE,kBAAkB,GAC3B,UAAU,GAAG,aAAa,GAAG,cAAc,CAoB7C"}
@@ -1,21 +0,0 @@
1
- import { convertTable } from '@loaders.gl/schema';
2
- import * as arrow from 'apache-arrow';
3
- import { convertApacheArrowToArrowTable, convertArrowToColumnarTable } from "../tables/convert-arrow-to-table.js";
4
- export default function parseArrowSync(arrayBuffer, options) {
5
- var _options$arrow;
6
- const apacheArrowTable = arrow.tableFromIPC([new Uint8Array(arrayBuffer)]);
7
- const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
8
- const shape = (options === null || options === void 0 ? void 0 : (_options$arrow = options.arrow) === null || _options$arrow === void 0 ? void 0 : _options$arrow.shape) || 'arrow-table';
9
- switch (shape) {
10
- case 'arrow-table':
11
- return arrowTable;
12
- case 'columnar-table':
13
- return convertArrowToColumnarTable(arrowTable);
14
- case 'object-row-table':
15
- const columnarTable = convertArrowToColumnarTable(arrowTable);
16
- return convertTable(columnarTable, 'object-row-table');
17
- default:
18
- throw new Error(shape);
19
- }
20
- }
21
- //# sourceMappingURL=parse-arrow-sync.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-arrow-sync.js","names":["convertTable","arrow","convertApacheArrowToArrowTable","convertArrowToColumnarTable","parseArrowSync","arrayBuffer","options","_options$arrow","apacheArrowTable","tableFromIPC","Uint8Array","arrowTable","shape","columnarTable","Error"],"sources":["../../src/lib/parse-arrow-sync.ts"],"sourcesContent":["import type {ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';\nimport type {ArrowTable} from './arrow-table';\nimport {convertTable} from '@loaders.gl/schema';\nimport * as arrow from 'apache-arrow';\nimport type {ArrowLoaderOptions} from '../arrow-loader';\nimport {\n convertApacheArrowToArrowTable,\n convertArrowToColumnarTable\n} from '../tables/convert-arrow-to-table';\n\n// Parses arrow to a columnar table\nexport default function parseArrowSync(\n arrayBuffer,\n options?: ArrowLoaderOptions\n): ArrowTable | ColumnarTable | ObjectRowTable {\n const apacheArrowTable = arrow.tableFromIPC([new Uint8Array(arrayBuffer)]);\n const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);\n\n const shape = options?.arrow?.shape || 'arrow-table';\n switch (shape) {\n case 'arrow-table':\n return arrowTable;\n\n case 'columnar-table':\n return convertArrowToColumnarTable(arrowTable);\n\n case 'object-row-table':\n const columnarTable = convertArrowToColumnarTable(arrowTable);\n return convertTable(columnarTable, 'object-row-table');\n\n default:\n // TODO\n throw new Error(shape);\n }\n}\n"],"mappings":"AAEA,SAAQA,YAAY,QAAO,oBAAoB;AAC/C,OAAO,KAAKC,KAAK,MAAM,cAAc;AAAC,SAGpCC,8BAA8B,EAC9BC,2BAA2B;AAI7B,eAAe,SAASC,cAAcA,CACpCC,WAAW,EACXC,OAA4B,EACiB;EAAA,IAAAC,cAAA;EAC7C,MAAMC,gBAAgB,GAAGP,KAAK,CAACQ,YAAY,CAAC,CAAC,IAAIC,UAAU,CAACL,WAAW,CAAC,CAAC,CAAC;EAC1E,MAAMM,UAAU,GAAGT,8BAA8B,CAACM,gBAAgB,CAAC;EAEnE,MAAMI,KAAK,GAAG,CAAAN,OAAO,aAAPA,OAAO,wBAAAC,cAAA,GAAPD,OAAO,CAAEL,KAAK,cAAAM,cAAA,uBAAdA,cAAA,CAAgBK,KAAK,KAAI,aAAa;EACpD,QAAQA,KAAK;IACX,KAAK,aAAa;MAChB,OAAOD,UAAU;IAEnB,KAAK,gBAAgB;MACnB,OAAOR,2BAA2B,CAACQ,UAAU,CAAC;IAEhD,KAAK,kBAAkB;MACrB,MAAME,aAAa,GAAGV,2BAA2B,CAACQ,UAAU,CAAC;MAC7D,OAAOX,YAAY,CAACa,aAAa,EAAE,kBAAkB,CAAC;IAExD;MAEE,MAAM,IAAIC,KAAK,CAACF,KAAK,CAAC;EAC1B;AACF"}
@@ -1,21 +0,0 @@
1
- import type { ColumnarTable, ObjectRowTable } from '@loaders.gl/schema';
2
- import type * as arrow from 'apache-arrow';
3
- import type { ArrowTable } from '../lib/arrow-table';
4
- /**
5
- * Wrap an apache arrow table in a loaders.gl table wrapper.
6
- * From this additional conversions are available.
7
- * @param arrowTable
8
- * @returns
9
- */
10
- export declare function convertApacheArrowToArrowTable(arrowTable: arrow.Table): ArrowTable;
11
- /**
12
- * Convert an Apache Arrow table to a ColumnarTable
13
- * @note Currently does not convert schema
14
- */
15
- export declare function convertArrowToColumnarTable(table: ArrowTable): ColumnarTable;
16
- /**
17
- *
18
- * @note - should be part of schema module
19
- */
20
- export declare function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable;
21
- //# sourceMappingURL=convert-arrow-to-table.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert-arrow-to-table.d.ts","sourceRoot":"","sources":["../../src/tables/convert-arrow-to-table.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAKlF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,CAkB5E;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,aAAa,GAAG,cAAc,CAmB5F"}
@@ -1,37 +0,0 @@
1
- export function convertApacheArrowToArrowTable(arrowTable) {
2
- return {
3
- shape: 'arrow-table',
4
- data: arrowTable
5
- };
6
- }
7
- export function convertArrowToColumnarTable(table) {
8
- const arrowTable = table.data;
9
- const columnarTable = {};
10
- for (const field of arrowTable.schema.fields) {
11
- const arrowColumn = arrowTable.getChild(field.name);
12
- const values = arrowColumn === null || arrowColumn === void 0 ? void 0 : arrowColumn.toArray();
13
- columnarTable[field.name] = values;
14
- }
15
- return {
16
- shape: 'columnar-table',
17
- data: columnarTable
18
- };
19
- }
20
- export function convertColumnarToRowFormatTable(columnarTable) {
21
- const tableKeys = Object.keys(columnarTable);
22
- const tableRowsCount = columnarTable[tableKeys[0]].length;
23
- const rowFormatTable = [];
24
- for (let index = 0; index < tableRowsCount; index++) {
25
- const tableItem = {};
26
- for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
27
- const fieldName = tableKeys[keyIndex];
28
- tableItem[fieldName] = columnarTable[fieldName][index];
29
- }
30
- rowFormatTable.push(tableItem);
31
- }
32
- return {
33
- shape: 'object-row-table',
34
- data: rowFormatTable
35
- };
36
- }
37
- //# sourceMappingURL=convert-arrow-to-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert-arrow-to-table.js","names":["convertApacheArrowToArrowTable","arrowTable","shape","data","convertArrowToColumnarTable","table","columnarTable","field","schema","fields","arrowColumn","getChild","name","values","toArray","convertColumnarToRowFormatTable","tableKeys","Object","keys","tableRowsCount","length","rowFormatTable","index","tableItem","keyIndex","fieldName","push"],"sources":["../../src/tables/convert-arrow-to-table.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';\nimport type * as arrow from 'apache-arrow';\nimport type {ArrowTable} from '../lib/arrow-table';\n\n/**\n * Wrap an apache arrow table in a loaders.gl table wrapper.\n * From this additional conversions are available.\n * @param arrowTable\n * @returns\n */\nexport function convertApacheArrowToArrowTable(arrowTable: arrow.Table): ArrowTable {\n return {\n shape: 'arrow-table',\n data: arrowTable\n };\n}\n\n/**\n * Convert an Apache Arrow table to a ColumnarTable\n * @note Currently does not convert schema\n */\nexport function convertArrowToColumnarTable(table: ArrowTable): ColumnarTable {\n // TODO - avoid calling `getColumn` on columns we are not interested in?\n // Add options object?\n\n const arrowTable = table.data;\n const columnarTable = {};\n\n for (const field of arrowTable.schema.fields) {\n // This (is intended to) coalesce all record batches into a single typed array\n const arrowColumn = arrowTable.getChild(field.name);\n const values = arrowColumn?.toArray();\n columnarTable[field.name] = values;\n }\n\n return {\n shape: 'columnar-table',\n data: columnarTable\n };\n}\n\n/**\n *\n * @note - should be part of schema module\n */\nexport function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable {\n const tableKeys = Object.keys(columnarTable);\n const tableRowsCount = columnarTable[tableKeys[0]].length;\n\n const rowFormatTable: {}[] = [];\n\n for (let index = 0; index < tableRowsCount; index++) {\n const tableItem = {};\n for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {\n const fieldName = tableKeys[keyIndex];\n tableItem[fieldName] = columnarTable[fieldName][index];\n }\n rowFormatTable.push(tableItem);\n }\n\n return {\n shape: 'object-row-table',\n data: rowFormatTable\n };\n}\n"],"mappings":"AAaA,OAAO,SAASA,8BAA8BA,CAACC,UAAuB,EAAc;EAClF,OAAO;IACLC,KAAK,EAAE,aAAa;IACpBC,IAAI,EAAEF;EACR,CAAC;AACH;AAMA,OAAO,SAASG,2BAA2BA,CAACC,KAAiB,EAAiB;EAI5E,MAAMJ,UAAU,GAAGI,KAAK,CAACF,IAAI;EAC7B,MAAMG,aAAa,GAAG,CAAC,CAAC;EAExB,KAAK,MAAMC,KAAK,IAAIN,UAAU,CAACO,MAAM,CAACC,MAAM,EAAE;IAE5C,MAAMC,WAAW,GAAGT,UAAU,CAACU,QAAQ,CAACJ,KAAK,CAACK,IAAI,CAAC;IACnD,MAAMC,MAAM,GAAGH,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAEI,OAAO,CAAC,CAAC;IACrCR,aAAa,CAACC,KAAK,CAACK,IAAI,CAAC,GAAGC,MAAM;EACpC;EAEA,OAAO;IACLX,KAAK,EAAE,gBAAgB;IACvBC,IAAI,EAAEG;EACR,CAAC;AACH;AAMA,OAAO,SAASS,+BAA+BA,CAACT,aAA4B,EAAkB;EAC5F,MAAMU,SAAS,GAAGC,MAAM,CAACC,IAAI,CAACZ,aAAa,CAAC;EAC5C,MAAMa,cAAc,GAAGb,aAAa,CAACU,SAAS,CAAC,CAAC,CAAC,CAAC,CAACI,MAAM;EAEzD,MAAMC,cAAoB,GAAG,EAAE;EAE/B,KAAK,IAAIC,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGH,cAAc,EAAEG,KAAK,EAAE,EAAE;IACnD,MAAMC,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,IAAIC,QAAQ,GAAG,CAAC,EAAEA,QAAQ,GAAGR,SAAS,CAACI,MAAM,EAAEI,QAAQ,EAAE,EAAE;MAC9D,MAAMC,SAAS,GAAGT,SAAS,CAACQ,QAAQ,CAAC;MACrCD,SAAS,CAACE,SAAS,CAAC,GAAGnB,aAAa,CAACmB,SAAS,CAAC,CAACH,KAAK,CAAC;IACxD;IACAD,cAAc,CAACK,IAAI,CAACH,SAAS,CAAC;EAChC;EAEA,OAAO;IACLrB,KAAK,EAAE,kBAAkB;IACzBC,IAAI,EAAEkB;EACR,CAAC;AACH"}
@@ -1,35 +0,0 @@
1
- import type {ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
2
- import type {ArrowTable} from './arrow-table';
3
- import {convertTable} from '@loaders.gl/schema';
4
- import * as arrow from 'apache-arrow';
5
- import type {ArrowLoaderOptions} from '../arrow-loader';
6
- import {
7
- convertApacheArrowToArrowTable,
8
- convertArrowToColumnarTable
9
- } from '../tables/convert-arrow-to-table';
10
-
11
- // Parses arrow to a columnar table
12
- export default function parseArrowSync(
13
- arrayBuffer,
14
- options?: ArrowLoaderOptions
15
- ): ArrowTable | ColumnarTable | ObjectRowTable {
16
- const apacheArrowTable = arrow.tableFromIPC([new Uint8Array(arrayBuffer)]);
17
- const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
18
-
19
- const shape = options?.arrow?.shape || 'arrow-table';
20
- switch (shape) {
21
- case 'arrow-table':
22
- return arrowTable;
23
-
24
- case 'columnar-table':
25
- return convertArrowToColumnarTable(arrowTable);
26
-
27
- case 'object-row-table':
28
- const columnarTable = convertArrowToColumnarTable(arrowTable);
29
- return convertTable(columnarTable, 'object-row-table');
30
-
31
- default:
32
- // TODO
33
- throw new Error(shape);
34
- }
35
- }