@loaders.gl/core 5.0.0-rc.2 → 5.0.0
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/arrow-geometry/geometry-codecs.cjs +51 -50
- package/dist/arrow-geometry/geometry-codecs.cjs.map +3 -3
- package/dist/arrow-geometry/geometry-codecs.d.ts +1 -1
- package/dist/arrow-geometry/geometry-codecs.d.ts.map +1 -1
- package/dist/arrow-geometry/geometry-codecs.js +27 -60
- package/dist/arrow-geometry/geometry-codecs.js.map +1 -1
- package/dist/arrow-geometry/triangulate-wkb.cjs +33 -118
- package/dist/arrow-geometry/triangulate-wkb.cjs.map +2 -2
- package/dist/arrow-geometry/triangulate-wkb.d.ts.map +1 -1
- package/dist/arrow-geometry/triangulate-wkb.js +39 -142
- package/dist/arrow-geometry/triangulate-wkb.js.map +1 -1
- package/dist/cluster-source.cjs +124 -370
- package/dist/cluster-source.cjs.map +3 -3
- package/dist/constants/index.cjs +2 -2
- package/dist/constants/index.d.ts +4 -4
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +2 -2
- package/dist/constants/index.js.map +1 -1
- package/dist/dist.dev.js +2 -2
- package/dist/dist.min.js +2 -2
- package/dist/federated-table-scan-source.cjs +166 -564
- package/dist/federated-table-scan-source.cjs.map +3 -3
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs +15 -0
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js +19 -1
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js.map +1 -1
- package/dist/geoarrow/get-geoarrow-vertex-count.cjs +6 -27
- package/dist/geoarrow/get-geoarrow-vertex-count.cjs.map +2 -2
- package/dist/geoarrow/get-geoarrow-vertex-count.d.ts.map +1 -1
- package/dist/geoarrow/get-geoarrow-vertex-count.js +9 -24
- package/dist/geoarrow/get-geoarrow-vertex-count.js.map +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs +3 -5
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs.map +2 -2
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts +2 -24
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts.map +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js +6 -28
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs +20 -226
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs.map +2 -2
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts +1 -2
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js +23 -264
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/init.js.map +1 -1
- package/dist/loader-utils/index.cjs +31 -217
- package/dist/loader-utils/index.cjs.map +2 -2
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/json-loader.js.map +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/columnar-predicate.d.ts +4 -52
- package/dist/loader-utils/lib/scan-utils/columnar-predicate.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/columnar-predicate.js +16 -236
- package/dist/loader-utils/lib/scan-utils/columnar-predicate.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/relational-query.d.ts +2 -0
- package/dist/loader-utils/lib/scan-utils/relational-query.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/relational-query.js.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-loader.js.map +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/dist/scan/arrow-execution/expressions.cjs +9 -78
- package/dist/scan/arrow-execution/expressions.cjs.map +3 -3
- package/dist/scan/arrow-execution/expressions.d.ts +2 -8
- package/dist/scan/arrow-execution/expressions.d.ts.map +1 -1
- package/dist/scan/arrow-execution/expressions.js +2 -55
- package/dist/scan/arrow-execution/expressions.js.map +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.cjs +41 -179
- package/dist/scan/arrow-execution/filter-arrow-table.cjs.map +3 -3
- package/dist/scan/arrow-execution/filter-arrow-table.d.ts +1 -5
- package/dist/scan/arrow-execution/filter-arrow-table.d.ts.map +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.js +44 -190
- package/dist/scan/arrow-execution/filter-arrow-table.js.map +1 -1
- package/dist/scan/arrow-execution.cjs +2 -2
- package/dist/scan/arrow-execution.cjs.map +2 -2
- package/dist/scan/arrow-execution.d.ts +1 -1
- package/dist/scan/arrow-execution.d.ts.map +1 -1
- package/dist/scan/arrow-execution.js +1 -1
- package/dist/scan/arrow-execution.js.map +1 -1
- package/dist/scan/arrow-query.cjs +3 -3
- package/dist/scan/arrow-query.cjs.map +2 -2
- package/dist/scan/arrow-query.d.ts +2 -2
- package/dist/scan/arrow-query.d.ts.map +1 -1
- package/dist/scan/arrow-query.js +2 -2
- package/dist/scan/arrow-query.js.map +1 -1
- package/dist/scan/federated-table-scan-source.cjs +3 -3
- package/dist/scan/federated-table-scan-source.cjs.map +2 -2
- package/dist/scan/federated-table-scan-source.js +1 -1
- package/dist/scan/federated-table-scan-source.js.map +1 -1
- package/dist/scan/index.cjs +9 -49
- package/dist/scan/index.cjs.map +3 -3
- package/dist/scan/index.d.ts +2 -2
- package/dist/scan/index.d.ts.map +1 -1
- package/dist/scan/index.js +2 -2
- package/dist/scan/index.js.map +1 -1
- package/dist/scan/plan-arrow-table-query.cjs +271 -0
- package/dist/scan/plan-arrow-table-query.cjs.map +7 -0
- package/dist/scan/plan-arrow-table-query.d.ts +50 -0
- package/dist/scan/plan-arrow-table-query.d.ts.map +1 -0
- package/dist/scan/plan-arrow-table-query.js +257 -0
- package/dist/scan/plan-arrow-table-query.js.map +1 -0
- package/dist/scan/query-arrow-table-in-batches.cjs +2 -39
- package/dist/scan/query-arrow-table-in-batches.cjs.map +2 -2
- package/dist/scan/query-arrow-table-in-batches.d.ts +1 -1
- package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -1
- package/dist/scan/query-arrow-table-in-batches.js +3 -26
- package/dist/scan/query-arrow-table-in-batches.js.map +1 -1
- package/dist/scan/query-arrow-table.cjs +7 -443
- package/dist/scan/query-arrow-table.cjs.map +3 -3
- package/dist/scan/query-arrow-table.d.ts +6 -54
- package/dist/scan/query-arrow-table.d.ts.map +1 -1
- package/dist/scan/query-arrow-table.js +6 -475
- package/dist/scan/query-arrow-table.js.map +1 -1
- package/dist/scan/query-pushdown.cjs +3 -4
- package/dist/scan/query-pushdown.cjs.map +2 -2
- package/dist/scan/query-pushdown.js +4 -5
- package/dist/scan/query-pushdown.js.map +1 -1
- package/dist/scan/query.cjs +10 -9
- package/dist/scan/query.cjs.map +2 -2
- package/dist/scan/query.d.ts.map +1 -1
- package/dist/scan/query.js +14 -5
- package/dist/scan/query.js.map +1 -1
- package/dist/scan/scan-engine.cjs +14 -7
- package/dist/scan/scan-engine.cjs.map +2 -2
- package/dist/scan/scan-engine.d.ts +1 -1
- package/dist/scan/scan-engine.d.ts.map +1 -1
- package/dist/scan/scan-engine.js +4 -9
- package/dist/scan/scan-engine.js.map +1 -1
- package/dist/scan/vector-table-scan-source.cjs +14 -3
- package/dist/scan/vector-table-scan-source.cjs.map +2 -2
- package/dist/scan/vector-table-scan-source.d.ts +1 -1
- package/dist/scan/vector-table-scan-source.d.ts.map +1 -1
- package/dist/scan/vector-table-scan-source.js +2 -1
- package/dist/scan/vector-table-scan-source.js.map +1 -1
- package/dist/schema-utils/index.cjs +11 -47
- package/dist/schema-utils/index.cjs.map +1 -1
- package/dist/schema-utils/lib/arrow/arrow-metadata.d.ts +2 -4
- package/dist/schema-utils/lib/arrow/arrow-metadata.d.ts.map +1 -1
- package/dist/schema-utils/lib/arrow/arrow-metadata.js +2 -43
- package/dist/schema-utils/lib/arrow/arrow-metadata.js.map +1 -1
- package/dist/vector-table-scan-source.cjs +854 -1314
- package/dist/vector-table-scan-source.cjs.map +3 -3
- package/dist/wkt/twkb/index.cjs +68 -5
- package/dist/wkt/twkb/index.cjs.map +3 -3
- package/dist/wkt/twkb/index.d.ts +10 -2
- package/dist/wkt/twkb/index.d.ts.map +1 -1
- package/dist/wkt/twkb/index.js +49 -2
- package/dist/wkt/twkb/index.js.map +1 -1
- package/dist/worker-utils/index.cjs +4 -4
- package/dist/worker-utils/index.cjs.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/env-utils/version.js.map +1 -1
- package/package.json +7 -7
- package/src/arrow-geometry/geometry-codecs.ts +35 -78
- package/src/arrow-geometry/triangulate-wkb.ts +37 -169
- package/src/constants/index.ts +2 -2
- package/src/geoarrow/geoarrow-converter/convert-geoarrow-geometry.ts +22 -1
- package/src/geoarrow/get-geoarrow-vertex-count.ts +7 -32
- package/src/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +6 -30
- package/src/geoarrow/lib/kernels/decode-wkt-native.ts +23 -269
- package/src/loader-utils/lib/scan-utils/columnar-predicate.ts +46 -363
- package/src/loader-utils/lib/scan-utils/relational-query.ts +7 -1
- package/src/scan/arrow-execution/expressions.ts +2 -86
- package/src/scan/arrow-execution/filter-arrow-table.ts +54 -238
- package/src/scan/arrow-execution.ts +1 -1
- package/src/scan/arrow-query.ts +2 -2
- package/src/scan/federated-table-scan-source.ts +1 -1
- package/src/scan/index.ts +2 -2
- package/src/scan/plan-arrow-table-query.ts +367 -0
- package/src/scan/query-arrow-table-in-batches.ts +4 -33
- package/src/scan/query-arrow-table.ts +10 -626
- package/src/scan/query-pushdown.ts +3 -4
- package/src/scan/query.ts +16 -10
- package/src/scan/scan-engine.ts +4 -11
- package/src/scan/vector-table-scan-source.ts +2 -1
- package/src/schema-utils/lib/arrow/arrow-metadata.ts +2 -50
- package/src/wkt/twkb/index.ts +63 -2
- package/dist/scan/arrow-execution/portable-predicate-compatibility.cjs +0 -41
- package/dist/scan/arrow-execution/portable-predicate-compatibility.cjs.map +0 -7
- package/dist/scan/arrow-execution/portable-predicate-compatibility.d.ts +0 -5
- package/dist/scan/arrow-execution/portable-predicate-compatibility.d.ts.map +0 -1
- package/dist/scan/arrow-execution/portable-predicate-compatibility.js +0 -23
- package/dist/scan/arrow-execution/portable-predicate-compatibility.js.map +0 -1
- package/dist/scan/arrow-execution/project-arrow-table.cjs +0 -70
- package/dist/scan/arrow-execution/project-arrow-table.cjs.map +0 -7
- package/dist/scan/arrow-execution/project-arrow-table.d.ts +0 -8
- package/dist/scan/arrow-execution/project-arrow-table.d.ts.map +0 -1
- package/dist/scan/arrow-execution/project-arrow-table.js +0 -39
- package/dist/scan/arrow-execution/project-arrow-table.js.map +0 -1
- package/dist/scan/query-arrow-table-math.cjs +0 -41
- package/dist/scan/query-arrow-table-math.cjs.map +0 -7
- package/dist/scan/query-arrow-table-math.d.ts +0 -5
- package/dist/scan/query-arrow-table-math.d.ts.map +0 -1
- package/dist/scan/query-arrow-table-math.js +0 -14
- package/dist/scan/query-arrow-table-math.js.map +0 -1
- package/dist/wkt/twkb/convert-geometry-to-twkb.cjs +0 -211
- package/dist/wkt/twkb/convert-geometry-to-twkb.cjs.map +0 -7
- package/dist/wkt/twkb/convert-geometry-to-twkb.d.ts +0 -6
- package/dist/wkt/twkb/convert-geometry-to-twkb.d.ts.map +0 -1
- package/dist/wkt/twkb/convert-geometry-to-twkb.js +0 -204
- package/dist/wkt/twkb/convert-geometry-to-twkb.js.map +0 -1
- package/dist/wkt/twkb/convert-twkb-to-geometry.cjs +0 -251
- package/dist/wkt/twkb/convert-twkb-to-geometry.cjs.map +0 -7
- package/dist/wkt/twkb/convert-twkb-to-geometry.d.ts +0 -10
- package/dist/wkt/twkb/convert-twkb-to-geometry.d.ts.map +0 -1
- package/dist/wkt/twkb/convert-twkb-to-geometry.js +0 -261
- package/dist/wkt/twkb/convert-twkb-to-geometry.js.map +0 -1
- package/dist/wkt/twkb/twkb-io.cjs +0 -102
- package/dist/wkt/twkb/twkb-io.cjs.map +0 -7
- package/dist/wkt/twkb/twkb-io.d.ts +0 -33
- package/dist/wkt/twkb/twkb-io.d.ts.map +0 -1
- package/dist/wkt/twkb/twkb-io.js +0 -78
- package/dist/wkt/twkb/twkb-io.js.map +0 -1
- package/dist/wkt/twkb/twkb-types.cjs +0 -40
- package/dist/wkt/twkb/twkb-types.cjs.map +0 -7
- package/dist/wkt/twkb/twkb-types.d.ts +0 -11
- package/dist/wkt/twkb/twkb-types.d.ts.map +0 -1
- package/dist/wkt/twkb/twkb-types.js +0 -15
- package/dist/wkt/twkb/twkb-types.js.map +0 -1
- package/src/scan/arrow-execution/portable-predicate-compatibility.ts +0 -27
- package/src/scan/arrow-execution/project-arrow-table.ts +0 -53
- package/src/scan/query-arrow-table-math.ts +0 -23
- package/src/wkt/twkb/convert-geometry-to-twkb.ts +0 -317
- package/src/wkt/twkb/convert-twkb-to-geometry.ts +0 -373
- package/src/wkt/twkb/twkb-io.ts +0 -85
- package/src/wkt/twkb/twkb-types.ts +0 -14
|
@@ -28,63 +28,74 @@ __export(geometry_codecs_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(geometry_codecs_exports);
|
|
30
30
|
var import_arrow = require("@math.gl/core/arrow");
|
|
31
|
+
|
|
32
|
+
// src/loader-utils/lib/javascript-utils/is-type.ts
|
|
33
|
+
var isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
|
|
34
|
+
|
|
35
|
+
// src/loader-utils/lib/binary-utils/memory-conversion-utils.ts
|
|
36
|
+
function ensureArrayBuffer(bufferSource) {
|
|
37
|
+
if (bufferSource instanceof ArrayBuffer) {
|
|
38
|
+
return bufferSource;
|
|
39
|
+
}
|
|
40
|
+
if (isSharedArrayBuffer(bufferSource)) {
|
|
41
|
+
return copyToArrayBuffer(bufferSource);
|
|
42
|
+
}
|
|
43
|
+
const { buffer, byteOffset, byteLength } = bufferSource;
|
|
44
|
+
if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
|
|
45
|
+
return buffer;
|
|
46
|
+
}
|
|
47
|
+
return copyToArrayBuffer(buffer, byteOffset, byteLength);
|
|
48
|
+
}
|
|
49
|
+
function copyToArrayBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
50
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
51
|
+
const copy = new Uint8Array(view.length);
|
|
52
|
+
copy.set(view);
|
|
53
|
+
return copy.buffer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/arrow-geometry/geometry-codecs.ts
|
|
31
57
|
var import_geometry_utils = require("./geometry-utils.cjs");
|
|
32
58
|
var import_geometry_to_wkt = require("./geometry-to-wkt.cjs");
|
|
33
59
|
function convertWKBToGeometry(input) {
|
|
34
60
|
const bytes = ArrayBuffer.isView(input) ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength) : new Uint8Array(input);
|
|
35
|
-
return (0,
|
|
61
|
+
return (0, import_arrow.parseWKB)(bytes, { normalizeEmptyPoints: true }).geometry;
|
|
36
62
|
}
|
|
37
63
|
function convertGeometryToWKB(input, options = {}) {
|
|
38
64
|
const geometry = input.type === "Feature" ? input.geometry : input;
|
|
39
65
|
if (!geometry) throw new Error("WKB writer does not support null feature geometry");
|
|
40
66
|
const dimension = options.hasZ ? options.hasM ? "xyzm" : "xyz" : options.hasM ? "xym" : "xy";
|
|
41
|
-
const bytes =
|
|
42
|
-
return bytes
|
|
67
|
+
const bytes = (0, import_arrow.writeWKB)(describeGeometry(geometry, dimension));
|
|
68
|
+
return ensureArrayBuffer(bytes);
|
|
43
69
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
headerBuilder.beginGeometry("GeometryCollection", children.length);
|
|
56
|
-
const headerLength = headerBuilder.finishGeometry();
|
|
57
|
-
const bytes = new Uint8Array(
|
|
58
|
-
headerLength + children.reduce((total, child) => total + child.length, 0)
|
|
59
|
-
);
|
|
60
|
-
const writer = new import_arrow.WKBBuilder({ mode: "write", target: bytes, dimension });
|
|
61
|
-
writer.beginGeometry("GeometryCollection", children.length);
|
|
62
|
-
let byteOffset = writer.finishGeometry();
|
|
63
|
-
for (const child of children) {
|
|
64
|
-
bytes.set(child, byteOffset);
|
|
65
|
-
byteOffset += child.length;
|
|
66
|
-
}
|
|
67
|
-
return bytes;
|
|
70
|
+
function describeGeometry(geometry, dimension) {
|
|
71
|
+
return {
|
|
72
|
+
geometry,
|
|
73
|
+
dimension,
|
|
74
|
+
children: geometry.type === "GeometryCollection" ? geometry.geometries.map(
|
|
75
|
+
(child) => describeGeometry(
|
|
76
|
+
child,
|
|
77
|
+
child.__geoarrowDimension ?? dimension
|
|
78
|
+
)
|
|
79
|
+
) : void 0
|
|
80
|
+
};
|
|
68
81
|
}
|
|
69
82
|
function getWKTDimension(input) {
|
|
70
|
-
|
|
71
|
-
/^(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(ZM|Z|M))?(?:\s|\()/i
|
|
72
|
-
);
|
|
73
|
-
if (!match) return null;
|
|
74
|
-
return match[1]?.toUpperCase() === "Z" ? "xyz" : match[1]?.toUpperCase() === "M" ? "xym" : match[1]?.toUpperCase() === "ZM" ? "xyzm" : "xy";
|
|
83
|
+
return (0, import_arrow.inspectWKTHeader)(input)?.dimension ?? null;
|
|
75
84
|
}
|
|
76
85
|
function convertWKTToGeometry(input, options) {
|
|
77
|
-
const
|
|
86
|
+
const dimension = getWKTDimension(input);
|
|
78
87
|
try {
|
|
79
|
-
if (/\(\s*\)\s*$/s.test(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
if (/\(\s*\)\s*$/s.test(input)) return null;
|
|
89
|
+
const collectionHeader = /^(\s*(?:SRID\s*=\s*\d+\s*;\s*)?GEOMETRYCOLLECTION)\s+(?:ZM|Z|M)(?=\s|\()/i;
|
|
90
|
+
const parseText = dimension !== "xym" ? input.replace(collectionHeader, "$1") : input;
|
|
91
|
+
const parsed = (0, import_arrow.parseWKTWithMetadata)(parseText, {
|
|
92
|
+
inferDimensions: true,
|
|
93
|
+
allowMissingInheritedOrdinates: true
|
|
94
|
+
});
|
|
95
|
+
const { srid } = parsed;
|
|
85
96
|
const geometry = toGeometryWithDimensionMetadata(
|
|
86
97
|
parsed,
|
|
87
|
-
collectionHeader ? dimension : void 0
|
|
98
|
+
collectionHeader.test(input) ? dimension ?? void 0 : void 0
|
|
88
99
|
);
|
|
89
100
|
if (options?.wkt?.crs && srid !== void 0) {
|
|
90
101
|
Object.defineProperty(geometry, "crs", {
|
|
@@ -118,16 +129,6 @@ function addDimensionMarker(geometry, dimension) {
|
|
|
118
129
|
}
|
|
119
130
|
return geometry;
|
|
120
131
|
}
|
|
121
|
-
function splitWKTHeader(input) {
|
|
122
|
-
const sridMatch = input.match(/^\s*SRID=(\d+)\s*;\s*/i);
|
|
123
|
-
const text = sridMatch ? input.slice(sridMatch[0].length) : input;
|
|
124
|
-
const dimensionMatch = text.match(
|
|
125
|
-
/^\s*(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(ZM|Z|M))?(?:\s|\()/i
|
|
126
|
-
);
|
|
127
|
-
const dimensionToken = dimensionMatch?.[1]?.toUpperCase();
|
|
128
|
-
const dimension = dimensionToken === "Z" ? "xyz" : dimensionToken === "M" ? "xym" : dimensionToken === "ZM" ? "xyzm" : void 0;
|
|
129
|
-
return { text, srid: sridMatch?.[1], dimension };
|
|
130
|
-
}
|
|
131
132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
133
|
0 && (module.exports = {
|
|
133
134
|
convertGeometryToWKB,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/arrow-geometry/geometry-codecs.ts"],
|
|
4
|
-
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {parseWKB, parseWKTWithMetadata, writeWKB, WKBBuilder} from '@math.gl/core/arrow';\nimport type {WellKnownDimension, WellKnownGeometry, WKTParseResult} from '@math.gl/core/arrow';\nimport type {Feature, Geometry, GeoArrowDimension} from '@loaders.gl/core/schema';\nimport {normalizeEmptyPoints} from './geometry-utils';\nexport {convertGeometryToWKT} from './geometry-to-wkt';\nexport type {WKTGeometryOptions} from './geometry-to-wkt';\n\n/** Legacy options for a materialized WKT geometry. */\nexport type ParseWKTOptions = {\n /** WKT-specific output options. */\n wkt?: {\n /** Only materialized GeoJSON geometry is supported. */\n shape?: 'geojson-geometry';\n /** Retain an EWKT SRID as a legacy GeoJSON CRS property. */\n crs?: boolean;\n };\n};\n\n/** Legacy WKB dimensional options; SRID was not serialized by this API. */\nexport type GeometryWKBOptions = {\n /** Include an elevation ordinate. */\n hasZ?: boolean;\n /** Include a measure ordinate. */\n hasM?: boolean;\n /** Retained for compatibility; use math.gl WKBBuilder for EWKB SRIDs. */\n srid?: unknown;\n};\n\n/** Parses WKB without copying an input view's byte range and normalizes empty points. */\nexport function convertWKBToGeometry(input: ArrayBufferLike | ArrayBufferView): Geometry {\n const bytes = ArrayBuffer.isView(input)\n ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength)\n : new Uint8Array(input);\n return normalizeEmptyPoints(parseWKB(bytes).geometry as Geometry);\n}\n\n/** Encodes legacy geometry options with math.gl; collection child markers retain their dimensions. */\nexport function convertGeometryToWKB(\n input: Geometry | Feature,\n options: GeometryWKBOptions = {}\n): ArrayBuffer {\n const geometry = input.type === 'Feature' ? input.geometry : input;\n if (!geometry) throw new Error('WKB writer does not support null feature geometry');\n const dimension: WellKnownDimension = options.hasZ\n ? options.hasM\n ? 'xyzm'\n : 'xyz'\n : options.hasM\n ? 'xym'\n : 'xy';\n const bytes = encodeGeometry(geometry, dimension);\n return bytes.buffer as ArrayBuffer;\n}\n\n/** Composes independently encoded collection children; math.gl owns all WKB byte emission. */\nfunction encodeGeometry(geometry: Geometry, dimension: WellKnownDimension): Uint8Array {\n if (geometry.type !== 'GeometryCollection') {\n return writeWKB(geometry as WellKnownGeometry, dimension);\n }\n const children = geometry.geometries.map(child =>\n encodeGeometry(\n child,\n (child as Geometry & {__geoarrowDimension?: WellKnownDimension}).__geoarrowDimension ??\n dimension\n )\n );\n const headerBuilder = new WKBBuilder({mode: 'measure', dimension});\n headerBuilder.beginGeometry('GeometryCollection', children.length);\n const headerLength = headerBuilder.finishGeometry();\n const bytes = new Uint8Array(\n headerLength + children.reduce((total, child) => total + child.length, 0)\n );\n const writer = new WKBBuilder({mode: 'write', target: bytes, dimension});\n writer.beginGeometry('GeometryCollection', children.length);\n let byteOffset = writer.finishGeometry();\n for (const child of children) {\n bytes.set(child, byteOffset);\n byteOffset += child.length;\n }\n return bytes;\n}\n\n/** Reads the declared root WKT dimension, retaining the legacy null-on-invalid-header contract. */\nexport function getWKTDimension(input: string): GeoArrowDimension | null {\n const match = input\n .trim()\n .match(\n /^(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\\s+(ZM|Z|M))?(?:\\s|\\()/i\n );\n if (!match) return null;\n return match[1]?.toUpperCase() === 'Z'\n ? 'xyz'\n : match[1]?.toUpperCase() === 'M'\n ? 'xym'\n : match[1]?.toUpperCase() === 'ZM'\n ? 'xyzm'\n : 'xy';\n}\n\n/** Parses WKT with loaders.gl's legacy SRID and invalid-input behavior. */\nexport function convertWKTToGeometry(input: string, options?: ParseWKTOptions): Geometry | null {\n const {text, srid, dimension} = splitWKTHeader(input);\n try {\n // Preserve the legacy parser's treatment of empty parentheses as invalid input.\n if (/\\(\\s*\\)\\s*$/s.test(text)) {\n return null;\n }\n const collectionHeader = text.match(/^(\\s*GEOMETRYCOLLECTION)\\s+(?:ZM|Z|M)(?=\\s|\\()/i);\n const parseText =\n collectionHeader && dimension !== 'xym'\n ? text.replace(collectionHeader[0], collectionHeader[1])\n : text;\n const parsed = parseWKTWithMetadata(parseText, {inferDimensions: true});\n const geometry = toGeometryWithDimensionMetadata(\n parsed,\n collectionHeader ? dimension : undefined\n );\n if (options?.wkt?.crs && srid !== undefined) {\n Object.defineProperty(geometry, 'crs', {\n configurable: true,\n enumerable: true,\n value: {\n type: 'name',\n properties: {name: `urn:ogc:def:crs:EPSG::${srid}`}\n }\n });\n }\n return geometry;\n } catch {\n return null;\n }\n}\n\n/** Converts parsed WKT metadata to loaders.gl geometries with legacy dimension markers. */\nfunction toGeometryWithDimensionMetadata(\n result: WKTParseResult,\n dimensionOverride?: WellKnownDimension\n): Geometry {\n const geometry: Geometry =\n result.geometry.type === 'GeometryCollection'\n ? {\n type: 'GeometryCollection',\n geometries: (result.children ?? []).map(child => toGeometryWithDimensionMetadata(child))\n }\n : (result.geometry as unknown as Geometry);\n return addDimensionMarker(normalizeEmptyPoints(geometry), dimensionOverride ?? result.dimension);\n}\n\n/** Adds a non-enumerable dimension marker used by the WKT writer. */\nfunction addDimensionMarker(geometry: Geometry, dimension?: WellKnownDimension): Geometry {\n if (dimension && dimension !== 'xy') {\n Object.defineProperty(geometry, '__geoarrowDimension', {\n configurable: true,\n enumerable: false,\n value: dimension\n });\n }\n return geometry;\n}\n\n/** Separates an optional EWKT SRID prefix and root dimension token. */\nfunction splitWKTHeader(input: string): {\n text: string;\n srid?: string;\n dimension?: WellKnownDimension;\n} {\n const sridMatch = input.match(/^\\s*SRID=(\\d+)\\s*;\\s*/i);\n const text = sridMatch ? input.slice(sridMatch[0].length) : input;\n const dimensionMatch = text.match(\n /^\\s*(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\\s+(ZM|Z|M))?(?:\\s|\\()/i\n );\n const dimensionToken = dimensionMatch?.[1]?.toUpperCase();\n const dimension =\n dimensionToken === 'Z'\n ? 'xyz'\n : dimensionToken === 'M'\n ? 'xym'\n : dimensionToken === 'ZM'\n ? 'xyzm'\n : undefined;\n return {text, srid: sridMatch?.[1], dimension};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,
|
|
3
|
+
"sources": ["../../src/arrow-geometry/geometry-codecs.ts", "../../src/loader-utils/lib/javascript-utils/is-type.ts", "../../src/loader-utils/lib/binary-utils/memory-conversion-utils.ts"],
|
|
4
|
+
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {inspectWKTHeader, parseWKB, parseWKTWithMetadata, writeWKB} from '@math.gl/core/arrow';\nimport {ensureArrayBuffer} from '../loader-utils/lib/binary-utils/memory-conversion-utils';\nimport type {WellKnownDimension, WellKnownGeometry, WKTParseResult} from '@math.gl/core/arrow';\nimport type {Feature, Geometry, GeoArrowDimension} from '@loaders.gl/core/schema';\nimport {normalizeEmptyPoints} from './geometry-utils';\nexport {convertGeometryToWKT} from './geometry-to-wkt';\nexport type {WKTGeometryOptions} from './geometry-to-wkt';\n\n/** Legacy options for a materialized WKT geometry. */\nexport type ParseWKTOptions = {\n /** WKT-specific output options. */\n wkt?: {\n /** Only materialized GeoJSON geometry is supported. */\n shape?: 'geojson-geometry';\n /** Retain an EWKT SRID as a legacy GeoJSON CRS property. */\n crs?: boolean;\n };\n};\n\n/** Legacy WKB dimensional options; SRID was not serialized by this API. */\nexport type GeometryWKBOptions = {\n /** Include an elevation ordinate. */\n hasZ?: boolean;\n /** Include a measure ordinate. */\n hasM?: boolean;\n /** Retained for compatibility; use math.gl WKBBuilder for EWKB SRIDs. */\n srid?: unknown;\n};\n\n/** Parses WKB without copying an input view's byte range and normalizes empty points. */\nexport function convertWKBToGeometry(input: ArrayBufferLike | ArrayBufferView): Geometry {\n const bytes = ArrayBuffer.isView(input)\n ? new Uint8Array(input.buffer, input.byteOffset, input.byteLength)\n : new Uint8Array(input);\n return parseWKB(bytes, {normalizeEmptyPoints: true}).geometry as Geometry;\n}\n\n/** Encodes legacy geometry options with math.gl; collection child markers retain their dimensions. */\nexport function convertGeometryToWKB(\n input: Geometry | Feature,\n options: GeometryWKBOptions = {}\n): ArrayBuffer {\n const geometry = input.type === 'Feature' ? input.geometry : input;\n if (!geometry) throw new Error('WKB writer does not support null feature geometry');\n const dimension: WellKnownDimension = options.hasZ\n ? options.hasM\n ? 'xyzm'\n : 'xyz'\n : options.hasM\n ? 'xym'\n : 'xy';\n const bytes = writeWKB(describeGeometry(geometry, dimension));\n return ensureArrayBuffer(bytes);\n}\n\n/** Supplies each collection member's effective dimension to the math.gl writer. */\nfunction describeGeometry(geometry: Geometry, dimension: WellKnownDimension): WKTParseResult {\n return {\n geometry: geometry as WellKnownGeometry,\n dimension,\n children:\n geometry.type === 'GeometryCollection'\n ? geometry.geometries.map(child =>\n describeGeometry(\n child,\n (child as Geometry & {__geoarrowDimension?: WellKnownDimension})\n .__geoarrowDimension ?? dimension\n )\n )\n : undefined\n };\n}\n\n/** Reads the declared root dimension without parsing the coordinate payload. */\nexport function getWKTDimension(input: string): GeoArrowDimension | null {\n return inspectWKTHeader(input)?.dimension ?? null;\n}\n\n/** Parses WKT with loaders.gl's legacy SRID and invalid-input behavior. */\nexport function convertWKTToGeometry(input: string, options?: ParseWKTOptions): Geometry | null {\n const dimension = getWKTDimension(input);\n try {\n // Preserve the legacy parser's treatment of empty parentheses as invalid input.\n if (/\\(\\s*\\)\\s*$/s.test(input)) return null;\n\n const collectionHeader =\n /^(\\s*(?:SRID\\s*=\\s*\\d+\\s*;\\s*)?GEOMETRYCOLLECTION)\\s+(?:ZM|Z|M)(?=\\s|\\()/i;\n const parseText = dimension !== 'xym' ? input.replace(collectionHeader, '$1') : input;\n const parsed = parseWKTWithMetadata(parseText, {\n inferDimensions: true,\n allowMissingInheritedOrdinates: true\n });\n const {srid} = parsed;\n const geometry = toGeometryWithDimensionMetadata(\n parsed,\n collectionHeader.test(input) ? (dimension ?? undefined) : undefined\n );\n if (options?.wkt?.crs && srid !== undefined) {\n Object.defineProperty(geometry, 'crs', {\n configurable: true,\n enumerable: true,\n value: {\n type: 'name',\n properties: {name: `urn:ogc:def:crs:EPSG::${srid}`}\n }\n });\n }\n return geometry;\n } catch {\n return null;\n }\n}\n\n/** Converts parsed WKT metadata to loaders.gl geometries with legacy dimension markers. */\nfunction toGeometryWithDimensionMetadata(\n result: WKTParseResult,\n dimensionOverride?: WellKnownDimension\n): Geometry {\n const geometry: Geometry =\n result.geometry.type === 'GeometryCollection'\n ? {\n type: 'GeometryCollection',\n geometries: (result.children ?? []).map(child => toGeometryWithDimensionMetadata(child))\n }\n : (result.geometry as unknown as Geometry);\n return addDimensionMarker(normalizeEmptyPoints(geometry), dimensionOverride ?? result.dimension);\n}\n\n/** Adds a non-enumerable dimension marker used by the WKT writer. */\nfunction addDimensionMarker(geometry: Geometry, dimension?: WellKnownDimension): Geometry {\n if (dimension && dimension !== 'xy') {\n Object.defineProperty(geometry, '__geoarrowDimension', {\n configurable: true,\n enumerable: false,\n value: dimension\n });\n }\n return geometry;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/* eslint-disable @typescript-eslint/unbound-method */\n\nimport type {Readable} from 'stream';\n\n/** Minimal shape for Node.js Buffer-like values */\ntype NodeBufferLike = {buffer: ArrayBufferLike; isBuffer: true};\n\n/** Minimal shape for Node.js writable streams */\ntype NodeWritableStream = {\n end: (...args: unknown[]) => unknown;\n write: (...args: unknown[]) => unknown;\n writable: boolean;\n};\n\n/** Minimal shape for WritableStream-like DOM implementations */\ntype WritableDOMStreamLike = WritableStream | {abort: () => unknown; getWriter: () => unknown};\n\n/** A DOM or Node readable stream */\nexport type ReadableStreamType = ReadableStream | Readable;\n\n/** Checks whether a value is a boolean */\nconst isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/** Checks whether a value is a function */\nconst isFunction = (value: unknown): value is (...args: unknown[]) => unknown =>\n typeof value === 'function';\n\n/** Checks whether a value is a non-null object */\nexport const isObject = (value: unknown): value is object =>\n value !== null && typeof value === 'object';\n\n/** Checks whether a value is a plain object (created by the Object constructor) */\nexport const isPureObject = (value: unknown): value is Record<string, unknown> =>\n isObject(value) && value.constructor === {}.constructor;\n\n/** Checks whether a value is an ArrayBuffer */\nexport const isArrayBuffer = (value: unknown): value is ArrayBuffer =>\n typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer;\n\n/** Checks whether a value is an ArrayBuffer */\nexport const isSharedArrayBuffer = (value: unknown): value is SharedArrayBuffer =>\n typeof SharedArrayBuffer !== 'undefined' && value instanceof SharedArrayBuffer;\n\n/** Checks whether a value is ArrayBuffer-like */\nexport const isArrayBufferLike = (value: unknown): value is ArrayBufferLike =>\n isObject(value) &&\n typeof (value as ArrayBufferLike).byteLength === 'number' &&\n typeof (value as ArrayBufferLike).slice === 'function';\n\n/** Checks whether a value behaves like a promise */\nexport const isPromise = (value: unknown): value is Promise<unknown> =>\n isObject(value) && 'then' in value && isFunction((value as {then: unknown}).then);\n\n/** Checks whether a value implements the iterable protocol */\nexport const isIterable = (value: unknown): value is Iterable<unknown> =>\n Boolean(value) && isFunction((value as Iterable<unknown>)[Symbol.iterator]);\n\n/** Checks whether a value implements the async iterable protocol */\nexport const isAsyncIterable = (value: unknown): value is AsyncIterable<unknown> =>\n Boolean(value) && isFunction((value as AsyncIterable<unknown>)[Symbol.asyncIterator]);\n\n/** Checks whether a value is an iterator (has a next function) */\nexport const isIterator = (value: unknown): value is Iterator<unknown> =>\n Boolean(value) && isFunction((value as Iterator<unknown>).next);\n\n/** Checks whether a value is a fetch Response or a duck-typed equivalent */\nexport const isResponse = (value: unknown): value is Response =>\n (typeof Response !== 'undefined' && value instanceof Response) ||\n (isObject(value) &&\n isFunction((value as {arrayBuffer?: unknown}).arrayBuffer) &&\n isFunction((value as {text?: unknown}).text) &&\n isFunction((value as {json?: unknown}).json));\n\n/** Checks whether a value is a File */\nexport const isFile = (value: unknown): value is File =>\n typeof File !== 'undefined' && value instanceof File;\n\n/** Checks whether a value is a Blob */\nexport const isBlob = (value: unknown): value is Blob =>\n typeof Blob !== 'undefined' && value instanceof Blob;\n\n/** Checks for Node.js Buffers without triggering bundlers to include the Buffer polyfill */\nexport const isBuffer = (value: unknown): value is NodeBufferLike =>\n Boolean(\n value &&\n typeof value === 'object' &&\n (value as Partial<NodeBufferLike>).isBuffer &&\n 'buffer' in (value as NodeBufferLike)\n );\n\n/** Checks whether a value looks like a DOM WritableStream */\nexport const isWritableDOMStream = (value: unknown): value is WritableDOMStreamLike =>\n isObject(value) &&\n isFunction((value as WritableDOMStreamLike).abort) &&\n isFunction((value as WritableDOMStreamLike).getWriter);\n\n/** Checks whether a value looks like a DOM ReadableStream */\nexport const isReadableDOMStream = (value: unknown): value is ReadableStream =>\n (typeof ReadableStream !== 'undefined' && value instanceof ReadableStream) ||\n (isObject(value) &&\n isFunction((value as ReadableStream).tee) &&\n isFunction((value as ReadableStream).cancel) &&\n isFunction((value as ReadableStream).getReader));\n// Not implemented in Firefox: && isFunction(x.pipeTo)\n\n/** Checks whether a value looks like a Node.js writable stream */\nexport const isWritableNodeStream = (value: unknown): value is NodeWritableStream =>\n isObject(value) &&\n isFunction((value as NodeWritableStream).end) &&\n isFunction((value as NodeWritableStream).write) &&\n isBoolean((value as NodeWritableStream).writable);\n\n/** Checks whether a value looks like a Node.js readable stream */\nexport const isReadableNodeStream = (value: unknown): value is Readable =>\n isObject(value) &&\n isFunction((value as Readable).read) &&\n isFunction((value as Readable).pipe) &&\n isBoolean((value as Readable).readable);\n\n/** Checks whether a value is any readable stream (DOM or Node.js) */\nexport const isReadableStream = (value: unknown): value is ReadableStreamType =>\n isReadableDOMStream(value) || isReadableNodeStream(value);\n\n/** Checks whether a value is any writable stream (DOM or Node.js) */\nexport const isWritableStream = (value: unknown): value is WritableStream | NodeWritableStream =>\n isWritableDOMStream(value) || isWritableNodeStream(value);\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {isSharedArrayBuffer} from '../javascript-utils/is-type';\nimport * as node from '../node/buffer';\n\n/**\n * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n */\nexport function isBuffer(value: any): value is Buffer {\n return value && typeof value === 'object' && value.isBuffer;\n}\n\n/**\n * Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)\n * @todo better data type\n */\nexport function toBuffer(data: unknown): Buffer {\n return node.toBuffer ? node.toBuffer(data as any) : (data as Buffer);\n}\n\n/**\n * Convert an object to an array buffer. Handles SharedArrayBuffers.\n */\nexport function toArrayBuffer(\n data: Buffer | ArrayBufferLike | ArrayBufferView | string | Blob\n): ArrayBuffer {\n // Note: Should be called first, Buffers can trigger other detections below\n if (isBuffer(data)) {\n return node.toArrayBuffer(data);\n }\n\n if (data instanceof ArrayBuffer) {\n return data;\n }\n\n if (isSharedArrayBuffer(data)) {\n return copyToArrayBuffer(data);\n }\n\n // Node Buffers look like Uint8Arrays (Check isBuffer first)\n if (ArrayBuffer.isView(data)) {\n // TODO - ArrayBufferLike type mess\n const buffer = data.buffer as ArrayBuffer;\n if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {\n return buffer;\n }\n return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n }\n\n if (typeof data === 'string') {\n const text = data;\n const uint8Array = new TextEncoder().encode(text);\n return uint8Array.buffer;\n }\n\n // HACK to support Blob polyfill\n if (data && typeof data === 'object' && (data as any)._toArrayBuffer) {\n return (data as any)._toArrayBuffer();\n }\n\n throw new Error('toArrayBuffer');\n}\n\n/** Ensure that SharedArrayBuffers are copied into ArrayBuffers */\nexport function ensureArrayBuffer(bufferSource: ArrayBufferLike | ArrayBufferView): ArrayBuffer {\n if (bufferSource instanceof ArrayBuffer) {\n return bufferSource;\n }\n\n if (isSharedArrayBuffer(bufferSource)) {\n return copyToArrayBuffer(bufferSource);\n }\n\n const {buffer, byteOffset, byteLength} = bufferSource;\n if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {\n return buffer;\n }\n return copyToArrayBuffer(buffer, byteOffset, byteLength);\n}\n\n/** Copies an ArrayBuffer or a section of an ArrayBuffer to a new ArrayBuffer, handles SharedArrayBuffers */\nexport function copyToArrayBuffer(\n buffer: ArrayBufferLike,\n byteOffset = 0,\n byteLength = buffer.byteLength - byteOffset\n): ArrayBuffer {\n const view = new Uint8Array(buffer, byteOffset, byteLength);\n const copy = new Uint8Array(view.length);\n copy.set(view);\n return copy.buffer;\n}\n\n/** Convert an object to an ArrayBufferView, handles SharedArrayBuffers */\nexport function toArrayBufferView(\n data: ArrayBufferLike | ArrayBufferView\n): ArrayBuffer | ArrayBufferView {\n if (ArrayBuffer.isView(data)) {\n return data;\n }\n\n // Create a view to support ArrayBufferLike sources such as SharedArrayBuffer\n return new Uint8Array(data);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAyE;;;ACwClE,IAAM,sBAAsB,CAAC,UAClC,OAAO,sBAAsB,eAAe,iBAAiB;;;ACqBxD,SAAS,kBAAkB,cAA8D;AAC9F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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,7 +24,7 @@ export type GeometryWKBOptions = {
|
|
|
24
24
|
export declare function convertWKBToGeometry(input: ArrayBufferLike | ArrayBufferView): Geometry;
|
|
25
25
|
/** Encodes legacy geometry options with math.gl; collection child markers retain their dimensions. */
|
|
26
26
|
export declare function convertGeometryToWKB(input: Geometry | Feature, options?: GeometryWKBOptions): ArrayBuffer;
|
|
27
|
-
/** Reads the declared root
|
|
27
|
+
/** Reads the declared root dimension without parsing the coordinate payload. */
|
|
28
28
|
export declare function getWKTDimension(input: string): GeoArrowDimension | null;
|
|
29
29
|
/** Parses WKT with loaders.gl's legacy SRID and invalid-input behavior. */
|
|
30
30
|
export declare function convertWKTToGeometry(input: string, options?: ParseWKTOptions): Geometry | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry-codecs.d.ts","sourceRoot":"","sources":["../../src/arrow-geometry/geometry-codecs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geometry-codecs.d.ts","sourceRoot":"","sources":["../../src/arrow-geometry/geometry-codecs.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AAElF,OAAO,EAAC,oBAAoB,EAAC,6BAA0B;AACvD,YAAY,EAAC,kBAAkB,EAAC,6BAA0B;AAE1D,sDAAsD;AACtD,MAAM,MAAM,eAAe,GAAG;IAC5B,mCAAmC;IACnC,GAAG,CAAC,EAAE;QACJ,uDAAuD;QACvD,KAAK,CAAC,EAAE,kBAAkB,CAAC;QAC3B,4DAA4D;QAC5D,GAAG,CAAC,EAAE,OAAO,CAAC;KACf,CAAC;CACH,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,qCAAqC;IACrC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,kCAAkC;IAClC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,yEAAyE;IACzE,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,yFAAyF;AACzF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,GAAG,QAAQ,CAKvF;AAED,sGAAsG;AACtG,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,QAAQ,GAAG,OAAO,EACzB,OAAO,GAAE,kBAAuB,GAC/B,WAAW,CAYb;AAoBD,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAEvE;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,GAAG,IAAI,CAgC9F"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { parseWKB, parseWKTWithMetadata, writeWKB
|
|
4
|
+
import { inspectWKTHeader, parseWKB, parseWKTWithMetadata, writeWKB } from '@math.gl/core/arrow';
|
|
5
|
+
import { ensureArrayBuffer } from "../loader-utils/lib/binary-utils/memory-conversion-utils.js";
|
|
5
6
|
import { normalizeEmptyPoints } from "./geometry-utils.js";
|
|
6
7
|
export { convertGeometryToWKT } from "./geometry-to-wkt.js";
|
|
7
8
|
/** Parses WKB without copying an input view's byte range and normalizes empty points. */
|
|
@@ -9,7 +10,7 @@ export function convertWKBToGeometry(input) {
|
|
|
9
10
|
const bytes = ArrayBuffer.isView(input)
|
|
10
11
|
? new Uint8Array(input.buffer, input.byteOffset, input.byteLength)
|
|
11
12
|
: new Uint8Array(input);
|
|
12
|
-
return
|
|
13
|
+
return parseWKB(bytes, { normalizeEmptyPoints: true }).geometry;
|
|
13
14
|
}
|
|
14
15
|
/** Encodes legacy geometry options with math.gl; collection child markers retain their dimensions. */
|
|
15
16
|
export function convertGeometryToWKB(input, options = {}) {
|
|
@@ -23,58 +24,39 @@ export function convertGeometryToWKB(input, options = {}) {
|
|
|
23
24
|
: options.hasM
|
|
24
25
|
? 'xym'
|
|
25
26
|
: 'xy';
|
|
26
|
-
const bytes =
|
|
27
|
-
return bytes
|
|
27
|
+
const bytes = writeWKB(describeGeometry(geometry, dimension));
|
|
28
|
+
return ensureArrayBuffer(bytes);
|
|
28
29
|
}
|
|
29
|
-
/**
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const bytes = new Uint8Array(headerLength + children.reduce((total, child) => total + child.length, 0));
|
|
40
|
-
const writer = new WKBBuilder({ mode: 'write', target: bytes, dimension });
|
|
41
|
-
writer.beginGeometry('GeometryCollection', children.length);
|
|
42
|
-
let byteOffset = writer.finishGeometry();
|
|
43
|
-
for (const child of children) {
|
|
44
|
-
bytes.set(child, byteOffset);
|
|
45
|
-
byteOffset += child.length;
|
|
46
|
-
}
|
|
47
|
-
return bytes;
|
|
30
|
+
/** Supplies each collection member's effective dimension to the math.gl writer. */
|
|
31
|
+
function describeGeometry(geometry, dimension) {
|
|
32
|
+
return {
|
|
33
|
+
geometry: geometry,
|
|
34
|
+
dimension,
|
|
35
|
+
children: geometry.type === 'GeometryCollection'
|
|
36
|
+
? geometry.geometries.map(child => describeGeometry(child, child
|
|
37
|
+
.__geoarrowDimension ?? dimension))
|
|
38
|
+
: undefined
|
|
39
|
+
};
|
|
48
40
|
}
|
|
49
|
-
/** Reads the declared root
|
|
41
|
+
/** Reads the declared root dimension without parsing the coordinate payload. */
|
|
50
42
|
export function getWKTDimension(input) {
|
|
51
|
-
|
|
52
|
-
.trim()
|
|
53
|
-
.match(/^(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(ZM|Z|M))?(?:\s|\()/i);
|
|
54
|
-
if (!match)
|
|
55
|
-
return null;
|
|
56
|
-
return match[1]?.toUpperCase() === 'Z'
|
|
57
|
-
? 'xyz'
|
|
58
|
-
: match[1]?.toUpperCase() === 'M'
|
|
59
|
-
? 'xym'
|
|
60
|
-
: match[1]?.toUpperCase() === 'ZM'
|
|
61
|
-
? 'xyzm'
|
|
62
|
-
: 'xy';
|
|
43
|
+
return inspectWKTHeader(input)?.dimension ?? null;
|
|
63
44
|
}
|
|
64
45
|
/** Parses WKT with loaders.gl's legacy SRID and invalid-input behavior. */
|
|
65
46
|
export function convertWKTToGeometry(input, options) {
|
|
66
|
-
const
|
|
47
|
+
const dimension = getWKTDimension(input);
|
|
67
48
|
try {
|
|
68
49
|
// Preserve the legacy parser's treatment of empty parentheses as invalid input.
|
|
69
|
-
if (/\(\s*\)\s*$/s.test(
|
|
50
|
+
if (/\(\s*\)\s*$/s.test(input))
|
|
70
51
|
return null;
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
:
|
|
76
|
-
|
|
77
|
-
const
|
|
52
|
+
const collectionHeader = /^(\s*(?:SRID\s*=\s*\d+\s*;\s*)?GEOMETRYCOLLECTION)\s+(?:ZM|Z|M)(?=\s|\()/i;
|
|
53
|
+
const parseText = dimension !== 'xym' ? input.replace(collectionHeader, '$1') : input;
|
|
54
|
+
const parsed = parseWKTWithMetadata(parseText, {
|
|
55
|
+
inferDimensions: true,
|
|
56
|
+
allowMissingInheritedOrdinates: true
|
|
57
|
+
});
|
|
58
|
+
const { srid } = parsed;
|
|
59
|
+
const geometry = toGeometryWithDimensionMetadata(parsed, collectionHeader.test(input) ? (dimension ?? undefined) : undefined);
|
|
78
60
|
if (options?.wkt?.crs && srid !== undefined) {
|
|
79
61
|
Object.defineProperty(geometry, 'crs', {
|
|
80
62
|
configurable: true,
|
|
@@ -112,19 +94,4 @@ function addDimensionMarker(geometry, dimension) {
|
|
|
112
94
|
}
|
|
113
95
|
return geometry;
|
|
114
96
|
}
|
|
115
|
-
/** Separates an optional EWKT SRID prefix and root dimension token. */
|
|
116
|
-
function splitWKTHeader(input) {
|
|
117
|
-
const sridMatch = input.match(/^\s*SRID=(\d+)\s*;\s*/i);
|
|
118
|
-
const text = sridMatch ? input.slice(sridMatch[0].length) : input;
|
|
119
|
-
const dimensionMatch = text.match(/^\s*(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(ZM|Z|M))?(?:\s|\()/i);
|
|
120
|
-
const dimensionToken = dimensionMatch?.[1]?.toUpperCase();
|
|
121
|
-
const dimension = dimensionToken === 'Z'
|
|
122
|
-
? 'xyz'
|
|
123
|
-
: dimensionToken === 'M'
|
|
124
|
-
? 'xym'
|
|
125
|
-
: dimensionToken === 'ZM'
|
|
126
|
-
? 'xyzm'
|
|
127
|
-
: undefined;
|
|
128
|
-
return { text, srid: sridMatch?.[1], dimension };
|
|
129
|
-
}
|
|
130
97
|
//# sourceMappingURL=geometry-codecs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry-codecs.js","sourceRoot":"","sources":["../../src/arrow-geometry/geometry-codecs.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,QAAQ,EAAE,oBAAoB,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"geometry-codecs.js","sourceRoot":"","sources":["../../src/arrow-geometry/geometry-codecs.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,gBAAgB,EAAE,QAAQ,EAAE,oBAAoB,EAAE,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAAC,iBAAiB,EAAC,oEAAiE;AAG3F,OAAO,EAAC,oBAAoB,EAAC,4BAAyB;AACtD,OAAO,EAAC,oBAAoB,EAAC,6BAA0B;AAwBv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L,IAAI,EAAE,MAAM;oBACZ,UAAU,EAAE,EAAC,IAAI,EAAE,yBAAyB,IAAI,EAAE,EAAC;iBACpD;aACF,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,2FAA2F;AAC3F,SAAS,+BAA+B,CACtC,MAAsB,EACtB,iBAAsC;IAEtC,MAAM,QAAQ,GACZ,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,oBAAoB;QAC3C,CAAC,CAAC;YACE,IAAI,EAAE,oBAAoB;YAC1B,UAAU,EAAE,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,+BAA+B,CAAC,KAAK,CAAC,CAAC;SACzF;QACH,CAAC,CAAE,MAAM,CAAC,QAAgC,CAAC;IAC/C,OAAO,kBAAkB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,iBAAiB,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;AACnG,CAAC;AAED,qEAAqE;AACrE,SAAS,kBAAkB,CAAC,QAAkB,EAAE,SAA8B;IAC5E,IAAI,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACpC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,qBAAqB,EAAE;YACrD,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,KAAK;YACjB,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -23,25 +23,46 @@ __export(triangulate_wkb_exports, {
|
|
|
23
23
|
triangulateWKB: () => triangulateWKB
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(triangulate_wkb_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_arrow = require("@math.gl/core/arrow");
|
|
27
27
|
function triangulateWKB(wkb) {
|
|
28
28
|
const dataView = getWKBDataView(wkb);
|
|
29
|
-
const wkbHeader = parseWKBHeaderFast(dataView);
|
|
30
29
|
const triangles = [];
|
|
31
30
|
resetVertexPool();
|
|
32
31
|
resetRingLayoutPool();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
let polygon;
|
|
33
|
+
let vertexOffset = 0;
|
|
34
|
+
try {
|
|
35
|
+
(0, import_arrow.visitWKB)(dataView, {
|
|
36
|
+
geometry(header, count, depth) {
|
|
37
|
+
if (depth === 0 && header.geometryType !== "Polygon" && header.geometryType !== "MultiPolygon") {
|
|
38
|
+
throw new Error(`WKB: Expected Polygon or MultiPolygon, found ${header.geometryType}`);
|
|
39
|
+
}
|
|
40
|
+
if (header.geometryType !== "Polygon") return;
|
|
41
|
+
if (polygon) triangulateWKBPolygon(dataView, polygon, triangles);
|
|
42
|
+
polygon = {
|
|
43
|
+
ringStart: ringLayoutPoolLength,
|
|
44
|
+
ringCount: count ?? 0,
|
|
45
|
+
vertexCount: 0,
|
|
46
|
+
dimensions: (0, import_arrow.getWellKnownDimensionSize)(header.dimension),
|
|
47
|
+
littleEndian: header.littleEndian
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
ring(pointCount, _ringIndex, _depth, byteOffset) {
|
|
51
|
+
ringPointCounts[ringLayoutPoolLength] = pointCount;
|
|
52
|
+
ringCoordinateByteOffsets[ringLayoutPoolLength] = byteOffset;
|
|
53
|
+
ringVertexOffsets[ringLayoutPoolLength++] = vertexOffset;
|
|
54
|
+
polygon.vertexCount += pointCount;
|
|
55
|
+
vertexOffset += pointCount;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
if (cause instanceof Error && cause.message.startsWith("WKB Polygon collection contains")) {
|
|
60
|
+
throw new Error("WKB: Inner geometries of MultiPolygon must be Polygon geometries.", { cause });
|
|
38
61
|
}
|
|
39
|
-
|
|
40
|
-
triangulateWKBMultiPolygon(dataView, wkbHeader.byteOffset, wkbHeader.littleEndian, triangles);
|
|
41
|
-
return triangles;
|
|
42
|
-
default:
|
|
43
|
-
throw new Error(`WKB: Expected Polygon or MultiPolygon, found ${wkbHeader.geometryType}`);
|
|
62
|
+
throw cause;
|
|
44
63
|
}
|
|
64
|
+
if (polygon) triangulateWKBPolygon(dataView, polygon, triangles);
|
|
65
|
+
return triangles;
|
|
45
66
|
}
|
|
46
67
|
function getWKBDataView(wkb) {
|
|
47
68
|
if (ArrayBuffer.isView(wkb)) {
|
|
@@ -49,112 +70,6 @@ function getWKBDataView(wkb) {
|
|
|
49
70
|
}
|
|
50
71
|
return new DataView(wkb);
|
|
51
72
|
}
|
|
52
|
-
function triangulateWKBMultiPolygon(dataView, byteOffset, littleEndian, triangles) {
|
|
53
|
-
const polygonCount = dataView.getUint32(byteOffset, littleEndian);
|
|
54
|
-
byteOffset += 4;
|
|
55
|
-
let vertexOffset = 0;
|
|
56
|
-
const polygonHeader = { byteOffset };
|
|
57
|
-
for (let polygonIndex = 0; polygonIndex < polygonCount; polygonIndex++) {
|
|
58
|
-
parseWKBHeaderFast(dataView, byteOffset, polygonHeader);
|
|
59
|
-
if (polygonHeader.geometryType !== import_wkb_types.WKBGeometryType.Polygon) {
|
|
60
|
-
throw new Error("WKB: Inner geometries of MultiPolygon must be Polygon geometries.");
|
|
61
|
-
}
|
|
62
|
-
const parsedPolygon = parseWKBPolygonLayout(
|
|
63
|
-
dataView,
|
|
64
|
-
polygonHeader.byteOffset,
|
|
65
|
-
polygonHeader,
|
|
66
|
-
vertexOffset
|
|
67
|
-
);
|
|
68
|
-
triangulateWKBPolygon(dataView, parsedPolygon.layout, triangles);
|
|
69
|
-
vertexOffset += parsedPolygon.layout.vertexCount;
|
|
70
|
-
byteOffset = parsedPolygon.byteOffset;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function parseWKBHeaderFast(dataView, byteOffset = 0, target) {
|
|
74
|
-
const wkbHeader = target || {};
|
|
75
|
-
const littleEndian = dataView.getUint8(byteOffset) === 1;
|
|
76
|
-
byteOffset++;
|
|
77
|
-
const geometryCode = dataView.getUint32(byteOffset, littleEndian);
|
|
78
|
-
byteOffset += 4;
|
|
79
|
-
const geometryType = geometryCode & 7;
|
|
80
|
-
let dimensions = 2;
|
|
81
|
-
let coordinates = "xy";
|
|
82
|
-
let variant = "wkb";
|
|
83
|
-
const isoType = (geometryCode - geometryType) / 1e3;
|
|
84
|
-
if (isoType === 1) {
|
|
85
|
-
variant = "iso-wkb";
|
|
86
|
-
dimensions = 3;
|
|
87
|
-
coordinates = "xyz";
|
|
88
|
-
} else if (isoType === 2) {
|
|
89
|
-
variant = "iso-wkb";
|
|
90
|
-
dimensions = 3;
|
|
91
|
-
coordinates = "xym";
|
|
92
|
-
} else if (isoType === 3) {
|
|
93
|
-
variant = "iso-wkb";
|
|
94
|
-
dimensions = 4;
|
|
95
|
-
coordinates = "xyzm";
|
|
96
|
-
} else if (isoType !== 0) {
|
|
97
|
-
const ewkbZ = geometryCode & import_wkb_types.EWKB_FLAG_Z;
|
|
98
|
-
const ewkbM = geometryCode & import_wkb_types.EWKB_FLAG_M;
|
|
99
|
-
const ewkbSRID = geometryCode & import_wkb_types.EWKB_FLAG_SRID;
|
|
100
|
-
if (ewkbZ && ewkbM) {
|
|
101
|
-
variant = "ewkb";
|
|
102
|
-
dimensions = 4;
|
|
103
|
-
coordinates = "xyzm";
|
|
104
|
-
} else if (ewkbZ) {
|
|
105
|
-
variant = "ewkb";
|
|
106
|
-
dimensions = 3;
|
|
107
|
-
coordinates = "xyz";
|
|
108
|
-
} else if (ewkbM) {
|
|
109
|
-
variant = "ewkb";
|
|
110
|
-
dimensions = 3;
|
|
111
|
-
coordinates = "xym";
|
|
112
|
-
}
|
|
113
|
-
if (ewkbSRID) {
|
|
114
|
-
variant = "ewkb";
|
|
115
|
-
wkbHeader.srid = dataView.getUint32(byteOffset, littleEndian);
|
|
116
|
-
byteOffset += 4;
|
|
117
|
-
} else {
|
|
118
|
-
wkbHeader.srid = void 0;
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
wkbHeader.srid = void 0;
|
|
122
|
-
}
|
|
123
|
-
wkbHeader.type = "wkb";
|
|
124
|
-
wkbHeader.variant = variant;
|
|
125
|
-
wkbHeader.geometryType = geometryType;
|
|
126
|
-
wkbHeader.dimensions = dimensions;
|
|
127
|
-
wkbHeader.coordinates = coordinates;
|
|
128
|
-
wkbHeader.littleEndian = littleEndian;
|
|
129
|
-
wkbHeader.byteOffset = byteOffset;
|
|
130
|
-
return wkbHeader;
|
|
131
|
-
}
|
|
132
|
-
function parseWKBPolygonLayout(dataView, byteOffset, wkbHeader, vertexOffset) {
|
|
133
|
-
const ringCount = dataView.getUint32(byteOffset, wkbHeader.littleEndian);
|
|
134
|
-
byteOffset += 4;
|
|
135
|
-
const ringStart = ringLayoutPoolLength;
|
|
136
|
-
let vertexCount = 0;
|
|
137
|
-
for (let ringIndex = 0; ringIndex < ringCount; ringIndex++) {
|
|
138
|
-
const pointCount = dataView.getUint32(byteOffset, wkbHeader.littleEndian);
|
|
139
|
-
byteOffset += 4;
|
|
140
|
-
ringPointCounts[ringLayoutPoolLength] = pointCount;
|
|
141
|
-
ringCoordinateByteOffsets[ringLayoutPoolLength] = byteOffset;
|
|
142
|
-
ringVertexOffsets[ringLayoutPoolLength] = vertexOffset + vertexCount;
|
|
143
|
-
ringLayoutPoolLength++;
|
|
144
|
-
byteOffset += pointCount * wkbHeader.dimensions * 8;
|
|
145
|
-
vertexCount += pointCount;
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
layout: {
|
|
149
|
-
ringStart,
|
|
150
|
-
ringCount,
|
|
151
|
-
vertexCount,
|
|
152
|
-
dimensions: wkbHeader.dimensions,
|
|
153
|
-
littleEndian: wkbHeader.littleEndian
|
|
154
|
-
},
|
|
155
|
-
byteOffset
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
73
|
function triangulateWKBPolygon(dataView, polygon, triangles) {
|
|
159
74
|
if (polygon.ringCount === 0) {
|
|
160
75
|
return;
|