@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,120 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// parse-wkt-crs was forked from https://github.com/DanielJDufour/wkt-crs under Creative Commons CC0 1.0 license.
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param wkt
|
|
8
|
+
* @param options
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function parseWKTCRS(wkt, options) {
|
|
12
|
+
if (options?.debug) {
|
|
13
|
+
console.log('[wktcrs] parse starting with\n', wkt);
|
|
14
|
+
}
|
|
15
|
+
// move all keywords into first array item slot
|
|
16
|
+
// from PARAM[12345, 67890] to ["PARAM", 12345, 67890]
|
|
17
|
+
wkt = wkt.replace(/[A-Z][A-Z\d_]+\[/gi, (match) => `["${match.substr(0, match.length - 1)}",`);
|
|
18
|
+
// wrap variables in strings
|
|
19
|
+
// from [...,NORTH] to [...,"NORTH"]
|
|
20
|
+
wkt = wkt.replace(/, ?([A-Z][A-Z\d_]+[,\]])/gi, (match, p1) => {
|
|
21
|
+
const varname = p1.substr(0, p1.length - 1);
|
|
22
|
+
return ',' + `"${options?.raw ? 'raw:' : ''}${varname}"${p1[p1.length - 1]}`;
|
|
23
|
+
});
|
|
24
|
+
if (options?.raw) {
|
|
25
|
+
// replace all numbers with strings
|
|
26
|
+
wkt = wkt.replace(/, {0,2}(-?[\.\d]+)(?=,|\])/g, function (match, p1) {
|
|
27
|
+
return ',' + `"${options?.raw ? 'raw:' : ''}${p1}"`;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
// str should now be valid JSON
|
|
31
|
+
if (options?.debug) {
|
|
32
|
+
console.log(`[wktcrs] json'd wkt: '${wkt}'`);
|
|
33
|
+
}
|
|
34
|
+
let data;
|
|
35
|
+
try {
|
|
36
|
+
data = JSON.parse(wkt);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error(`[wktcrs] failed to parse '${wkt}'`);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
if (options?.debug) {
|
|
43
|
+
console.log(`[wktcrs] json parsed: '${wkt}'`);
|
|
44
|
+
}
|
|
45
|
+
function process(data, parent) {
|
|
46
|
+
const kw = data[0];
|
|
47
|
+
// after removing the first element with .shift()
|
|
48
|
+
// data is now just an array of attributes
|
|
49
|
+
data.forEach(function (it) {
|
|
50
|
+
if (Array.isArray(it)) {
|
|
51
|
+
process(it, data);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const kwarr = `MULTIPLE_${kw}`;
|
|
55
|
+
if (kwarr in parent) {
|
|
56
|
+
parent[kwarr].push(data);
|
|
57
|
+
}
|
|
58
|
+
else if (kw in parent) {
|
|
59
|
+
parent[kwarr] = [parent[kw], data];
|
|
60
|
+
delete parent[kw];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
parent[kw] = data;
|
|
64
|
+
}
|
|
65
|
+
return parent;
|
|
66
|
+
}
|
|
67
|
+
const result = process(data, [data]);
|
|
68
|
+
if (options?.debug) {
|
|
69
|
+
console.log('[wktcrs] parse returning', result);
|
|
70
|
+
}
|
|
71
|
+
if (options?.sort) {
|
|
72
|
+
sort(result, options);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function sort(data, options) {
|
|
77
|
+
const keys = Object.keys(data).filter((k) => !/\d+/.test(k));
|
|
78
|
+
const keywords = options?.keywords || [];
|
|
79
|
+
if (!options?.keywords) {
|
|
80
|
+
// try to find multiples
|
|
81
|
+
const counts = {};
|
|
82
|
+
if (Array.isArray(data)) {
|
|
83
|
+
data.forEach((it) => {
|
|
84
|
+
if (Array.isArray(it) && it.length >= 2 && typeof it[1] === 'string') {
|
|
85
|
+
const k = it[0];
|
|
86
|
+
if (!counts[k])
|
|
87
|
+
counts[k] = 0;
|
|
88
|
+
counts[k]++;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
for (const k in counts) {
|
|
92
|
+
if (counts[k] > 0)
|
|
93
|
+
keywords.push(k);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
keys.forEach((key) => {
|
|
98
|
+
data[key] = sort(data[key]);
|
|
99
|
+
});
|
|
100
|
+
keywords.forEach((key) => {
|
|
101
|
+
const indices = [];
|
|
102
|
+
const params = [];
|
|
103
|
+
data.forEach((item, i) => {
|
|
104
|
+
if (Array.isArray(item) && item[0] === key) {
|
|
105
|
+
indices.push(i);
|
|
106
|
+
params.push(item);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
params.sort((a, b) => {
|
|
110
|
+
a = a[1].toString();
|
|
111
|
+
b = b[1].toString();
|
|
112
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
113
|
+
});
|
|
114
|
+
// replace in order
|
|
115
|
+
params.forEach((param, i) => {
|
|
116
|
+
data[indices[i]] = param;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
return data;
|
|
120
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/gis",
|
|
3
3
|
"description": "Helpers for GIS category data",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.4.0-alpha.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -32,8 +32,10 @@
|
|
|
32
32
|
"README.md"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@loaders.gl/
|
|
36
|
-
"@loaders.gl/
|
|
35
|
+
"@loaders.gl/geoarrow": "4.4.0-alpha.1",
|
|
36
|
+
"@loaders.gl/loader-utils": "4.4.0-alpha.1",
|
|
37
|
+
"@loaders.gl/schema": "4.4.0-alpha.1",
|
|
38
|
+
"@loaders.gl/schema-utils": "4.4.0-alpha.1",
|
|
37
39
|
"@mapbox/vector-tile": "^1.3.1",
|
|
38
40
|
"@math.gl/polygon": "^4.1.0",
|
|
39
41
|
"pbf": "^3.2.1"
|
|
@@ -42,7 +44,7 @@
|
|
|
42
44
|
"@math.gl/proj4": "^4.1.0"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
|
-
"@loaders.gl/core": "
|
|
47
|
+
"@loaders.gl/core": "4.4.0-alpha.0"
|
|
46
48
|
},
|
|
47
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "f1732de45907bd500bf4eedb4803beca8bf4bfb0"
|
|
48
50
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,21 +3,94 @@
|
|
|
3
3
|
// Geo Metadata
|
|
4
4
|
// import {default as GEOPARQUET_METADATA_SCHEMA} from './lib/geo/geoparquet-metadata-schema.json';
|
|
5
5
|
// export {GEOPARQUET_METADATA_SCHEMA};
|
|
6
|
-
export {GEOPARQUET_METADATA_JSON_SCHEMA} from './lib/
|
|
6
|
+
// export {GEOPARQUET_METADATA_JSON_SCHEMA} from './lib/geoarrow/geoparquet-metadata-schema';
|
|
7
7
|
|
|
8
|
-
export type {GeoMetadata} from './lib/
|
|
9
|
-
export {
|
|
10
|
-
|
|
8
|
+
// export type {GeoMetadata} from './lib/geoarrow/geoparquet-metadata';
|
|
9
|
+
// export {
|
|
10
|
+
// getGeoMetadata,
|
|
11
|
+
// setGeoMetadata,
|
|
12
|
+
// unpackGeoMetadata
|
|
13
|
+
// } from './lib/geoarrow/geoparquet-metadata';
|
|
14
|
+
// export {unpackJSONStringMetadata} from './lib/geoarrow/geoparquet-metadata';
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
export {
|
|
16
|
+
//
|
|
17
|
+
export type {GeojsonGeometryInfo} from './lib/geometry-api/geometry-info';
|
|
18
|
+
export {getGeometryInfo} from './lib/geometry-api/geometry-info';
|
|
14
19
|
|
|
15
|
-
//
|
|
16
|
-
export {
|
|
20
|
+
// Binary Geometry Utilities
|
|
21
|
+
export type {BinaryGeometryInfo} from './lib/binary-geometry-api/binary-geometry-info';
|
|
22
|
+
export {getBinaryGeometryInfo} from './lib/binary-geometry-api/binary-geometry-info';
|
|
23
|
+
export {
|
|
24
|
+
transformBinaryCoords,
|
|
25
|
+
transformGeoJsonCoords
|
|
26
|
+
} from './lib/binary-geometry-api/transform-coordinates';
|
|
17
27
|
|
|
18
|
-
//
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export {
|
|
28
|
+
// TABLE CONVERSION
|
|
29
|
+
export {convertGeoArrowToTable} from './lib/table-converters/convert-geoarrow-table';
|
|
30
|
+
export {convertWKBTableToGeoJSON} from './lib/table-converters/convert-wkb-table-to-geojson';
|
|
31
|
+
|
|
32
|
+
// FEATURE COLLECTION CONVERSION
|
|
33
|
+
export {
|
|
34
|
+
convertFlatGeojsonToBinaryFeatureCollection,
|
|
35
|
+
// deprecated
|
|
36
|
+
convertFlatGeojsonToBinaryFeatureCollection as flatGeojsonToBinary
|
|
37
|
+
} from './lib/feature-collection-converters/convert-flat-geojson-to-binary-features';
|
|
38
|
+
export {
|
|
39
|
+
convertGeojsonToBinaryFeatureCollection,
|
|
40
|
+
// deprecated
|
|
41
|
+
convertGeojsonToBinaryFeatureCollection as geojsonToBinary
|
|
42
|
+
} from './lib/feature-collection-converters/convert-geojson-to-binary-features';
|
|
43
|
+
export {
|
|
44
|
+
convertGeojsonToFlatGeojson,
|
|
45
|
+
// deprecated
|
|
46
|
+
convertGeojsonToFlatGeojson as geojsonToFlatGeojson
|
|
47
|
+
} from './lib/feature-collection-converters/convert-geojson-to-flat-geojson';
|
|
48
|
+
export {
|
|
49
|
+
convertBinaryFeatureCollectionToGeojson,
|
|
50
|
+
convertBinaryFeatureCollectionToGeojson as binaryToGeojson
|
|
51
|
+
} from './lib/feature-collection-converters/convert-binary-features-to-geojson';
|
|
52
|
+
|
|
53
|
+
// GEOMETRY ENCODING DETECTION
|
|
54
|
+
export {isWKB, isTWKB, isWKT} from './lib/geometry-converters/wkb/helpers/parse-wkb-header';
|
|
55
|
+
|
|
56
|
+
export type {WKBHeader} from './lib/geometry-converters/wkb/helpers/wkb-types';
|
|
57
|
+
export {WKT_MAGIC_STRINGS} from './lib/geometry-converters/wkb/helpers/wkb-types';
|
|
58
|
+
|
|
59
|
+
// GEOMETRY CONVERSION
|
|
60
|
+
export {convertBinaryGeometryToGeometry} from './lib/geometry-converters/convert-binary-geometry-to-geojson';
|
|
61
|
+
|
|
62
|
+
export {convertWKTToGeometry} from './lib/geometry-converters/wkb/convert-wkt-to-geometry';
|
|
63
|
+
export {convertWKBToGeometry} from './lib/geometry-converters/wkb/convert-wkb-to-geometry';
|
|
64
|
+
export {convertWKBToBinaryGeometry} from './lib/geometry-converters/wkb/convert-wkb-to-binary-geometry';
|
|
65
|
+
export {convertTWKBToGeometry} from './lib/geometry-converters/wkb/convert-twkb-to-geometry';
|
|
66
|
+
|
|
67
|
+
export {convertGeometryToWKT} from './lib/geometry-converters/wkb/convert-geometry-to-wkt';
|
|
68
|
+
export {convertGeometryToWKB} from './lib/geometry-converters/wkb/convert-geometry-to-wkb';
|
|
69
|
+
export {convertGeometryToTWKB} from './lib/geometry-converters/wkb/convert-geometry-to-twkb';
|
|
70
|
+
|
|
71
|
+
// CRS
|
|
72
|
+
export type {WKTCRS, ParseWKTCRSOptions} from './lib//wkt-crs/parse-wkt-crs';
|
|
73
|
+
export {parseWKTCRS} from './lib//wkt-crs/parse-wkt-crs';
|
|
74
|
+
export type {EncodeWKTCRSOptions} from './lib//wkt-crs/encode-wkt-crs';
|
|
75
|
+
export {encodeWKTCRS} from './lib//wkt-crs/encode-wkt-crs';
|
|
76
|
+
|
|
77
|
+
// GEOARROW
|
|
78
|
+
export type {
|
|
79
|
+
BinaryDataFromGeoArrow,
|
|
80
|
+
BinaryGeometriesFromArrowOptions
|
|
81
|
+
} from './lib/feature-collection-converters/convert-geoarrow-to-binary-features';
|
|
82
|
+
export {
|
|
83
|
+
convertGeoArrowToBinaryFeatureCollection,
|
|
84
|
+
// deprecated
|
|
85
|
+
convertGeoArrowToBinaryFeatureCollection as getBinaryGeometriesFromArrow,
|
|
86
|
+
getBinaryGeometryTemplate,
|
|
87
|
+
getTriangleIndices,
|
|
88
|
+
getMeanCentersFromBinaryGeometries
|
|
89
|
+
} from './lib/feature-collection-converters/convert-geoarrow-to-binary-features';
|
|
90
|
+
|
|
91
|
+
export {convertGeoArrowGeometryToGeoJSON} from './lib/geometry-converters/convert-geoarrow-to-geojson';
|
|
92
|
+
|
|
93
|
+
// EXPERIMENTAL APIs
|
|
94
|
+
|
|
95
|
+
export {encodeHex, decodeHex} from './lib/utils/hex-transcoder';
|
|
96
|
+
export {extractNumericPropTypes as _extractNumericPropTypes} from './lib/feature-collection-converters/convert-flat-geojson-to-binary-features';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {BinaryGeometry} from '@loaders.gl/schema';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Information about a binary geometry
|
|
9
|
+
*/
|
|
10
|
+
export type BinaryGeometryInfo = {
|
|
11
|
+
/** The GeoJSON style geometry type corresponding to this particular binary geometry */
|
|
12
|
+
multiGeometryType:
|
|
13
|
+
| 'Point'
|
|
14
|
+
| 'LineString'
|
|
15
|
+
| 'Polygon'
|
|
16
|
+
| 'MultiPoint'
|
|
17
|
+
| 'MultiLineString'
|
|
18
|
+
| 'MultiPolygon';
|
|
19
|
+
/** Is this a "Multi" version of the binary geometry? */
|
|
20
|
+
isMultiGeometry: boolean;
|
|
21
|
+
/** How many dimensions are the coordinates? */
|
|
22
|
+
dimension: number;
|
|
23
|
+
/** How many points does this geometry have? */
|
|
24
|
+
pointCount: number;
|
|
25
|
+
/** How many coordinates does this geometry have? */
|
|
26
|
+
coordinateCount: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @returns information about a binary geometry
|
|
31
|
+
*/
|
|
32
|
+
export function getBinaryGeometryInfo(geometry: BinaryGeometry): BinaryGeometryInfo {
|
|
33
|
+
return {
|
|
34
|
+
isMultiGeometry: isMultiGeometryType(geometry),
|
|
35
|
+
multiGeometryType: getMultiGeometryType(geometry),
|
|
36
|
+
dimension: geometry.positions.size,
|
|
37
|
+
pointCount: geometry.positions.value.length / geometry.positions.size,
|
|
38
|
+
coordinateCount: geometry.positions.value.length
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @returns true if a binary geometry corresponds to a MultiPoint, MultiLineString or MultiPolygon */
|
|
43
|
+
function isMultiGeometryType(geometry: BinaryGeometry) {
|
|
44
|
+
switch (geometry.type) {
|
|
45
|
+
case 'Point':
|
|
46
|
+
const {positions} = geometry;
|
|
47
|
+
return positions.value.length / positions.size > 1;
|
|
48
|
+
case 'LineString':
|
|
49
|
+
const {pathIndices} = geometry;
|
|
50
|
+
return pathIndices.value.length > 1;
|
|
51
|
+
case 'Polygon':
|
|
52
|
+
const {polygonIndices} = geometry;
|
|
53
|
+
return polygonIndices.value.length > 1;
|
|
54
|
+
default:
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @returns geometry type of binary geometry, including MultiPoint, MultiLineString or MultiPolygon
|
|
61
|
+
*/
|
|
62
|
+
function getMultiGeometryType(geometry: BinaryGeometry) {
|
|
63
|
+
const isMulti = isMultiGeometryType(geometry);
|
|
64
|
+
switch (geometry.type) {
|
|
65
|
+
case 'Point':
|
|
66
|
+
return isMulti ? 'MultiPoint' : 'Point';
|
|
67
|
+
case 'LineString':
|
|
68
|
+
return isMulti ? 'MultiLineString' : 'LineString';
|
|
69
|
+
case 'Polygon':
|
|
70
|
+
return isMulti ? 'MultiPolygon' : 'Polygon';
|
|
71
|
+
default:
|
|
72
|
+
// @ts-expect-error
|
|
73
|
+
throw new Error(`Illegal geometry type: ${type}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
TypedArray,
|
|
7
|
+
BinaryPointGeometry,
|
|
8
|
+
BinaryLineGeometry,
|
|
9
|
+
BinaryPolygonGeometry
|
|
10
|
+
} from '@loaders.gl/schema';
|
|
11
|
+
import {concatTypedArrays} from '../utils/concat-typed-arrays';
|
|
12
|
+
|
|
13
|
+
export function concatenateBinaryPointGeometries(
|
|
14
|
+
binaryPointGeometries: BinaryPointGeometry[],
|
|
15
|
+
dimension: number
|
|
16
|
+
): BinaryPointGeometry {
|
|
17
|
+
const positions: TypedArray[] = binaryPointGeometries.map((geometry) => geometry.positions.value);
|
|
18
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
type: 'Point',
|
|
22
|
+
positions: {value: concatenatedPositions, size: dimension}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function concatenateBinaryLineGeometries(
|
|
27
|
+
binaryLineGeometries: BinaryLineGeometry[],
|
|
28
|
+
dimension: number
|
|
29
|
+
): BinaryLineGeometry {
|
|
30
|
+
const lines: TypedArray[] = binaryLineGeometries.map((geometry) => geometry.positions.value);
|
|
31
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
|
|
32
|
+
const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
|
|
33
|
+
pathIndices.unshift(0);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
type: 'LineString',
|
|
37
|
+
positions: {value: concatenatedPositions, size: dimension},
|
|
38
|
+
pathIndices: {value: new Uint32Array(pathIndices), size: 1}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function concatenateBinaryPolygonGeometries(
|
|
43
|
+
binaryPolygonGeometries: BinaryPolygonGeometry[],
|
|
44
|
+
dimension: number
|
|
45
|
+
): BinaryPolygonGeometry {
|
|
46
|
+
const polygons: TypedArray[] = [];
|
|
47
|
+
const primitivePolygons: TypedArray[] = [];
|
|
48
|
+
|
|
49
|
+
for (const binaryPolygon of binaryPolygonGeometries) {
|
|
50
|
+
const {positions, primitivePolygonIndices} = binaryPolygon;
|
|
51
|
+
polygons.push(positions.value);
|
|
52
|
+
primitivePolygons.push(primitivePolygonIndices.value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
|
|
56
|
+
const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
|
|
57
|
+
polygonIndices.unshift(0);
|
|
58
|
+
|
|
59
|
+
// Combine primitivePolygonIndices from each individual polygon
|
|
60
|
+
const primitivePolygonIndices = [0];
|
|
61
|
+
for (const primitivePolygon of primitivePolygons) {
|
|
62
|
+
primitivePolygonIndices.push(
|
|
63
|
+
...primitivePolygon
|
|
64
|
+
.filter((x: number) => x > 0)
|
|
65
|
+
.map((x: number) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1])
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
type: 'Polygon',
|
|
71
|
+
positions: {value: concatenatedPositions, size: dimension},
|
|
72
|
+
polygonIndices: {value: new Uint32Array(polygonIndices), size: 1},
|
|
73
|
+
primitivePolygonIndices: {value: new Uint32Array(primitivePolygonIndices), size: 1}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// https://stackoverflow.com/a/55261098
|
|
78
|
+
const cumulativeSum = (sum: number) => (value: number) => (sum += value);
|
package/src/lib/{binary-features/transform.ts → binary-geometry-api/transform-coordinates.ts}
RENAMED
|
@@ -38,7 +38,6 @@ function transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: Tr
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Apply transformation to every coordinate of GeoJSON features
|
|
41
|
-
*
|
|
42
41
|
* @param features Array of GeoJSON features
|
|
43
42
|
* @param fn Function to call on each coordinate
|
|
44
43
|
* @return Transformed GeoJSON features
|
|
@@ -3,30 +3,18 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
-
BinaryGeometry,
|
|
7
6
|
BinaryGeometryType,
|
|
8
|
-
BinaryPointGeometry,
|
|
9
|
-
BinaryLineGeometry,
|
|
10
|
-
BinaryPolygonGeometry,
|
|
11
7
|
BinaryFeatureCollection,
|
|
12
8
|
BinaryFeature,
|
|
13
9
|
// BinaryPointFeature,
|
|
14
10
|
// BinaryLineFeature,
|
|
15
11
|
// BinaryPolygonFeature,
|
|
16
|
-
BinaryAttribute,
|
|
17
12
|
Feature,
|
|
18
|
-
|
|
19
|
-
Position,
|
|
20
|
-
GeoJsonProperties,
|
|
21
|
-
Point,
|
|
22
|
-
MultiPoint,
|
|
23
|
-
LineString,
|
|
24
|
-
MultiLineString,
|
|
25
|
-
Polygon,
|
|
26
|
-
MultiPolygon
|
|
13
|
+
GeoJsonProperties
|
|
27
14
|
} from '@loaders.gl/schema';
|
|
15
|
+
import {convertBinaryGeometryToGeometry} from '../geometry-converters/convert-binary-geometry-to-geojson';
|
|
28
16
|
|
|
29
|
-
// Note:
|
|
17
|
+
// Note: We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.
|
|
30
18
|
// type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
|
|
31
19
|
|
|
32
20
|
type BinaryToGeoJsonOptions = {
|
|
@@ -42,7 +30,7 @@ type BinaryToGeoJsonOptions = {
|
|
|
42
30
|
* @param options.featureId Global feature id. If specified, only a single feature is extracted
|
|
43
31
|
* @return GeoJSON objects
|
|
44
32
|
*/
|
|
45
|
-
export function
|
|
33
|
+
export function convertBinaryFeatureCollectionToGeojson(
|
|
46
34
|
data: BinaryFeatureCollection,
|
|
47
35
|
options?: BinaryToGeoJsonOptions
|
|
48
36
|
): Feature[] | Feature {
|
|
@@ -91,25 +79,6 @@ function parseFeatures(data: BinaryFeatureCollection, type?: BinaryGeometryType)
|
|
|
91
79
|
return parseFeatureCollection(dataArray);
|
|
92
80
|
}
|
|
93
81
|
|
|
94
|
-
/** Parse input binary data and return a valid GeoJSON geometry object */
|
|
95
|
-
export function binaryToGeometry(
|
|
96
|
-
data: BinaryGeometry,
|
|
97
|
-
startIndex?: number,
|
|
98
|
-
endIndex?: number
|
|
99
|
-
): Geometry {
|
|
100
|
-
switch (data.type) {
|
|
101
|
-
case 'Point':
|
|
102
|
-
return pointToGeoJson(data, startIndex, endIndex);
|
|
103
|
-
case 'LineString':
|
|
104
|
-
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
105
|
-
case 'Polygon':
|
|
106
|
-
return polygonToGeoJson(data, startIndex, endIndex);
|
|
107
|
-
default:
|
|
108
|
-
const unexpectedInput: never = data;
|
|
109
|
-
throw new Error(`Unsupported geometry type: ${(unexpectedInput as any)?.type}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
82
|
// Normalize features
|
|
114
83
|
// Return an array of data objects, each of which have a type key
|
|
115
84
|
function normalizeInput(data: BinaryFeatureCollection, type?: BinaryGeometryType): BinaryFeature[] {
|
|
@@ -162,7 +131,7 @@ function parseFeatureCollection(dataArray: BinaryFeature[]): Feature[] {
|
|
|
162
131
|
|
|
163
132
|
/** Parse input binary data and return a single GeoJSON Feature */
|
|
164
133
|
function parseFeature(data: BinaryFeature, startIndex?: number, endIndex?: number): Feature {
|
|
165
|
-
const geometry =
|
|
134
|
+
const geometry = convertBinaryGeometryToGeometry(data, startIndex, endIndex);
|
|
166
135
|
const properties = parseProperties(data, startIndex, endIndex);
|
|
167
136
|
const fields = parseFields(data, startIndex, endIndex);
|
|
168
137
|
return {type: 'Feature', geometry, properties, ...fields};
|
|
@@ -181,109 +150,3 @@ function parseProperties(data, startIndex: number = 0, endIndex?: number): GeoJs
|
|
|
181
150
|
}
|
|
182
151
|
return properties;
|
|
183
152
|
}
|
|
184
|
-
|
|
185
|
-
/** Parse binary data of type Polygon */
|
|
186
|
-
function polygonToGeoJson(
|
|
187
|
-
data: BinaryPolygonGeometry,
|
|
188
|
-
startIndex: number = -Infinity,
|
|
189
|
-
endIndex: number = Infinity
|
|
190
|
-
): Polygon | MultiPolygon {
|
|
191
|
-
const {positions} = data;
|
|
192
|
-
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
193
|
-
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(
|
|
194
|
-
(x) => x >= startIndex && x <= endIndex
|
|
195
|
-
);
|
|
196
|
-
const multi = polygonIndices.length > 2;
|
|
197
|
-
|
|
198
|
-
// Polygon
|
|
199
|
-
if (!multi) {
|
|
200
|
-
const coordinates: Position[][] = [];
|
|
201
|
-
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
202
|
-
const startRingIndex = primitivePolygonIndices[i];
|
|
203
|
-
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
204
|
-
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
205
|
-
coordinates.push(ringCoordinates);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return {type: 'Polygon', coordinates};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// MultiPolygon
|
|
212
|
-
const coordinates: Position[][][] = [];
|
|
213
|
-
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
214
|
-
const startPolygonIndex = polygonIndices[i];
|
|
215
|
-
const endPolygonIndex = polygonIndices[i + 1];
|
|
216
|
-
const polygonCoordinates = polygonToGeoJson(
|
|
217
|
-
data,
|
|
218
|
-
startPolygonIndex,
|
|
219
|
-
endPolygonIndex
|
|
220
|
-
).coordinates;
|
|
221
|
-
coordinates.push(polygonCoordinates as Position[][]);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return {type: 'MultiPolygon', coordinates};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/** Parse binary data of type LineString */
|
|
228
|
-
function lineStringToGeoJson(
|
|
229
|
-
data: BinaryLineGeometry,
|
|
230
|
-
startIndex: number = -Infinity,
|
|
231
|
-
endIndex: number = Infinity
|
|
232
|
-
): LineString | MultiLineString {
|
|
233
|
-
const {positions} = data;
|
|
234
|
-
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
235
|
-
const multi = pathIndices.length > 2;
|
|
236
|
-
|
|
237
|
-
if (!multi) {
|
|
238
|
-
const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
239
|
-
return {type: 'LineString', coordinates};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const coordinates: Position[][] = [];
|
|
243
|
-
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
244
|
-
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
245
|
-
coordinates.push(ringCoordinates);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return {type: 'MultiLineString', coordinates};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/** Parse binary data of type Point */
|
|
252
|
-
function pointToGeoJson(data: BinaryPointGeometry, startIndex, endIndex): Point | MultiPoint {
|
|
253
|
-
const {positions} = data;
|
|
254
|
-
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
255
|
-
const multi = coordinates.length > 1;
|
|
256
|
-
|
|
257
|
-
if (multi) {
|
|
258
|
-
return {type: 'MultiPoint', coordinates};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return {type: 'Point', coordinates: coordinates[0]};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Parse a linear ring of positions to a GeoJSON linear ring
|
|
266
|
-
*
|
|
267
|
-
* @param positions Positions TypedArray
|
|
268
|
-
* @param startIndex Start index to include in ring
|
|
269
|
-
* @param endIndex End index to include in ring
|
|
270
|
-
* @returns GeoJSON ring
|
|
271
|
-
*/
|
|
272
|
-
function ringToGeoJson(
|
|
273
|
-
positions: BinaryAttribute,
|
|
274
|
-
startIndex?: number,
|
|
275
|
-
endIndex?: number
|
|
276
|
-
): Position[] {
|
|
277
|
-
startIndex = startIndex || 0;
|
|
278
|
-
endIndex = endIndex || positions.value.length / positions.size;
|
|
279
|
-
|
|
280
|
-
const ringCoordinates: Position[] = [];
|
|
281
|
-
for (let j = startIndex; j < endIndex; j++) {
|
|
282
|
-
const coord = Array<number>();
|
|
283
|
-
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
284
|
-
coord.push(Number(positions.value[k]));
|
|
285
|
-
}
|
|
286
|
-
ringCoordinates.push(coord);
|
|
287
|
-
}
|
|
288
|
-
return ringCoordinates;
|
|
289
|
-
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
/* eslint-disable indent */
|
|
2
6
|
import {earcut} from '@math.gl/polygon';
|
|
3
7
|
import type {
|
|
@@ -8,10 +12,15 @@ import type {
|
|
|
8
12
|
FlatPoint,
|
|
9
13
|
FlatLineString,
|
|
10
14
|
FlatPolygon,
|
|
11
|
-
GeojsonGeometryInfo,
|
|
12
15
|
TypedArray
|
|
13
16
|
} from '@loaders.gl/schema';
|
|
14
|
-
import {
|
|
17
|
+
import {GeojsonGeometryInfo} from '../geometry-api/geometry-info';
|
|
18
|
+
import {
|
|
19
|
+
PropArrayConstructor,
|
|
20
|
+
Lines,
|
|
21
|
+
Points,
|
|
22
|
+
Polygons
|
|
23
|
+
} from './helpers/flat-geojson-to-binary-types';
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
26
|
* Convert binary features to flat binary arrays. Similar to
|
|
@@ -26,11 +35,11 @@ import {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-b
|
|
|
26
35
|
* @param options
|
|
27
36
|
* @returns filled arrays
|
|
28
37
|
*/
|
|
29
|
-
export function
|
|
38
|
+
export function convertFlatGeojsonToBinaryFeatureCollection(
|
|
30
39
|
features: FlatFeature[],
|
|
31
40
|
geometryInfo: GeojsonGeometryInfo,
|
|
32
41
|
options?: FlatGeojsonToBinaryOptions
|
|
33
|
-
) {
|
|
42
|
+
): BinaryFeatureCollection {
|
|
34
43
|
const propArrayTypes = extractNumericPropTypes(features);
|
|
35
44
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
36
45
|
return fillArrays(
|
|
@@ -56,17 +65,13 @@ export type FlatGeojsonToBinaryOptions = {
|
|
|
56
65
|
triangulate?: boolean;
|
|
57
66
|
};
|
|
58
67
|
|
|
59
|
-
export const TEST_EXPORTS = {
|
|
60
|
-
extractNumericPropTypes
|
|
61
|
-
};
|
|
62
|
-
|
|
63
68
|
/**
|
|
64
69
|
* Extracts properties that are always numeric
|
|
65
70
|
*
|
|
66
71
|
* @param features
|
|
67
72
|
* @returns object with numeric types
|
|
68
73
|
*/
|
|
69
|
-
function extractNumericPropTypes(features: FlatFeature[]): {
|
|
74
|
+
export function extractNumericPropTypes(features: FlatFeature[]): {
|
|
70
75
|
[key: string]: PropArrayConstructor;
|
|
71
76
|
} {
|
|
72
77
|
const propArrayTypes = {};
|