@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
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
Point,
|
|
8
|
-
MultiPoint,
|
|
9
|
-
LineString,
|
|
10
|
-
MultiLineString,
|
|
11
|
-
Polygon,
|
|
12
|
-
MultiPolygon,
|
|
13
|
-
GeometryCollection,
|
|
14
|
-
Geometry
|
|
15
|
-
} from '@loaders.gl/core/schema';
|
|
16
|
-
|
|
17
|
-
import {TWKBWriter as BinaryWriter} from './twkb-io';
|
|
18
|
-
import {TWKBGeometryType as WKBGeometryType} from './twkb-types';
|
|
19
|
-
|
|
20
|
-
type TWKBPrecision = {
|
|
21
|
-
xy: number;
|
|
22
|
-
z: number;
|
|
23
|
-
m: number;
|
|
24
|
-
xyFactor: number;
|
|
25
|
-
zFactor: number;
|
|
26
|
-
mFactor: number;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type TWKBEncoderContext = TWKBPrecision & {
|
|
30
|
-
hasZ?: boolean;
|
|
31
|
-
hasM?: boolean;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export function convertGeometryToTWKB(
|
|
35
|
-
geometry: Geometry,
|
|
36
|
-
options?: {hasZ?: boolean; hasM?: boolean}
|
|
37
|
-
): ArrayBuffer {
|
|
38
|
-
const writer = new BinaryWriter(0, true);
|
|
39
|
-
|
|
40
|
-
const context: TWKBEncoderContext = {
|
|
41
|
-
...getTwkbPrecision(5, 0, 0),
|
|
42
|
-
hasZ: options?.hasZ,
|
|
43
|
-
hasM: options?.hasM
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
encodeGeometry(writer, geometry, context);
|
|
47
|
-
|
|
48
|
-
return writer.getArrayBuffer();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function encodeGeometry(writer: BinaryWriter, geometry: Geometry, context: TWKBEncoderContext) {
|
|
52
|
-
switch (geometry.type) {
|
|
53
|
-
case 'Point':
|
|
54
|
-
return encodePoint(writer, context, geometry);
|
|
55
|
-
case 'LineString':
|
|
56
|
-
return encodeLineString(writer, context, geometry);
|
|
57
|
-
case 'Polygon':
|
|
58
|
-
return encodePolygon(writer, context, geometry);
|
|
59
|
-
case 'MultiPoint':
|
|
60
|
-
return encodeMultiPoint(writer, context, geometry);
|
|
61
|
-
case 'MultiLineString':
|
|
62
|
-
return encodeMultiLineString(writer, context, geometry);
|
|
63
|
-
case 'MultiPolygon':
|
|
64
|
-
return encodeMultiPolygon(writer, context, geometry);
|
|
65
|
-
case 'GeometryCollection':
|
|
66
|
-
return encodeGeometryCollection(writer, context, geometry);
|
|
67
|
-
default:
|
|
68
|
-
throw new Error('unsupported geometry type');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function encodePoint(writer: BinaryWriter, context: TWKBEncoderContext, point: Point): void {
|
|
73
|
-
const isEmpty =
|
|
74
|
-
point.coordinates.length === 0 ||
|
|
75
|
-
point.coordinates[0] === undefined ||
|
|
76
|
-
point.coordinates[1] === undefined;
|
|
77
|
-
|
|
78
|
-
writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
|
|
79
|
-
|
|
80
|
-
if (!isEmpty) {
|
|
81
|
-
const previousPoint = [0, 0, 0, 0];
|
|
82
|
-
writeTwkbPoint(writer, context, point.coordinates, previousPoint);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function encodeLineString(
|
|
87
|
-
writer: BinaryWriter,
|
|
88
|
-
context: TWKBEncoderContext,
|
|
89
|
-
lineString: LineString
|
|
90
|
-
): ArrayBuffer {
|
|
91
|
-
const points = lineString.coordinates;
|
|
92
|
-
const isEmpty = !hasCoordinateValues(points);
|
|
93
|
-
|
|
94
|
-
writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
|
|
95
|
-
|
|
96
|
-
if (!isEmpty) {
|
|
97
|
-
writer.writeVarInt(points.length);
|
|
98
|
-
const previousPoint = [0, 0, 0, 0];
|
|
99
|
-
for (const point of points) {
|
|
100
|
-
writeTwkbPoint(writer, context, point, previousPoint);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return writer.arrayBuffer;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function encodePolygon(
|
|
108
|
-
writer: BinaryWriter,
|
|
109
|
-
context: TWKBEncoderContext,
|
|
110
|
-
polygon: Polygon
|
|
111
|
-
): ArrayBuffer {
|
|
112
|
-
const polygonRings = polygon.coordinates;
|
|
113
|
-
|
|
114
|
-
const isEmpty = !hasCoordinateValues(polygonRings);
|
|
115
|
-
|
|
116
|
-
writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
|
|
117
|
-
|
|
118
|
-
if (!isEmpty) {
|
|
119
|
-
writer.writeVarInt(polygonRings.length);
|
|
120
|
-
|
|
121
|
-
const previousPoint = [0, 0, 0, 0];
|
|
122
|
-
for (const ring of polygonRings) {
|
|
123
|
-
writer.writeVarInt(ring.length);
|
|
124
|
-
for (const point of ring) {
|
|
125
|
-
writeTwkbPoint(writer, context, point, previousPoint);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return writer.arrayBuffer;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function encodeMultiPoint(
|
|
134
|
-
writer: BinaryWriter,
|
|
135
|
-
context: TWKBEncoderContext,
|
|
136
|
-
multiPoint: MultiPoint
|
|
137
|
-
): void {
|
|
138
|
-
const points = multiPoint.coordinates;
|
|
139
|
-
const isEmpty = !hasCoordinateValues(points);
|
|
140
|
-
|
|
141
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
|
|
142
|
-
|
|
143
|
-
if (!isEmpty) {
|
|
144
|
-
writer.writeVarInt(points.length);
|
|
145
|
-
|
|
146
|
-
const previousPoint = [0, 0, 0, 0];
|
|
147
|
-
for (let i = 0; i < points.length; i++) {
|
|
148
|
-
writeTwkbPoint(writer, context, points[i], previousPoint);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function encodeMultiLineString(
|
|
154
|
-
writer: BinaryWriter,
|
|
155
|
-
context: TWKBEncoderContext,
|
|
156
|
-
multiLineStrings: MultiLineString
|
|
157
|
-
): ArrayBuffer {
|
|
158
|
-
const lineStrings = multiLineStrings.coordinates;
|
|
159
|
-
const isEmpty = !hasCoordinateValues(lineStrings);
|
|
160
|
-
|
|
161
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
|
|
162
|
-
|
|
163
|
-
if (!isEmpty) {
|
|
164
|
-
writer.writeVarInt(lineStrings.length);
|
|
165
|
-
|
|
166
|
-
const previousPoint = [0, 0, 0, 0];
|
|
167
|
-
for (const lineString of lineStrings) {
|
|
168
|
-
writer.writeVarInt(lineString.length);
|
|
169
|
-
|
|
170
|
-
for (const point of lineString) {
|
|
171
|
-
writeTwkbPoint(writer, context, point, previousPoint);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return writer.arrayBuffer;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function encodeMultiPolygon(
|
|
180
|
-
writer: BinaryWriter,
|
|
181
|
-
context: TWKBEncoderContext,
|
|
182
|
-
multiPolygon: MultiPolygon
|
|
183
|
-
): void {
|
|
184
|
-
const {coordinates} = multiPolygon;
|
|
185
|
-
const isEmpty = !hasCoordinateValues(coordinates);
|
|
186
|
-
|
|
187
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
|
|
188
|
-
|
|
189
|
-
if (!isEmpty) {
|
|
190
|
-
const polygons = coordinates;
|
|
191
|
-
writer.writeVarInt(polygons.length);
|
|
192
|
-
|
|
193
|
-
const previousPoint = [0, 0, 0, 0];
|
|
194
|
-
|
|
195
|
-
for (const polygonRings of polygons) {
|
|
196
|
-
writer.writeVarInt(polygonRings.length);
|
|
197
|
-
for (const ring of polygonRings) {
|
|
198
|
-
writer.writeVarInt(ring.length);
|
|
199
|
-
for (const point of ring) {
|
|
200
|
-
writeTwkbPoint(writer, context, point, previousPoint);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function encodeGeometryCollection(
|
|
208
|
-
writer: BinaryWriter,
|
|
209
|
-
context: TWKBEncoderContext,
|
|
210
|
-
geometryCollection: GeometryCollection
|
|
211
|
-
): void {
|
|
212
|
-
const {geometries} = geometryCollection;
|
|
213
|
-
const isEmpty = geometries.length === 0;
|
|
214
|
-
|
|
215
|
-
writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
|
|
216
|
-
|
|
217
|
-
if (geometries.length > 0) {
|
|
218
|
-
writer.writeVarInt(geometries.length);
|
|
219
|
-
for (const geometry of geometries) {
|
|
220
|
-
encodeGeometry(writer, geometry, context);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
*
|
|
227
|
-
* @param writer
|
|
228
|
-
* @param context
|
|
229
|
-
* @param geometryType
|
|
230
|
-
* @param isEmpty
|
|
231
|
-
*/
|
|
232
|
-
function writeTwkbHeader(
|
|
233
|
-
writer: BinaryWriter,
|
|
234
|
-
context: TWKBEncoderContext,
|
|
235
|
-
geometryType: WKBGeometryType,
|
|
236
|
-
isEmpty: boolean
|
|
237
|
-
) {
|
|
238
|
-
const type = (zigZagEncode(context.xy) << 4) + geometryType;
|
|
239
|
-
let metadataHeader = context.hasZ || context.hasM ? 1 << 3 : 0;
|
|
240
|
-
metadataHeader += isEmpty ? 1 << 4 : 0;
|
|
241
|
-
|
|
242
|
-
writer.writeUInt8(type);
|
|
243
|
-
writer.writeUInt8(metadataHeader);
|
|
244
|
-
|
|
245
|
-
if (context.hasZ || context.hasM) {
|
|
246
|
-
let extendedPrecision = 0;
|
|
247
|
-
if (context.hasZ) {
|
|
248
|
-
extendedPrecision |= 0x1;
|
|
249
|
-
}
|
|
250
|
-
if (context.hasM) {
|
|
251
|
-
extendedPrecision |= 0x2;
|
|
252
|
-
}
|
|
253
|
-
writer.writeUInt8(extendedPrecision);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Write one point to array buffer. ZigZagEncoding the delta fdrom the previous point. Mutates previousPoint.
|
|
259
|
-
* @param writer
|
|
260
|
-
* @param context
|
|
261
|
-
* @param previousPoint - Mutated by this function
|
|
262
|
-
* @param point
|
|
263
|
-
*/
|
|
264
|
-
function writeTwkbPoint(
|
|
265
|
-
writer: BinaryWriter,
|
|
266
|
-
context: TWKBEncoderContext,
|
|
267
|
-
point: number[],
|
|
268
|
-
previousPoint: number[]
|
|
269
|
-
): void {
|
|
270
|
-
const x = point[0] * context.xyFactor;
|
|
271
|
-
const y = point[1] * context.xyFactor;
|
|
272
|
-
const z = point[2] * context.zFactor;
|
|
273
|
-
const m = point[3] * context.mFactor;
|
|
274
|
-
|
|
275
|
-
writer.writeVarInt(zigZagEncode(x - previousPoint[0]));
|
|
276
|
-
writer.writeVarInt(zigZagEncode(y - previousPoint[1]));
|
|
277
|
-
if (context.hasZ) {
|
|
278
|
-
writer.writeVarInt(zigZagEncode(z - previousPoint[2]));
|
|
279
|
-
}
|
|
280
|
-
if (context.hasM) {
|
|
281
|
-
writer.writeVarInt(zigZagEncode(m - previousPoint[3]));
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
previousPoint[0] = x;
|
|
285
|
-
previousPoint[1] = y;
|
|
286
|
-
previousPoint[2] = z;
|
|
287
|
-
previousPoint[3] = m;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// HELPERS
|
|
291
|
-
|
|
292
|
-
function zigZagEncode(value: number): number {
|
|
293
|
-
return (value << 1) ^ (value >> 31);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/** Returns whether a nested coordinate array contains at least one numeric ordinate. */
|
|
297
|
-
function hasCoordinateValues(coordinates: unknown): boolean {
|
|
298
|
-
if (typeof coordinates === 'number') {
|
|
299
|
-
return true;
|
|
300
|
-
}
|
|
301
|
-
return Array.isArray(coordinates) && coordinates.some(hasCoordinateValues);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function getTwkbPrecision(
|
|
305
|
-
xyPrecision: number,
|
|
306
|
-
zPrecision: number,
|
|
307
|
-
mPrecision: number
|
|
308
|
-
): TWKBPrecision {
|
|
309
|
-
return {
|
|
310
|
-
xy: xyPrecision,
|
|
311
|
-
z: zPrecision,
|
|
312
|
-
m: mPrecision,
|
|
313
|
-
xyFactor: Math.pow(10, xyPrecision),
|
|
314
|
-
zFactor: Math.pow(10, zPrecision),
|
|
315
|
-
mFactor: Math.pow(10, mPrecision)
|
|
316
|
-
};
|
|
317
|
-
}
|
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
Geometry,
|
|
8
|
-
GeometryCollection,
|
|
9
|
-
Point,
|
|
10
|
-
LineString,
|
|
11
|
-
Polygon,
|
|
12
|
-
MultiPoint,
|
|
13
|
-
MultiLineString,
|
|
14
|
-
MultiPolygon
|
|
15
|
-
} from '@loaders.gl/core/schema';
|
|
16
|
-
import {TWKBReader as BinaryReader} from './twkb-io';
|
|
17
|
-
import {TWKBGeometryType as WKBGeometryType} from './twkb-types';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Check if an array buffer might be a TWKB array buffer
|
|
21
|
-
* @param arrayBuffer The array buffer to check
|
|
22
|
-
* @returns false if this is definitely not a TWKB array buffer, true if it might be a TWKB array buffer
|
|
23
|
-
*/
|
|
24
|
-
export function isTWKB(arrayBuffer: ArrayBufferLike): boolean {
|
|
25
|
-
const binaryReader = new BinaryReader(toArrayBuffer(arrayBuffer));
|
|
26
|
-
|
|
27
|
-
const type = binaryReader.readUInt8();
|
|
28
|
-
const geometryType = type & 0x0f;
|
|
29
|
-
|
|
30
|
-
// Only geometry types 1 to 7 (point to geometry collection are currently defined)
|
|
31
|
-
if (geometryType < 1 || geometryType > 7) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Copies shared-buffer input into an ArrayBuffer for DataView-based TWKB inspection. */
|
|
39
|
-
function toArrayBuffer(arrayBuffer: ArrayBufferLike): ArrayBuffer {
|
|
40
|
-
return arrayBuffer instanceof ArrayBuffer
|
|
41
|
-
? arrayBuffer
|
|
42
|
-
: new Uint8Array(arrayBuffer).slice().buffer;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Passed around between parsing functions, extracted from the header */
|
|
46
|
-
type TWKBHeader = {
|
|
47
|
-
geometryType: WKBGeometryType;
|
|
48
|
-
|
|
49
|
-
hasBoundingBox: boolean;
|
|
50
|
-
hasSizeAttribute: boolean;
|
|
51
|
-
hasIdList: boolean;
|
|
52
|
-
hasExtendedPrecision: boolean;
|
|
53
|
-
isEmpty: boolean;
|
|
54
|
-
|
|
55
|
-
precision: number;
|
|
56
|
-
precisionFactor: number;
|
|
57
|
-
|
|
58
|
-
hasZ: boolean;
|
|
59
|
-
zPrecision: number;
|
|
60
|
-
zPrecisionFactor: number;
|
|
61
|
-
|
|
62
|
-
hasM: boolean;
|
|
63
|
-
mPrecision: number;
|
|
64
|
-
mPrecisionFactor: number;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/** Converts a TWKB encoded buffer to a GeoJSON Geometry */
|
|
68
|
-
export function convertTWKBToGeometry(arrayBuffer: ArrayBuffer): Geometry {
|
|
69
|
-
const binaryReader = new BinaryReader(arrayBuffer);
|
|
70
|
-
|
|
71
|
-
const context = parseTWKBHeader(binaryReader);
|
|
72
|
-
|
|
73
|
-
if (context.hasSizeAttribute) {
|
|
74
|
-
binaryReader.readVarInt();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (context.hasBoundingBox) {
|
|
78
|
-
let dimensions = 2;
|
|
79
|
-
|
|
80
|
-
if (context.hasZ) {
|
|
81
|
-
dimensions++;
|
|
82
|
-
}
|
|
83
|
-
if (context.hasM) {
|
|
84
|
-
dimensions++;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// TODO why are we throwing away these datums?
|
|
88
|
-
for (let i = 0; i < dimensions; i++) {
|
|
89
|
-
binaryReader.readVarInt();
|
|
90
|
-
binaryReader.readVarInt();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return parseGeometry(binaryReader, context, context.geometryType);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function parseTWKBHeader(binaryReader: BinaryReader): TWKBHeader {
|
|
98
|
-
const type = binaryReader.readUInt8();
|
|
99
|
-
const metadataHeader = binaryReader.readUInt8();
|
|
100
|
-
|
|
101
|
-
const geometryType = type & 0x0f;
|
|
102
|
-
|
|
103
|
-
const precision = zigZagDecode(type >> 4);
|
|
104
|
-
|
|
105
|
-
const hasExtendedPrecision = Boolean((metadataHeader >> 3) & 1);
|
|
106
|
-
let hasZ = false;
|
|
107
|
-
let hasM = false;
|
|
108
|
-
let zPrecision = 0;
|
|
109
|
-
let zPrecisionFactor = 1;
|
|
110
|
-
let mPrecision = 0;
|
|
111
|
-
let mPrecisionFactor = 1;
|
|
112
|
-
|
|
113
|
-
if (hasExtendedPrecision) {
|
|
114
|
-
const extendedPrecision = binaryReader.readUInt8();
|
|
115
|
-
hasZ = (extendedPrecision & 0x01) === 0x01;
|
|
116
|
-
hasM = (extendedPrecision & 0x02) === 0x02;
|
|
117
|
-
|
|
118
|
-
zPrecision = zigZagDecode((extendedPrecision & 0x1c) >> 2);
|
|
119
|
-
zPrecisionFactor = Math.pow(10, zPrecision);
|
|
120
|
-
|
|
121
|
-
mPrecision = zigZagDecode((extendedPrecision & 0xe0) >> 5);
|
|
122
|
-
mPrecisionFactor = Math.pow(10, mPrecision);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
geometryType,
|
|
127
|
-
|
|
128
|
-
precision,
|
|
129
|
-
precisionFactor: Math.pow(10, precision),
|
|
130
|
-
|
|
131
|
-
hasBoundingBox: Boolean((metadataHeader >> 0) & 1),
|
|
132
|
-
hasSizeAttribute: Boolean((metadataHeader >> 1) & 1),
|
|
133
|
-
hasIdList: Boolean((metadataHeader >> 2) & 1),
|
|
134
|
-
hasExtendedPrecision,
|
|
135
|
-
isEmpty: Boolean((metadataHeader >> 4) & 1),
|
|
136
|
-
|
|
137
|
-
hasZ,
|
|
138
|
-
hasM,
|
|
139
|
-
zPrecision,
|
|
140
|
-
zPrecisionFactor,
|
|
141
|
-
mPrecision,
|
|
142
|
-
mPrecisionFactor
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function parseGeometry(
|
|
147
|
-
binaryReader: BinaryReader,
|
|
148
|
-
context: TWKBHeader,
|
|
149
|
-
geometryType: WKBGeometryType
|
|
150
|
-
): Geometry {
|
|
151
|
-
switch (geometryType) {
|
|
152
|
-
case WKBGeometryType.Point:
|
|
153
|
-
return parsePoint(binaryReader, context);
|
|
154
|
-
case WKBGeometryType.LineString:
|
|
155
|
-
return parseLineString(binaryReader, context);
|
|
156
|
-
case WKBGeometryType.Polygon:
|
|
157
|
-
return parsePolygon(binaryReader, context);
|
|
158
|
-
case WKBGeometryType.MultiPoint:
|
|
159
|
-
return parseMultiPoint(binaryReader, context);
|
|
160
|
-
case WKBGeometryType.MultiLineString:
|
|
161
|
-
return parseMultiLineString(binaryReader, context);
|
|
162
|
-
case WKBGeometryType.MultiPolygon:
|
|
163
|
-
return parseMultiPolygon(binaryReader, context);
|
|
164
|
-
case WKBGeometryType.GeometryCollection:
|
|
165
|
-
return parseGeometryCollection(binaryReader, context);
|
|
166
|
-
default:
|
|
167
|
-
throw new Error(`GeometryType ${geometryType} not supported`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// GEOMETRIES
|
|
172
|
-
|
|
173
|
-
function parsePoint(reader: BinaryReader, context: TWKBHeader): Point {
|
|
174
|
-
if (context.isEmpty) {
|
|
175
|
-
return {type: 'Point', coordinates: []};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return {type: 'Point', coordinates: readFirstPoint(reader, context)};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function parseLineString(reader: BinaryReader, context: TWKBHeader): LineString {
|
|
182
|
-
if (context.isEmpty) {
|
|
183
|
-
return {type: 'LineString', coordinates: []};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const pointCount = reader.readVarInt();
|
|
187
|
-
|
|
188
|
-
const previousPoint = makePreviousPoint(context);
|
|
189
|
-
|
|
190
|
-
const points: number[][] = [];
|
|
191
|
-
for (let i = 0; i < pointCount; i++) {
|
|
192
|
-
points.push(parseNextPoint(reader, context, previousPoint));
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return {type: 'LineString', coordinates: points};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function parsePolygon(reader: BinaryReader, context: TWKBHeader): Polygon {
|
|
199
|
-
if (context.isEmpty) {
|
|
200
|
-
return {type: 'Polygon', coordinates: []};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const ringCount = reader.readVarInt();
|
|
204
|
-
|
|
205
|
-
const previousPoint = makePreviousPoint(context);
|
|
206
|
-
|
|
207
|
-
const exteriorRingLength = reader.readVarInt();
|
|
208
|
-
const exteriorRing: number[][] = [];
|
|
209
|
-
|
|
210
|
-
for (let i = 0; i < exteriorRingLength; i++) {
|
|
211
|
-
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const polygon: number[][][] = [exteriorRing];
|
|
215
|
-
for (let i = 1; i < ringCount; i++) {
|
|
216
|
-
const interiorRingCount = reader.readVarInt();
|
|
217
|
-
|
|
218
|
-
const interiorRing: number[][] = [];
|
|
219
|
-
for (let j = 0; j < interiorRingCount; j++) {
|
|
220
|
-
interiorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
polygon.push(interiorRing);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return {type: 'Polygon', coordinates: polygon};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function parseMultiPoint(reader: BinaryReader, context: TWKBHeader): MultiPoint {
|
|
230
|
-
if (context.isEmpty) {
|
|
231
|
-
return {type: 'MultiPoint', coordinates: []};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const previousPoint = makePreviousPoint(context);
|
|
235
|
-
const pointCount = reader.readVarInt();
|
|
236
|
-
|
|
237
|
-
const coordinates: number[][] = [];
|
|
238
|
-
for (let i = 0; i < pointCount; i++) {
|
|
239
|
-
coordinates.push(parseNextPoint(reader, context, previousPoint));
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return {type: 'MultiPoint', coordinates};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function parseMultiLineString(reader: BinaryReader, context: TWKBHeader): MultiLineString {
|
|
246
|
-
if (context.isEmpty) {
|
|
247
|
-
return {type: 'MultiLineString', coordinates: []};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const previousPoint = makePreviousPoint(context);
|
|
251
|
-
const lineStringCount = reader.readVarInt();
|
|
252
|
-
|
|
253
|
-
const coordinates: number[][][] = [];
|
|
254
|
-
for (let i = 0; i < lineStringCount; i++) {
|
|
255
|
-
const pointCount = reader.readVarInt();
|
|
256
|
-
|
|
257
|
-
const lineString: number[][] = [];
|
|
258
|
-
for (let j = 0; j < pointCount; j++) {
|
|
259
|
-
lineString.push(parseNextPoint(reader, context, previousPoint));
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
coordinates.push(lineString);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return {type: 'MultiLineString', coordinates};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function parseMultiPolygon(reader: BinaryReader, context: TWKBHeader): MultiPolygon {
|
|
269
|
-
if (context.isEmpty) {
|
|
270
|
-
return {type: 'MultiPolygon', coordinates: []};
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const previousPoint = makePreviousPoint(context);
|
|
274
|
-
const polygonCount = reader.readVarInt();
|
|
275
|
-
|
|
276
|
-
const polygons: number[][][][] = [];
|
|
277
|
-
for (let i = 0; i < polygonCount; i++) {
|
|
278
|
-
const ringCount = reader.readVarInt();
|
|
279
|
-
|
|
280
|
-
const exteriorPointCount = reader.readVarInt();
|
|
281
|
-
|
|
282
|
-
const exteriorRing: number[][] = [];
|
|
283
|
-
for (let j = 0; j < exteriorPointCount; j++) {
|
|
284
|
-
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const polygon: number[][][] = exteriorRing ? [exteriorRing] : [];
|
|
288
|
-
|
|
289
|
-
for (let j = 1; j < ringCount; j++) {
|
|
290
|
-
const interiorRing: number[][] = [];
|
|
291
|
-
|
|
292
|
-
const interiorRingLength = reader.readVarInt();
|
|
293
|
-
|
|
294
|
-
for (let k = 0; k < interiorRingLength; k++) {
|
|
295
|
-
interiorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
polygon.push(interiorRing);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
polygons.push(polygon);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return {type: 'MultiPolygon', coordinates: polygons};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/** Geometry collection not yet supported */
|
|
308
|
-
function parseGeometryCollection(reader: BinaryReader, context: TWKBHeader): GeometryCollection {
|
|
309
|
-
return {type: 'GeometryCollection', geometries: []};
|
|
310
|
-
/**
|
|
311
|
-
if (context.isEmpty) {
|
|
312
|
-
return {type: 'GeometryCollection', geometries: []};
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const geometryCount = reader.readVarInt();
|
|
316
|
-
|
|
317
|
-
const geometries: Geometry[] = new Array(geometryCount);
|
|
318
|
-
for (let i = 0; i < geometryCount; i++) {
|
|
319
|
-
const geometry = parseGeometry(reader, context, geometryType);
|
|
320
|
-
geometries.push(geometry);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return {type: 'GeometryCollection', geometries: []};
|
|
324
|
-
*/
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// HELPERS
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Maps negative values to positive values while going back and
|
|
331
|
-
forth (0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6 ...)
|
|
332
|
-
*/
|
|
333
|
-
function zigZagDecode(value: number): number {
|
|
334
|
-
return (value >> 1) ^ -(value & 1);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function makePointCoordinates(x: number, y: number, z?: number, m?: number): number[] {
|
|
338
|
-
return (z !== undefined ? (m !== undefined ? [x, y, z, m] : [x, y, z]) : [x, y]) as number[];
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
function makePreviousPoint(context: TWKBHeader): number[] {
|
|
342
|
-
return makePointCoordinates(0, 0, context.hasZ ? 0 : undefined, context.hasM ? 0 : undefined);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function readFirstPoint(reader: BinaryReader, context: TWKBHeader): number[] {
|
|
346
|
-
const x = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
347
|
-
const y = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
348
|
-
const z = context.hasZ ? zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor : undefined;
|
|
349
|
-
const m = context.hasM ? zigZagDecode(reader.readVarInt()) / context.mPrecisionFactor : undefined;
|
|
350
|
-
return makePointCoordinates(x, y, z, m);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Modifies previousPoint
|
|
355
|
-
*/
|
|
356
|
-
function parseNextPoint(
|
|
357
|
-
reader: BinaryReader,
|
|
358
|
-
context: TWKBHeader,
|
|
359
|
-
previousPoint: number[]
|
|
360
|
-
): number[] {
|
|
361
|
-
previousPoint[0] += zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
362
|
-
previousPoint[1] += zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
363
|
-
|
|
364
|
-
if (context.hasZ) {
|
|
365
|
-
previousPoint[2] += zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor;
|
|
366
|
-
}
|
|
367
|
-
if (context.hasM) {
|
|
368
|
-
previousPoint[3] += zigZagDecode(reader.readVarInt()) / context.mPrecisionFactor;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// Copy the point
|
|
372
|
-
return previousPoint.slice();
|
|
373
|
-
}
|