@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.
- package/LICENSE +41 -0
- package/README.md +7 -0
- package/dist/geo-column/geo-column-info.d.ts +20 -0
- package/dist/geo-column/geo-column-info.d.ts.map +1 -0
- package/dist/geo-column/geo-column-info.js +74 -0
- package/dist/geo-column/geo-column.d.ts +61 -0
- package/dist/geo-column/geo-column.d.ts.map +1 -0
- package/dist/geo-column/geo-column.js +4 -0
- package/dist/geoarrow-functions.d.ts +131 -0
- package/dist/geoarrow-functions.d.ts.map +1 -0
- package/dist/geoarrow-functions.js +218 -0
- package/dist/geoarrow-types.d.ts +49 -0
- package/dist/geoarrow-types.d.ts.map +1 -0
- package/dist/geoarrow-types.js +4 -0
- package/dist/get-arrow-bounds.d.ts +11 -0
- package/dist/get-arrow-bounds.d.ts.map +1 -0
- package/dist/get-arrow-bounds.js +34 -0
- package/dist/get-geoarrow-geometry-info.d.ts +30 -0
- package/dist/get-geoarrow-geometry-info.d.ts.map +1 -0
- package/dist/get-geoarrow-geometry-info.js +124 -0
- package/dist/index.cjs +430 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/mesharrow/arrow-fixed-size-list-utils.d.ts +11 -0
- package/dist/mesharrow/arrow-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/mesharrow/arrow-fixed-size-list-utils.js +39 -0
- package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.d.ts +11 -0
- package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/mesharrow/arrow-list-of-fixed-size-list-utils.js +31 -0
- package/dist/mesharrow/get-bounding-box.d.ts +5 -0
- package/dist/mesharrow/get-bounding-box.d.ts.map +1 -0
- package/dist/mesharrow/get-bounding-box.js +33 -0
- package/dist/mesharrow/get-deck-binary-data.d.ts +13 -0
- package/dist/mesharrow/get-deck-binary-data.d.ts.map +1 -0
- package/dist/mesharrow/get-deck-binary-data.js +24 -0
- package/dist/mesharrow/mesh-accessors.d.ts +8 -0
- package/dist/mesharrow/mesh-accessors.d.ts.map +1 -0
- package/dist/mesharrow/mesh-accessors.js +18 -0
- package/dist/metadata/geoarrow-metadata.d.ts +27 -0
- package/dist/metadata/geoarrow-metadata.d.ts.map +1 -0
- package/dist/metadata/geoarrow-metadata.js +71 -0
- package/dist/metadata/geoparquet-metadata-schema.d.ts +79 -0
- package/dist/metadata/geoparquet-metadata-schema.d.ts.map +1 -0
- package/dist/metadata/geoparquet-metadata-schema.js +69 -0
- package/dist/metadata/geoparquet-metadata.d.ts +45 -0
- package/dist/metadata/geoparquet-metadata.d.ts.map +1 -0
- package/dist/metadata/geoparquet-metadata.js +131 -0
- package/dist/metadata/metadata-utils.d.ts +21 -0
- package/dist/metadata/metadata-utils.d.ts.map +1 -0
- package/dist/metadata/metadata-utils.js +14 -0
- package/package.json +63 -0
- package/src/geo-column/geo-column-info.ts +114 -0
- package/src/geo-column/geo-column.ts +85 -0
- package/src/geoarrow-functions.ts +258 -0
- package/src/geoarrow-types.ts +72 -0
- package/src/get-arrow-bounds.ts +41 -0
- package/src/get-geo-column-from-geoarrow.ts.disabled +251 -0
- package/src/get-geoarrow-geometry-info.ts +172 -0
- package/src/index.ts +57 -0
- package/src/mesharrow/arrow-fixed-size-list-utils.ts +62 -0
- package/src/mesharrow/arrow-list-of-fixed-size-list-utils.ts +47 -0
- package/src/mesharrow/get-bounding-box.ts +39 -0
- package/src/mesharrow/get-deck-binary-data.ts +43 -0
- package/src/mesharrow/mesh-accessors.ts +27 -0
- package/src/metadata/geoarrow-metadata.ts +102 -0
- package/src/metadata/geoparquet-metadata-schema.ts +71 -0
- package/src/metadata/geoparquet-metadata.ts +195 -0
- package/src/metadata/metadata-utils.ts +32 -0
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
2
|
+
import type { GeoArrowEncoding } from "./metadata/geoarrow-metadata.js";
|
|
3
|
+
/**
|
|
4
|
+
* @see https://geoarrow.org/format.html#memory-layouts
|
|
5
|
+
*/
|
|
6
|
+
export type GeoArrowGeometryInfo = {
|
|
7
|
+
/** Geometry encodings that are compatible with this column (Field) */
|
|
8
|
+
compatibleEncodings: GeoArrowEncoding[];
|
|
9
|
+
/** How many levels of List<> nesting */
|
|
10
|
+
nesting: 0 | 1 | 2 | 3;
|
|
11
|
+
/** How many values per coordinate */
|
|
12
|
+
dimension: number;
|
|
13
|
+
/**
|
|
14
|
+
* - 0: A point is just a Coordinate
|
|
15
|
+
* - 1: A line string or a multipoint is a List<Coordinate>
|
|
16
|
+
* - 2: A polygon or a multilinestring are List<List<Coordinate>>
|
|
17
|
+
* - 3: multipolygons are List<List<List<Coordinate>>>
|
|
18
|
+
*/
|
|
19
|
+
/** Coordinate memory layout {x,y,...} vs [x,y,...] */
|
|
20
|
+
coordinates: 'separated' | 'interleaved';
|
|
21
|
+
/** Coordinate */
|
|
22
|
+
valueType: 'double';
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Examines a column containing GeoArrow formatted data and returns information about the geometry type
|
|
26
|
+
* that can be useful during traversal
|
|
27
|
+
* @see https://geoarrow.org/format.html#memory-layouts
|
|
28
|
+
*/
|
|
29
|
+
export declare function getGeoArrowGeometryInfo(arrowField: arrow.Field): GeoArrowGeometryInfo | null;
|
|
30
|
+
//# sourceMappingURL=get-geoarrow-geometry-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-geoarrow-geometry-info.d.ts","sourceRoot":"","sources":["../src/get-geoarrow-geometry-info.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAC,gBAAgB,EAAC,wCAAqC;AAEnE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,sEAAsE;IACtE,mBAAmB,EAAE,gBAAgB,EAAE,CAAC;IACxC,yCAAyC;IACzC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,sDAAsD;IACtD,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC;IACzC,kBAAkB;IAClB,SAAS,EAAE,QAAQ,CAAC;CACrB,CAAC;AASF;;;;GAIG;AAEH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,oBAAoB,GAAG,IAAI,CA8E5F"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import * as arrow from 'apache-arrow';
|
|
5
|
+
/**
|
|
6
|
+
* Examines a column containing GeoArrow formatted data and returns information about the geometry type
|
|
7
|
+
* that can be useful during traversal
|
|
8
|
+
* @see https://geoarrow.org/format.html#memory-layouts
|
|
9
|
+
*/
|
|
10
|
+
// eslint-disable-next-line max-statements
|
|
11
|
+
export function getGeoArrowGeometryInfo(arrowField) {
|
|
12
|
+
if (arrowField.type instanceof arrow.Utf8) {
|
|
13
|
+
return {
|
|
14
|
+
compatibleEncodings: ['geoarrow.wkt'],
|
|
15
|
+
nesting: 0,
|
|
16
|
+
/** @note: Dimension encoded in WKT */
|
|
17
|
+
dimension: 2,
|
|
18
|
+
coordinates: 'interleaved',
|
|
19
|
+
valueType: 'double'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (arrowField.type instanceof arrow.Binary || arrowField.type instanceof arrow.LargeBinary) {
|
|
23
|
+
return {
|
|
24
|
+
compatibleEncodings: ['geoarrow.wkb'],
|
|
25
|
+
nesting: 0,
|
|
26
|
+
/** @note: Dimension encoded in WKB */
|
|
27
|
+
dimension: 2,
|
|
28
|
+
coordinates: 'interleaved',
|
|
29
|
+
valueType: 'double'
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
let coordinateInfo = getCoordinateFieldInfo(arrowField);
|
|
33
|
+
// A point is just a Coordinate
|
|
34
|
+
if (coordinateInfo) {
|
|
35
|
+
return {
|
|
36
|
+
compatibleEncodings: ['geoarrow.point'],
|
|
37
|
+
nesting: 0,
|
|
38
|
+
...coordinateInfo
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// A line string or a multipoint is a List<Coordinate>
|
|
42
|
+
if (!(arrowField.type instanceof arrow.List)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
arrowField = arrowField.type.children[0];
|
|
46
|
+
coordinateInfo = getCoordinateFieldInfo(arrowField);
|
|
47
|
+
if (coordinateInfo) {
|
|
48
|
+
return {
|
|
49
|
+
compatibleEncodings: ['geoarrow.linestring', 'geoarrow.multipoint'],
|
|
50
|
+
nesting: 1,
|
|
51
|
+
...coordinateInfo
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// A polygon or a multiline string are List<List<Coordinate>>
|
|
55
|
+
if (!(arrowField.type instanceof arrow.List)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
arrowField = arrowField.type.children[0];
|
|
59
|
+
coordinateInfo = getCoordinateFieldInfo(arrowField);
|
|
60
|
+
if (coordinateInfo) {
|
|
61
|
+
return {
|
|
62
|
+
compatibleEncodings: ['geoarrow.polygon', 'geoarrow.multilinestring'],
|
|
63
|
+
nesting: 2,
|
|
64
|
+
...coordinateInfo
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// A multipolygons are List<List<List<Coordinate>>>
|
|
68
|
+
if (!(arrowField.type instanceof arrow.List)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
arrowField = arrowField.type.children[0];
|
|
72
|
+
coordinateInfo = getCoordinateFieldInfo(arrowField);
|
|
73
|
+
if (coordinateInfo) {
|
|
74
|
+
return {
|
|
75
|
+
compatibleEncodings: ['geoarrow.multipolygon'],
|
|
76
|
+
nesting: 3,
|
|
77
|
+
...coordinateInfo
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @see https://geoarrow.org/format.html#memory-layouts
|
|
84
|
+
*/
|
|
85
|
+
function getCoordinateFieldInfo(arrowField) {
|
|
86
|
+
// interleaved case
|
|
87
|
+
if (arrowField.type instanceof arrow.FixedSizeList) {
|
|
88
|
+
const dimension = arrowField.type.listSize;
|
|
89
|
+
if (dimension < 2 || dimension > 4) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const child = arrowField.type.children[0];
|
|
93
|
+
// Spec currently only supports 64 bit coordinates
|
|
94
|
+
if (!(child.type instanceof arrow.Float)) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
coordinates: 'interleaved',
|
|
99
|
+
dimension: dimension,
|
|
100
|
+
valueType: 'double'
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// separated case
|
|
104
|
+
if (arrowField.type instanceof arrow.Struct) {
|
|
105
|
+
const children = arrowField.type.children;
|
|
106
|
+
const dimension = children.length;
|
|
107
|
+
if (dimension < 2 || dimension > 4) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
// Spec currently only supports 64 bit coordinates
|
|
111
|
+
for (const child of children) {
|
|
112
|
+
if (!(child.type instanceof arrow.Float)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
coordinates: 'separated',
|
|
118
|
+
dimension: dimension,
|
|
119
|
+
valueType: 'double'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
// No other types are valid coordinates
|
|
123
|
+
return null;
|
|
124
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// dist/index.js
|
|
31
|
+
var dist_exports = {};
|
|
32
|
+
__export(dist_exports, {
|
|
33
|
+
getBoundingBoxFromArrowPositions: () => getBoundingBoxFromArrowPositions,
|
|
34
|
+
getDeckBinaryDataFromArrowMesh: () => getDeckBinaryDataFromArrowMesh,
|
|
35
|
+
getGeoArrowGeometryInfo: () => getGeoArrowGeometryInfo,
|
|
36
|
+
getGeoMetadata: () => getGeoMetadata,
|
|
37
|
+
getGeometryColumnsFromSchema: () => getGeometryColumnsFromSchema,
|
|
38
|
+
isGeoArrowGeometry: () => isGeoArrowGeometry,
|
|
39
|
+
isGeoArrowLineString: () => isGeoArrowLineString,
|
|
40
|
+
isGeoArrowMultiLineString: () => isGeoArrowMultiLineString,
|
|
41
|
+
isGeoArrowMultiPoint: () => isGeoArrowMultiPoint,
|
|
42
|
+
isGeoArrowMultiPolygon: () => isGeoArrowMultiPolygon,
|
|
43
|
+
isGeoArrowPoint: () => isGeoArrowPoint,
|
|
44
|
+
isGeoArrowPolygon: () => isGeoArrowPolygon,
|
|
45
|
+
unpackGeoMetadata: () => unpackGeoMetadata,
|
|
46
|
+
unpackJSONStringMetadata: () => unpackJSONStringMetadata,
|
|
47
|
+
updateBoundsFromGeoArrowSamples: () => updateBoundsFromGeoArrowSamples
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(dist_exports);
|
|
50
|
+
|
|
51
|
+
// dist/mesharrow/get-bounding-box.js
|
|
52
|
+
var arrow = __toESM(require("apache-arrow"), 1);
|
|
53
|
+
function getBoundingBoxFromArrowPositions(column) {
|
|
54
|
+
const mins = [Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE];
|
|
55
|
+
const maxs = [Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE];
|
|
56
|
+
const valueColumn = column.getChildAt(0);
|
|
57
|
+
for (const data of valueColumn.data) {
|
|
58
|
+
const pointSize = 3;
|
|
59
|
+
const pointData = data.buffers[arrow.BufferType.DATA];
|
|
60
|
+
const pointCount = pointData.length / pointSize;
|
|
61
|
+
for (let i = 0; i < pointCount; i += pointSize) {
|
|
62
|
+
const x = pointData[i];
|
|
63
|
+
const y = pointData[i + 1];
|
|
64
|
+
const z = pointData[i + 2];
|
|
65
|
+
if (x < mins[0])
|
|
66
|
+
mins[0] = x;
|
|
67
|
+
else if (x > maxs[0])
|
|
68
|
+
maxs[0] = x;
|
|
69
|
+
if (y < mins[1])
|
|
70
|
+
mins[1] = y;
|
|
71
|
+
else if (y > maxs[1])
|
|
72
|
+
maxs[1] = y;
|
|
73
|
+
if (z < mins[2])
|
|
74
|
+
mins[2] = z;
|
|
75
|
+
else if (z > maxs[2])
|
|
76
|
+
maxs[2] = z;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return [mins, maxs];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// dist/mesharrow/arrow-fixed-size-list-utils.js
|
|
83
|
+
var arrow2 = __toESM(require("apache-arrow"), 1);
|
|
84
|
+
var import_schema_utils = require("@loaders.gl/schema-utils");
|
|
85
|
+
function getFixedSizeListSize(vector) {
|
|
86
|
+
return vector.type instanceof arrow2.FixedSizeList ? vector.type.listSize : 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// dist/mesharrow/mesh-accessors.js
|
|
90
|
+
function getSizeAndValueFromMeshArrowVector(attributeVector) {
|
|
91
|
+
const size = getFixedSizeListSize(attributeVector);
|
|
92
|
+
const typedArrays = getTypedArraysFromMeshArrowVector(attributeVector);
|
|
93
|
+
return { size, value: typedArrays[0] };
|
|
94
|
+
}
|
|
95
|
+
function getTypedArraysFromMeshArrowVector(attributeVector) {
|
|
96
|
+
const typedArrays = [];
|
|
97
|
+
for (const attributeData of attributeVector.data) {
|
|
98
|
+
const valueData = attributeData == null ? void 0 : attributeData.children[0];
|
|
99
|
+
const typedArray = valueData.values;
|
|
100
|
+
typedArrays.push(typedArray);
|
|
101
|
+
}
|
|
102
|
+
return typedArrays;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// dist/mesharrow/get-deck-binary-data.js
|
|
106
|
+
function getDeckBinaryDataFromArrowMesh(table) {
|
|
107
|
+
const positionVector = table.getChild("POSITION");
|
|
108
|
+
if (!positionVector) {
|
|
109
|
+
throw new Error("POSITION attribute not found");
|
|
110
|
+
}
|
|
111
|
+
const getPosition = getSizeAndValueFromMeshArrowVector(positionVector);
|
|
112
|
+
const deckAttributes = {
|
|
113
|
+
getPosition
|
|
114
|
+
};
|
|
115
|
+
const colorVector = table.getChild("COLOR_0");
|
|
116
|
+
if (colorVector) {
|
|
117
|
+
deckAttributes.getColor = getSizeAndValueFromMeshArrowVector(colorVector);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
length: table.numRows,
|
|
121
|
+
attributes: deckAttributes
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// dist/geoarrow-functions.js
|
|
126
|
+
var import_type = require("apache-arrow/type");
|
|
127
|
+
function isGeoArrowPoint(type) {
|
|
128
|
+
if (import_type.DataType.isFixedSizeList(type)) {
|
|
129
|
+
if (![2, 3, 4].includes(type.listSize)) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (!import_type.DataType.isFloat(type.children[0])) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
function isGeoArrowLineString(type) {
|
|
140
|
+
if (!import_type.DataType.isList(type)) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
if (!isGeoArrowPoint(type.children[0].type)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
function isGeoArrowPolygon(type) {
|
|
149
|
+
if (!import_type.DataType.isList(type)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (!isGeoArrowLineString(type.children[0].type)) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
function isGeoArrowMultiPoint(type) {
|
|
158
|
+
if (!import_type.DataType.isList(type)) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
if (!isGeoArrowPoint(type.children[0].type)) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
function isGeoArrowMultiLineString(type) {
|
|
167
|
+
if (!import_type.DataType.isList(type)) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (!isGeoArrowLineString(type.children[0].type)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
function isGeoArrowMultiPolygon(type) {
|
|
176
|
+
if (!import_type.DataType.isList(type)) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (!isGeoArrowPolygon(type.children[0].type)) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
function isGeoArrowGeometry(type) {
|
|
185
|
+
return isGeoArrowPoint(type) || isGeoArrowLineString(type) || isGeoArrowPolygon(type) || isGeoArrowMultiPoint(type) || isGeoArrowMultiLineString(type) || isGeoArrowMultiPolygon(type);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// dist/metadata/metadata-utils.js
|
|
189
|
+
function getMetadataValue(metadata, key) {
|
|
190
|
+
return metadata instanceof Map ? metadata.get(key) || null : metadata[key] || null;
|
|
191
|
+
}
|
|
192
|
+
function setMetadataValue(metadata, key, value) {
|
|
193
|
+
if (metadata instanceof Map) {
|
|
194
|
+
metadata.set("key", key);
|
|
195
|
+
} else {
|
|
196
|
+
metadata.key = key;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// dist/metadata/geoarrow-metadata.js
|
|
201
|
+
var GEOARROW_ENCODINGS = [
|
|
202
|
+
"geoarrow.multipolygon",
|
|
203
|
+
"geoarrow.polygon",
|
|
204
|
+
"geoarrow.multilinestring",
|
|
205
|
+
"geoarrow.linestring",
|
|
206
|
+
"geoarrow.multipoint",
|
|
207
|
+
"geoarrow.point",
|
|
208
|
+
"geoarrow.wkb",
|
|
209
|
+
"geoarrow.wkt"
|
|
210
|
+
];
|
|
211
|
+
var GEOARROW_ENCODING = "ARROW:extension:name";
|
|
212
|
+
var GEOARROW_METADATA = "ARROW:extension:metadata";
|
|
213
|
+
function getGeometryColumnsFromSchema(schema) {
|
|
214
|
+
const geometryColumns = {};
|
|
215
|
+
for (const field of schema.fields || []) {
|
|
216
|
+
const metadata = getGeometryMetadataForField((field == null ? void 0 : field.metadata) || {});
|
|
217
|
+
if (metadata) {
|
|
218
|
+
geometryColumns[field.name] = metadata;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return geometryColumns;
|
|
222
|
+
}
|
|
223
|
+
function getGeometryMetadataForField(fieldMetadata) {
|
|
224
|
+
let metadata = null;
|
|
225
|
+
let geoEncoding = getMetadataValue(fieldMetadata, GEOARROW_ENCODING);
|
|
226
|
+
if (geoEncoding) {
|
|
227
|
+
geoEncoding = geoEncoding.toLowerCase();
|
|
228
|
+
if (geoEncoding === "wkb") {
|
|
229
|
+
geoEncoding = "geoarrow.wkb";
|
|
230
|
+
}
|
|
231
|
+
if (geoEncoding === "wkt") {
|
|
232
|
+
geoEncoding = "geoarrow.wkt";
|
|
233
|
+
}
|
|
234
|
+
if (!GEOARROW_ENCODINGS.includes(geoEncoding)) {
|
|
235
|
+
console.warn(`Invalid GeoArrow encoding: ${geoEncoding}`);
|
|
236
|
+
} else {
|
|
237
|
+
metadata ||= {};
|
|
238
|
+
metadata.encoding = geoEncoding;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const columnMetadata = getMetadataValue(fieldMetadata, GEOARROW_METADATA);
|
|
242
|
+
if (columnMetadata) {
|
|
243
|
+
try {
|
|
244
|
+
metadata = JSON.parse(columnMetadata);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
console.warn("Failed to parse GeoArrow metadata", error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return metadata || null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// dist/metadata/geoparquet-metadata.js
|
|
253
|
+
function getGeoMetadata(metadata) {
|
|
254
|
+
const stringifiedGeoMetadata = getMetadataValue(metadata, "geo");
|
|
255
|
+
const geoMetadata = stringifiedGeoMetadata && parseJSONStringMetadata(stringifiedGeoMetadata);
|
|
256
|
+
if (!geoMetadata) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
for (const column of Object.values(geoMetadata.columns || {})) {
|
|
260
|
+
if (column.encoding) {
|
|
261
|
+
column.encoding = column.encoding.toLowerCase();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return geoMetadata;
|
|
265
|
+
}
|
|
266
|
+
function unpackGeoMetadata(metadata) {
|
|
267
|
+
const geoMetadata = getGeoMetadata(metadata);
|
|
268
|
+
if (!geoMetadata) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const { version, primary_column, columns } = geoMetadata;
|
|
272
|
+
if (version) {
|
|
273
|
+
setMetadataValue(metadata, "geo.version", version);
|
|
274
|
+
}
|
|
275
|
+
if (primary_column) {
|
|
276
|
+
setMetadataValue(metadata, "geo.primary_column", primary_column);
|
|
277
|
+
}
|
|
278
|
+
setMetadataValue(metadata, "geo.columns", Object.keys(columns || {}).join(""));
|
|
279
|
+
}
|
|
280
|
+
function unpackJSONStringMetadata(metadata, metadataKey) {
|
|
281
|
+
const stringifiedGeoMetadata = getMetadataValue(metadata, "geo");
|
|
282
|
+
const json = stringifiedGeoMetadata && parseJSONStringMetadata(stringifiedGeoMetadata);
|
|
283
|
+
for (const [key, value] of Object.entries(json || {})) {
|
|
284
|
+
setMetadataValue(metadata, `${metadataKey}.${key}`, typeof value === "string" ? value : JSON.stringify(value));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function parseJSONStringMetadata(stringifiedMetadata) {
|
|
288
|
+
if (!stringifiedMetadata) {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
const metadata = JSON.parse(stringifiedMetadata);
|
|
293
|
+
if (!metadata || typeof metadata !== "object") {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
return metadata;
|
|
297
|
+
} catch {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// dist/get-geoarrow-geometry-info.js
|
|
303
|
+
var arrow3 = __toESM(require("apache-arrow"), 1);
|
|
304
|
+
function getGeoArrowGeometryInfo(arrowField) {
|
|
305
|
+
if (arrowField.type instanceof arrow3.Utf8) {
|
|
306
|
+
return {
|
|
307
|
+
compatibleEncodings: ["geoarrow.wkt"],
|
|
308
|
+
nesting: 0,
|
|
309
|
+
/** @note: Dimension encoded in WKT */
|
|
310
|
+
dimension: 2,
|
|
311
|
+
coordinates: "interleaved",
|
|
312
|
+
valueType: "double"
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (arrowField.type instanceof arrow3.Binary || arrowField.type instanceof arrow3.LargeBinary) {
|
|
316
|
+
return {
|
|
317
|
+
compatibleEncodings: ["geoarrow.wkb"],
|
|
318
|
+
nesting: 0,
|
|
319
|
+
/** @note: Dimension encoded in WKB */
|
|
320
|
+
dimension: 2,
|
|
321
|
+
coordinates: "interleaved",
|
|
322
|
+
valueType: "double"
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
let coordinateInfo = getCoordinateFieldInfo(arrowField);
|
|
326
|
+
if (coordinateInfo) {
|
|
327
|
+
return {
|
|
328
|
+
compatibleEncodings: ["geoarrow.point"],
|
|
329
|
+
nesting: 0,
|
|
330
|
+
...coordinateInfo
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
if (!(arrowField.type instanceof arrow3.List)) {
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
arrowField = arrowField.type.children[0];
|
|
337
|
+
coordinateInfo = getCoordinateFieldInfo(arrowField);
|
|
338
|
+
if (coordinateInfo) {
|
|
339
|
+
return {
|
|
340
|
+
compatibleEncodings: ["geoarrow.linestring", "geoarrow.multipoint"],
|
|
341
|
+
nesting: 1,
|
|
342
|
+
...coordinateInfo
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
if (!(arrowField.type instanceof arrow3.List)) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
arrowField = arrowField.type.children[0];
|
|
349
|
+
coordinateInfo = getCoordinateFieldInfo(arrowField);
|
|
350
|
+
if (coordinateInfo) {
|
|
351
|
+
return {
|
|
352
|
+
compatibleEncodings: ["geoarrow.polygon", "geoarrow.multilinestring"],
|
|
353
|
+
nesting: 2,
|
|
354
|
+
...coordinateInfo
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
if (!(arrowField.type instanceof arrow3.List)) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
arrowField = arrowField.type.children[0];
|
|
361
|
+
coordinateInfo = getCoordinateFieldInfo(arrowField);
|
|
362
|
+
if (coordinateInfo) {
|
|
363
|
+
return {
|
|
364
|
+
compatibleEncodings: ["geoarrow.multipolygon"],
|
|
365
|
+
nesting: 3,
|
|
366
|
+
...coordinateInfo
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
function getCoordinateFieldInfo(arrowField) {
|
|
372
|
+
if (arrowField.type instanceof arrow3.FixedSizeList) {
|
|
373
|
+
const dimension = arrowField.type.listSize;
|
|
374
|
+
if (dimension < 2 || dimension > 4) {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
const child = arrowField.type.children[0];
|
|
378
|
+
if (!(child.type instanceof arrow3.Float)) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
coordinates: "interleaved",
|
|
383
|
+
dimension,
|
|
384
|
+
valueType: "double"
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
if (arrowField.type instanceof arrow3.Struct) {
|
|
388
|
+
const children = arrowField.type.children;
|
|
389
|
+
const dimension = children.length;
|
|
390
|
+
if (dimension < 2 || dimension > 4) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
for (const child of children) {
|
|
394
|
+
if (!(child.type instanceof arrow3.Float)) {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
coordinates: "separated",
|
|
400
|
+
dimension,
|
|
401
|
+
valueType: "double"
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// dist/get-arrow-bounds.js
|
|
408
|
+
function updateBoundsFromGeoArrowSamples(flatCoords, nDim, bounds, sampleSize = 100) {
|
|
409
|
+
const numberOfFeatures = flatCoords.length / nDim;
|
|
410
|
+
const sampleStep = Math.max(Math.floor(numberOfFeatures / sampleSize), 1);
|
|
411
|
+
const newBounds = [...bounds];
|
|
412
|
+
for (let i = 0; i < numberOfFeatures; i += sampleStep) {
|
|
413
|
+
const lng = flatCoords[i * nDim];
|
|
414
|
+
const lat = flatCoords[i * nDim + 1];
|
|
415
|
+
if (lng < newBounds[0]) {
|
|
416
|
+
newBounds[0] = lng;
|
|
417
|
+
}
|
|
418
|
+
if (lat < newBounds[1]) {
|
|
419
|
+
newBounds[1] = lat;
|
|
420
|
+
}
|
|
421
|
+
if (lng > newBounds[2]) {
|
|
422
|
+
newBounds[2] = lng;
|
|
423
|
+
}
|
|
424
|
+
if (lat > newBounds[3]) {
|
|
425
|
+
newBounds[3] = lat;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return newBounds;
|
|
429
|
+
}
|
|
430
|
+
//# sourceMappingURL=index.cjs.map
|