@loaders.gl/gis 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.
- package/dist/index.cjs +2411 -469
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +31 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -15
- package/dist/lib/binary-geometry-api/binary-geometry-info.d.ts +21 -0
- package/dist/lib/binary-geometry-api/binary-geometry-info.d.ts.map +1 -0
- package/dist/lib/binary-geometry-api/binary-geometry-info.js +48 -0
- package/dist/lib/binary-geometry-api/concat-binary-geometry.d.ts +5 -0
- package/dist/lib/binary-geometry-api/concat-binary-geometry.d.ts.map +1 -0
- package/dist/lib/binary-geometry-api/concat-binary-geometry.js +50 -0
- package/dist/lib/{binary-features/transform.d.ts → binary-geometry-api/transform-coordinates.d.ts} +1 -2
- package/dist/lib/binary-geometry-api/transform-coordinates.d.ts.map +1 -0
- package/dist/lib/{binary-features/transform.js → binary-geometry-api/transform-coordinates.js} +0 -1
- package/dist/lib/feature-collection-converters/convert-binary-features-to-geojson.d.ts +16 -0
- package/dist/lib/feature-collection-converters/convert-binary-features-to-geojson.d.ts.map +1 -0
- package/dist/lib/{binary-features/binary-to-geojson.js → feature-collection-converters/convert-binary-features-to-geojson.js} +3 -90
- package/dist/lib/{binary-features/flat-geojson-to-binary.d.ts → feature-collection-converters/convert-flat-geojson-to-binary-features.d.ts} +6 -9
- package/dist/lib/feature-collection-converters/convert-flat-geojson-to-binary-features.d.ts.map +1 -0
- package/dist/lib/{binary-features/flat-geojson-to-binary.js → feature-collection-converters/convert-flat-geojson-to-binary-features.js} +5 -5
- package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.d.ts +74 -0
- package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.d.ts.map +1 -0
- package/dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.js +377 -0
- package/dist/lib/{binary-features/geojson-to-binary.d.ts → feature-collection-converters/convert-geojson-to-binary-features.d.ts} +2 -2
- package/dist/lib/feature-collection-converters/convert-geojson-to-binary-features.d.ts.map +1 -0
- package/dist/lib/feature-collection-converters/convert-geojson-to-binary-features.js +24 -0
- package/dist/lib/{binary-features/geojson-to-flat-geojson.d.ts → feature-collection-converters/convert-geojson-to-flat-geojson.d.ts} +2 -2
- package/dist/lib/feature-collection-converters/convert-geojson-to-flat-geojson.d.ts.map +1 -0
- package/dist/lib/{binary-features/geojson-to-flat-geojson.js → feature-collection-converters/convert-geojson-to-flat-geojson.js} +4 -1
- package/dist/lib/feature-collection-converters/helpers/flat-geojson-to-binary-types.d.ts.map +1 -0
- package/dist/lib/feature-collection-converters/helpers/flat-geojson-to-binary-types.js +4 -0
- package/dist/lib/geometry-api/geometry-info.d.ts +21 -0
- package/dist/lib/geometry-api/geometry-info.d.ts.map +1 -0
- package/dist/lib/{binary-features/extract-geometry-info.js → geometry-api/geometry-info.js} +4 -1
- package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.d.ts +4 -0
- package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.d.ts.map +1 -0
- package/dist/lib/geometry-converters/convert-binary-geometry-to-geojson.js +91 -0
- package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.d.ts +13 -0
- package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.d.ts.map +1 -0
- package/dist/lib/geometry-converters/convert-geoarrow-to-geojson.js +164 -0
- package/dist/lib/geometry-converters/convert-to-geojson.d.ts +6 -0
- package/dist/lib/geometry-converters/convert-to-geojson.d.ts.map +1 -0
- package/dist/lib/geometry-converters/convert-to-geojson.js +39 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.d.ts +6 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.js +195 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.d.ts +9 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.js +273 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.d.ts +8 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.js +44 -0
- package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.d.ts +10 -0
- package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.js +254 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.d.ts +3 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js +164 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.d.ts +11 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.js +9 -0
- package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.d.ts +16 -0
- package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.js +258 -0
- package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts +43 -0
- package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.js +174 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-types.d.ts +64 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-types.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-types.js +46 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.d.ts +21 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/helpers/wkb-utils.js +64 -0
- package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.d.ts +8 -0
- package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.d.ts.map +1 -0
- package/dist/lib/geometry-converters/wkb/helpers/write-wkb-header.js +33 -0
- package/dist/lib/table-converters/convert-geoarrow-table.d.ts +27 -0
- package/dist/lib/table-converters/convert-geoarrow-table.d.ts.map +1 -0
- package/dist/lib/table-converters/convert-geoarrow-table.js +154 -0
- package/dist/lib/table-converters/convert-wkb-table-to-geojson.d.ts +4 -0
- package/dist/lib/table-converters/convert-wkb-table-to-geojson.d.ts.map +1 -0
- package/dist/lib/{tables/convert-table-to-geojson.js → table-converters/convert-wkb-table-to-geojson.js} +10 -16
- package/dist/lib/table-converters/make-arrow-batch-iterator.d.ts +6 -0
- package/dist/lib/table-converters/make-arrow-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table-converters/make-arrow-batch-iterator.js +35 -0
- package/dist/lib/utils/base64-encoder.d.ts +5 -0
- package/dist/lib/utils/base64-encoder.d.ts.map +1 -0
- package/dist/lib/utils/base64-encoder.js +153 -0
- package/dist/lib/utils/binary-reader.d.ts +18 -0
- package/dist/lib/utils/binary-reader.d.ts.map +1 -0
- package/dist/lib/utils/binary-reader.js +69 -0
- package/dist/lib/utils/binary-writer.d.ts +30 -0
- package/dist/lib/utils/binary-writer.d.ts.map +1 -0
- package/dist/lib/utils/binary-writer.js +127 -0
- package/dist/lib/utils/concat-typed-arrays.d.ts +3 -0
- package/dist/lib/utils/concat-typed-arrays.d.ts.map +1 -0
- package/dist/lib/utils/concat-typed-arrays.js +18 -0
- package/dist/lib/utils/hex-encoder.d.ts +15 -0
- package/dist/lib/utils/hex-encoder.d.ts.map +1 -0
- package/dist/lib/utils/hex-encoder.js +54 -0
- package/dist/lib/utils/hex-transcoder.d.ts +15 -0
- package/dist/lib/utils/hex-transcoder.d.ts.map +1 -0
- package/dist/lib/utils/hex-transcoder.js +50 -0
- package/dist/lib/wkt-crs/encode-wkt-crs.d.ts +10 -0
- package/dist/lib/wkt-crs/encode-wkt-crs.d.ts.map +1 -0
- package/dist/lib/wkt-crs/encode-wkt-crs.js +35 -0
- package/dist/lib/wkt-crs/parse-wkt-crs.d.ts +15 -0
- package/dist/lib/wkt-crs/parse-wkt-crs.d.ts.map +1 -0
- package/dist/lib/wkt-crs/parse-wkt-crs.js +120 -0
- package/package.json +7 -5
- package/src/index.ts +87 -14
- package/src/lib/binary-geometry-api/binary-geometry-info.ts +75 -0
- package/src/lib/binary-geometry-api/concat-binary-geometry.ts +78 -0
- package/src/lib/{binary-features/transform.ts → binary-geometry-api/transform-coordinates.ts} +0 -1
- package/src/lib/{binary-features/binary-to-geojson.ts → feature-collection-converters/convert-binary-features-to-geojson.ts} +5 -142
- package/src/lib/{binary-features/flat-geojson-to-binary.ts → feature-collection-converters/convert-flat-geojson-to-binary-features.ts} +14 -9
- package/src/lib/feature-collection-converters/convert-geoarrow-to-binary-features.ts +496 -0
- package/src/lib/{binary-features/geojson-to-binary.ts → feature-collection-converters/convert-geojson-to-binary-features.ts} +11 -7
- package/src/lib/{binary-features/geojson-to-flat-geojson.ts → feature-collection-converters/convert-geojson-to-flat-geojson.ts} +5 -1
- package/src/lib/{binary-features → feature-collection-converters/helpers}/flat-geojson-to-binary-types.ts +4 -0
- package/src/lib/{binary-features/extract-geometry-info.ts → geometry-api/geometry-info.ts} +20 -2
- package/src/lib/geometry-converters/convert-binary-geometry-to-geojson.ts +148 -0
- package/src/lib/geometry-converters/convert-geoarrow-to-geojson.ts +193 -0
- package/src/lib/geometry-converters/convert-to-geojson.ts +52 -0
- package/src/lib/geometry-converters/wkb/convert-geometry-to-twkb.ts +308 -0
- package/src/lib/geometry-converters/wkb/convert-geometry-to-wkb.ts +365 -0
- package/src/lib/geometry-converters/wkb/convert-geometry-to-wkt.ts +54 -0
- package/src/lib/geometry-converters/wkb/convert-twkb-to-geometry.ts +366 -0
- package/src/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.ts +238 -0
- package/src/lib/geometry-converters/wkb/convert-wkb-to-geometry.ts +23 -0
- package/src/lib/geometry-converters/wkb/convert-wkt-to-geometry.ts +294 -0
- package/src/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +213 -0
- package/src/lib/geometry-converters/wkb/helpers/wkb-types.ts +82 -0
- package/src/lib/geometry-converters/wkb/helpers/wkb-utils.ts +85 -0
- package/src/lib/geometry-converters/wkb/helpers/write-wkb-header.ts +41 -0
- package/src/lib/table-converters/convert-geoarrow-table.ts +218 -0
- package/src/lib/{tables/convert-table-to-geojson.ts → table-converters/convert-wkb-table-to-geojson.ts} +10 -23
- package/src/lib/table-converters/make-arrow-batch-iterator.ts +53 -0
- package/src/lib/utils/base64-encoder.ts +157 -0
- package/src/lib/utils/binary-reader.ts +76 -0
- package/src/lib/utils/binary-writer.ts +136 -0
- package/src/lib/utils/concat-typed-arrays.ts +24 -0
- package/src/lib/utils/hex-encoder.ts +60 -0
- package/src/lib/utils/hex-transcoder.ts +54 -0
- package/src/lib/wkt-crs/encode-wkt-crs.ts +41 -0
- package/src/lib/wkt-crs/parse-wkt-crs.ts +149 -0
- package/dist/lib/binary-features/binary-to-geojson.d.ts +0 -18
- package/dist/lib/binary-features/binary-to-geojson.d.ts.map +0 -1
- package/dist/lib/binary-features/extract-geometry-info.d.ts +0 -8
- package/dist/lib/binary-features/extract-geometry-info.d.ts.map +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary-types.d.ts.map +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary-types.js +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary.d.ts.map +0 -1
- package/dist/lib/binary-features/geojson-to-binary.d.ts.map +0 -1
- package/dist/lib/binary-features/geojson-to-binary.js +0 -21
- package/dist/lib/binary-features/geojson-to-flat-geojson.d.ts.map +0 -1
- package/dist/lib/binary-features/transform.d.ts.map +0 -1
- package/dist/lib/geo/geoarrow-metadata.d.ts +0 -27
- package/dist/lib/geo/geoarrow-metadata.d.ts.map +0 -1
- package/dist/lib/geo/geoarrow-metadata.js +0 -70
- package/dist/lib/geo/geoparquet-metadata-schema.d.ts +0 -79
- package/dist/lib/geo/geoparquet-metadata-schema.d.ts.map +0 -1
- package/dist/lib/geo/geoparquet-metadata-schema.js +0 -69
- package/dist/lib/geo/geoparquet-metadata.d.ts +0 -45
- package/dist/lib/geo/geoparquet-metadata.d.ts.map +0 -1
- package/dist/lib/geo/geoparquet-metadata.js +0 -117
- package/dist/lib/tables/convert-table-to-geojson.d.ts +0 -5
- package/dist/lib/tables/convert-table-to-geojson.d.ts.map +0 -1
- package/src/lib/geo/geoarrow-metadata.ts +0 -100
- package/src/lib/geo/geoparquet-metadata-schema.json +0 -60
- package/src/lib/geo/geoparquet-metadata-schema.ts +0 -71
- package/src/lib/geo/geoparquet-metadata.ts +0 -191
- /package/dist/lib/{binary-features → feature-collection-converters/helpers}/flat-geojson-to-binary-types.d.ts +0 -0
|
@@ -0,0 +1,377 @@
|
|
|
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 '@loaders.gl/geoarrow';
|
|
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
|
+
* get binary geometries from geoarrow column
|
|
17
|
+
*
|
|
18
|
+
* @param geoColumn the geoarrow column, e.g. arrowTable.getChildAt(geoColumnIndex)
|
|
19
|
+
* @param geoEncoding the geo encoding of the geoarrow column, e.g. getGeoArrowEncoding(arrowTable.schema, geoColumnName)
|
|
20
|
+
* @param options options for getting binary geometries {meanCenter: boolean}
|
|
21
|
+
* @returns BinaryDataFromGeoArrow
|
|
22
|
+
*/
|
|
23
|
+
export function convertGeoArrowToBinaryFeatureCollection(geoColumn, geoEncoding, options) {
|
|
24
|
+
const featureTypes = {
|
|
25
|
+
polygon: geoEncoding === 'geoarrow.multipolygon' || geoEncoding === 'geoarrow.polygon',
|
|
26
|
+
point: geoEncoding === 'geoarrow.multipoint' || geoEncoding === 'geoarrow.point',
|
|
27
|
+
line: geoEncoding === 'geoarrow.multilinestring' || geoEncoding === 'geoarrow.linestring'
|
|
28
|
+
};
|
|
29
|
+
const chunks = options?.chunkIndex !== undefined && options?.chunkIndex >= 0
|
|
30
|
+
? [geoColumn.data[options?.chunkIndex]]
|
|
31
|
+
: geoColumn.data;
|
|
32
|
+
let bounds = [Infinity, Infinity, -Infinity, -Infinity];
|
|
33
|
+
let globalFeatureIdOffset = options?.chunkOffset || 0;
|
|
34
|
+
const binaryGeometries = [];
|
|
35
|
+
chunks.forEach((chunk) => {
|
|
36
|
+
const { featureIds, flatCoordinateArray, nDim, geomOffset, triangles } = getBinaryGeometriesFromChunk(chunk, geoEncoding, options);
|
|
37
|
+
const globalFeatureIds = new Uint32Array(featureIds.length);
|
|
38
|
+
for (let i = 0; i < featureIds.length; i++) {
|
|
39
|
+
globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
|
|
40
|
+
}
|
|
41
|
+
const binaryContent = {
|
|
42
|
+
globalFeatureIds: { value: globalFeatureIds, size: 1 },
|
|
43
|
+
positions: {
|
|
44
|
+
value: flatCoordinateArray,
|
|
45
|
+
size: nDim
|
|
46
|
+
},
|
|
47
|
+
featureIds: { value: featureIds, size: 1 },
|
|
48
|
+
// eslint-disable-next-line no-loop-func
|
|
49
|
+
properties: [...Array(chunk.length).keys()].map((i) => ({
|
|
50
|
+
index: i + globalFeatureIdOffset
|
|
51
|
+
}))
|
|
52
|
+
};
|
|
53
|
+
// TODO: check if chunks are sequentially accessed
|
|
54
|
+
globalFeatureIdOffset += chunk.length;
|
|
55
|
+
// NOTE: deck.gl defines the BinaryFeatureCollection structure must have points, lines, polygons even if they are empty
|
|
56
|
+
binaryGeometries.push({
|
|
57
|
+
shape: 'binary-feature-collection',
|
|
58
|
+
points: {
|
|
59
|
+
type: 'Point',
|
|
60
|
+
...getBinaryGeometryTemplate(),
|
|
61
|
+
...(featureTypes.point ? binaryContent : {})
|
|
62
|
+
},
|
|
63
|
+
lines: {
|
|
64
|
+
type: 'LineString',
|
|
65
|
+
...getBinaryGeometryTemplate(),
|
|
66
|
+
...(featureTypes.line ? binaryContent : {}),
|
|
67
|
+
pathIndices: { value: featureTypes.line ? geomOffset : new Uint16Array(0), size: 1 }
|
|
68
|
+
},
|
|
69
|
+
polygons: {
|
|
70
|
+
type: 'Polygon',
|
|
71
|
+
...getBinaryGeometryTemplate(),
|
|
72
|
+
...(featureTypes.polygon ? binaryContent : {}),
|
|
73
|
+
polygonIndices: {
|
|
74
|
+
// use geomOffset as polygonIndices same as primitivePolygonIndices since we are using earcut to get triangule indices
|
|
75
|
+
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
76
|
+
size: 1
|
|
77
|
+
},
|
|
78
|
+
primitivePolygonIndices: {
|
|
79
|
+
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
80
|
+
size: 1
|
|
81
|
+
},
|
|
82
|
+
...(triangles ? { triangles: { value: triangles, size: 1 } } : {})
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
bounds = updateBoundsFromGeoArrowSamples(flatCoordinateArray, nDim, bounds);
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
binaryGeometries,
|
|
89
|
+
bounds,
|
|
90
|
+
featureTypes,
|
|
91
|
+
...(options?.calculateMeanCenters
|
|
92
|
+
? { meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries) }
|
|
93
|
+
: {})
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* binary geometry template, see deck.gl BinaryGeometry
|
|
98
|
+
*/
|
|
99
|
+
export function getBinaryGeometryTemplate() {
|
|
100
|
+
return {
|
|
101
|
+
globalFeatureIds: { value: new Uint32Array(0), size: 1 },
|
|
102
|
+
positions: { value: new Float32Array(0), size: 2 },
|
|
103
|
+
properties: [],
|
|
104
|
+
numericProps: {},
|
|
105
|
+
featureIds: { value: new Uint32Array(0), size: 1 }
|
|
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 geometryIndexes = new Uint16Array(polygonOffset.length);
|
|
268
|
+
for (let i = 0; i < polygonOffset.length; i++) {
|
|
269
|
+
geometryIndexes[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(geometryIndexes, geomOffset, flatCoordinateArray, nDim)
|
|
282
|
+
: null;
|
|
283
|
+
return {
|
|
284
|
+
featureIds,
|
|
285
|
+
nDim,
|
|
286
|
+
flatCoordinateArray,
|
|
287
|
+
geomOffset,
|
|
288
|
+
geometryIndexes,
|
|
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
|
+
// geometryIndexes is not needed for line string
|
|
307
|
+
const geometryIndexes = 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
|
+
geometryIndexes
|
|
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 geometryIndexes = 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
|
+
geometryIndexes
|
|
376
|
+
};
|
|
377
|
+
}
|
|
@@ -15,5 +15,5 @@ export type GeojsonToBinaryOptions = {
|
|
|
15
15
|
* @param options
|
|
16
16
|
* @returns features in binary format, grouped by geometry type
|
|
17
17
|
*/
|
|
18
|
-
export declare function
|
|
19
|
-
//# sourceMappingURL=geojson-to-binary.d.ts.map
|
|
18
|
+
export declare function convertGeojsonToBinaryFeatureCollection(features: Feature[], options?: GeojsonToBinaryOptions): BinaryFeatureCollection;
|
|
19
|
+
//# sourceMappingURL=convert-geojson-to-binary-features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-geojson-to-binary-features.d.ts","sourceRoot":"","sources":["../../../src/lib/feature-collection-converters/convert-geojson-to-binary-features.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,OAAO,EAAE,uBAAuB,EAAC,MAAM,oBAAoB,CAAC;AAMzE;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,CAAC;IACrE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,uCAAuC,CACrD,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,sBAAkE,GAC1E,uBAAuB,CAUzB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getGeometryInfo } from "../geometry-api/geometry-info.js";
|
|
5
|
+
import { convertGeojsonToFlatGeojson } from "./convert-geojson-to-flat-geojson.js";
|
|
6
|
+
import { convertFlatGeojsonToBinaryFeatureCollection } from "./convert-flat-geojson-to-binary-features.js";
|
|
7
|
+
/**
|
|
8
|
+
* Convert GeoJSON features to flat binary arrays
|
|
9
|
+
*
|
|
10
|
+
* @param features
|
|
11
|
+
* @param options
|
|
12
|
+
* @returns features in binary format, grouped by geometry type
|
|
13
|
+
*/
|
|
14
|
+
export function convertGeojsonToBinaryFeatureCollection(features, options = { fixRingWinding: true, triangulate: true }) {
|
|
15
|
+
const geometryInfo = getGeometryInfo(features);
|
|
16
|
+
const coordLength = geometryInfo.coordLength;
|
|
17
|
+
const { fixRingWinding } = options;
|
|
18
|
+
const flatFeatures = convertGeojsonToFlatGeojson(features, { coordLength, fixRingWinding });
|
|
19
|
+
return convertFlatGeojsonToBinaryFeatureCollection(flatFeatures, geometryInfo, {
|
|
20
|
+
numericPropKeys: options.numericPropKeys,
|
|
21
|
+
PositionDataType: options.PositionDataType || Float32Array,
|
|
22
|
+
triangulate: options.triangulate
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -13,5 +13,5 @@ export type GeojsonToFlatGeojsonOptions = {
|
|
|
13
13
|
* @param options
|
|
14
14
|
* @returns an Array of Flat GeoJSON features
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
17
|
-
//# sourceMappingURL=geojson-to-flat-geojson.d.ts.map
|
|
16
|
+
export declare function convertGeojsonToFlatGeojson(features: Feature[], options?: GeojsonToFlatGeojsonOptions): FlatFeature[];
|
|
17
|
+
//# sourceMappingURL=convert-geojson-to-flat-geojson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-geojson-to-flat-geojson.d.ts","sourceRoot":"","sources":["../../../src/lib/feature-collection-converters/convert-geojson-to-flat-geojson.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAY,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AASF;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,2BAAoE,GAC5E,WAAW,EAAE,CAEf"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { getPolygonSignedArea } from '@math.gl/polygon';
|
|
2
5
|
/**
|
|
3
6
|
* Convert GeoJSON features to Flat GeoJSON features
|
|
@@ -6,7 +9,7 @@ import { getPolygonSignedArea } from '@math.gl/polygon';
|
|
|
6
9
|
* @param options
|
|
7
10
|
* @returns an Array of Flat GeoJSON features
|
|
8
11
|
*/
|
|
9
|
-
export function
|
|
12
|
+
export function convertGeojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
|
|
10
13
|
return features.map((feature) => flattenFeature(feature, options));
|
|
11
14
|
}
|
|
12
15
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flat-geojson-to-binary-types.d.ts","sourceRoot":"","sources":["../../../../src/lib/feature-collection-converters/helpers/flat-geojson-to-binary-types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC5B,uBAAuB,GACvB,uBAAuB,GACvB,gBAAgB,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,YAAY,GAAG,YAAY,CAAC;IACvC,gBAAgB,EAAE,WAAW,GAAG,WAAW,CAAC;IAC5C,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC;IACtC,YAAY,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;KAAC,CAAC;IAC1C,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,MAAM,EAAE;QACN,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KACtB,EAAE,CAAC;CACL,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,YAAY,GAAG,YAAY,CAAC;IACvC,WAAW,EAAE,WAAW,GAAG,WAAW,CAAC;IACvC,gBAAgB,EAAE,WAAW,GAAG,WAAW,CAAC;IAC5C,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC;IACtC,YAAY,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;KAAC,CAAC;IAC1C,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,MAAM,EAAE;QACN,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KACtB,EAAE,CAAC;CACL,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,YAAY,GAAG,YAAY,CAAC;IACvC,cAAc,EAAE,WAAW,GAAG,WAAW,CAAC;IAC1C,uBAAuB,EAAE,WAAW,GAAG,WAAW,CAAC;IACnD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,gBAAgB,EAAE,WAAW,GAAG,WAAW,CAAC;IAC5C,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC;IACtC,YAAY,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;KAAC,CAAC;IAC1C,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,MAAM,EAAE;QACN,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KACtB,EAAE,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Feature } from '@loaders.gl/schema';
|
|
2
|
+
/** Aggregate information for converting GeoJSON into other formats */
|
|
3
|
+
export type GeojsonGeometryInfo = {
|
|
4
|
+
coordLength: number;
|
|
5
|
+
pointPositionsCount: number;
|
|
6
|
+
pointFeaturesCount: number;
|
|
7
|
+
linePositionsCount: number;
|
|
8
|
+
linePathsCount: number;
|
|
9
|
+
lineFeaturesCount: number;
|
|
10
|
+
polygonPositionsCount: number;
|
|
11
|
+
polygonObjectsCount: number;
|
|
12
|
+
polygonRingsCount: number;
|
|
13
|
+
polygonFeaturesCount: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Initial scan over GeoJSON features
|
|
17
|
+
* Counts number of coordinates of each geometry type and
|
|
18
|
+
* keeps track of the max coordinate dimensions
|
|
19
|
+
*/
|
|
20
|
+
export declare function getGeometryInfo(features: Feature[]): GeojsonGeometryInfo;
|
|
21
|
+
//# sourceMappingURL=geometry-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry-info.d.ts","sourceRoot":"","sources":["../../../src/lib/geometry-api/geometry-info.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAEhD,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AAEH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,mBAAmB,CA4FxE"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
/**
|
|
2
5
|
* Initial scan over GeoJSON features
|
|
3
6
|
* Counts number of coordinates of each geometry type and
|
|
4
7
|
* keeps track of the max coordinate dimensions
|
|
5
8
|
*/
|
|
6
9
|
// eslint-disable-next-line complexity, max-statements
|
|
7
|
-
export function
|
|
10
|
+
export function getGeometryInfo(features) {
|
|
8
11
|
// Counts the number of _positions_, so [x, y, z] counts as one
|
|
9
12
|
let pointPositionsCount = 0;
|
|
10
13
|
let pointFeaturesCount = 0;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BinaryGeometry, Geometry } from '@loaders.gl/schema';
|
|
2
|
+
/** Parse input binary data and return a valid GeoJSON geometry object */
|
|
3
|
+
export declare function convertBinaryGeometryToGeometry(data: BinaryGeometry, startIndex?: number, endIndex?: number): Geometry;
|
|
4
|
+
//# sourceMappingURL=convert-binary-geometry-to-geojson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-binary-geometry-to-geojson.d.ts","sourceRoot":"","sources":["../../../src/lib/geometry-converters/convert-binary-geometry-to-geojson.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,cAAc,EAKd,QAAQ,EAQT,MAAM,oBAAoB,CAAC;AAE5B,yEAAyE;AACzE,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,cAAc,EACpB,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,GAChB,QAAQ,CAYV"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/** Parse input binary data and return a valid GeoJSON geometry object */
|
|
5
|
+
export function convertBinaryGeometryToGeometry(data, startIndex, endIndex) {
|
|
6
|
+
switch (data.type) {
|
|
7
|
+
case 'Point':
|
|
8
|
+
return pointToGeoJson(data, startIndex, endIndex);
|
|
9
|
+
case 'LineString':
|
|
10
|
+
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
11
|
+
case 'Polygon':
|
|
12
|
+
return polygonToGeoJson(data, startIndex, endIndex);
|
|
13
|
+
default:
|
|
14
|
+
const unexpectedInput = data;
|
|
15
|
+
throw new Error(`Unsupported geometry type: ${unexpectedInput?.type}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Parse binary data of type Polygon */
|
|
19
|
+
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
20
|
+
const { positions } = data;
|
|
21
|
+
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
22
|
+
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
23
|
+
const multi = polygonIndices.length > 2;
|
|
24
|
+
// Polygon
|
|
25
|
+
if (!multi) {
|
|
26
|
+
const coordinates = [];
|
|
27
|
+
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
28
|
+
const startRingIndex = primitivePolygonIndices[i];
|
|
29
|
+
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
30
|
+
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
31
|
+
coordinates.push(ringCoordinates);
|
|
32
|
+
}
|
|
33
|
+
return { type: 'Polygon', coordinates };
|
|
34
|
+
}
|
|
35
|
+
// MultiPolygon
|
|
36
|
+
const coordinates = [];
|
|
37
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
38
|
+
const startPolygonIndex = polygonIndices[i];
|
|
39
|
+
const endPolygonIndex = polygonIndices[i + 1];
|
|
40
|
+
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
41
|
+
coordinates.push(polygonCoordinates);
|
|
42
|
+
}
|
|
43
|
+
return { type: 'MultiPolygon', coordinates };
|
|
44
|
+
}
|
|
45
|
+
/** Parse binary data of type LineString */
|
|
46
|
+
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
47
|
+
const { positions } = data;
|
|
48
|
+
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
49
|
+
const multi = pathIndices.length > 2;
|
|
50
|
+
if (!multi) {
|
|
51
|
+
const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
52
|
+
return { type: 'LineString', coordinates };
|
|
53
|
+
}
|
|
54
|
+
const coordinates = [];
|
|
55
|
+
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
56
|
+
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
57
|
+
coordinates.push(ringCoordinates);
|
|
58
|
+
}
|
|
59
|
+
return { type: 'MultiLineString', coordinates };
|
|
60
|
+
}
|
|
61
|
+
/** Parse binary data of type Point */
|
|
62
|
+
function pointToGeoJson(data, startIndex, endIndex) {
|
|
63
|
+
const { positions } = data;
|
|
64
|
+
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
65
|
+
const multi = coordinates.length > 1;
|
|
66
|
+
if (multi) {
|
|
67
|
+
return { type: 'MultiPoint', coordinates };
|
|
68
|
+
}
|
|
69
|
+
return { type: 'Point', coordinates: coordinates[0] };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Parse a linear ring of positions to a GeoJSON linear ring
|
|
73
|
+
*
|
|
74
|
+
* @param positions Positions TypedArray
|
|
75
|
+
* @param startIndex Start index to include in ring
|
|
76
|
+
* @param endIndex End index to include in ring
|
|
77
|
+
* @returns GeoJSON ring
|
|
78
|
+
*/
|
|
79
|
+
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
80
|
+
startIndex = startIndex || 0;
|
|
81
|
+
endIndex = endIndex || positions.value.length / positions.size;
|
|
82
|
+
const ringCoordinates = [];
|
|
83
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
84
|
+
const coord = Array();
|
|
85
|
+
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
86
|
+
coord.push(Number(positions.value[k]));
|
|
87
|
+
}
|
|
88
|
+
ringCoordinates.push(coord);
|
|
89
|
+
}
|
|
90
|
+
return ringCoordinates;
|
|
91
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Geometry } from '@loaders.gl/schema';
|
|
2
|
+
import type { GeoArrowEncoding } from '@loaders.gl/geoarrow';
|
|
3
|
+
/**
|
|
4
|
+
* parse geometry from arrow data that is returned from processArrowData()
|
|
5
|
+
* NOTE: this function could be deduplicated with the binaryToGeometry() 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 convertGeoArrowGeometryToGeoJSON(arrowCellValue: any, encoding?: GeoArrowEncoding): Geometry | null;
|
|
13
|
+
//# sourceMappingURL=convert-geoarrow-to-geojson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-geoarrow-to-geojson.d.ts","sourceRoot":"","sources":["../../../src/lib/geometry-converters/convert-geoarrow-to-geojson.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAQV,QAAQ,EACT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAI3D;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,CAC9C,cAAc,EAAE,GAAG,EACnB,QAAQ,CAAC,EAAE,gBAAgB,GAC1B,QAAQ,GAAG,IAAI,CA4BjB"}
|