@loaders.gl/gis 4.3.1 → 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
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,280 +17,1129 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// dist/index.js
|
|
21
31
|
var dist_exports = {};
|
|
22
32
|
__export(dist_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
WKT_MAGIC_STRINGS: () => WKT_MAGIC_STRINGS,
|
|
34
|
+
_extractNumericPropTypes: () => extractNumericPropTypes,
|
|
35
|
+
binaryToGeojson: () => convertBinaryFeatureCollectionToGeojson,
|
|
36
|
+
convertBinaryFeatureCollectionToGeojson: () => convertBinaryFeatureCollectionToGeojson,
|
|
37
|
+
convertBinaryGeometryToGeometry: () => convertBinaryGeometryToGeometry,
|
|
38
|
+
convertFlatGeojsonToBinaryFeatureCollection: () => convertFlatGeojsonToBinaryFeatureCollection,
|
|
39
|
+
convertGeoArrowGeometryToGeoJSON: () => convertGeoArrowGeometryToGeoJSON,
|
|
40
|
+
convertGeoArrowToBinaryFeatureCollection: () => convertGeoArrowToBinaryFeatureCollection,
|
|
41
|
+
convertGeoArrowToTable: () => convertGeoArrowToTable,
|
|
42
|
+
convertGeojsonToBinaryFeatureCollection: () => convertGeojsonToBinaryFeatureCollection,
|
|
43
|
+
convertGeojsonToFlatGeojson: () => convertGeojsonToFlatGeojson,
|
|
44
|
+
convertGeometryToTWKB: () => convertGeometryToTWKB,
|
|
45
|
+
convertGeometryToWKB: () => convertGeometryToWKB,
|
|
46
|
+
convertGeometryToWKT: () => convertGeometryToWKT,
|
|
47
|
+
convertTWKBToGeometry: () => convertTWKBToGeometry,
|
|
26
48
|
convertWKBTableToGeoJSON: () => convertWKBTableToGeoJSON,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
49
|
+
convertWKBToBinaryGeometry: () => convertWKBToBinaryGeometry,
|
|
50
|
+
convertWKBToGeometry: () => convertWKBToGeometry,
|
|
51
|
+
convertWKTToGeometry: () => convertWKTToGeometry,
|
|
52
|
+
decodeHex: () => decodeHex,
|
|
53
|
+
encodeHex: () => encodeHex,
|
|
54
|
+
encodeWKTCRS: () => encodeWKTCRS,
|
|
55
|
+
flatGeojsonToBinary: () => convertFlatGeojsonToBinaryFeatureCollection,
|
|
56
|
+
geojsonToBinary: () => convertGeojsonToBinaryFeatureCollection,
|
|
57
|
+
geojsonToFlatGeojson: () => convertGeojsonToFlatGeojson,
|
|
58
|
+
getBinaryGeometriesFromArrow: () => convertGeoArrowToBinaryFeatureCollection,
|
|
59
|
+
getBinaryGeometryInfo: () => getBinaryGeometryInfo,
|
|
60
|
+
getBinaryGeometryTemplate: () => getBinaryGeometryTemplate,
|
|
61
|
+
getGeometryInfo: () => getGeometryInfo,
|
|
62
|
+
getMeanCentersFromBinaryGeometries: () => getMeanCentersFromBinaryGeometries,
|
|
63
|
+
getTriangleIndices: () => getTriangleIndices,
|
|
64
|
+
isTWKB: () => isTWKB,
|
|
65
|
+
isWKB: () => isWKB,
|
|
66
|
+
isWKT: () => isWKT,
|
|
67
|
+
parseWKTCRS: () => parseWKTCRS,
|
|
33
68
|
transformBinaryCoords: () => transformBinaryCoords,
|
|
34
|
-
transformGeoJsonCoords: () => transformGeoJsonCoords
|
|
35
|
-
unpackGeoMetadata: () => unpackGeoMetadata,
|
|
36
|
-
unpackJSONStringMetadata: () => unpackJSONStringMetadata
|
|
69
|
+
transformGeoJsonCoords: () => transformGeoJsonCoords
|
|
37
70
|
});
|
|
38
71
|
module.exports = __toCommonJS(dist_exports);
|
|
39
72
|
|
|
40
|
-
// dist/lib/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
description: "2D bbox consisting of (xmin, ymin, xmax, ymax)",
|
|
83
|
-
minItems: 4,
|
|
84
|
-
maxItems: 4
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
description: "3D bbox consisting of (xmin, ymin, zmin, xmax, ymax, zmax)",
|
|
88
|
-
minItems: 6,
|
|
89
|
-
maxItems: 6
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
},
|
|
93
|
-
epoch: { type: "number" }
|
|
73
|
+
// dist/lib/geometry-api/geometry-info.js
|
|
74
|
+
function getGeometryInfo(features) {
|
|
75
|
+
let pointPositionsCount = 0;
|
|
76
|
+
let pointFeaturesCount = 0;
|
|
77
|
+
let linePositionsCount = 0;
|
|
78
|
+
let linePathsCount = 0;
|
|
79
|
+
let lineFeaturesCount = 0;
|
|
80
|
+
let polygonPositionsCount = 0;
|
|
81
|
+
let polygonObjectsCount = 0;
|
|
82
|
+
let polygonRingsCount = 0;
|
|
83
|
+
let polygonFeaturesCount = 0;
|
|
84
|
+
const coordLengths = /* @__PURE__ */ new Set();
|
|
85
|
+
for (const feature of features) {
|
|
86
|
+
const geometry = feature.geometry;
|
|
87
|
+
switch (geometry.type) {
|
|
88
|
+
case "Point":
|
|
89
|
+
pointFeaturesCount++;
|
|
90
|
+
pointPositionsCount++;
|
|
91
|
+
coordLengths.add(geometry.coordinates.length);
|
|
92
|
+
break;
|
|
93
|
+
case "MultiPoint":
|
|
94
|
+
pointFeaturesCount++;
|
|
95
|
+
pointPositionsCount += geometry.coordinates.length;
|
|
96
|
+
for (const point of geometry.coordinates) {
|
|
97
|
+
coordLengths.add(point.length);
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case "LineString":
|
|
101
|
+
lineFeaturesCount++;
|
|
102
|
+
linePositionsCount += geometry.coordinates.length;
|
|
103
|
+
linePathsCount++;
|
|
104
|
+
for (const coord of geometry.coordinates) {
|
|
105
|
+
coordLengths.add(coord.length);
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case "MultiLineString":
|
|
109
|
+
lineFeaturesCount++;
|
|
110
|
+
for (const line of geometry.coordinates) {
|
|
111
|
+
linePositionsCount += line.length;
|
|
112
|
+
linePathsCount++;
|
|
113
|
+
for (const coord of line) {
|
|
114
|
+
coordLengths.add(coord.length);
|
|
94
115
|
}
|
|
95
116
|
}
|
|
96
|
-
|
|
97
|
-
|
|
117
|
+
break;
|
|
118
|
+
case "Polygon":
|
|
119
|
+
polygonFeaturesCount++;
|
|
120
|
+
polygonObjectsCount++;
|
|
121
|
+
polygonRingsCount += geometry.coordinates.length;
|
|
122
|
+
const flattened = geometry.coordinates.flat();
|
|
123
|
+
polygonPositionsCount += flattened.length;
|
|
124
|
+
for (const coord of flattened) {
|
|
125
|
+
coordLengths.add(coord.length);
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case "MultiPolygon":
|
|
129
|
+
polygonFeaturesCount++;
|
|
130
|
+
for (const polygon of geometry.coordinates) {
|
|
131
|
+
polygonObjectsCount++;
|
|
132
|
+
polygonRingsCount += polygon.length;
|
|
133
|
+
const flattened2 = polygon.flat();
|
|
134
|
+
polygonPositionsCount += flattened2.length;
|
|
135
|
+
for (const coord of flattened2) {
|
|
136
|
+
coordLengths.add(coord.length);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
98
142
|
}
|
|
99
143
|
}
|
|
100
|
-
|
|
144
|
+
return {
|
|
145
|
+
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
146
|
+
pointPositionsCount,
|
|
147
|
+
pointFeaturesCount,
|
|
148
|
+
linePositionsCount,
|
|
149
|
+
linePathsCount,
|
|
150
|
+
lineFeaturesCount,
|
|
151
|
+
polygonPositionsCount,
|
|
152
|
+
polygonObjectsCount,
|
|
153
|
+
polygonRingsCount,
|
|
154
|
+
polygonFeaturesCount
|
|
155
|
+
};
|
|
156
|
+
}
|
|
101
157
|
|
|
102
|
-
// dist/lib/
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
158
|
+
// dist/lib/binary-geometry-api/binary-geometry-info.js
|
|
159
|
+
function getBinaryGeometryInfo(geometry) {
|
|
160
|
+
return {
|
|
161
|
+
isMultiGeometry: isMultiGeometryType(geometry),
|
|
162
|
+
multiGeometryType: getMultiGeometryType(geometry),
|
|
163
|
+
dimension: geometry.positions.size,
|
|
164
|
+
pointCount: geometry.positions.value.length / geometry.positions.size,
|
|
165
|
+
coordinateCount: geometry.positions.value.length
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function isMultiGeometryType(geometry) {
|
|
169
|
+
switch (geometry.type) {
|
|
170
|
+
case "Point":
|
|
171
|
+
const { positions } = geometry;
|
|
172
|
+
return positions.value.length / positions.size > 1;
|
|
173
|
+
case "LineString":
|
|
174
|
+
const { pathIndices } = geometry;
|
|
175
|
+
return pathIndices.value.length > 1;
|
|
176
|
+
case "Polygon":
|
|
177
|
+
const { polygonIndices } = geometry;
|
|
178
|
+
return polygonIndices.value.length > 1;
|
|
179
|
+
default:
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function getMultiGeometryType(geometry) {
|
|
184
|
+
const isMulti = isMultiGeometryType(geometry);
|
|
185
|
+
switch (geometry.type) {
|
|
186
|
+
case "Point":
|
|
187
|
+
return isMulti ? "MultiPoint" : "Point";
|
|
188
|
+
case "LineString":
|
|
189
|
+
return isMulti ? "MultiLineString" : "LineString";
|
|
190
|
+
case "Polygon":
|
|
191
|
+
return isMulti ? "MultiPolygon" : "Polygon";
|
|
192
|
+
default:
|
|
193
|
+
throw new Error(`Illegal geometry type: ${type}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// dist/lib/binary-geometry-api/transform-coordinates.js
|
|
198
|
+
function transformBinaryCoords(binaryFeatures, transformCoordinate) {
|
|
199
|
+
if (binaryFeatures.points) {
|
|
200
|
+
transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);
|
|
107
201
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
202
|
+
if (binaryFeatures.lines) {
|
|
203
|
+
transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);
|
|
204
|
+
}
|
|
205
|
+
if (binaryFeatures.polygons) {
|
|
206
|
+
transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);
|
|
207
|
+
}
|
|
208
|
+
return binaryFeatures;
|
|
209
|
+
}
|
|
210
|
+
function transformBinaryGeometryPositions(binaryGeometry, fn) {
|
|
211
|
+
const { positions } = binaryGeometry;
|
|
212
|
+
for (let i = 0; i < positions.value.length; i += positions.size) {
|
|
213
|
+
const coord = Array.from(positions.value.subarray(i, i + positions.size));
|
|
214
|
+
const transformedCoord = fn(coord);
|
|
215
|
+
positions.value.set(transformedCoord, i);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function transformGeoJsonCoords(features, fn) {
|
|
219
|
+
for (const feature of features) {
|
|
220
|
+
feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
|
|
221
|
+
}
|
|
222
|
+
return features;
|
|
223
|
+
}
|
|
224
|
+
function coordMap(array, fn) {
|
|
225
|
+
if (isCoord(array)) {
|
|
226
|
+
return fn(array);
|
|
227
|
+
}
|
|
228
|
+
return array.map((item) => {
|
|
229
|
+
return coordMap(item, fn);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function isCoord(array) {
|
|
233
|
+
return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// dist/lib/table-converters/convert-geoarrow-table.js
|
|
237
|
+
var arrow = __toESM(require("apache-arrow"), 1);
|
|
238
|
+
var import_schema_utils = require("@loaders.gl/schema-utils");
|
|
239
|
+
var import_geoarrow = require("@loaders.gl/geoarrow");
|
|
240
|
+
|
|
241
|
+
// dist/lib/geometry-converters/convert-binary-geometry-to-geojson.js
|
|
242
|
+
function convertBinaryGeometryToGeometry(data, startIndex, endIndex) {
|
|
243
|
+
switch (data.type) {
|
|
244
|
+
case "Point":
|
|
245
|
+
return pointToGeoJson(data, startIndex, endIndex);
|
|
246
|
+
case "LineString":
|
|
247
|
+
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
248
|
+
case "Polygon":
|
|
249
|
+
return polygonToGeoJson(data, startIndex, endIndex);
|
|
250
|
+
default:
|
|
251
|
+
const unexpectedInput = data;
|
|
252
|
+
throw new Error(`Unsupported geometry type: ${unexpectedInput == null ? void 0 : unexpectedInput.type}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
256
|
+
const { positions } = data;
|
|
257
|
+
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
258
|
+
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
259
|
+
const multi = polygonIndices.length > 2;
|
|
260
|
+
if (!multi) {
|
|
261
|
+
const coordinates2 = [];
|
|
262
|
+
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
263
|
+
const startRingIndex = primitivePolygonIndices[i];
|
|
264
|
+
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
265
|
+
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
266
|
+
coordinates2.push(ringCoordinates);
|
|
111
267
|
}
|
|
268
|
+
return { type: "Polygon", coordinates: coordinates2 };
|
|
269
|
+
}
|
|
270
|
+
const coordinates = [];
|
|
271
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
272
|
+
const startPolygonIndex = polygonIndices[i];
|
|
273
|
+
const endPolygonIndex = polygonIndices[i + 1];
|
|
274
|
+
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
275
|
+
coordinates.push(polygonCoordinates);
|
|
112
276
|
}
|
|
113
|
-
return
|
|
277
|
+
return { type: "MultiPolygon", coordinates };
|
|
114
278
|
}
|
|
115
|
-
function
|
|
116
|
-
const
|
|
117
|
-
|
|
279
|
+
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
280
|
+
const { positions } = data;
|
|
281
|
+
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
282
|
+
const multi = pathIndices.length > 2;
|
|
283
|
+
if (!multi) {
|
|
284
|
+
const coordinates2 = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
285
|
+
return { type: "LineString", coordinates: coordinates2 };
|
|
286
|
+
}
|
|
287
|
+
const coordinates = [];
|
|
288
|
+
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
289
|
+
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
290
|
+
coordinates.push(ringCoordinates);
|
|
291
|
+
}
|
|
292
|
+
return { type: "MultiLineString", coordinates };
|
|
118
293
|
}
|
|
119
|
-
function
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
294
|
+
function pointToGeoJson(data, startIndex, endIndex) {
|
|
295
|
+
const { positions } = data;
|
|
296
|
+
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
297
|
+
const multi = coordinates.length > 1;
|
|
298
|
+
if (multi) {
|
|
299
|
+
return { type: "MultiPoint", coordinates };
|
|
123
300
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
301
|
+
return { type: "Point", coordinates: coordinates[0] };
|
|
302
|
+
}
|
|
303
|
+
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
304
|
+
startIndex = startIndex || 0;
|
|
305
|
+
endIndex = endIndex || positions.value.length / positions.size;
|
|
306
|
+
const ringCoordinates = [];
|
|
307
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
308
|
+
const coord = Array();
|
|
309
|
+
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
310
|
+
coord.push(Number(positions.value[k]));
|
|
311
|
+
}
|
|
312
|
+
ringCoordinates.push(coord);
|
|
127
313
|
}
|
|
128
|
-
|
|
129
|
-
|
|
314
|
+
return ringCoordinates;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// dist/lib/utils/concat-typed-arrays.js
|
|
318
|
+
function concatTypedArrays(arrays) {
|
|
319
|
+
let byteLength = 0;
|
|
320
|
+
for (let i = 0; i < arrays.length; ++i) {
|
|
321
|
+
byteLength += arrays[i].byteLength;
|
|
130
322
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
unpackGeoFieldMetadata(field, columnMetadata);
|
|
323
|
+
const buffer = new Uint8Array(byteLength);
|
|
324
|
+
let byteOffset = 0;
|
|
325
|
+
for (let i = 0; i < arrays.length; ++i) {
|
|
326
|
+
const data = new Uint8Array(arrays[i].buffer);
|
|
327
|
+
byteLength = data.length;
|
|
328
|
+
for (let j = 0; j < byteLength; ++j) {
|
|
329
|
+
buffer[byteOffset++] = data[j];
|
|
139
330
|
}
|
|
140
331
|
}
|
|
332
|
+
return buffer;
|
|
141
333
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
334
|
+
|
|
335
|
+
// dist/lib/binary-geometry-api/concat-binary-geometry.js
|
|
336
|
+
function concatenateBinaryPointGeometries(binaryPointGeometries, dimension) {
|
|
337
|
+
const positions = binaryPointGeometries.map((geometry) => geometry.positions.value);
|
|
338
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
|
|
339
|
+
return {
|
|
340
|
+
type: "Point",
|
|
341
|
+
positions: { value: concatenatedPositions, size: dimension }
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
|
|
345
|
+
const lines = binaryLineGeometries.map((geometry) => geometry.positions.value);
|
|
346
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
|
|
347
|
+
const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
|
|
348
|
+
pathIndices.unshift(0);
|
|
349
|
+
return {
|
|
350
|
+
type: "LineString",
|
|
351
|
+
positions: { value: concatenatedPositions, size: dimension },
|
|
352
|
+
pathIndices: { value: new Uint32Array(pathIndices), size: 1 }
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
|
|
356
|
+
const polygons = [];
|
|
357
|
+
const primitivePolygons = [];
|
|
358
|
+
for (const binaryPolygon of binaryPolygonGeometries) {
|
|
359
|
+
const { positions, primitivePolygonIndices: primitivePolygonIndices2 } = binaryPolygon;
|
|
360
|
+
polygons.push(positions.value);
|
|
361
|
+
primitivePolygons.push(primitivePolygonIndices2.value);
|
|
362
|
+
}
|
|
363
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
|
|
364
|
+
const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
|
|
365
|
+
polygonIndices.unshift(0);
|
|
366
|
+
const primitivePolygonIndices = [0];
|
|
367
|
+
for (const primitivePolygon of primitivePolygons) {
|
|
368
|
+
primitivePolygonIndices.push(...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
type: "Polygon",
|
|
372
|
+
positions: { value: concatenatedPositions, size: dimension },
|
|
373
|
+
polygonIndices: { value: new Uint32Array(polygonIndices), size: 1 },
|
|
374
|
+
primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
var cumulativeSum = (sum) => (value) => sum += value;
|
|
378
|
+
|
|
379
|
+
// dist/lib/geometry-converters/wkb/helpers/wkb-types.js
|
|
380
|
+
var WKBGeometryType;
|
|
381
|
+
(function(WKBGeometryType2) {
|
|
382
|
+
WKBGeometryType2[WKBGeometryType2["Point"] = 1] = "Point";
|
|
383
|
+
WKBGeometryType2[WKBGeometryType2["LineString"] = 2] = "LineString";
|
|
384
|
+
WKBGeometryType2[WKBGeometryType2["Polygon"] = 3] = "Polygon";
|
|
385
|
+
WKBGeometryType2[WKBGeometryType2["MultiPoint"] = 4] = "MultiPoint";
|
|
386
|
+
WKBGeometryType2[WKBGeometryType2["MultiLineString"] = 5] = "MultiLineString";
|
|
387
|
+
WKBGeometryType2[WKBGeometryType2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
388
|
+
WKBGeometryType2[WKBGeometryType2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
389
|
+
})(WKBGeometryType || (WKBGeometryType = {}));
|
|
390
|
+
var EWKB_FLAG_Z = 2147483648;
|
|
391
|
+
var EWKB_FLAG_M = 1073741824;
|
|
392
|
+
var EWKB_FLAG_SRID = 536870912;
|
|
393
|
+
var MAX_SRID = 1e4;
|
|
394
|
+
var WKT_MAGIC_STRINGS = [
|
|
395
|
+
"POINT(",
|
|
396
|
+
"LINESTRING(",
|
|
397
|
+
"POLYGON(",
|
|
398
|
+
"MULTIPOINT(",
|
|
399
|
+
"MULTILINESTRING(",
|
|
400
|
+
"MULTIPOLYGON(",
|
|
401
|
+
"GEOMETRYCOLLECTION("
|
|
402
|
+
];
|
|
403
|
+
var textEncoder = new TextEncoder();
|
|
404
|
+
var WKT_MAGIC_BYTES = WKT_MAGIC_STRINGS.map((string) => textEncoder.encode(string));
|
|
405
|
+
|
|
406
|
+
// dist/lib/geometry-converters/wkb/helpers/parse-wkb-header.js
|
|
407
|
+
function isWKT(input) {
|
|
408
|
+
return getWKTGeometryType(input) !== null;
|
|
409
|
+
}
|
|
410
|
+
function getWKTGeometryType(input) {
|
|
411
|
+
if (typeof input === "string") {
|
|
412
|
+
const index2 = WKT_MAGIC_STRINGS.findIndex((magicString) => input.startsWith(magicString));
|
|
413
|
+
return index2 >= 0 ? index2 + 1 : null;
|
|
414
|
+
}
|
|
415
|
+
const inputArray = new Uint8Array(input);
|
|
416
|
+
const index = WKT_MAGIC_BYTES.findIndex((magicBytes) => magicBytes.every((value, index2) => value === inputArray[index2]));
|
|
417
|
+
return index >= 0 ? index + 1 : null;
|
|
418
|
+
}
|
|
419
|
+
function isTWKB(arrayBuffer) {
|
|
420
|
+
const dataView = new DataView(arrayBuffer);
|
|
421
|
+
const byteOffset = 0;
|
|
422
|
+
const type2 = dataView.getUint8(byteOffset);
|
|
423
|
+
const geometryType = type2 & 15;
|
|
424
|
+
if (geometryType < 1 || geometryType > 7) {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
function isWKB(arrayBuffer) {
|
|
430
|
+
const dataView = new DataView(arrayBuffer);
|
|
431
|
+
let byteOffset = 0;
|
|
432
|
+
const endianness = dataView.getUint8(byteOffset);
|
|
433
|
+
byteOffset += 1;
|
|
434
|
+
if (endianness > 1) {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
const littleEndian = endianness === 1;
|
|
438
|
+
const geometry = dataView.getUint32(byteOffset, littleEndian);
|
|
439
|
+
byteOffset += 4;
|
|
440
|
+
const geometryType = geometry & 7;
|
|
441
|
+
if (geometryType === 0 || geometryType > 7) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
const geometryFlags = geometry - geometryType;
|
|
445
|
+
if (geometryFlags === 0 || geometryFlags === 1e3 || geometryFlags === 2e3 || geometryFlags === 3e3) {
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
if ((geometryFlags & ~(EWKB_FLAG_Z | EWKB_FLAG_M | EWKB_FLAG_SRID)) !== 0) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
if (geometryFlags & EWKB_FLAG_SRID) {
|
|
452
|
+
const srid = dataView.getUint32(byteOffset, littleEndian);
|
|
453
|
+
byteOffset += 4;
|
|
454
|
+
if (srid > MAX_SRID) {
|
|
455
|
+
return false;
|
|
170
456
|
}
|
|
171
457
|
}
|
|
458
|
+
return true;
|
|
172
459
|
}
|
|
173
|
-
function
|
|
174
|
-
|
|
175
|
-
|
|
460
|
+
function parseWKBHeader(dataView, target) {
|
|
461
|
+
const wkbHeader = Object.assign(target || {}, {
|
|
462
|
+
type: "wkb",
|
|
463
|
+
variant: "wkb",
|
|
464
|
+
geometryType: 1,
|
|
465
|
+
dimensions: 2,
|
|
466
|
+
coordinates: "xy",
|
|
467
|
+
littleEndian: true,
|
|
468
|
+
byteOffset: 0
|
|
469
|
+
});
|
|
470
|
+
if (isWKT(dataView.buffer)) {
|
|
471
|
+
throw new Error("WKB: Cannot parse WKT data");
|
|
472
|
+
}
|
|
473
|
+
wkbHeader.littleEndian = dataView.getUint8(wkbHeader.byteOffset) === 1;
|
|
474
|
+
wkbHeader.byteOffset++;
|
|
475
|
+
const geometryCode = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
476
|
+
wkbHeader.byteOffset += 4;
|
|
477
|
+
wkbHeader.geometryType = geometryCode & 7;
|
|
478
|
+
const isoType = (geometryCode - wkbHeader.geometryType) / 1e3;
|
|
479
|
+
switch (isoType) {
|
|
480
|
+
case 0:
|
|
481
|
+
break;
|
|
482
|
+
case 1:
|
|
483
|
+
wkbHeader.variant = "iso-wkb";
|
|
484
|
+
wkbHeader.dimensions = 3;
|
|
485
|
+
wkbHeader.coordinates = "xyz";
|
|
486
|
+
break;
|
|
487
|
+
case 2:
|
|
488
|
+
wkbHeader.variant = "iso-wkb";
|
|
489
|
+
wkbHeader.dimensions = 3;
|
|
490
|
+
wkbHeader.coordinates = "xym";
|
|
491
|
+
break;
|
|
492
|
+
case 3:
|
|
493
|
+
wkbHeader.variant = "iso-wkb";
|
|
494
|
+
wkbHeader.dimensions = 4;
|
|
495
|
+
wkbHeader.coordinates = "xyzm";
|
|
496
|
+
break;
|
|
497
|
+
default:
|
|
498
|
+
throw new Error(`WKB: Unsupported iso-wkb type: ${isoType}`);
|
|
499
|
+
}
|
|
500
|
+
const ewkbZ = geometryCode & EWKB_FLAG_Z;
|
|
501
|
+
const ewkbM = geometryCode & EWKB_FLAG_M;
|
|
502
|
+
const ewkbSRID = geometryCode & EWKB_FLAG_SRID;
|
|
503
|
+
if (ewkbZ && ewkbM) {
|
|
504
|
+
wkbHeader.variant = "ewkb";
|
|
505
|
+
wkbHeader.dimensions = 4;
|
|
506
|
+
wkbHeader.coordinates = "xyzm";
|
|
507
|
+
} else if (ewkbZ) {
|
|
508
|
+
wkbHeader.variant = "ewkb";
|
|
509
|
+
wkbHeader.dimensions = 3;
|
|
510
|
+
wkbHeader.coordinates = "xyz";
|
|
511
|
+
} else if (ewkbM) {
|
|
512
|
+
wkbHeader.variant = "ewkb";
|
|
513
|
+
wkbHeader.dimensions = 3;
|
|
514
|
+
wkbHeader.coordinates = "xym";
|
|
515
|
+
}
|
|
516
|
+
if (ewkbSRID) {
|
|
517
|
+
wkbHeader.variant = "ewkb";
|
|
518
|
+
wkbHeader.srid = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
519
|
+
wkbHeader.byteOffset += 4;
|
|
520
|
+
}
|
|
521
|
+
return wkbHeader;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// dist/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js
|
|
525
|
+
function convertWKBToBinaryGeometry(arrayBuffer) {
|
|
526
|
+
const dataView = new DataView(arrayBuffer);
|
|
527
|
+
const wkbHeader = parseWKBHeader(dataView);
|
|
528
|
+
const { geometryType, dimensions, littleEndian } = wkbHeader;
|
|
529
|
+
const offset = wkbHeader.byteOffset;
|
|
530
|
+
switch (geometryType) {
|
|
531
|
+
case WKBGeometryType.Point:
|
|
532
|
+
const point = parsePoint(dataView, offset, dimensions, littleEndian);
|
|
533
|
+
return point.geometry;
|
|
534
|
+
case WKBGeometryType.LineString:
|
|
535
|
+
const line = parseLineString(dataView, offset, dimensions, littleEndian);
|
|
536
|
+
return line.geometry;
|
|
537
|
+
case WKBGeometryType.Polygon:
|
|
538
|
+
const polygon = parsePolygon(dataView, offset, dimensions, littleEndian);
|
|
539
|
+
return polygon.geometry;
|
|
540
|
+
case WKBGeometryType.MultiPoint:
|
|
541
|
+
const multiPoint = parseMultiPoint(dataView, offset, dimensions, littleEndian);
|
|
542
|
+
multiPoint.type = "Point";
|
|
543
|
+
return multiPoint;
|
|
544
|
+
case WKBGeometryType.MultiLineString:
|
|
545
|
+
const multiLine = parseMultiLineString(dataView, offset, dimensions, littleEndian);
|
|
546
|
+
multiLine.type = "LineString";
|
|
547
|
+
return multiLine;
|
|
548
|
+
case WKBGeometryType.MultiPolygon:
|
|
549
|
+
const multiPolygon = parseMultiPolygon(dataView, offset, dimensions, littleEndian);
|
|
550
|
+
multiPolygon.type = "Polygon";
|
|
551
|
+
return multiPolygon;
|
|
552
|
+
default:
|
|
553
|
+
throw new Error(`WKB: Unsupported geometry type: ${geometryType}`);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
function parsePoint(dataView, offset, dimension, littleEndian) {
|
|
557
|
+
const positions = new Float64Array(dimension);
|
|
558
|
+
for (let i = 0; i < dimension; i++) {
|
|
559
|
+
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
560
|
+
offset += 8;
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
geometry: { type: "Point", positions: { value: positions, size: dimension } },
|
|
564
|
+
offset
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function parseLineString(dataView, offset, dimension, littleEndian) {
|
|
568
|
+
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
569
|
+
offset += 4;
|
|
570
|
+
const positions = new Float64Array(nPoints * dimension);
|
|
571
|
+
for (let i = 0; i < nPoints * dimension; i++) {
|
|
572
|
+
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
573
|
+
offset += 8;
|
|
574
|
+
}
|
|
575
|
+
const pathIndices = [0];
|
|
576
|
+
if (nPoints > 0) {
|
|
577
|
+
pathIndices.push(nPoints);
|
|
578
|
+
}
|
|
579
|
+
return {
|
|
580
|
+
geometry: {
|
|
581
|
+
type: "LineString",
|
|
582
|
+
positions: { value: positions, size: dimension },
|
|
583
|
+
pathIndices: { value: new Uint32Array(pathIndices), size: 1 }
|
|
584
|
+
},
|
|
585
|
+
offset
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
var cumulativeSum2 = (sum) => (value) => sum += value;
|
|
589
|
+
function parsePolygon(dataView, offset, dimension, littleEndian) {
|
|
590
|
+
const nRings = dataView.getUint32(offset, littleEndian);
|
|
591
|
+
offset += 4;
|
|
592
|
+
const rings = [];
|
|
593
|
+
for (let i = 0; i < nRings; i++) {
|
|
594
|
+
const parsed = parseLineString(dataView, offset, dimension, littleEndian);
|
|
595
|
+
const { positions } = parsed.geometry;
|
|
596
|
+
offset = parsed.offset;
|
|
597
|
+
rings.push(positions.value);
|
|
598
|
+
}
|
|
599
|
+
const concatenatedPositions = new Float64Array(concatTypedArrays(rings).buffer);
|
|
600
|
+
const polygonIndices = [0];
|
|
601
|
+
if (concatenatedPositions.length > 0) {
|
|
602
|
+
polygonIndices.push(concatenatedPositions.length / dimension);
|
|
603
|
+
}
|
|
604
|
+
const primitivePolygonIndices = rings.map((l) => l.length / dimension).map(cumulativeSum2(0));
|
|
605
|
+
primitivePolygonIndices.unshift(0);
|
|
606
|
+
return {
|
|
607
|
+
geometry: {
|
|
608
|
+
type: "Polygon",
|
|
609
|
+
positions: { value: concatenatedPositions, size: dimension },
|
|
610
|
+
polygonIndices: {
|
|
611
|
+
value: new Uint32Array(polygonIndices),
|
|
612
|
+
size: 1
|
|
613
|
+
},
|
|
614
|
+
primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
|
|
615
|
+
},
|
|
616
|
+
offset
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function parseMultiPoint(dataView, offset, dimension, littleEndian) {
|
|
620
|
+
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
621
|
+
offset += 4;
|
|
622
|
+
const binaryPointGeometries = [];
|
|
623
|
+
for (let i = 0; i < nPoints; i++) {
|
|
624
|
+
const littleEndianPoint = dataView.getUint8(offset) === 1;
|
|
625
|
+
offset++;
|
|
626
|
+
if (dataView.getUint32(offset, littleEndianPoint) % 1e3 !== 1) {
|
|
627
|
+
throw new Error("WKB: Inner geometries of MultiPoint not of type Point");
|
|
628
|
+
}
|
|
629
|
+
offset += 4;
|
|
630
|
+
const parsed = parsePoint(dataView, offset, dimension, littleEndianPoint);
|
|
631
|
+
offset = parsed.offset;
|
|
632
|
+
binaryPointGeometries.push(parsed.geometry);
|
|
633
|
+
}
|
|
634
|
+
return concatenateBinaryPointGeometries(binaryPointGeometries, dimension);
|
|
635
|
+
}
|
|
636
|
+
function parseMultiLineString(dataView, offset, dimension, littleEndian) {
|
|
637
|
+
const nLines = dataView.getUint32(offset, littleEndian);
|
|
638
|
+
offset += 4;
|
|
639
|
+
const binaryLineGeometries = [];
|
|
640
|
+
for (let i = 0; i < nLines; i++) {
|
|
641
|
+
const littleEndianLine = dataView.getUint8(offset) === 1;
|
|
642
|
+
offset++;
|
|
643
|
+
if (dataView.getUint32(offset, littleEndianLine) % 1e3 !== 2) {
|
|
644
|
+
throw new Error("WKB: Inner geometries of MultiLineString not of type LineString");
|
|
645
|
+
}
|
|
646
|
+
offset += 4;
|
|
647
|
+
const parsed = parseLineString(dataView, offset, dimension, littleEndianLine);
|
|
648
|
+
offset = parsed.offset;
|
|
649
|
+
binaryLineGeometries.push(parsed.geometry);
|
|
650
|
+
}
|
|
651
|
+
return concatenateBinaryLineGeometries(binaryLineGeometries, dimension);
|
|
652
|
+
}
|
|
653
|
+
function parseMultiPolygon(dataView, offset, dimension, littleEndian) {
|
|
654
|
+
const nPolygons = dataView.getUint32(offset, littleEndian);
|
|
655
|
+
offset += 4;
|
|
656
|
+
const binaryPolygonGeometries = [];
|
|
657
|
+
for (let i = 0; i < nPolygons; i++) {
|
|
658
|
+
const littleEndianPolygon = dataView.getUint8(offset) === 1;
|
|
659
|
+
offset++;
|
|
660
|
+
if (dataView.getUint32(offset, littleEndianPolygon) % 1e3 !== 3) {
|
|
661
|
+
throw new Error("WKB: Inner geometries of MultiPolygon not of type Polygon");
|
|
662
|
+
}
|
|
663
|
+
offset += 4;
|
|
664
|
+
const parsed = parsePolygon(dataView, offset, dimension, littleEndianPolygon);
|
|
665
|
+
offset = parsed.offset;
|
|
666
|
+
binaryPolygonGeometries.push(parsed.geometry);
|
|
667
|
+
}
|
|
668
|
+
return concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// dist/lib/geometry-converters/wkb/convert-wkb-to-geometry.js
|
|
672
|
+
function convertWKBToGeometry(arrayBuffer) {
|
|
673
|
+
const binaryGeometry = convertWKBToBinaryGeometry(arrayBuffer);
|
|
674
|
+
return convertBinaryGeometryToGeometry(binaryGeometry);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// dist/lib/geometry-converters/wkb/convert-wkt-to-geometry.js
|
|
678
|
+
var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
|
|
679
|
+
var tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
|
|
680
|
+
function convertWKTToGeometry(input, options) {
|
|
681
|
+
var _a;
|
|
682
|
+
const parts = input.split(";");
|
|
683
|
+
let _ = parts.pop();
|
|
684
|
+
const srid = (parts.shift() || "").split("=").pop();
|
|
685
|
+
const state = { parts, _, i: 0 };
|
|
686
|
+
const geometry = parseGeometry(state);
|
|
687
|
+
return ((_a = options == null ? void 0 : options.wkt) == null ? void 0 : _a.crs) ? addCRS(geometry, srid) : geometry;
|
|
688
|
+
}
|
|
689
|
+
function parseGeometry(state) {
|
|
690
|
+
return parsePoint2(state) || parseLineString2(state) || parsePolygon2(state) || parseMultiPoint2(state) || parseMultiLineString2(state) || parseMultiPolygon2(state) || parseGeometryCollection(state);
|
|
691
|
+
}
|
|
692
|
+
function addCRS(obj, srid) {
|
|
693
|
+
if (obj && (srid == null ? void 0 : srid.match(/\d+/))) {
|
|
694
|
+
const crs = {
|
|
695
|
+
type: "name",
|
|
696
|
+
properties: {
|
|
697
|
+
name: "urn:ogc:def:crs:EPSG::" + srid
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
obj.crs = crs;
|
|
701
|
+
}
|
|
702
|
+
return obj;
|
|
176
703
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
if (!stringifiedMetadata) {
|
|
704
|
+
function parsePoint2(state) {
|
|
705
|
+
if (!$(/^(POINT(\sz)?)/i, state)) {
|
|
180
706
|
return null;
|
|
181
707
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
708
|
+
white(state);
|
|
709
|
+
if (!$(/^(\()/, state)) {
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
const c = coords(state);
|
|
713
|
+
if (!c) {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
white(state);
|
|
717
|
+
if (!$(/^(\))/, state)) {
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
return {
|
|
721
|
+
type: "Point",
|
|
722
|
+
coordinates: c[0]
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
function parseMultiPoint2(state) {
|
|
726
|
+
var _a, _b;
|
|
727
|
+
if (!$(/^(MULTIPOINT)/i, state)) {
|
|
728
|
+
return null;
|
|
729
|
+
}
|
|
730
|
+
white(state);
|
|
731
|
+
const newCoordsFormat = (_b = state._) == null ? void 0 : _b.substring(((_a = state._) == null ? void 0 : _a.indexOf("(")) + 1, state._.length - 1).replace(/\(/g, "").replace(/\)/g, "");
|
|
732
|
+
state._ = "MULTIPOINT (" + newCoordsFormat + ")";
|
|
733
|
+
const c = multicoords(state);
|
|
734
|
+
if (!c) {
|
|
735
|
+
return null;
|
|
736
|
+
}
|
|
737
|
+
white(state);
|
|
738
|
+
return {
|
|
739
|
+
type: "MultiPoint",
|
|
740
|
+
coordinates: c
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
function parseLineString2(state) {
|
|
744
|
+
if (!$(/^(LINESTRING(\sz)?)/i, state)) {
|
|
745
|
+
return null;
|
|
746
|
+
}
|
|
747
|
+
white(state);
|
|
748
|
+
if (!$(/^(\()/, state)) {
|
|
749
|
+
return null;
|
|
750
|
+
}
|
|
751
|
+
const c = coords(state);
|
|
752
|
+
if (!c) {
|
|
753
|
+
return null;
|
|
754
|
+
}
|
|
755
|
+
if (!$(/^(\))/, state)) {
|
|
756
|
+
return null;
|
|
757
|
+
}
|
|
758
|
+
return {
|
|
759
|
+
type: "LineString",
|
|
760
|
+
coordinates: c
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
function parseMultiLineString2(state) {
|
|
764
|
+
if (!$(/^(MULTILINESTRING)/i, state))
|
|
765
|
+
return null;
|
|
766
|
+
white(state);
|
|
767
|
+
const c = multicoords(state);
|
|
768
|
+
if (!c) {
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
white(state);
|
|
772
|
+
return {
|
|
773
|
+
// @ts-ignore
|
|
774
|
+
type: "MultiLineString",
|
|
775
|
+
// @ts-expect-error
|
|
776
|
+
coordinates: c
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
function parsePolygon2(state) {
|
|
780
|
+
if (!$(/^(POLYGON(\sz)?)/i, state)) {
|
|
781
|
+
return null;
|
|
782
|
+
}
|
|
783
|
+
white(state);
|
|
784
|
+
const c = multicoords(state);
|
|
785
|
+
if (!c) {
|
|
786
|
+
return null;
|
|
787
|
+
}
|
|
788
|
+
return {
|
|
789
|
+
// @ts-ignore
|
|
790
|
+
type: "Polygon",
|
|
791
|
+
// @ts-expect-error
|
|
792
|
+
coordinates: c
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function parseMultiPolygon2(state) {
|
|
796
|
+
if (!$(/^(MULTIPOLYGON)/i, state)) {
|
|
797
|
+
return null;
|
|
798
|
+
}
|
|
799
|
+
white(state);
|
|
800
|
+
const c = multicoords(state);
|
|
801
|
+
if (!c) {
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
return {
|
|
805
|
+
type: "MultiPolygon",
|
|
806
|
+
// @ts-expect-error
|
|
807
|
+
coordinates: c
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
function parseGeometryCollection(state) {
|
|
811
|
+
const geometries = [];
|
|
812
|
+
let geometry;
|
|
813
|
+
if (!$(/^(GEOMETRYCOLLECTION)/i, state)) {
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
white(state);
|
|
817
|
+
if (!$(/^(\()/, state)) {
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
while (geometry = parseGeometry(state)) {
|
|
821
|
+
geometries.push(geometry);
|
|
822
|
+
white(state);
|
|
823
|
+
$(/^(,)/, state);
|
|
824
|
+
white(state);
|
|
825
|
+
}
|
|
826
|
+
if (!$(/^(\))/, state)) {
|
|
827
|
+
return null;
|
|
828
|
+
}
|
|
829
|
+
return {
|
|
830
|
+
type: "GeometryCollection",
|
|
831
|
+
geometries
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
function multicoords(state) {
|
|
835
|
+
white(state);
|
|
836
|
+
let depth = 0;
|
|
837
|
+
const rings = [];
|
|
838
|
+
const stack = [rings];
|
|
839
|
+
let pointer = rings;
|
|
840
|
+
let elem;
|
|
841
|
+
while (elem = $(/^(\()/, state) || $(/^(\))/, state) || $(/^(,)/, state) || $(tuples, state)) {
|
|
842
|
+
if (elem === "(") {
|
|
843
|
+
stack.push(pointer);
|
|
844
|
+
pointer = [];
|
|
845
|
+
stack[stack.length - 1].push(pointer);
|
|
846
|
+
depth++;
|
|
847
|
+
} else if (elem === ")") {
|
|
848
|
+
if (pointer.length === 0)
|
|
849
|
+
return null;
|
|
850
|
+
pointer = stack.pop();
|
|
851
|
+
if (!pointer)
|
|
852
|
+
return null;
|
|
853
|
+
depth--;
|
|
854
|
+
if (depth === 0)
|
|
855
|
+
break;
|
|
856
|
+
} else if (elem === ",") {
|
|
857
|
+
pointer = [];
|
|
858
|
+
stack[stack.length - 1].push(pointer);
|
|
859
|
+
} else if (!elem.split(/\s/g).some(isNaN)) {
|
|
860
|
+
Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
|
|
861
|
+
} else {
|
|
185
862
|
return null;
|
|
186
863
|
}
|
|
187
|
-
|
|
188
|
-
}
|
|
864
|
+
white(state);
|
|
865
|
+
}
|
|
866
|
+
if (depth !== 0)
|
|
189
867
|
return null;
|
|
868
|
+
return rings;
|
|
869
|
+
}
|
|
870
|
+
function coords(state) {
|
|
871
|
+
const list = [];
|
|
872
|
+
let item;
|
|
873
|
+
let pt;
|
|
874
|
+
while (pt = $(tuples, state) || $(/^(,)/, state)) {
|
|
875
|
+
if (pt === ",") {
|
|
876
|
+
list.push(item);
|
|
877
|
+
item = [];
|
|
878
|
+
} else if (!pt.split(/\s/g).some(isNaN)) {
|
|
879
|
+
if (!item)
|
|
880
|
+
item = [];
|
|
881
|
+
Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
|
|
882
|
+
}
|
|
883
|
+
white(state);
|
|
190
884
|
}
|
|
885
|
+
if (item)
|
|
886
|
+
list.push(item);
|
|
887
|
+
else
|
|
888
|
+
return null;
|
|
889
|
+
return list.length ? list : null;
|
|
191
890
|
}
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
891
|
+
function $(regexp, state) {
|
|
892
|
+
var _a;
|
|
893
|
+
const match = (_a = state._) == null ? void 0 : _a.substring(state.i).match(regexp);
|
|
894
|
+
if (!match)
|
|
895
|
+
return null;
|
|
896
|
+
else {
|
|
897
|
+
state.i += match[0].length;
|
|
898
|
+
return match[0];
|
|
196
899
|
}
|
|
197
900
|
}
|
|
901
|
+
function white(state) {
|
|
902
|
+
$(/^\s*/, state);
|
|
903
|
+
}
|
|
198
904
|
|
|
199
|
-
// dist/lib/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
905
|
+
// dist/lib/geometry-converters/convert-geoarrow-to-geojson.js
|
|
906
|
+
function convertGeoArrowGeometryToGeoJSON(arrowCellValue, encoding) {
|
|
907
|
+
encoding = encoding == null ? void 0 : encoding.toLowerCase();
|
|
908
|
+
if (!encoding || !arrowCellValue) {
|
|
909
|
+
return null;
|
|
910
|
+
}
|
|
911
|
+
switch (encoding) {
|
|
912
|
+
case "geoarrow.multipolygon":
|
|
913
|
+
return arrowMultiPolygonToGeometry(arrowCellValue);
|
|
914
|
+
case "geoarrow.polygon":
|
|
915
|
+
return arrowPolygonToGeometry(arrowCellValue);
|
|
916
|
+
case "geoarrow.multipoint":
|
|
917
|
+
return arrowMultiPointToGeometry(arrowCellValue);
|
|
918
|
+
case "geoarrow.point":
|
|
919
|
+
return arrowPointToGeometry(arrowCellValue);
|
|
920
|
+
case "geoarrow.multilinestring":
|
|
921
|
+
return arrowMultiLineStringToGeometry(arrowCellValue);
|
|
922
|
+
case "geoarrow.linestring":
|
|
923
|
+
return arrowLineStringToGeometry(arrowCellValue);
|
|
924
|
+
case "geoarrow.wkb":
|
|
925
|
+
return arrowWKBToGeometry(arrowCellValue);
|
|
926
|
+
case "geoarrow.wkt":
|
|
927
|
+
return arrowWKTToGeometry(arrowCellValue);
|
|
928
|
+
default: {
|
|
929
|
+
throw Error(`GeoArrow encoding not supported ${encoding}`);
|
|
218
930
|
}
|
|
219
931
|
}
|
|
220
|
-
return geometryColumns;
|
|
221
932
|
}
|
|
222
|
-
function
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
933
|
+
function arrowWKBToGeometry(arrowCellValue) {
|
|
934
|
+
const arrayBuffer = arrowCellValue.buffer.slice(arrowCellValue.byteOffset, arrowCellValue.byteOffset + arrowCellValue.byteLength);
|
|
935
|
+
return convertWKBToGeometry(arrayBuffer);
|
|
936
|
+
}
|
|
937
|
+
function arrowWKTToGeometry(arrowCellValue) {
|
|
938
|
+
const string = arrowCellValue;
|
|
939
|
+
return convertWKTToGeometry(string);
|
|
940
|
+
}
|
|
941
|
+
function arrowMultiPolygonToGeometry(arrowMultiPolygon) {
|
|
942
|
+
const multiPolygon = [];
|
|
943
|
+
for (let m = 0; m < arrowMultiPolygon.length; m++) {
|
|
944
|
+
const arrowPolygon = arrowMultiPolygon.get(m);
|
|
945
|
+
const polygon = [];
|
|
946
|
+
for (let i = 0; arrowPolygon && i < (arrowPolygon == null ? void 0 : arrowPolygon.length); i++) {
|
|
947
|
+
const arrowRing = arrowPolygon == null ? void 0 : arrowPolygon.get(i);
|
|
948
|
+
const ring = [];
|
|
949
|
+
for (let j = 0; arrowRing && j < arrowRing.length; j++) {
|
|
950
|
+
const arrowCoord = arrowRing.get(j);
|
|
951
|
+
const coord = Array.from(arrowCoord);
|
|
952
|
+
ring.push(coord);
|
|
953
|
+
}
|
|
954
|
+
polygon.push(ring);
|
|
955
|
+
}
|
|
956
|
+
multiPolygon.push(polygon);
|
|
957
|
+
}
|
|
958
|
+
const geometry = {
|
|
959
|
+
type: "MultiPolygon",
|
|
960
|
+
coordinates: multiPolygon
|
|
961
|
+
};
|
|
962
|
+
return geometry;
|
|
963
|
+
}
|
|
964
|
+
function arrowPolygonToGeometry(arrowPolygon) {
|
|
965
|
+
const polygon = [];
|
|
966
|
+
for (let i = 0; arrowPolygon && i < arrowPolygon.length; i++) {
|
|
967
|
+
const arrowRing = arrowPolygon.get(i);
|
|
968
|
+
const ring = [];
|
|
969
|
+
for (let j = 0; arrowRing && j < arrowRing.length; j++) {
|
|
970
|
+
const arrowCoord = arrowRing.get(j);
|
|
971
|
+
const coords2 = Array.from(arrowCoord);
|
|
972
|
+
ring.push(coords2);
|
|
973
|
+
}
|
|
974
|
+
polygon.push(ring);
|
|
975
|
+
}
|
|
976
|
+
const geometry = {
|
|
977
|
+
type: "Polygon",
|
|
978
|
+
coordinates: polygon
|
|
979
|
+
};
|
|
980
|
+
return geometry;
|
|
981
|
+
}
|
|
982
|
+
function arrowMultiPointToGeometry(arrowMultiPoint) {
|
|
983
|
+
const multiPoint = [];
|
|
984
|
+
for (let i = 0; arrowMultiPoint && i < arrowMultiPoint.length; i++) {
|
|
985
|
+
const arrowPoint = arrowMultiPoint.get(i);
|
|
986
|
+
if (arrowPoint) {
|
|
987
|
+
const coord = Array.from(arrowPoint);
|
|
988
|
+
multiPoint.push(coord);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return {
|
|
992
|
+
type: "MultiPoint",
|
|
993
|
+
coordinates: multiPoint
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
function arrowPointToGeometry(arrowPoint) {
|
|
997
|
+
const point = Array.from(arrowPoint);
|
|
998
|
+
return {
|
|
999
|
+
type: "Point",
|
|
1000
|
+
coordinates: point
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
function arrowMultiLineStringToGeometry(arrowMultiLineString) {
|
|
1004
|
+
const multiLineString = [];
|
|
1005
|
+
for (let i = 0; arrowMultiLineString && i < arrowMultiLineString.length; i++) {
|
|
1006
|
+
const arrowLineString = arrowMultiLineString.get(i);
|
|
1007
|
+
const lineString = [];
|
|
1008
|
+
for (let j = 0; arrowLineString && j < arrowLineString.length; j++) {
|
|
1009
|
+
const arrowCoord = arrowLineString.get(j);
|
|
1010
|
+
if (arrowCoord) {
|
|
1011
|
+
const coords2 = Array.from(arrowCoord);
|
|
1012
|
+
lineString.push(coords2);
|
|
1013
|
+
}
|
|
239
1014
|
}
|
|
1015
|
+
multiLineString.push(lineString);
|
|
1016
|
+
}
|
|
1017
|
+
return {
|
|
1018
|
+
type: "MultiLineString",
|
|
1019
|
+
coordinates: multiLineString
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
function arrowLineStringToGeometry(arrowLineString) {
|
|
1023
|
+
const lineString = [];
|
|
1024
|
+
for (let i = 0; arrowLineString && i < arrowLineString.length; i++) {
|
|
1025
|
+
const arrowCoord = arrowLineString.get(i);
|
|
1026
|
+
if (arrowCoord) {
|
|
1027
|
+
const coords2 = Array.from(arrowCoord);
|
|
1028
|
+
lineString.push(coords2);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
return {
|
|
1032
|
+
type: "LineString",
|
|
1033
|
+
coordinates: lineString
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// dist/lib/table-converters/convert-geoarrow-table.js
|
|
1038
|
+
function convertGeoArrowToTable(arrowTable, shape) {
|
|
1039
|
+
switch (shape) {
|
|
1040
|
+
case "arrow-table":
|
|
1041
|
+
return convertArrowToArrowTable(arrowTable);
|
|
1042
|
+
case "array-row-table":
|
|
1043
|
+
return convertArrowToArrayRowTable(arrowTable);
|
|
1044
|
+
case "object-row-table":
|
|
1045
|
+
return convertArrowToObjectRowTable(arrowTable);
|
|
1046
|
+
case "columnar-table":
|
|
1047
|
+
return convertArrowToColumnarTable(arrowTable);
|
|
1048
|
+
case "geojson-table":
|
|
1049
|
+
return convertArrowToGeoJSONTable(arrowTable);
|
|
1050
|
+
default:
|
|
1051
|
+
throw new Error(shape);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
function convertArrowToArrowTable(arrowTable) {
|
|
1055
|
+
return {
|
|
1056
|
+
shape: "arrow-table",
|
|
1057
|
+
schema: (0, import_schema_utils.convertArrowToSchema)(arrowTable.schema),
|
|
1058
|
+
data: arrowTable
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
function convertArrowToArrayRowTable(arrowTable) {
|
|
1062
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
1063
|
+
return (0, import_schema_utils.convertTable)(columnarTable, "array-row-table");
|
|
1064
|
+
}
|
|
1065
|
+
function convertArrowToObjectRowTable(arrowTable) {
|
|
1066
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
1067
|
+
return (0, import_schema_utils.convertTable)(columnarTable, "object-row-table");
|
|
1068
|
+
}
|
|
1069
|
+
function convertArrowToColumnarTable(arrowTable) {
|
|
1070
|
+
const columns = {};
|
|
1071
|
+
for (const field of arrowTable.schema.fields) {
|
|
1072
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
1073
|
+
const values = arrowColumn == null ? void 0 : arrowColumn.toArray();
|
|
1074
|
+
columns[field.name] = values;
|
|
240
1075
|
}
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
1076
|
+
const schema = (0, import_schema_utils.convertArrowToSchema)(arrowTable.schema);
|
|
1077
|
+
return {
|
|
1078
|
+
shape: "columnar-table",
|
|
1079
|
+
schema,
|
|
1080
|
+
data: columns
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
function convertArrowToGeoJSONTable(arrowTable) {
|
|
1084
|
+
var _a;
|
|
1085
|
+
const schema = (0, import_schema_utils.convertArrowToSchema)(arrowTable.schema);
|
|
1086
|
+
const geometryColumns = (0, import_geoarrow.getGeometryColumnsFromSchema)(schema);
|
|
1087
|
+
const encoding = geometryColumns.geometry.encoding;
|
|
1088
|
+
const features = [];
|
|
1089
|
+
const propertyColumnNames = arrowTable.schema.fields.map((field) => field.name).filter((name) => !(name in geometryColumns));
|
|
1090
|
+
const propertiesTable = arrowTable.select(propertyColumnNames);
|
|
1091
|
+
const arrowGeometryColumn = arrowTable.getChild("geometry");
|
|
1092
|
+
for (let row = 0; row < arrowTable.numRows; row++) {
|
|
1093
|
+
const arrowGeometry = arrowGeometryColumn == null ? void 0 : arrowGeometryColumn.get(row);
|
|
1094
|
+
const feature = convertGeoArrowGeometryToGeoJSON(arrowGeometry, encoding);
|
|
1095
|
+
if (feature) {
|
|
1096
|
+
const properties = ((_a = propertiesTable.get(row)) == null ? void 0 : _a.toJSON()) || {};
|
|
1097
|
+
features.push({ type: "Feature", geometry: feature, properties });
|
|
247
1098
|
}
|
|
248
1099
|
}
|
|
249
|
-
return
|
|
1100
|
+
return {
|
|
1101
|
+
shape: "geojson-table",
|
|
1102
|
+
type: "FeatureCollection",
|
|
1103
|
+
schema,
|
|
1104
|
+
features
|
|
1105
|
+
};
|
|
250
1106
|
}
|
|
251
1107
|
|
|
252
|
-
// dist/lib/
|
|
253
|
-
var
|
|
254
|
-
|
|
255
|
-
|
|
1108
|
+
// dist/lib/table-converters/convert-wkb-table-to-geojson.js
|
|
1109
|
+
var import_schema_utils2 = require("@loaders.gl/schema-utils");
|
|
1110
|
+
var import_geoarrow2 = require("@loaders.gl/geoarrow");
|
|
1111
|
+
function convertWKBTableToGeoJSON(table, schema) {
|
|
1112
|
+
const geoMetadata = (0, import_geoarrow2.getGeoMetadata)(schema.metadata);
|
|
256
1113
|
const primaryColumn = geoMetadata == null ? void 0 : geoMetadata.primary_column;
|
|
257
1114
|
if (!primaryColumn) {
|
|
258
1115
|
throw new Error("no geometry column");
|
|
259
1116
|
}
|
|
260
1117
|
const columnMetadata = geoMetadata.columns[primaryColumn];
|
|
261
1118
|
const features = [];
|
|
262
|
-
const length = (0,
|
|
1119
|
+
const length = (0, import_schema_utils2.getTableLength)(table);
|
|
263
1120
|
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
264
|
-
const row = (0,
|
|
265
|
-
const geometry =
|
|
1121
|
+
const row = (0, import_schema_utils2.getTableRowAsObject)(table, rowIndex);
|
|
1122
|
+
const geometry = parseGeometry2(row[primaryColumn], columnMetadata);
|
|
266
1123
|
delete row[primaryColumn];
|
|
267
1124
|
const feature = { type: "Feature", geometry, properties: row };
|
|
268
1125
|
features.push(feature);
|
|
269
1126
|
}
|
|
270
1127
|
return { shape: "geojson-table", schema, type: "FeatureCollection", features };
|
|
271
1128
|
}
|
|
272
|
-
function
|
|
273
|
-
var _a, _b;
|
|
1129
|
+
function parseGeometry2(geometry, columnMetadata) {
|
|
274
1130
|
switch (columnMetadata.encoding) {
|
|
275
1131
|
case "wkt":
|
|
276
|
-
|
|
277
|
-
return ((_a = wktLoader == null ? void 0 : wktLoader.parseTextSync) == null ? void 0 : _a.call(wktLoader, geometry)) || null;
|
|
1132
|
+
return convertWKTToGeometry(geometry) || null;
|
|
278
1133
|
case "wkb":
|
|
279
1134
|
default:
|
|
280
|
-
const wkbLoader = loaders.find((loader) => loader.id === "wkb");
|
|
281
1135
|
const arrayBuffer = ArrayBuffer.isView(geometry) ? geometry.buffer.slice(geometry.byteOffset, geometry.byteOffset + geometry.byteLength) : geometry;
|
|
282
|
-
|
|
283
|
-
wkb: { shape: "geojson-geometry" }
|
|
284
|
-
});
|
|
285
|
-
return geojson;
|
|
1136
|
+
return convertWKBToGeometry(arrayBuffer);
|
|
286
1137
|
}
|
|
287
1138
|
}
|
|
288
1139
|
|
|
289
|
-
// dist/lib/
|
|
1140
|
+
// dist/lib/feature-collection-converters/convert-flat-geojson-to-binary-features.js
|
|
290
1141
|
var import_polygon = require("@math.gl/polygon");
|
|
291
|
-
function
|
|
1142
|
+
function convertFlatGeojsonToBinaryFeatureCollection(features, geometryInfo, options) {
|
|
292
1143
|
const propArrayTypes = extractNumericPropTypes(features);
|
|
293
1144
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
294
1145
|
return fillArrays(features, {
|
|
@@ -514,111 +1365,26 @@ function fillNumericProperties(object, properties, index, length) {
|
|
|
514
1365
|
object.numericProps[numericPropName].fill(value, index, index + length);
|
|
515
1366
|
}
|
|
516
1367
|
}
|
|
517
|
-
}
|
|
518
|
-
function keepStringProperties(properties, numericKeys) {
|
|
519
|
-
const props = {};
|
|
520
|
-
for (const key in properties) {
|
|
521
|
-
if (!numericKeys.includes(key)) {
|
|
522
|
-
props[key] = properties[key];
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
return props;
|
|
526
|
-
}
|
|
527
|
-
function deduceArrayType(x, constructor) {
|
|
528
|
-
if (constructor === Array || !Number.isFinite(x)) {
|
|
529
|
-
return Array;
|
|
530
|
-
}
|
|
531
|
-
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
// dist/lib/binary-features/extract-geometry-info.js
|
|
535
|
-
function extractGeometryInfo(features) {
|
|
536
|
-
let pointPositionsCount = 0;
|
|
537
|
-
let pointFeaturesCount = 0;
|
|
538
|
-
let linePositionsCount = 0;
|
|
539
|
-
let linePathsCount = 0;
|
|
540
|
-
let lineFeaturesCount = 0;
|
|
541
|
-
let polygonPositionsCount = 0;
|
|
542
|
-
let polygonObjectsCount = 0;
|
|
543
|
-
let polygonRingsCount = 0;
|
|
544
|
-
let polygonFeaturesCount = 0;
|
|
545
|
-
const coordLengths = /* @__PURE__ */ new Set();
|
|
546
|
-
for (const feature of features) {
|
|
547
|
-
const geometry = feature.geometry;
|
|
548
|
-
switch (geometry.type) {
|
|
549
|
-
case "Point":
|
|
550
|
-
pointFeaturesCount++;
|
|
551
|
-
pointPositionsCount++;
|
|
552
|
-
coordLengths.add(geometry.coordinates.length);
|
|
553
|
-
break;
|
|
554
|
-
case "MultiPoint":
|
|
555
|
-
pointFeaturesCount++;
|
|
556
|
-
pointPositionsCount += geometry.coordinates.length;
|
|
557
|
-
for (const point of geometry.coordinates) {
|
|
558
|
-
coordLengths.add(point.length);
|
|
559
|
-
}
|
|
560
|
-
break;
|
|
561
|
-
case "LineString":
|
|
562
|
-
lineFeaturesCount++;
|
|
563
|
-
linePositionsCount += geometry.coordinates.length;
|
|
564
|
-
linePathsCount++;
|
|
565
|
-
for (const coord of geometry.coordinates) {
|
|
566
|
-
coordLengths.add(coord.length);
|
|
567
|
-
}
|
|
568
|
-
break;
|
|
569
|
-
case "MultiLineString":
|
|
570
|
-
lineFeaturesCount++;
|
|
571
|
-
for (const line of geometry.coordinates) {
|
|
572
|
-
linePositionsCount += line.length;
|
|
573
|
-
linePathsCount++;
|
|
574
|
-
for (const coord of line) {
|
|
575
|
-
coordLengths.add(coord.length);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
break;
|
|
579
|
-
case "Polygon":
|
|
580
|
-
polygonFeaturesCount++;
|
|
581
|
-
polygonObjectsCount++;
|
|
582
|
-
polygonRingsCount += geometry.coordinates.length;
|
|
583
|
-
const flattened = geometry.coordinates.flat();
|
|
584
|
-
polygonPositionsCount += flattened.length;
|
|
585
|
-
for (const coord of flattened) {
|
|
586
|
-
coordLengths.add(coord.length);
|
|
587
|
-
}
|
|
588
|
-
break;
|
|
589
|
-
case "MultiPolygon":
|
|
590
|
-
polygonFeaturesCount++;
|
|
591
|
-
for (const polygon of geometry.coordinates) {
|
|
592
|
-
polygonObjectsCount++;
|
|
593
|
-
polygonRingsCount += polygon.length;
|
|
594
|
-
const flattened2 = polygon.flat();
|
|
595
|
-
polygonPositionsCount += flattened2.length;
|
|
596
|
-
for (const coord of flattened2) {
|
|
597
|
-
coordLengths.add(coord.length);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
break;
|
|
601
|
-
default:
|
|
602
|
-
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
1368
|
+
}
|
|
1369
|
+
function keepStringProperties(properties, numericKeys) {
|
|
1370
|
+
const props = {};
|
|
1371
|
+
for (const key in properties) {
|
|
1372
|
+
if (!numericKeys.includes(key)) {
|
|
1373
|
+
props[key] = properties[key];
|
|
603
1374
|
}
|
|
604
1375
|
}
|
|
605
|
-
return
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
polygonPositionsCount,
|
|
613
|
-
polygonObjectsCount,
|
|
614
|
-
polygonRingsCount,
|
|
615
|
-
polygonFeaturesCount
|
|
616
|
-
};
|
|
1376
|
+
return props;
|
|
1377
|
+
}
|
|
1378
|
+
function deduceArrayType(x, constructor) {
|
|
1379
|
+
if (constructor === Array || !Number.isFinite(x)) {
|
|
1380
|
+
return Array;
|
|
1381
|
+
}
|
|
1382
|
+
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
617
1383
|
}
|
|
618
1384
|
|
|
619
|
-
// dist/lib/
|
|
1385
|
+
// dist/lib/feature-collection-converters/convert-geojson-to-flat-geojson.js
|
|
620
1386
|
var import_polygon2 = require("@math.gl/polygon");
|
|
621
|
-
function
|
|
1387
|
+
function convertGeojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
|
|
622
1388
|
return features.map((feature) => flattenFeature(feature, options));
|
|
623
1389
|
}
|
|
624
1390
|
function flattenPoint(coordinates, data, indices, options) {
|
|
@@ -666,251 +1432,1427 @@ function flattenFeature(feature, options) {
|
|
|
666
1432
|
const data = [];
|
|
667
1433
|
const indices = [];
|
|
668
1434
|
let areas;
|
|
669
|
-
let
|
|
1435
|
+
let type2;
|
|
670
1436
|
switch (geometry.type) {
|
|
671
1437
|
case "Point":
|
|
672
|
-
|
|
1438
|
+
type2 = "Point";
|
|
673
1439
|
flattenPoint(geometry.coordinates, data, indices, options);
|
|
674
1440
|
break;
|
|
675
1441
|
case "MultiPoint":
|
|
676
|
-
|
|
1442
|
+
type2 = "Point";
|
|
677
1443
|
geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
|
|
678
1444
|
break;
|
|
679
1445
|
case "LineString":
|
|
680
|
-
|
|
1446
|
+
type2 = "LineString";
|
|
681
1447
|
flattenLineString(geometry.coordinates, data, indices, options);
|
|
682
1448
|
break;
|
|
683
1449
|
case "MultiLineString":
|
|
684
|
-
|
|
1450
|
+
type2 = "LineString";
|
|
685
1451
|
geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
|
|
686
1452
|
break;
|
|
687
1453
|
case "Polygon":
|
|
688
|
-
|
|
1454
|
+
type2 = "Polygon";
|
|
689
1455
|
areas = [];
|
|
690
1456
|
flattenPolygon(geometry.coordinates, data, indices, areas, options);
|
|
691
1457
|
break;
|
|
692
1458
|
case "MultiPolygon":
|
|
693
|
-
|
|
1459
|
+
type2 = "Polygon";
|
|
694
1460
|
areas = [];
|
|
695
1461
|
geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
|
|
696
1462
|
break;
|
|
697
1463
|
default:
|
|
698
|
-
throw new Error(`Unknown type: ${
|
|
1464
|
+
throw new Error(`Unknown type: ${type2}`);
|
|
699
1465
|
}
|
|
700
|
-
return { ...feature, geometry: { type, indices, data, areas } };
|
|
1466
|
+
return { ...feature, geometry: { type: type2, indices, data, areas } };
|
|
701
1467
|
}
|
|
702
1468
|
|
|
703
|
-
// dist/lib/
|
|
704
|
-
function
|
|
705
|
-
const geometryInfo =
|
|
1469
|
+
// dist/lib/feature-collection-converters/convert-geojson-to-binary-features.js
|
|
1470
|
+
function convertGeojsonToBinaryFeatureCollection(features, options = { fixRingWinding: true, triangulate: true }) {
|
|
1471
|
+
const geometryInfo = getGeometryInfo(features);
|
|
706
1472
|
const coordLength = geometryInfo.coordLength;
|
|
707
1473
|
const { fixRingWinding } = options;
|
|
708
|
-
const flatFeatures =
|
|
709
|
-
return
|
|
1474
|
+
const flatFeatures = convertGeojsonToFlatGeojson(features, { coordLength, fixRingWinding });
|
|
1475
|
+
return convertFlatGeojsonToBinaryFeatureCollection(flatFeatures, geometryInfo, {
|
|
710
1476
|
numericPropKeys: options.numericPropKeys,
|
|
711
1477
|
PositionDataType: options.PositionDataType || Float32Array,
|
|
712
1478
|
triangulate: options.triangulate
|
|
713
1479
|
});
|
|
714
1480
|
}
|
|
715
|
-
|
|
716
|
-
// dist/lib/
|
|
717
|
-
function
|
|
718
|
-
const globalFeatureId = options == null ? void 0 : options.globalFeatureId;
|
|
719
|
-
if (globalFeatureId !== void 0) {
|
|
720
|
-
return getSingleFeature(data, globalFeatureId);
|
|
1481
|
+
|
|
1482
|
+
// dist/lib/feature-collection-converters/convert-binary-features-to-geojson.js
|
|
1483
|
+
function convertBinaryFeatureCollectionToGeojson(data, options) {
|
|
1484
|
+
const globalFeatureId = options == null ? void 0 : options.globalFeatureId;
|
|
1485
|
+
if (globalFeatureId !== void 0) {
|
|
1486
|
+
return getSingleFeature(data, globalFeatureId);
|
|
1487
|
+
}
|
|
1488
|
+
return parseFeatures(data, options == null ? void 0 : options.type);
|
|
1489
|
+
}
|
|
1490
|
+
function getSingleFeature(data, globalFeatureId) {
|
|
1491
|
+
const dataArray = normalizeInput(data);
|
|
1492
|
+
for (const data2 of dataArray) {
|
|
1493
|
+
let lastIndex = 0;
|
|
1494
|
+
let lastValue = data2.featureIds.value[0];
|
|
1495
|
+
for (let i = 0; i < data2.featureIds.value.length; i++) {
|
|
1496
|
+
const currValue = data2.featureIds.value[i];
|
|
1497
|
+
if (currValue === lastValue) {
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
if (globalFeatureId === data2.globalFeatureIds.value[lastIndex]) {
|
|
1501
|
+
return parseFeature(data2, lastIndex, i);
|
|
1502
|
+
}
|
|
1503
|
+
lastIndex = i;
|
|
1504
|
+
lastValue = currValue;
|
|
1505
|
+
}
|
|
1506
|
+
if (globalFeatureId === data2.globalFeatureIds.value[lastIndex]) {
|
|
1507
|
+
return parseFeature(data2, lastIndex, data2.featureIds.value.length);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
throw new Error(`featureId:${globalFeatureId} not found`);
|
|
1511
|
+
}
|
|
1512
|
+
function parseFeatures(data, type2) {
|
|
1513
|
+
const dataArray = normalizeInput(data, type2);
|
|
1514
|
+
return parseFeatureCollection(dataArray);
|
|
1515
|
+
}
|
|
1516
|
+
function normalizeInput(data, type2) {
|
|
1517
|
+
const features = [];
|
|
1518
|
+
if (data.points) {
|
|
1519
|
+
data.points.type = "Point";
|
|
1520
|
+
features.push(data.points);
|
|
1521
|
+
}
|
|
1522
|
+
if (data.lines) {
|
|
1523
|
+
data.lines.type = "LineString";
|
|
1524
|
+
features.push(data.lines);
|
|
1525
|
+
}
|
|
1526
|
+
if (data.polygons) {
|
|
1527
|
+
data.polygons.type = "Polygon";
|
|
1528
|
+
features.push(data.polygons);
|
|
1529
|
+
}
|
|
1530
|
+
return features;
|
|
1531
|
+
}
|
|
1532
|
+
function parseFeatureCollection(dataArray) {
|
|
1533
|
+
const features = [];
|
|
1534
|
+
for (const data of dataArray) {
|
|
1535
|
+
if (data.featureIds.value.length === 0) {
|
|
1536
|
+
continue;
|
|
1537
|
+
}
|
|
1538
|
+
let lastIndex = 0;
|
|
1539
|
+
let lastValue = data.featureIds.value[0];
|
|
1540
|
+
for (let i = 0; i < data.featureIds.value.length; i++) {
|
|
1541
|
+
const currValue = data.featureIds.value[i];
|
|
1542
|
+
if (currValue === lastValue) {
|
|
1543
|
+
continue;
|
|
1544
|
+
}
|
|
1545
|
+
features.push(parseFeature(data, lastIndex, i));
|
|
1546
|
+
lastIndex = i;
|
|
1547
|
+
lastValue = currValue;
|
|
1548
|
+
}
|
|
1549
|
+
features.push(parseFeature(data, lastIndex, data.featureIds.value.length));
|
|
1550
|
+
}
|
|
1551
|
+
return features;
|
|
1552
|
+
}
|
|
1553
|
+
function parseFeature(data, startIndex, endIndex) {
|
|
1554
|
+
const geometry = convertBinaryGeometryToGeometry(data, startIndex, endIndex);
|
|
1555
|
+
const properties = parseProperties(data, startIndex, endIndex);
|
|
1556
|
+
const fields = parseFields(data, startIndex, endIndex);
|
|
1557
|
+
return { type: "Feature", geometry, properties, ...fields };
|
|
1558
|
+
}
|
|
1559
|
+
function parseFields(data, startIndex = 0, endIndex) {
|
|
1560
|
+
return data.fields && data.fields[data.featureIds.value[startIndex]];
|
|
1561
|
+
}
|
|
1562
|
+
function parseProperties(data, startIndex = 0, endIndex) {
|
|
1563
|
+
const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);
|
|
1564
|
+
for (const key in data.numericProps) {
|
|
1565
|
+
properties[key] = data.numericProps[key].value[startIndex];
|
|
1566
|
+
}
|
|
1567
|
+
return properties;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// dist/lib/utils/binary-reader.js
|
|
1571
|
+
var BinaryReader = class {
|
|
1572
|
+
arrayBuffer;
|
|
1573
|
+
dataView;
|
|
1574
|
+
byteOffset;
|
|
1575
|
+
littleEndian;
|
|
1576
|
+
constructor(arrayBuffer, isBigEndian = false) {
|
|
1577
|
+
this.arrayBuffer = arrayBuffer;
|
|
1578
|
+
this.dataView = new DataView(arrayBuffer);
|
|
1579
|
+
this.byteOffset = 0;
|
|
1580
|
+
this.littleEndian = !isBigEndian;
|
|
1581
|
+
}
|
|
1582
|
+
readUInt8() {
|
|
1583
|
+
const value = this.dataView.getUint8(this.byteOffset);
|
|
1584
|
+
this.byteOffset += 1;
|
|
1585
|
+
return value;
|
|
1586
|
+
}
|
|
1587
|
+
readUInt16() {
|
|
1588
|
+
const value = this.dataView.getUint16(this.byteOffset, this.littleEndian);
|
|
1589
|
+
this.byteOffset += 2;
|
|
1590
|
+
return value;
|
|
1591
|
+
}
|
|
1592
|
+
readUInt32() {
|
|
1593
|
+
const value = this.dataView.getUint32(this.byteOffset, this.littleEndian);
|
|
1594
|
+
this.byteOffset += 4;
|
|
1595
|
+
return value;
|
|
1596
|
+
}
|
|
1597
|
+
readInt8() {
|
|
1598
|
+
const value = this.dataView.getInt8(this.byteOffset);
|
|
1599
|
+
this.byteOffset += 1;
|
|
1600
|
+
return value;
|
|
1601
|
+
}
|
|
1602
|
+
readInt16() {
|
|
1603
|
+
const value = this.dataView.getInt16(this.byteOffset, this.littleEndian);
|
|
1604
|
+
this.byteOffset += 2;
|
|
1605
|
+
return value;
|
|
1606
|
+
}
|
|
1607
|
+
readInt32() {
|
|
1608
|
+
const value = this.dataView.getInt32(this.byteOffset, this.littleEndian);
|
|
1609
|
+
this.byteOffset += 4;
|
|
1610
|
+
return value;
|
|
1611
|
+
}
|
|
1612
|
+
readFloat() {
|
|
1613
|
+
const value = this.dataView.getFloat32(this.byteOffset, this.littleEndian);
|
|
1614
|
+
this.byteOffset += 4;
|
|
1615
|
+
return value;
|
|
1616
|
+
}
|
|
1617
|
+
readDouble() {
|
|
1618
|
+
const value = this.dataView.getFloat64(this.byteOffset, this.littleEndian);
|
|
1619
|
+
this.byteOffset += 8;
|
|
1620
|
+
return value;
|
|
1621
|
+
}
|
|
1622
|
+
readVarInt() {
|
|
1623
|
+
let result = 0;
|
|
1624
|
+
let bytesRead = 0;
|
|
1625
|
+
let nextByte;
|
|
1626
|
+
do {
|
|
1627
|
+
nextByte = this.dataView.getUint8(this.byteOffset + bytesRead);
|
|
1628
|
+
result += (nextByte & 127) << 7 * bytesRead;
|
|
1629
|
+
bytesRead++;
|
|
1630
|
+
} while (nextByte >= 128);
|
|
1631
|
+
this.byteOffset += bytesRead;
|
|
1632
|
+
return result;
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
|
|
1636
|
+
// dist/lib/geometry-converters/wkb/convert-twkb-to-geometry.js
|
|
1637
|
+
function convertTWKBToGeometry(arrayBuffer) {
|
|
1638
|
+
const binaryReader = new BinaryReader(arrayBuffer);
|
|
1639
|
+
const context = parseTWKBHeader(binaryReader);
|
|
1640
|
+
if (context.hasSizeAttribute) {
|
|
1641
|
+
binaryReader.readVarInt();
|
|
1642
|
+
}
|
|
1643
|
+
if (context.hasBoundingBox) {
|
|
1644
|
+
let dimensions = 2;
|
|
1645
|
+
if (context.hasZ) {
|
|
1646
|
+
dimensions++;
|
|
1647
|
+
}
|
|
1648
|
+
if (context.hasM) {
|
|
1649
|
+
dimensions++;
|
|
1650
|
+
}
|
|
1651
|
+
for (let i = 0; i < dimensions; i++) {
|
|
1652
|
+
binaryReader.readVarInt();
|
|
1653
|
+
binaryReader.readVarInt();
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
return parseGeometry3(binaryReader, context, context.geometryType);
|
|
1657
|
+
}
|
|
1658
|
+
function parseTWKBHeader(binaryReader) {
|
|
1659
|
+
const type2 = binaryReader.readUInt8();
|
|
1660
|
+
const metadataHeader = binaryReader.readUInt8();
|
|
1661
|
+
const geometryType = type2 & 15;
|
|
1662
|
+
const precision = zigZagDecode(type2 >> 4);
|
|
1663
|
+
const hasExtendedPrecision = Boolean(metadataHeader >> 3 & 1);
|
|
1664
|
+
let hasZ = false;
|
|
1665
|
+
let hasM = false;
|
|
1666
|
+
let zPrecision = 0;
|
|
1667
|
+
let zPrecisionFactor = 1;
|
|
1668
|
+
let mPrecision = 0;
|
|
1669
|
+
let mPrecisionFactor = 1;
|
|
1670
|
+
if (hasExtendedPrecision) {
|
|
1671
|
+
const extendedPrecision = binaryReader.readUInt8();
|
|
1672
|
+
hasZ = (extendedPrecision & 1) === 1;
|
|
1673
|
+
hasM = (extendedPrecision & 2) === 2;
|
|
1674
|
+
zPrecision = zigZagDecode((extendedPrecision & 28) >> 2);
|
|
1675
|
+
zPrecisionFactor = Math.pow(10, zPrecision);
|
|
1676
|
+
mPrecision = zigZagDecode((extendedPrecision & 224) >> 5);
|
|
1677
|
+
mPrecisionFactor = Math.pow(10, mPrecision);
|
|
1678
|
+
}
|
|
1679
|
+
return {
|
|
1680
|
+
geometryType,
|
|
1681
|
+
precision,
|
|
1682
|
+
precisionFactor: Math.pow(10, precision),
|
|
1683
|
+
hasBoundingBox: Boolean(metadataHeader >> 0 & 1),
|
|
1684
|
+
hasSizeAttribute: Boolean(metadataHeader >> 1 & 1),
|
|
1685
|
+
hasIdList: Boolean(metadataHeader >> 2 & 1),
|
|
1686
|
+
hasExtendedPrecision,
|
|
1687
|
+
isEmpty: Boolean(metadataHeader >> 4 & 1),
|
|
1688
|
+
hasZ,
|
|
1689
|
+
hasM,
|
|
1690
|
+
zPrecision,
|
|
1691
|
+
zPrecisionFactor,
|
|
1692
|
+
mPrecision,
|
|
1693
|
+
mPrecisionFactor
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
function parseGeometry3(binaryReader, context, geometryType) {
|
|
1697
|
+
switch (geometryType) {
|
|
1698
|
+
case WKBGeometryType.Point:
|
|
1699
|
+
return parsePoint3(binaryReader, context);
|
|
1700
|
+
case WKBGeometryType.LineString:
|
|
1701
|
+
return parseLineString3(binaryReader, context);
|
|
1702
|
+
case WKBGeometryType.Polygon:
|
|
1703
|
+
return parsePolygon3(binaryReader, context);
|
|
1704
|
+
case WKBGeometryType.MultiPoint:
|
|
1705
|
+
return parseMultiPoint3(binaryReader, context);
|
|
1706
|
+
case WKBGeometryType.MultiLineString:
|
|
1707
|
+
return parseMultiLineString3(binaryReader, context);
|
|
1708
|
+
case WKBGeometryType.MultiPolygon:
|
|
1709
|
+
return parseMultiPolygon3(binaryReader, context);
|
|
1710
|
+
case WKBGeometryType.GeometryCollection:
|
|
1711
|
+
return parseGeometryCollection2(binaryReader, context);
|
|
1712
|
+
default:
|
|
1713
|
+
throw new Error(`GeometryType ${geometryType} not supported`);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
function parsePoint3(reader, context) {
|
|
1717
|
+
if (context.isEmpty) {
|
|
1718
|
+
return { type: "Point", coordinates: [] };
|
|
1719
|
+
}
|
|
1720
|
+
return { type: "Point", coordinates: readFirstPoint(reader, context) };
|
|
1721
|
+
}
|
|
1722
|
+
function parseLineString3(reader, context) {
|
|
1723
|
+
if (context.isEmpty) {
|
|
1724
|
+
return { type: "LineString", coordinates: [] };
|
|
1725
|
+
}
|
|
1726
|
+
const pointCount = reader.readVarInt();
|
|
1727
|
+
const previousPoint = makePreviousPoint(context);
|
|
1728
|
+
const points = [];
|
|
1729
|
+
for (let i = 0; i < pointCount; i++) {
|
|
1730
|
+
points.push(parseNextPoint(reader, context, previousPoint));
|
|
1731
|
+
}
|
|
1732
|
+
return { type: "LineString", coordinates: points };
|
|
1733
|
+
}
|
|
1734
|
+
function parsePolygon3(reader, context) {
|
|
1735
|
+
if (context.isEmpty) {
|
|
1736
|
+
return { type: "Polygon", coordinates: [] };
|
|
1737
|
+
}
|
|
1738
|
+
const ringCount = reader.readVarInt();
|
|
1739
|
+
const previousPoint = makePreviousPoint(context);
|
|
1740
|
+
const exteriorRingLength = reader.readVarInt();
|
|
1741
|
+
const exteriorRing = [];
|
|
1742
|
+
for (let i = 0; i < exteriorRingLength; i++) {
|
|
1743
|
+
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
1744
|
+
}
|
|
1745
|
+
const polygon = [exteriorRing];
|
|
1746
|
+
for (let i = 1; i < ringCount; i++) {
|
|
1747
|
+
const interiorRingCount = reader.readVarInt();
|
|
1748
|
+
const interiorRing = [];
|
|
1749
|
+
for (let j = 0; j < interiorRingCount; j++) {
|
|
1750
|
+
interiorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
1751
|
+
}
|
|
1752
|
+
polygon.push(interiorRing);
|
|
1753
|
+
}
|
|
1754
|
+
return { type: "Polygon", coordinates: polygon };
|
|
1755
|
+
}
|
|
1756
|
+
function parseMultiPoint3(reader, context) {
|
|
1757
|
+
if (context.isEmpty) {
|
|
1758
|
+
return { type: "MultiPoint", coordinates: [] };
|
|
1759
|
+
}
|
|
1760
|
+
const previousPoint = makePreviousPoint(context);
|
|
1761
|
+
const pointCount = reader.readVarInt();
|
|
1762
|
+
const coordinates = [];
|
|
1763
|
+
for (let i = 0; i < pointCount; i++) {
|
|
1764
|
+
coordinates.push(parseNextPoint(reader, context, previousPoint));
|
|
1765
|
+
}
|
|
1766
|
+
return { type: "MultiPoint", coordinates };
|
|
1767
|
+
}
|
|
1768
|
+
function parseMultiLineString3(reader, context) {
|
|
1769
|
+
if (context.isEmpty) {
|
|
1770
|
+
return { type: "MultiLineString", coordinates: [] };
|
|
1771
|
+
}
|
|
1772
|
+
const previousPoint = makePreviousPoint(context);
|
|
1773
|
+
const lineStringCount = reader.readVarInt();
|
|
1774
|
+
const coordinates = [];
|
|
1775
|
+
for (let i = 0; i < lineStringCount; i++) {
|
|
1776
|
+
const pointCount = reader.readVarInt();
|
|
1777
|
+
const lineString = [];
|
|
1778
|
+
for (let j = 0; j < pointCount; j++) {
|
|
1779
|
+
lineString.push(parseNextPoint(reader, context, previousPoint));
|
|
1780
|
+
}
|
|
1781
|
+
coordinates.push(lineString);
|
|
1782
|
+
}
|
|
1783
|
+
return { type: "MultiLineString", coordinates };
|
|
1784
|
+
}
|
|
1785
|
+
function parseMultiPolygon3(reader, context) {
|
|
1786
|
+
if (context.isEmpty) {
|
|
1787
|
+
return { type: "MultiPolygon", coordinates: [] };
|
|
1788
|
+
}
|
|
1789
|
+
const previousPoint = makePreviousPoint(context);
|
|
1790
|
+
const polygonCount = reader.readVarInt();
|
|
1791
|
+
const polygons = [];
|
|
1792
|
+
for (let i = 0; i < polygonCount; i++) {
|
|
1793
|
+
const ringCount = reader.readVarInt();
|
|
1794
|
+
const exteriorPointCount = reader.readVarInt();
|
|
1795
|
+
const exteriorRing = [];
|
|
1796
|
+
for (let j = 0; j < exteriorPointCount; j++) {
|
|
1797
|
+
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
1798
|
+
}
|
|
1799
|
+
const polygon = exteriorRing ? [exteriorRing] : [];
|
|
1800
|
+
for (let j = 1; j < ringCount; j++) {
|
|
1801
|
+
const interiorRing = [];
|
|
1802
|
+
const interiorRingLength = reader.readVarInt();
|
|
1803
|
+
for (let k = 0; k < interiorRingLength; k++) {
|
|
1804
|
+
interiorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
1805
|
+
}
|
|
1806
|
+
polygon.push(interiorRing);
|
|
1807
|
+
}
|
|
1808
|
+
polygons.push(polygon);
|
|
1809
|
+
}
|
|
1810
|
+
return { type: "MultiPolygon", coordinates: polygons };
|
|
1811
|
+
}
|
|
1812
|
+
function parseGeometryCollection2(reader, context) {
|
|
1813
|
+
return { type: "GeometryCollection", geometries: [] };
|
|
1814
|
+
}
|
|
1815
|
+
function zigZagDecode(value) {
|
|
1816
|
+
return value >> 1 ^ -(value & 1);
|
|
1817
|
+
}
|
|
1818
|
+
function makePointCoordinates(x, y, z, m) {
|
|
1819
|
+
return z !== void 0 ? m !== void 0 ? [x, y, z, m] : [x, y, z] : [x, y];
|
|
1820
|
+
}
|
|
1821
|
+
function makePreviousPoint(context) {
|
|
1822
|
+
return makePointCoordinates(0, 0, context.hasZ ? 0 : void 0, context.hasM ? 0 : void 0);
|
|
1823
|
+
}
|
|
1824
|
+
function readFirstPoint(reader, context) {
|
|
1825
|
+
const x = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
1826
|
+
const y = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
1827
|
+
const z = context.hasZ ? zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor : void 0;
|
|
1828
|
+
const m = context.hasM ? zigZagDecode(reader.readVarInt()) / context.mPrecisionFactor : void 0;
|
|
1829
|
+
return makePointCoordinates(x, y, z, m);
|
|
1830
|
+
}
|
|
1831
|
+
function parseNextPoint(reader, context, previousPoint) {
|
|
1832
|
+
previousPoint[0] += zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
1833
|
+
previousPoint[1] += zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
1834
|
+
if (context.hasZ) {
|
|
1835
|
+
previousPoint[2] += zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor;
|
|
1836
|
+
}
|
|
1837
|
+
if (context.hasM) {
|
|
1838
|
+
previousPoint[3] += zigZagDecode(reader.readVarInt()) / context.mPrecisionFactor;
|
|
1839
|
+
}
|
|
1840
|
+
return previousPoint.slice();
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// dist/lib/geometry-converters/wkb/convert-geometry-to-wkt.js
|
|
1844
|
+
function convertGeometryToWKT(geometry) {
|
|
1845
|
+
switch (geometry.type) {
|
|
1846
|
+
case "Point":
|
|
1847
|
+
return `POINT ${wrapParens(pairWKT(geometry.coordinates))}`;
|
|
1848
|
+
case "LineString":
|
|
1849
|
+
return `LINESTRING ${wrapParens(ringWKT(geometry.coordinates))}`;
|
|
1850
|
+
case "Polygon":
|
|
1851
|
+
return `POLYGON ${wrapParens(ringsWKT(geometry.coordinates))}`;
|
|
1852
|
+
case "MultiPoint":
|
|
1853
|
+
return `MULTIPOINT ${wrapParens(ringWKT(geometry.coordinates))}`;
|
|
1854
|
+
case "MultiPolygon":
|
|
1855
|
+
return `MULTIPOLYGON ${wrapParens(multiRingsWKT(geometry.coordinates))}`;
|
|
1856
|
+
case "MultiLineString":
|
|
1857
|
+
return `MULTILINESTRING ${wrapParens(ringsWKT(geometry.coordinates))}`;
|
|
1858
|
+
case "GeometryCollection":
|
|
1859
|
+
return `GEOMETRYCOLLECTION ${wrapParens(geometry.geometries.map(convertGeometryToWKT).join(", "))}`;
|
|
1860
|
+
default:
|
|
1861
|
+
throw new Error("convertGeometryToWKT requires a valid GeoJSON Geometry (not Feature) as input");
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
function pairWKT(c) {
|
|
1865
|
+
return c.join(" ");
|
|
1866
|
+
}
|
|
1867
|
+
function ringWKT(r) {
|
|
1868
|
+
return r.map(pairWKT).join(", ");
|
|
1869
|
+
}
|
|
1870
|
+
function ringsWKT(r) {
|
|
1871
|
+
return r.map(ringWKT).map(wrapParens).join(", ");
|
|
1872
|
+
}
|
|
1873
|
+
function multiRingsWKT(r) {
|
|
1874
|
+
return r.map(ringsWKT).map(wrapParens).join(", ");
|
|
1875
|
+
}
|
|
1876
|
+
function wrapParens(s) {
|
|
1877
|
+
return `(${s})`;
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
// dist/lib/utils/binary-writer.js
|
|
1881
|
+
var LE = true;
|
|
1882
|
+
var BE = false;
|
|
1883
|
+
var BinaryWriter = class {
|
|
1884
|
+
arrayBuffer;
|
|
1885
|
+
dataView;
|
|
1886
|
+
byteOffset = 0;
|
|
1887
|
+
allowResize = false;
|
|
1888
|
+
constructor(size, allowResize) {
|
|
1889
|
+
this.arrayBuffer = new ArrayBuffer(size);
|
|
1890
|
+
this.dataView = new DataView(this.arrayBuffer);
|
|
1891
|
+
this.byteOffset = 0;
|
|
1892
|
+
this.allowResize = allowResize || false;
|
|
1893
|
+
}
|
|
1894
|
+
writeUInt8(value) {
|
|
1895
|
+
this._ensureSize(1);
|
|
1896
|
+
this.dataView.setUint8(this.byteOffset, value);
|
|
1897
|
+
this.byteOffset += 1;
|
|
1898
|
+
}
|
|
1899
|
+
writeUInt16LE(value) {
|
|
1900
|
+
this._ensureSize(2);
|
|
1901
|
+
this.dataView.setUint16(this.byteOffset, value, LE);
|
|
1902
|
+
this.byteOffset += 2;
|
|
1903
|
+
}
|
|
1904
|
+
writeUInt16BE(value) {
|
|
1905
|
+
this._ensureSize(2);
|
|
1906
|
+
this.dataView.setUint16(this.byteOffset, value, BE);
|
|
1907
|
+
this.byteOffset += 2;
|
|
1908
|
+
}
|
|
1909
|
+
writeUInt32LE(value) {
|
|
1910
|
+
this._ensureSize(4);
|
|
1911
|
+
this.dataView.setUint32(this.byteOffset, value, LE);
|
|
1912
|
+
this.byteOffset += 4;
|
|
1913
|
+
}
|
|
1914
|
+
writeUInt32BE(value) {
|
|
1915
|
+
this._ensureSize(4);
|
|
1916
|
+
this.dataView.setUint32(this.byteOffset, value, BE);
|
|
1917
|
+
this.byteOffset += 4;
|
|
1918
|
+
}
|
|
1919
|
+
writeInt8(value) {
|
|
1920
|
+
this._ensureSize(1);
|
|
1921
|
+
this.dataView.setInt8(this.byteOffset, value);
|
|
1922
|
+
this.byteOffset += 1;
|
|
1923
|
+
}
|
|
1924
|
+
writeInt16LE(value) {
|
|
1925
|
+
this._ensureSize(2);
|
|
1926
|
+
this.dataView.setInt16(this.byteOffset, value, LE);
|
|
1927
|
+
this.byteOffset += 2;
|
|
1928
|
+
}
|
|
1929
|
+
writeInt16BE(value) {
|
|
1930
|
+
this._ensureSize(2);
|
|
1931
|
+
this.dataView.setInt16(this.byteOffset, value, BE);
|
|
1932
|
+
this.byteOffset += 2;
|
|
1933
|
+
}
|
|
1934
|
+
writeInt32LE(value) {
|
|
1935
|
+
this._ensureSize(4);
|
|
1936
|
+
this.dataView.setInt32(this.byteOffset, value, LE);
|
|
1937
|
+
this.byteOffset += 4;
|
|
1938
|
+
}
|
|
1939
|
+
writeInt32BE(value) {
|
|
1940
|
+
this._ensureSize(4);
|
|
1941
|
+
this.dataView.setInt32(this.byteOffset, value, BE);
|
|
1942
|
+
this.byteOffset += 4;
|
|
1943
|
+
}
|
|
1944
|
+
writeFloatLE(value) {
|
|
1945
|
+
this._ensureSize(4);
|
|
1946
|
+
this.dataView.setFloat32(this.byteOffset, value, LE);
|
|
1947
|
+
this.byteOffset += 4;
|
|
1948
|
+
}
|
|
1949
|
+
writeFloatBE(value) {
|
|
1950
|
+
this._ensureSize(4);
|
|
1951
|
+
this.dataView.setFloat32(this.byteOffset, value, BE);
|
|
1952
|
+
this.byteOffset += 4;
|
|
1953
|
+
}
|
|
1954
|
+
writeDoubleLE(value) {
|
|
1955
|
+
this._ensureSize(8);
|
|
1956
|
+
this.dataView.setFloat64(this.byteOffset, value, LE);
|
|
1957
|
+
this.byteOffset += 8;
|
|
1958
|
+
}
|
|
1959
|
+
writeDoubleBE(value) {
|
|
1960
|
+
this._ensureSize(8);
|
|
1961
|
+
this.dataView.setFloat64(this.byteOffset, value, BE);
|
|
1962
|
+
this.byteOffset += 8;
|
|
1963
|
+
}
|
|
1964
|
+
/** A varint uses a variable number of bytes */
|
|
1965
|
+
writeVarInt(value) {
|
|
1966
|
+
let length = 1;
|
|
1967
|
+
while ((value & 4294967168) !== 0) {
|
|
1968
|
+
this.writeUInt8(value & 127 | 128);
|
|
1969
|
+
value >>>= 7;
|
|
1970
|
+
length++;
|
|
1971
|
+
}
|
|
1972
|
+
this.writeUInt8(value & 127);
|
|
1973
|
+
return length;
|
|
1974
|
+
}
|
|
1975
|
+
writeTypedArray(typedArray) {
|
|
1976
|
+
this._ensureSize(typedArray.byteLength);
|
|
1977
|
+
const tempArray = new Uint8Array(this.arrayBuffer);
|
|
1978
|
+
tempArray.set(typedArray, this.byteOffset);
|
|
1979
|
+
this.byteOffset += typedArray.byteLength;
|
|
1980
|
+
}
|
|
1981
|
+
/** Append another ArrayBuffer to this ArrayBuffer */
|
|
1982
|
+
writeBuffer(arrayBuffer) {
|
|
1983
|
+
this._ensureSize(arrayBuffer.byteLength);
|
|
1984
|
+
const tempArray = new Uint8Array(this.arrayBuffer);
|
|
1985
|
+
tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
|
|
1986
|
+
this.byteOffset += arrayBuffer.byteLength;
|
|
1987
|
+
}
|
|
1988
|
+
/** Resizes this.arrayBuffer if not enough space */
|
|
1989
|
+
_ensureSize(size) {
|
|
1990
|
+
if (this.arrayBuffer.byteLength < this.byteOffset + size) {
|
|
1991
|
+
if (this.allowResize) {
|
|
1992
|
+
const newArrayBuffer = new ArrayBuffer(this.byteOffset + size);
|
|
1993
|
+
const tempArray = new Uint8Array(newArrayBuffer);
|
|
1994
|
+
tempArray.set(new Uint8Array(this.arrayBuffer));
|
|
1995
|
+
this.arrayBuffer = newArrayBuffer;
|
|
1996
|
+
} else {
|
|
1997
|
+
throw new Error("BinaryWriter overflow");
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
|
|
2003
|
+
// dist/lib/geometry-converters/wkb/convert-geometry-to-wkb.js
|
|
2004
|
+
function convertGeometryToWKB(geometry, options = {}) {
|
|
2005
|
+
if (geometry.type === "Feature") {
|
|
2006
|
+
geometry = geometry.geometry;
|
|
2007
|
+
}
|
|
2008
|
+
switch (geometry.type) {
|
|
2009
|
+
case "Point":
|
|
2010
|
+
return encodePoint(geometry.coordinates, options);
|
|
2011
|
+
case "LineString":
|
|
2012
|
+
return encodeLineString(geometry.coordinates, options);
|
|
2013
|
+
case "Polygon":
|
|
2014
|
+
return encodePolygon(geometry.coordinates, options);
|
|
2015
|
+
case "MultiPoint":
|
|
2016
|
+
return encodeMultiPoint(geometry, options);
|
|
2017
|
+
case "MultiPolygon":
|
|
2018
|
+
return encodeMultiPolygon(geometry, options);
|
|
2019
|
+
case "MultiLineString":
|
|
2020
|
+
return encodeMultiLineString(geometry, options);
|
|
2021
|
+
case "GeometryCollection":
|
|
2022
|
+
return encodeGeometryCollection(geometry, options);
|
|
2023
|
+
default:
|
|
2024
|
+
const exhaustiveCheck = geometry;
|
|
2025
|
+
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
function getGeometrySize(geometry, options) {
|
|
2029
|
+
switch (geometry.type) {
|
|
2030
|
+
case "Point":
|
|
2031
|
+
return getPointSize(options);
|
|
2032
|
+
case "LineString":
|
|
2033
|
+
return getLineStringSize(geometry.coordinates, options);
|
|
2034
|
+
case "Polygon":
|
|
2035
|
+
return getPolygonSize(geometry.coordinates, options);
|
|
2036
|
+
case "MultiPoint":
|
|
2037
|
+
return getMultiPointSize(geometry, options);
|
|
2038
|
+
case "MultiPolygon":
|
|
2039
|
+
return getMultiPolygonSize(geometry, options);
|
|
2040
|
+
case "MultiLineString":
|
|
2041
|
+
return getMultiLineStringSize(geometry, options);
|
|
2042
|
+
case "GeometryCollection":
|
|
2043
|
+
return getGeometryCollectionSize(geometry, options);
|
|
2044
|
+
default:
|
|
2045
|
+
const exhaustiveCheck = geometry;
|
|
2046
|
+
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
function encodePoint(coordinates, options) {
|
|
2050
|
+
const writer = new BinaryWriter(getPointSize(options));
|
|
2051
|
+
writer.writeInt8(1);
|
|
2052
|
+
writeWkbType(writer, WKBGeometryType.Point, options);
|
|
2053
|
+
if (typeof coordinates[0] === "undefined" && typeof coordinates[1] === "undefined") {
|
|
2054
|
+
writer.writeDoubleLE(NaN);
|
|
2055
|
+
writer.writeDoubleLE(NaN);
|
|
2056
|
+
if (options.hasZ) {
|
|
2057
|
+
writer.writeDoubleLE(NaN);
|
|
2058
|
+
}
|
|
2059
|
+
if (options.hasM) {
|
|
2060
|
+
writer.writeDoubleLE(NaN);
|
|
2061
|
+
}
|
|
2062
|
+
} else {
|
|
2063
|
+
writeCoordinate(writer, coordinates, options);
|
|
2064
|
+
}
|
|
2065
|
+
return writer.arrayBuffer;
|
|
2066
|
+
}
|
|
2067
|
+
function writeCoordinate(writer, coordinate, options) {
|
|
2068
|
+
writer.writeDoubleLE(coordinate[0]);
|
|
2069
|
+
writer.writeDoubleLE(coordinate[1]);
|
|
2070
|
+
if (options.hasZ) {
|
|
2071
|
+
writer.writeDoubleLE(coordinate[2]);
|
|
2072
|
+
}
|
|
2073
|
+
if (options.hasM) {
|
|
2074
|
+
writer.writeDoubleLE(coordinate[3]);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
function getPointSize(options) {
|
|
2078
|
+
const coordinateSize = getCoordinateSize(options);
|
|
2079
|
+
return 1 + 4 + coordinateSize;
|
|
2080
|
+
}
|
|
2081
|
+
function encodeLineString(coordinates, options) {
|
|
2082
|
+
const size = getLineStringSize(coordinates, options);
|
|
2083
|
+
const writer = new BinaryWriter(size);
|
|
2084
|
+
writer.writeInt8(1);
|
|
2085
|
+
writeWkbType(writer, WKBGeometryType.LineString, options);
|
|
2086
|
+
writer.writeUInt32LE(coordinates.length);
|
|
2087
|
+
for (const coordinate of coordinates) {
|
|
2088
|
+
writeCoordinate(writer, coordinate, options);
|
|
2089
|
+
}
|
|
2090
|
+
return writer.arrayBuffer;
|
|
2091
|
+
}
|
|
2092
|
+
function getLineStringSize(coordinates, options) {
|
|
2093
|
+
const coordinateSize = getCoordinateSize(options);
|
|
2094
|
+
return 1 + 4 + 4 + coordinates.length * coordinateSize;
|
|
2095
|
+
}
|
|
2096
|
+
function encodePolygon(coordinates, options) {
|
|
2097
|
+
const writer = new BinaryWriter(getPolygonSize(coordinates, options));
|
|
2098
|
+
writer.writeInt8(1);
|
|
2099
|
+
writeWkbType(writer, WKBGeometryType.Polygon, options);
|
|
2100
|
+
const [exteriorRing = [], ...interiorRings] = coordinates;
|
|
2101
|
+
if (exteriorRing.length > 0) {
|
|
2102
|
+
writer.writeUInt32LE(1 + interiorRings.length);
|
|
2103
|
+
writer.writeUInt32LE(exteriorRing.length);
|
|
2104
|
+
} else {
|
|
2105
|
+
writer.writeUInt32LE(0);
|
|
2106
|
+
}
|
|
2107
|
+
for (const coordinate of exteriorRing) {
|
|
2108
|
+
writeCoordinate(writer, coordinate, options);
|
|
2109
|
+
}
|
|
2110
|
+
for (const interiorRing of interiorRings) {
|
|
2111
|
+
writer.writeUInt32LE(interiorRing.length);
|
|
2112
|
+
for (const coordinate of interiorRing) {
|
|
2113
|
+
writeCoordinate(writer, coordinate, options);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
return writer.arrayBuffer;
|
|
2117
|
+
}
|
|
2118
|
+
function getPolygonSize(coordinates, options) {
|
|
2119
|
+
const coordinateSize = getCoordinateSize(options);
|
|
2120
|
+
const [exteriorRing = [], ...interiorRings] = coordinates;
|
|
2121
|
+
let size = 1 + 4 + 4;
|
|
2122
|
+
if (exteriorRing.length > 0) {
|
|
2123
|
+
size += 4 + exteriorRing.length * coordinateSize;
|
|
2124
|
+
}
|
|
2125
|
+
for (const interiorRing of interiorRings) {
|
|
2126
|
+
size += 4 + interiorRing.length * coordinateSize;
|
|
2127
|
+
}
|
|
2128
|
+
return size;
|
|
2129
|
+
}
|
|
2130
|
+
function encodeMultiPoint(multiPoint, options) {
|
|
2131
|
+
const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
|
|
2132
|
+
const points = multiPoint.coordinates;
|
|
2133
|
+
writer.writeInt8(1);
|
|
2134
|
+
writeWkbType(writer, WKBGeometryType.MultiPoint, options);
|
|
2135
|
+
writer.writeUInt32LE(points.length);
|
|
2136
|
+
for (const point of points) {
|
|
2137
|
+
const arrayBuffer = encodePoint(point, options);
|
|
2138
|
+
writer.writeBuffer(arrayBuffer);
|
|
2139
|
+
}
|
|
2140
|
+
return writer.arrayBuffer;
|
|
2141
|
+
}
|
|
2142
|
+
function getMultiPointSize(multiPoint, options) {
|
|
2143
|
+
let coordinateSize = getCoordinateSize(options);
|
|
2144
|
+
const points = multiPoint.coordinates;
|
|
2145
|
+
coordinateSize += 5;
|
|
2146
|
+
return 1 + 4 + 4 + points.length * coordinateSize;
|
|
2147
|
+
}
|
|
2148
|
+
function encodeMultiLineString(multiLineString, options) {
|
|
2149
|
+
const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
|
|
2150
|
+
const lineStrings = multiLineString.coordinates;
|
|
2151
|
+
writer.writeInt8(1);
|
|
2152
|
+
writeWkbType(writer, WKBGeometryType.MultiLineString, options);
|
|
2153
|
+
writer.writeUInt32LE(lineStrings.length);
|
|
2154
|
+
for (const lineString of lineStrings) {
|
|
2155
|
+
const encodedLineString = encodeLineString(lineString, options);
|
|
2156
|
+
writer.writeBuffer(encodedLineString);
|
|
2157
|
+
}
|
|
2158
|
+
return writer.arrayBuffer;
|
|
2159
|
+
}
|
|
2160
|
+
function getMultiLineStringSize(multiLineString, options) {
|
|
2161
|
+
let size = 1 + 4 + 4;
|
|
2162
|
+
const lineStrings = multiLineString.coordinates;
|
|
2163
|
+
for (const lineString of lineStrings) {
|
|
2164
|
+
size += getLineStringSize(lineString, options);
|
|
2165
|
+
}
|
|
2166
|
+
return size;
|
|
2167
|
+
}
|
|
2168
|
+
function encodeMultiPolygon(multiPolygon, options) {
|
|
2169
|
+
const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
|
|
2170
|
+
const polygons = multiPolygon.coordinates;
|
|
2171
|
+
writer.writeInt8(1);
|
|
2172
|
+
writeWkbType(writer, WKBGeometryType.MultiPolygon, options);
|
|
2173
|
+
writer.writeUInt32LE(polygons.length);
|
|
2174
|
+
for (const polygon of polygons) {
|
|
2175
|
+
const encodedPolygon = encodePolygon(polygon, options);
|
|
2176
|
+
writer.writeBuffer(encodedPolygon);
|
|
721
2177
|
}
|
|
722
|
-
return
|
|
2178
|
+
return writer.arrayBuffer;
|
|
723
2179
|
}
|
|
724
|
-
function
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
2180
|
+
function getMultiPolygonSize(multiPolygon, options) {
|
|
2181
|
+
let size = 1 + 4 + 4;
|
|
2182
|
+
const polygons = multiPolygon.coordinates;
|
|
2183
|
+
for (const polygon of polygons) {
|
|
2184
|
+
size += getPolygonSize(polygon, options);
|
|
2185
|
+
}
|
|
2186
|
+
return size;
|
|
2187
|
+
}
|
|
2188
|
+
function encodeGeometryCollection(collection, options) {
|
|
2189
|
+
const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
|
|
2190
|
+
writer.writeInt8(1);
|
|
2191
|
+
writeWkbType(writer, WKBGeometryType.GeometryCollection, options);
|
|
2192
|
+
writer.writeUInt32LE(collection.geometries.length);
|
|
2193
|
+
for (const geometry of collection.geometries) {
|
|
2194
|
+
const arrayBuffer = convertGeometryToWKB(geometry, options);
|
|
2195
|
+
writer.writeBuffer(arrayBuffer);
|
|
2196
|
+
}
|
|
2197
|
+
return writer.arrayBuffer;
|
|
2198
|
+
}
|
|
2199
|
+
function getGeometryCollectionSize(collection, options) {
|
|
2200
|
+
let size = 1 + 4 + 4;
|
|
2201
|
+
for (const geometry of collection.geometries) {
|
|
2202
|
+
size += getGeometrySize(geometry, options);
|
|
2203
|
+
}
|
|
2204
|
+
return size;
|
|
2205
|
+
}
|
|
2206
|
+
function writeWkbType(writer, geometryType, options) {
|
|
2207
|
+
const { hasZ, hasM, srid } = options;
|
|
2208
|
+
let dimensionType = 0;
|
|
2209
|
+
if (!srid) {
|
|
2210
|
+
if (hasZ && hasM) {
|
|
2211
|
+
dimensionType += 3e3;
|
|
2212
|
+
} else if (hasZ) {
|
|
2213
|
+
dimensionType += 1e3;
|
|
2214
|
+
} else if (hasM) {
|
|
2215
|
+
dimensionType += 2e3;
|
|
739
2216
|
}
|
|
740
|
-
|
|
741
|
-
|
|
2217
|
+
} else {
|
|
2218
|
+
if (hasZ) {
|
|
2219
|
+
dimensionType |= 2147483648;
|
|
2220
|
+
}
|
|
2221
|
+
if (hasM) {
|
|
2222
|
+
dimensionType |= 1073741824;
|
|
742
2223
|
}
|
|
743
2224
|
}
|
|
744
|
-
|
|
2225
|
+
writer.writeUInt32LE(dimensionType + geometryType >>> 0);
|
|
745
2226
|
}
|
|
746
|
-
function
|
|
747
|
-
|
|
748
|
-
|
|
2227
|
+
function getCoordinateSize(options) {
|
|
2228
|
+
let coordinateSize = 16;
|
|
2229
|
+
if (options.hasZ) {
|
|
2230
|
+
coordinateSize += 8;
|
|
2231
|
+
}
|
|
2232
|
+
if (options.hasM) {
|
|
2233
|
+
coordinateSize += 8;
|
|
2234
|
+
}
|
|
2235
|
+
return coordinateSize;
|
|
749
2236
|
}
|
|
750
|
-
|
|
751
|
-
|
|
2237
|
+
|
|
2238
|
+
// dist/lib/geometry-converters/wkb/convert-geometry-to-twkb.js
|
|
2239
|
+
function convertGeometryToTWKB(geometry, options) {
|
|
2240
|
+
const writer = new BinaryWriter(0, true);
|
|
2241
|
+
const context = {
|
|
2242
|
+
...getTwkbPrecision(5, 0, 0),
|
|
2243
|
+
hasZ: options == null ? void 0 : options.hasZ,
|
|
2244
|
+
hasM: options == null ? void 0 : options.hasM
|
|
2245
|
+
};
|
|
2246
|
+
encodeGeometry(writer, geometry, context);
|
|
2247
|
+
return writer.arrayBuffer;
|
|
2248
|
+
}
|
|
2249
|
+
function encodeGeometry(writer, geometry, context) {
|
|
2250
|
+
switch (geometry.type) {
|
|
752
2251
|
case "Point":
|
|
753
|
-
return
|
|
2252
|
+
return encodePoint2(writer, context, geometry);
|
|
754
2253
|
case "LineString":
|
|
755
|
-
return
|
|
2254
|
+
return encodeLineString2(writer, context, geometry);
|
|
756
2255
|
case "Polygon":
|
|
757
|
-
return
|
|
2256
|
+
return encodePolygon2(writer, context, geometry);
|
|
2257
|
+
case "MultiPoint":
|
|
2258
|
+
return encodeMultiPoint2(writer, context, geometry);
|
|
2259
|
+
case "MultiLineString":
|
|
2260
|
+
return encodeMultiLineString2(writer, context, geometry);
|
|
2261
|
+
case "MultiPolygon":
|
|
2262
|
+
return encodeMultiPolygon2(writer, context, geometry);
|
|
2263
|
+
case "GeometryCollection":
|
|
2264
|
+
return encodeGeometryCollection2(writer, context, geometry);
|
|
758
2265
|
default:
|
|
759
|
-
|
|
760
|
-
throw new Error(`Unsupported geometry type: ${unexpectedInput == null ? void 0 : unexpectedInput.type}`);
|
|
2266
|
+
throw new Error("unsupported geometry type");
|
|
761
2267
|
}
|
|
762
2268
|
}
|
|
763
|
-
function
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
2269
|
+
function encodePoint2(writer, context, point) {
|
|
2270
|
+
const isEmpty = point.coordinates.length === 0 || point[0] === "undefined" || point[1] === "undefined";
|
|
2271
|
+
writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
|
|
2272
|
+
if (!isEmpty) {
|
|
2273
|
+
const previousPoint = [0, 0, 0, 0];
|
|
2274
|
+
writeTwkbPoint(writer, context, point.coordinates, previousPoint);
|
|
768
2275
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
2276
|
+
}
|
|
2277
|
+
function encodeLineString2(writer, context, lineString) {
|
|
2278
|
+
const points = lineString.coordinates;
|
|
2279
|
+
const isEmpty = points.length === 0;
|
|
2280
|
+
writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
|
|
2281
|
+
if (!isEmpty) {
|
|
2282
|
+
writer.writeVarInt(points.length);
|
|
2283
|
+
const previousPoint = [0, 0, 0, 0];
|
|
2284
|
+
for (const point of points) {
|
|
2285
|
+
writeTwkbPoint(writer, context, point, previousPoint);
|
|
2286
|
+
}
|
|
772
2287
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
2288
|
+
return writer.arrayBuffer;
|
|
2289
|
+
}
|
|
2290
|
+
function encodePolygon2(writer, context, polygon) {
|
|
2291
|
+
const polygonRings = polygon.coordinates;
|
|
2292
|
+
const isEmpty = polygonRings.length === 0;
|
|
2293
|
+
writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
|
|
2294
|
+
if (!isEmpty) {
|
|
2295
|
+
writer.writeVarInt(polygonRings.length);
|
|
2296
|
+
const previousPoint = [0, 0, 0, 0];
|
|
2297
|
+
for (const ring of polygonRings) {
|
|
2298
|
+
writer.writeVarInt(ring.length);
|
|
2299
|
+
for (const point of ring) {
|
|
2300
|
+
writeTwkbPoint(writer, context, previousPoint, point);
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
776
2303
|
}
|
|
777
|
-
return
|
|
2304
|
+
return writer.arrayBuffer;
|
|
778
2305
|
}
|
|
779
|
-
function
|
|
780
|
-
const
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
2306
|
+
function encodeMultiPoint2(writer, context, multiPoint) {
|
|
2307
|
+
const points = multiPoint.coordinates;
|
|
2308
|
+
const isEmpty = points.length === 0;
|
|
2309
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
|
|
2310
|
+
if (!isEmpty) {
|
|
2311
|
+
writer.writeVarInt(points.length);
|
|
2312
|
+
const previousPoint = [0, 0, 0, 0];
|
|
2313
|
+
for (let i = 0; i < points.length; i++) {
|
|
2314
|
+
writeTwkbPoint(writer, context, previousPoint, points[i]);
|
|
784
2315
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
function encodeMultiLineString2(writer, context, multiLineStrings) {
|
|
2319
|
+
const lineStrings = multiLineStrings.coordinates;
|
|
2320
|
+
const isEmpty = lineStrings.length === 0;
|
|
2321
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
|
|
2322
|
+
if (!isEmpty) {
|
|
2323
|
+
writer.writeVarInt(lineStrings.length);
|
|
2324
|
+
const previousPoint = [0, 0, 0, 0];
|
|
2325
|
+
for (const lineString of lineStrings) {
|
|
2326
|
+
writer.writeVarInt(lineString.length);
|
|
2327
|
+
for (const point of lineString) {
|
|
2328
|
+
writeTwkbPoint(writer, context, previousPoint, point);
|
|
791
2329
|
}
|
|
792
|
-
features.push(parseFeature(data, lastIndex, i));
|
|
793
|
-
lastIndex = i;
|
|
794
|
-
lastValue = currValue;
|
|
795
2330
|
}
|
|
796
|
-
features.push(parseFeature(data, lastIndex, data.featureIds.value.length));
|
|
797
2331
|
}
|
|
798
|
-
return
|
|
2332
|
+
return writer.arrayBuffer;
|
|
799
2333
|
}
|
|
800
|
-
function
|
|
801
|
-
const
|
|
802
|
-
const
|
|
803
|
-
|
|
804
|
-
|
|
2334
|
+
function encodeMultiPolygon2(writer, context, multiPolygon) {
|
|
2335
|
+
const { coordinates } = multiPolygon;
|
|
2336
|
+
const isEmpty = coordinates.length === 0;
|
|
2337
|
+
writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
|
|
2338
|
+
if (!isEmpty) {
|
|
2339
|
+
const polygons = coordinates;
|
|
2340
|
+
writer.writeVarInt(polygons.length);
|
|
2341
|
+
const previousPoint = [0, 0, 0, 0];
|
|
2342
|
+
for (const polygonRings of polygons) {
|
|
2343
|
+
writer.writeVarInt(polygonRings.length);
|
|
2344
|
+
for (const ring of polygonRings) {
|
|
2345
|
+
writer.writeVarInt(ring.length);
|
|
2346
|
+
for (const point of ring) {
|
|
2347
|
+
writeTwkbPoint(writer, context, previousPoint, point);
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
805
2352
|
}
|
|
806
|
-
function
|
|
807
|
-
|
|
2353
|
+
function encodeGeometryCollection2(writer, context, geometryCollection) {
|
|
2354
|
+
const { geometries } = geometryCollection;
|
|
2355
|
+
const isEmpty = geometries.length === 0;
|
|
2356
|
+
writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
|
|
2357
|
+
if (geometries.length > 0) {
|
|
2358
|
+
writer.writeVarInt(geometries.length);
|
|
2359
|
+
for (const geometry of geometries) {
|
|
2360
|
+
encodeGeometry(writer, geometry, context);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
808
2363
|
}
|
|
809
|
-
function
|
|
810
|
-
const
|
|
811
|
-
|
|
812
|
-
|
|
2364
|
+
function writeTwkbHeader(writer, context, geometryType, isEmpty) {
|
|
2365
|
+
const type2 = (zigZagEncode(context.xy) << 4) + geometryType;
|
|
2366
|
+
let metadataHeader = context.hasZ || context.hasM ? 1 << 3 : 0;
|
|
2367
|
+
metadataHeader += isEmpty ? 1 << 4 : 0;
|
|
2368
|
+
writer.writeUInt8(type2);
|
|
2369
|
+
writer.writeUInt8(metadataHeader);
|
|
2370
|
+
if (context.hasZ || context.hasM) {
|
|
2371
|
+
let extendedPrecision = 0;
|
|
2372
|
+
if (context.hasZ) {
|
|
2373
|
+
extendedPrecision |= 1;
|
|
2374
|
+
}
|
|
2375
|
+
if (context.hasM) {
|
|
2376
|
+
extendedPrecision |= 2;
|
|
2377
|
+
}
|
|
2378
|
+
writer.writeUInt8(extendedPrecision);
|
|
813
2379
|
}
|
|
814
|
-
return properties;
|
|
815
2380
|
}
|
|
816
|
-
function
|
|
817
|
-
const
|
|
818
|
-
const
|
|
819
|
-
const
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
2381
|
+
function writeTwkbPoint(writer, context, point, previousPoint) {
|
|
2382
|
+
const x = point[0] * context.xyFactor;
|
|
2383
|
+
const y = point[1] * context.xyFactor;
|
|
2384
|
+
const z = point[2] * context.zFactor;
|
|
2385
|
+
const m = point[3] * context.mFactor;
|
|
2386
|
+
writer.writeVarInt(zigZagEncode(x - previousPoint[0]));
|
|
2387
|
+
writer.writeVarInt(zigZagEncode(y - previousPoint[1]));
|
|
2388
|
+
if (context.hasZ) {
|
|
2389
|
+
writer.writeVarInt(zigZagEncode(z - previousPoint[2]));
|
|
2390
|
+
}
|
|
2391
|
+
if (context.hasM) {
|
|
2392
|
+
writer.writeVarInt(zigZagEncode(m - previousPoint[3]));
|
|
2393
|
+
}
|
|
2394
|
+
previousPoint[0] = x;
|
|
2395
|
+
previousPoint[1] = y;
|
|
2396
|
+
previousPoint[2] = z;
|
|
2397
|
+
previousPoint[3] = m;
|
|
2398
|
+
}
|
|
2399
|
+
function zigZagEncode(value) {
|
|
2400
|
+
return value << 1 ^ value >> 31;
|
|
2401
|
+
}
|
|
2402
|
+
function getTwkbPrecision(xyPrecision, zPrecision, mPrecision) {
|
|
2403
|
+
return {
|
|
2404
|
+
xy: xyPrecision,
|
|
2405
|
+
z: zPrecision,
|
|
2406
|
+
m: mPrecision,
|
|
2407
|
+
xyFactor: Math.pow(10, xyPrecision),
|
|
2408
|
+
zFactor: Math.pow(10, zPrecision),
|
|
2409
|
+
mFactor: Math.pow(10, mPrecision)
|
|
2410
|
+
};
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
// dist/lib/wkt-crs/parse-wkt-crs.js
|
|
2414
|
+
function parseWKTCRS(wkt, options) {
|
|
2415
|
+
if (options == null ? void 0 : options.debug) {
|
|
2416
|
+
console.log("[wktcrs] parse starting with\n", wkt);
|
|
2417
|
+
}
|
|
2418
|
+
wkt = wkt.replace(/[A-Z][A-Z\d_]+\[/gi, (match) => `["${match.substr(0, match.length - 1)}",`);
|
|
2419
|
+
wkt = wkt.replace(/, ?([A-Z][A-Z\d_]+[,\]])/gi, (match, p1) => {
|
|
2420
|
+
const varname = p1.substr(0, p1.length - 1);
|
|
2421
|
+
return `,"${(options == null ? void 0 : options.raw) ? "raw:" : ""}${varname}"${p1[p1.length - 1]}`;
|
|
2422
|
+
});
|
|
2423
|
+
if (options == null ? void 0 : options.raw) {
|
|
2424
|
+
wkt = wkt.replace(/, {0,2}(-?[\.\d]+)(?=,|\])/g, function(match, p1) {
|
|
2425
|
+
return `,"${(options == null ? void 0 : options.raw) ? "raw:" : ""}${p1}"`;
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2428
|
+
if (options == null ? void 0 : options.debug) {
|
|
2429
|
+
console.log(`[wktcrs] json'd wkt: '${wkt}'`);
|
|
2430
|
+
}
|
|
2431
|
+
let data;
|
|
2432
|
+
try {
|
|
2433
|
+
data = JSON.parse(wkt);
|
|
2434
|
+
} catch (error) {
|
|
2435
|
+
console.error(`[wktcrs] failed to parse '${wkt}'`);
|
|
2436
|
+
throw error;
|
|
2437
|
+
}
|
|
2438
|
+
if (options == null ? void 0 : options.debug) {
|
|
2439
|
+
console.log(`[wktcrs] json parsed: '${wkt}'`);
|
|
2440
|
+
}
|
|
2441
|
+
function process(data2, parent) {
|
|
2442
|
+
const kw = data2[0];
|
|
2443
|
+
data2.forEach(function(it) {
|
|
2444
|
+
if (Array.isArray(it)) {
|
|
2445
|
+
process(it, data2);
|
|
2446
|
+
}
|
|
2447
|
+
});
|
|
2448
|
+
const kwarr = `MULTIPLE_${kw}`;
|
|
2449
|
+
if (kwarr in parent) {
|
|
2450
|
+
parent[kwarr].push(data2);
|
|
2451
|
+
} else if (kw in parent) {
|
|
2452
|
+
parent[kwarr] = [parent[kw], data2];
|
|
2453
|
+
delete parent[kw];
|
|
2454
|
+
} else {
|
|
2455
|
+
parent[kw] = data2;
|
|
828
2456
|
}
|
|
829
|
-
return
|
|
2457
|
+
return parent;
|
|
830
2458
|
}
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
const endPolygonIndex = polygonIndices[i + 1];
|
|
835
|
-
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
836
|
-
coordinates.push(polygonCoordinates);
|
|
2459
|
+
const result = process(data, [data]);
|
|
2460
|
+
if (options == null ? void 0 : options.debug) {
|
|
2461
|
+
console.log("[wktcrs] parse returning", result);
|
|
837
2462
|
}
|
|
838
|
-
|
|
2463
|
+
if (options == null ? void 0 : options.sort) {
|
|
2464
|
+
sort(result, options);
|
|
2465
|
+
}
|
|
2466
|
+
return result;
|
|
839
2467
|
}
|
|
840
|
-
function
|
|
841
|
-
const
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
2468
|
+
function sort(data, options) {
|
|
2469
|
+
const keys = Object.keys(data).filter((k) => !/\d+/.test(k));
|
|
2470
|
+
const keywords = (options == null ? void 0 : options.keywords) || [];
|
|
2471
|
+
if (!(options == null ? void 0 : options.keywords)) {
|
|
2472
|
+
const counts = {};
|
|
2473
|
+
if (Array.isArray(data)) {
|
|
2474
|
+
data.forEach((it) => {
|
|
2475
|
+
if (Array.isArray(it) && it.length >= 2 && typeof it[1] === "string") {
|
|
2476
|
+
const k = it[0];
|
|
2477
|
+
if (!counts[k])
|
|
2478
|
+
counts[k] = 0;
|
|
2479
|
+
counts[k]++;
|
|
2480
|
+
}
|
|
2481
|
+
});
|
|
2482
|
+
for (const k in counts) {
|
|
2483
|
+
if (counts[k] > 0)
|
|
2484
|
+
keywords.push(k);
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
847
2487
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
2488
|
+
keys.forEach((key) => {
|
|
2489
|
+
data[key] = sort(data[key]);
|
|
2490
|
+
});
|
|
2491
|
+
keywords.forEach((key) => {
|
|
2492
|
+
const indices = [];
|
|
2493
|
+
const params = [];
|
|
2494
|
+
data.forEach((item, i) => {
|
|
2495
|
+
if (Array.isArray(item) && item[0] === key) {
|
|
2496
|
+
indices.push(i);
|
|
2497
|
+
params.push(item);
|
|
2498
|
+
}
|
|
2499
|
+
});
|
|
2500
|
+
params.sort((a, b) => {
|
|
2501
|
+
a = a[1].toString();
|
|
2502
|
+
b = b[1].toString();
|
|
2503
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
2504
|
+
});
|
|
2505
|
+
params.forEach((param, i) => {
|
|
2506
|
+
data[indices[i]] = param;
|
|
2507
|
+
});
|
|
2508
|
+
});
|
|
2509
|
+
return data;
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
// dist/lib/wkt-crs/encode-wkt-crs.js
|
|
2513
|
+
function encodeWKTCRS(wkt, options) {
|
|
2514
|
+
if (Array.isArray(wkt) && wkt.length === 1 && Array.isArray(wkt[0])) {
|
|
2515
|
+
wkt = wkt[0];
|
|
852
2516
|
}
|
|
853
|
-
|
|
2517
|
+
const [kw, ...attrs] = wkt;
|
|
2518
|
+
const str = `${kw}[${attrs.map((attr) => {
|
|
2519
|
+
if (Array.isArray(attr)) {
|
|
2520
|
+
return encodeWKTCRS(attr, options);
|
|
2521
|
+
} else if (typeof attr === "number") {
|
|
2522
|
+
return attr.toString();
|
|
2523
|
+
} else if (typeof attr === "string") {
|
|
2524
|
+
if (attr.startsWith("raw:")) {
|
|
2525
|
+
return attr.replace("raw:", "");
|
|
2526
|
+
}
|
|
2527
|
+
return `"${attr}"`;
|
|
2528
|
+
}
|
|
2529
|
+
throw new Error(`[wktcrs] unexpected attribute "${attr}"`);
|
|
2530
|
+
}).join(",")}]`;
|
|
2531
|
+
return str;
|
|
854
2532
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
2533
|
+
|
|
2534
|
+
// dist/lib/feature-collection-converters/convert-geoarrow-to-binary-features.js
|
|
2535
|
+
var import_polygon3 = require("@math.gl/polygon");
|
|
2536
|
+
var import_geoarrow3 = require("@loaders.gl/geoarrow");
|
|
2537
|
+
var BinaryGeometryType;
|
|
2538
|
+
(function(BinaryGeometryType2) {
|
|
2539
|
+
BinaryGeometryType2["points"] = "points";
|
|
2540
|
+
BinaryGeometryType2["lines"] = "lines";
|
|
2541
|
+
BinaryGeometryType2["polygons"] = "polygons";
|
|
2542
|
+
})(BinaryGeometryType || (BinaryGeometryType = {}));
|
|
2543
|
+
function convertGeoArrowToBinaryFeatureCollection(geoColumn, geoEncoding, options) {
|
|
2544
|
+
const featureTypes = {
|
|
2545
|
+
polygon: geoEncoding === "geoarrow.multipolygon" || geoEncoding === "geoarrow.polygon",
|
|
2546
|
+
point: geoEncoding === "geoarrow.multipoint" || geoEncoding === "geoarrow.point",
|
|
2547
|
+
line: geoEncoding === "geoarrow.multilinestring" || geoEncoding === "geoarrow.linestring"
|
|
2548
|
+
};
|
|
2549
|
+
const chunks = (options == null ? void 0 : options.chunkIndex) !== void 0 && (options == null ? void 0 : options.chunkIndex) >= 0 ? [geoColumn.data[options == null ? void 0 : options.chunkIndex]] : geoColumn.data;
|
|
2550
|
+
let bounds = [Infinity, Infinity, -Infinity, -Infinity];
|
|
2551
|
+
let globalFeatureIdOffset = (options == null ? void 0 : options.chunkOffset) || 0;
|
|
2552
|
+
const binaryGeometries = [];
|
|
2553
|
+
chunks.forEach((chunk) => {
|
|
2554
|
+
const { featureIds, flatCoordinateArray, nDim, geomOffset, triangles } = getBinaryGeometriesFromChunk(chunk, geoEncoding, options);
|
|
2555
|
+
const globalFeatureIds = new Uint32Array(featureIds.length);
|
|
2556
|
+
for (let i = 0; i < featureIds.length; i++) {
|
|
2557
|
+
globalFeatureIds[i] = featureIds[i] + globalFeatureIdOffset;
|
|
2558
|
+
}
|
|
2559
|
+
const binaryContent = {
|
|
2560
|
+
globalFeatureIds: { value: globalFeatureIds, size: 1 },
|
|
2561
|
+
positions: {
|
|
2562
|
+
value: flatCoordinateArray,
|
|
2563
|
+
size: nDim
|
|
2564
|
+
},
|
|
2565
|
+
featureIds: { value: featureIds, size: 1 },
|
|
2566
|
+
// eslint-disable-next-line no-loop-func
|
|
2567
|
+
properties: [...Array(chunk.length).keys()].map((i) => ({
|
|
2568
|
+
index: i + globalFeatureIdOffset
|
|
2569
|
+
}))
|
|
2570
|
+
};
|
|
2571
|
+
globalFeatureIdOffset += chunk.length;
|
|
2572
|
+
binaryGeometries.push({
|
|
2573
|
+
shape: "binary-feature-collection",
|
|
2574
|
+
points: {
|
|
2575
|
+
type: "Point",
|
|
2576
|
+
...getBinaryGeometryTemplate(),
|
|
2577
|
+
...featureTypes.point ? binaryContent : {}
|
|
2578
|
+
},
|
|
2579
|
+
lines: {
|
|
2580
|
+
type: "LineString",
|
|
2581
|
+
...getBinaryGeometryTemplate(),
|
|
2582
|
+
...featureTypes.line ? binaryContent : {},
|
|
2583
|
+
pathIndices: { value: featureTypes.line ? geomOffset : new Uint16Array(0), size: 1 }
|
|
2584
|
+
},
|
|
2585
|
+
polygons: {
|
|
2586
|
+
type: "Polygon",
|
|
2587
|
+
...getBinaryGeometryTemplate(),
|
|
2588
|
+
...featureTypes.polygon ? binaryContent : {},
|
|
2589
|
+
polygonIndices: {
|
|
2590
|
+
// use geomOffset as polygonIndices same as primitivePolygonIndices since we are using earcut to get triangule indices
|
|
2591
|
+
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
2592
|
+
size: 1
|
|
2593
|
+
},
|
|
2594
|
+
primitivePolygonIndices: {
|
|
2595
|
+
value: featureTypes.polygon ? geomOffset : new Uint16Array(0),
|
|
2596
|
+
size: 1
|
|
2597
|
+
},
|
|
2598
|
+
...triangles ? { triangles: { value: triangles, size: 1 } } : {}
|
|
2599
|
+
}
|
|
2600
|
+
});
|
|
2601
|
+
bounds = (0, import_geoarrow3.updateBoundsFromGeoArrowSamples)(flatCoordinateArray, nDim, bounds);
|
|
2602
|
+
});
|
|
2603
|
+
return {
|
|
2604
|
+
binaryGeometries,
|
|
2605
|
+
bounds,
|
|
2606
|
+
featureTypes,
|
|
2607
|
+
...(options == null ? void 0 : options.calculateMeanCenters) ? { meanCenters: getMeanCentersFromBinaryGeometries(binaryGeometries) } : {}
|
|
2608
|
+
};
|
|
2609
|
+
}
|
|
2610
|
+
function getBinaryGeometryTemplate() {
|
|
2611
|
+
return {
|
|
2612
|
+
globalFeatureIds: { value: new Uint32Array(0), size: 1 },
|
|
2613
|
+
positions: { value: new Float32Array(0), size: 2 },
|
|
2614
|
+
properties: [],
|
|
2615
|
+
numericProps: {},
|
|
2616
|
+
featureIds: { value: new Uint32Array(0), size: 1 }
|
|
2617
|
+
};
|
|
2618
|
+
}
|
|
2619
|
+
function getMeanCentersFromBinaryGeometries(binaryGeometries) {
|
|
2620
|
+
const globalMeanCenters = [];
|
|
2621
|
+
binaryGeometries.forEach((binaryGeometry) => {
|
|
2622
|
+
var _a;
|
|
2623
|
+
let binaryGeometryType = null;
|
|
2624
|
+
if (binaryGeometry.points && binaryGeometry.points.positions.value.length > 0) {
|
|
2625
|
+
binaryGeometryType = BinaryGeometryType.points;
|
|
2626
|
+
} else if (binaryGeometry.lines && binaryGeometry.lines.positions.value.length > 0) {
|
|
2627
|
+
binaryGeometryType = BinaryGeometryType.lines;
|
|
2628
|
+
} else if (binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0) {
|
|
2629
|
+
binaryGeometryType = BinaryGeometryType.polygons;
|
|
2630
|
+
}
|
|
2631
|
+
const binaryContent = binaryGeometryType ? binaryGeometry[binaryGeometryType] : null;
|
|
2632
|
+
if (binaryContent && binaryGeometryType !== null) {
|
|
2633
|
+
const featureIds = binaryContent.featureIds.value;
|
|
2634
|
+
const flatCoordinateArray = binaryContent.positions.value;
|
|
2635
|
+
const nDim = binaryContent.positions.size;
|
|
2636
|
+
const primitivePolygonIndices = binaryContent.type === "Polygon" ? (_a = binaryContent.primitivePolygonIndices) == null ? void 0 : _a.value : void 0;
|
|
2637
|
+
const meanCenters = getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, binaryGeometryType, primitivePolygonIndices);
|
|
2638
|
+
meanCenters.forEach((center) => {
|
|
2639
|
+
globalMeanCenters.push(center);
|
|
2640
|
+
});
|
|
2641
|
+
}
|
|
2642
|
+
});
|
|
2643
|
+
return globalMeanCenters;
|
|
2644
|
+
}
|
|
2645
|
+
function getMeanCentersFromGeometry(featureIds, flatCoordinateArray, nDim, geometryType, primitivePolygonIndices) {
|
|
2646
|
+
const meanCenters = [];
|
|
2647
|
+
const vertexCount = flatCoordinateArray.length;
|
|
2648
|
+
let vertexIndex = 0;
|
|
2649
|
+
let coordIdx = 0;
|
|
2650
|
+
let primitiveIdx = 0;
|
|
2651
|
+
while (vertexIndex < vertexCount) {
|
|
2652
|
+
const featureId = featureIds[vertexIndex / nDim];
|
|
2653
|
+
const center = [0, 0];
|
|
2654
|
+
let vertexCountInFeature = 0;
|
|
2655
|
+
while (vertexIndex < vertexCount && featureIds[coordIdx] === featureId) {
|
|
2656
|
+
if (geometryType === BinaryGeometryType.polygons && (primitivePolygonIndices == null ? void 0 : primitivePolygonIndices[primitiveIdx]) === coordIdx) {
|
|
2657
|
+
vertexIndex += nDim;
|
|
2658
|
+
primitiveIdx++;
|
|
2659
|
+
} else {
|
|
2660
|
+
center[0] += flatCoordinateArray[vertexIndex];
|
|
2661
|
+
center[1] += flatCoordinateArray[vertexIndex + 1];
|
|
2662
|
+
vertexIndex += nDim;
|
|
2663
|
+
vertexCountInFeature++;
|
|
2664
|
+
}
|
|
2665
|
+
coordIdx += 1;
|
|
2666
|
+
}
|
|
2667
|
+
center[0] /= vertexCountInFeature;
|
|
2668
|
+
center[1] /= vertexCountInFeature;
|
|
2669
|
+
meanCenters.push(center);
|
|
861
2670
|
}
|
|
862
|
-
return
|
|
2671
|
+
return meanCenters;
|
|
863
2672
|
}
|
|
864
|
-
function
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
2673
|
+
function getBinaryGeometriesFromChunk(chunk, geoEncoding, options) {
|
|
2674
|
+
switch (geoEncoding) {
|
|
2675
|
+
case "geoarrow.point":
|
|
2676
|
+
case "geoarrow.multipoint":
|
|
2677
|
+
return getBinaryPointsFromChunk(chunk, geoEncoding);
|
|
2678
|
+
case "geoarrow.linestring":
|
|
2679
|
+
case "geoarrow.multilinestring":
|
|
2680
|
+
return getBinaryLinesFromChunk(chunk, geoEncoding);
|
|
2681
|
+
case "geoarrow.polygon":
|
|
2682
|
+
case "geoarrow.multipolygon":
|
|
2683
|
+
return getBinaryPolygonsFromChunk(chunk, geoEncoding, options);
|
|
2684
|
+
default:
|
|
2685
|
+
throw Error("invalid geoarrow encoding");
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
function getTriangleIndices(polygonIndices, primitivePolygonIndices, flatCoordinateArray, nDim) {
|
|
2689
|
+
try {
|
|
2690
|
+
let primitiveIndex = 0;
|
|
2691
|
+
const triangles = [];
|
|
2692
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
2693
|
+
const startIdx = polygonIndices[i];
|
|
2694
|
+
const endIdx = polygonIndices[i + 1];
|
|
2695
|
+
const slicedFlatCoords = flatCoordinateArray.subarray(startIdx * nDim, endIdx * nDim);
|
|
2696
|
+
const holeIndices = [];
|
|
2697
|
+
while (primitivePolygonIndices[primitiveIndex] < endIdx) {
|
|
2698
|
+
if (primitivePolygonIndices[primitiveIndex] > startIdx) {
|
|
2699
|
+
holeIndices.push(primitivePolygonIndices[primitiveIndex] - startIdx);
|
|
2700
|
+
}
|
|
2701
|
+
primitiveIndex++;
|
|
2702
|
+
}
|
|
2703
|
+
const triangleIndices = (0, import_polygon3.earcut)(slicedFlatCoords, holeIndices.length > 0 ? holeIndices : void 0, nDim);
|
|
2704
|
+
if (triangleIndices.length === 0) {
|
|
2705
|
+
throw Error("earcut failed e.g. invalid polygon");
|
|
2706
|
+
}
|
|
2707
|
+
for (let j = 0; j < triangleIndices.length; j++) {
|
|
2708
|
+
triangles.push(triangleIndices[j] + startIdx);
|
|
2709
|
+
}
|
|
872
2710
|
}
|
|
873
|
-
|
|
2711
|
+
const trianglesUint32 = new Uint32Array(triangles.length);
|
|
2712
|
+
for (let i = 0; i < triangles.length; i++) {
|
|
2713
|
+
trianglesUint32[i] = triangles[i];
|
|
2714
|
+
}
|
|
2715
|
+
return trianglesUint32;
|
|
2716
|
+
} catch (error) {
|
|
2717
|
+
return null;
|
|
874
2718
|
}
|
|
875
|
-
return ringCoordinates;
|
|
876
2719
|
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
2720
|
+
function getBinaryPolygonsFromChunk(chunk, geoEncoding, options) {
|
|
2721
|
+
const isMultiPolygon = geoEncoding === "geoarrow.multipolygon";
|
|
2722
|
+
const polygonData = isMultiPolygon ? chunk.children[0] : chunk;
|
|
2723
|
+
const polygonOffset = polygonData.valueOffsets;
|
|
2724
|
+
const partData = isMultiPolygon ? chunk.valueOffsets.map((i) => polygonOffset.at(i) || i) : chunk.valueOffsets;
|
|
2725
|
+
const ringData = polygonData.children[0];
|
|
2726
|
+
const pointData = ringData.children[0];
|
|
2727
|
+
const coordData = pointData.children[0];
|
|
2728
|
+
const nDim = pointData.stride;
|
|
2729
|
+
const geomOffset = ringData.valueOffsets;
|
|
2730
|
+
const flatCoordinateArray = coordData.values;
|
|
2731
|
+
const geometryIndexes = new Uint16Array(polygonOffset.length);
|
|
2732
|
+
for (let i = 0; i < polygonOffset.length; i++) {
|
|
2733
|
+
geometryIndexes[i] = geomOffset[polygonOffset[i]];
|
|
882
2734
|
}
|
|
883
|
-
|
|
884
|
-
|
|
2735
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
2736
|
+
const featureIds = new Uint32Array(numOfVertices);
|
|
2737
|
+
for (let i = 0; i < partData.length - 1; i++) {
|
|
2738
|
+
const startIdx = geomOffset[partData[i]];
|
|
2739
|
+
const endIdx = geomOffset[partData[i + 1]];
|
|
2740
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
2741
|
+
featureIds[j] = i;
|
|
2742
|
+
}
|
|
885
2743
|
}
|
|
886
|
-
|
|
887
|
-
|
|
2744
|
+
const triangles = (options == null ? void 0 : options.triangulate) ? getTriangleIndices(geometryIndexes, geomOffset, flatCoordinateArray, nDim) : null;
|
|
2745
|
+
return {
|
|
2746
|
+
featureIds,
|
|
2747
|
+
nDim,
|
|
2748
|
+
flatCoordinateArray,
|
|
2749
|
+
geomOffset,
|
|
2750
|
+
geometryIndexes,
|
|
2751
|
+
...(options == null ? void 0 : options.triangulate) && triangles ? { triangles } : {}
|
|
2752
|
+
};
|
|
2753
|
+
}
|
|
2754
|
+
function getBinaryLinesFromChunk(chunk, geoEncoding) {
|
|
2755
|
+
const isMultiLineString = geoEncoding === "geoarrow.multilinestring";
|
|
2756
|
+
const lineData = isMultiLineString ? chunk.children[0] : chunk;
|
|
2757
|
+
const pointData = lineData.children[0];
|
|
2758
|
+
const coordData = pointData.children[0];
|
|
2759
|
+
const nDim = pointData.stride;
|
|
2760
|
+
const geomOffset = lineData.valueOffsets;
|
|
2761
|
+
const flatCoordinateArray = coordData.values;
|
|
2762
|
+
const geometryIndexes = new Uint16Array(0);
|
|
2763
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
2764
|
+
const featureIds = new Uint32Array(numOfVertices);
|
|
2765
|
+
if (isMultiLineString) {
|
|
2766
|
+
const partData = chunk.valueOffsets;
|
|
2767
|
+
for (let i = 0; i < partData.length - 1; i++) {
|
|
2768
|
+
const startIdx = geomOffset[partData[i]];
|
|
2769
|
+
const endIdx = geomOffset[partData[i + 1]];
|
|
2770
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
2771
|
+
featureIds[j] = i;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
} else {
|
|
2775
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
2776
|
+
const startIdx = geomOffset[i];
|
|
2777
|
+
const endIdx = geomOffset[i + 1];
|
|
2778
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
2779
|
+
featureIds[j] = i;
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
888
2782
|
}
|
|
889
|
-
return
|
|
2783
|
+
return {
|
|
2784
|
+
featureIds,
|
|
2785
|
+
flatCoordinateArray,
|
|
2786
|
+
nDim,
|
|
2787
|
+
geomOffset,
|
|
2788
|
+
geometryIndexes
|
|
2789
|
+
};
|
|
890
2790
|
}
|
|
891
|
-
function
|
|
892
|
-
const
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
2791
|
+
function getBinaryPointsFromChunk(chunk, geoEncoding) {
|
|
2792
|
+
const isMultiPoint = geoEncoding === "geoarrow.multipoint";
|
|
2793
|
+
const pointData = isMultiPoint ? chunk.children[0] : chunk;
|
|
2794
|
+
const coordData = pointData.children[0];
|
|
2795
|
+
const nDim = pointData.stride;
|
|
2796
|
+
const flatCoordinateArray = coordData.values;
|
|
2797
|
+
const geometryIndexes = new Uint16Array(0);
|
|
2798
|
+
const geomOffset = new Int32Array(0);
|
|
2799
|
+
const numOfVertices = flatCoordinateArray.length / nDim;
|
|
2800
|
+
const featureIds = new Uint32Array(numOfVertices);
|
|
2801
|
+
if (isMultiPoint) {
|
|
2802
|
+
const partData = chunk.valueOffsets;
|
|
2803
|
+
for (let i = 0; i < partData.length - 1; i++) {
|
|
2804
|
+
const startIdx = partData[i];
|
|
2805
|
+
const endIdx = partData[i + 1];
|
|
2806
|
+
for (let j = startIdx; j < endIdx; j++) {
|
|
2807
|
+
featureIds[j] = i;
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
} else {
|
|
2811
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
2812
|
+
featureIds[i] = i;
|
|
2813
|
+
}
|
|
897
2814
|
}
|
|
2815
|
+
return {
|
|
2816
|
+
featureIds,
|
|
2817
|
+
flatCoordinateArray,
|
|
2818
|
+
nDim,
|
|
2819
|
+
geomOffset,
|
|
2820
|
+
geometryIndexes
|
|
2821
|
+
};
|
|
898
2822
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
2823
|
+
|
|
2824
|
+
// dist/lib/utils/hex-transcoder.js
|
|
2825
|
+
var alphabet = "0123456789abcdef";
|
|
2826
|
+
var encodeLookup = [];
|
|
2827
|
+
var decodeLookup = [];
|
|
2828
|
+
for (let i = 0; i < 256; i++) {
|
|
2829
|
+
encodeLookup[i] = alphabet[i >> 4 & 15] + alphabet[i & 15];
|
|
2830
|
+
if (i < 16) {
|
|
2831
|
+
if (i < 10) {
|
|
2832
|
+
decodeLookup[48 + i] = i;
|
|
2833
|
+
} else {
|
|
2834
|
+
decodeLookup[97 - 10 + i] = i;
|
|
2835
|
+
}
|
|
902
2836
|
}
|
|
903
|
-
return features;
|
|
904
2837
|
}
|
|
905
|
-
function
|
|
906
|
-
|
|
907
|
-
|
|
2838
|
+
function encodeHex(array) {
|
|
2839
|
+
const length = array.length;
|
|
2840
|
+
let string = "";
|
|
2841
|
+
let i = 0;
|
|
2842
|
+
while (i < length) {
|
|
2843
|
+
string += encodeLookup[array[i++]];
|
|
908
2844
|
}
|
|
909
|
-
return
|
|
910
|
-
return coordMap(item, fn);
|
|
911
|
-
});
|
|
2845
|
+
return string;
|
|
912
2846
|
}
|
|
913
|
-
function
|
|
914
|
-
|
|
2847
|
+
function decodeHex(string) {
|
|
2848
|
+
const sizeof = string.length >> 1;
|
|
2849
|
+
const length = sizeof << 1;
|
|
2850
|
+
const array = new Uint8Array(sizeof);
|
|
2851
|
+
let n = 0;
|
|
2852
|
+
let i = 0;
|
|
2853
|
+
while (i < length) {
|
|
2854
|
+
array[n++] = decodeLookup[string.charCodeAt(i++)] << 4 | decodeLookup[string.charCodeAt(i++)];
|
|
2855
|
+
}
|
|
2856
|
+
return array;
|
|
915
2857
|
}
|
|
916
2858
|
//# sourceMappingURL=index.cjs.map
|