@loaders.gl/wkt 4.3.2 → 4.4.0-alpha.2
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/dist.dev.js +1281 -1266
- package/dist/dist.min.js +2 -2
- package/dist/hex-wkb-loader.d.ts +6 -5
- package/dist/hex-wkb-loader.d.ts.map +1 -1
- package/dist/hex-wkb-loader.js +4 -4
- package/dist/index.cjs +51 -1622
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -5
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/{utils/version.js → version.js} +1 -1
- package/dist/twkb-loader.d.ts +3 -3
- package/dist/twkb-loader.d.ts.map +1 -1
- package/dist/twkb-loader.js +4 -4
- package/dist/twkb-writer.d.ts +2 -1
- package/dist/twkb-writer.d.ts.map +1 -1
- package/dist/twkb-writer.js +5 -4
- package/dist/wkb-loader.d.ts +13 -11
- package/dist/wkb-loader.d.ts.map +1 -1
- package/dist/wkb-loader.js +14 -6
- package/dist/wkb-writer.d.ts +3 -2
- package/dist/wkb-writer.d.ts.map +1 -1
- package/dist/wkb-writer.js +5 -4
- package/dist/wkt-crs-loader.d.ts +1 -1
- package/dist/wkt-crs-loader.d.ts.map +1 -1
- package/dist/wkt-crs-loader.js +2 -2
- package/dist/wkt-crs-writer.d.ts +1 -1
- package/dist/wkt-crs-writer.d.ts.map +1 -1
- package/dist/wkt-crs-writer.js +2 -2
- package/dist/wkt-loader.d.ts +2 -2
- package/dist/wkt-loader.d.ts.map +1 -1
- package/dist/wkt-loader.js +4 -4
- package/dist/wkt-worker.js +26 -13
- package/dist/wkt-writer.d.ts +6 -5
- package/dist/wkt-writer.d.ts.map +1 -1
- package/dist/wkt-writer.js +10 -7
- package/package.json +6 -6
- package/src/hex-wkb-loader.ts +8 -8
- package/src/index.ts +0 -10
- package/src/twkb-loader.ts +5 -5
- package/src/twkb-writer.ts +6 -5
- package/src/wkb-loader.ts +24 -12
- package/src/wkb-writer.ts +8 -7
- package/src/wkt-crs-loader.ts +3 -3
- package/src/wkt-crs-writer.ts +3 -5
- package/src/wkt-loader.ts +6 -5
- package/src/wkt-writer.ts +11 -8
- package/dist/lib/encode-twkb.d.ts +0 -6
- package/dist/lib/encode-twkb.d.ts.map +0 -1
- package/dist/lib/encode-twkb.js +0 -195
- package/dist/lib/encode-wkb.d.ts +0 -33
- package/dist/lib/encode-wkb.d.ts.map +0 -1
- package/dist/lib/encode-wkb.js +0 -286
- package/dist/lib/encode-wkt-crs.d.ts +0 -10
- package/dist/lib/encode-wkt-crs.d.ts.map +0 -1
- package/dist/lib/encode-wkt-crs.js +0 -35
- package/dist/lib/encode-wkt.d.ts +0 -8
- package/dist/lib/encode-wkt.d.ts.map +0 -1
- package/dist/lib/encode-wkt.js +0 -47
- package/dist/lib/parse-hex-wkb.d.ts +0 -1
- package/dist/lib/parse-hex-wkb.d.ts.map +0 -1
- package/dist/lib/parse-hex-wkb.js +0 -1
- package/dist/lib/parse-twkb.d.ts +0 -9
- package/dist/lib/parse-twkb.d.ts.map +0 -1
- package/dist/lib/parse-twkb.js +0 -253
- package/dist/lib/parse-wkb-header.d.ts +0 -39
- package/dist/lib/parse-wkb-header.d.ts.map +0 -1
- package/dist/lib/parse-wkb-header.js +0 -134
- package/dist/lib/parse-wkb.d.ts +0 -5
- package/dist/lib/parse-wkb.d.ts.map +0 -1
- package/dist/lib/parse-wkb.js +0 -241
- package/dist/lib/parse-wkt-crs.d.ts +0 -15
- package/dist/lib/parse-wkt-crs.d.ts.map +0 -1
- package/dist/lib/parse-wkt-crs.js +0 -120
- package/dist/lib/parse-wkt.d.ts +0 -30
- package/dist/lib/parse-wkt.d.ts.map +0 -1
- package/dist/lib/parse-wkt.js +0 -288
- package/dist/lib/utils/base64-encoder.d.ts +0 -5
- package/dist/lib/utils/base64-encoder.d.ts.map +0 -1
- package/dist/lib/utils/base64-encoder.js +0 -153
- package/dist/lib/utils/binary-reader.d.ts +0 -18
- package/dist/lib/utils/binary-reader.d.ts.map +0 -1
- package/dist/lib/utils/binary-reader.js +0 -69
- package/dist/lib/utils/binary-writer.d.ts +0 -28
- package/dist/lib/utils/binary-writer.d.ts.map +0 -1
- package/dist/lib/utils/binary-writer.js +0 -121
- package/dist/lib/utils/hex-encoder.d.ts +0 -15
- package/dist/lib/utils/hex-encoder.d.ts.map +0 -1
- package/dist/lib/utils/hex-encoder.js +0 -54
- package/dist/lib/utils/hex-transcoder.d.ts +0 -15
- package/dist/lib/utils/hex-transcoder.d.ts.map +0 -1
- package/dist/lib/utils/hex-transcoder.js +0 -50
- package/dist/lib/utils/version.d.ts.map +0 -1
- package/src/lib/encode-twkb.ts +0 -308
- package/src/lib/encode-wkb.ts +0 -390
- package/src/lib/encode-wkt-crs.ts +0 -41
- package/src/lib/encode-wkt.ts +0 -56
- package/src/lib/parse-hex-wkb.ts +0 -0
- package/src/lib/parse-twkb.ts +0 -365
- package/src/lib/parse-wkb-header.ts +0 -174
- package/src/lib/parse-wkb.ts +0 -343
- package/src/lib/parse-wkt-crs.ts +0 -149
- package/src/lib/parse-wkt.ts +0 -327
- package/src/lib/utils/base64-encoder.ts +0 -157
- package/src/lib/utils/binary-reader.ts +0 -76
- package/src/lib/utils/binary-writer.ts +0 -127
- package/src/lib/utils/hex-encoder.ts +0 -60
- package/src/lib/utils/hex-transcoder.ts +0 -54
- /package/dist/lib/{utils/version.d.ts → version.d.ts} +0 -0
- /package/src/lib/{utils/version.ts → version.ts} +0 -0
package/dist/lib/parse-twkb.js
DELETED
|
@@ -1,253 +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
|
-
import { BinaryReader } from "./utils/binary-reader.js";
|
|
6
|
-
import { WKBGeometryType } from "./parse-wkb-header.js";
|
|
7
|
-
/**
|
|
8
|
-
* Check if an array buffer might be a TWKB array buffer
|
|
9
|
-
* @param arrayBuffer The array buffer to check
|
|
10
|
-
* @returns false if this is definitely not a TWKB array buffer, true if it might be a TWKB array buffer
|
|
11
|
-
*/
|
|
12
|
-
export function isTWKB(arrayBuffer) {
|
|
13
|
-
const binaryReader = new BinaryReader(arrayBuffer);
|
|
14
|
-
const type = binaryReader.readUInt8();
|
|
15
|
-
const geometryType = type & 0x0f;
|
|
16
|
-
// Only geometry types 1 to 7 (point to geometry collection are currently defined)
|
|
17
|
-
if (geometryType < 1 || geometryType > 7) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
export function parseTWKBGeometry(arrayBuffer) {
|
|
23
|
-
const binaryReader = new BinaryReader(arrayBuffer);
|
|
24
|
-
const context = parseTWKBHeader(binaryReader);
|
|
25
|
-
if (context.hasSizeAttribute) {
|
|
26
|
-
binaryReader.readVarInt();
|
|
27
|
-
}
|
|
28
|
-
if (context.hasBoundingBox) {
|
|
29
|
-
let dimensions = 2;
|
|
30
|
-
if (context.hasZ) {
|
|
31
|
-
dimensions++;
|
|
32
|
-
}
|
|
33
|
-
if (context.hasM) {
|
|
34
|
-
dimensions++;
|
|
35
|
-
}
|
|
36
|
-
// TODO why are we throwing away these datums?
|
|
37
|
-
for (let i = 0; i < dimensions; i++) {
|
|
38
|
-
binaryReader.readVarInt();
|
|
39
|
-
binaryReader.readVarInt();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return parseGeometry(binaryReader, context, context.geometryType);
|
|
43
|
-
}
|
|
44
|
-
function parseTWKBHeader(binaryReader) {
|
|
45
|
-
const type = binaryReader.readUInt8();
|
|
46
|
-
const metadataHeader = binaryReader.readUInt8();
|
|
47
|
-
const geometryType = type & 0x0f;
|
|
48
|
-
const precision = zigZagDecode(type >> 4);
|
|
49
|
-
const hasExtendedPrecision = Boolean((metadataHeader >> 3) & 1);
|
|
50
|
-
let hasZ = false;
|
|
51
|
-
let hasM = false;
|
|
52
|
-
let zPrecision = 0;
|
|
53
|
-
let zPrecisionFactor = 1;
|
|
54
|
-
let mPrecision = 0;
|
|
55
|
-
let mPrecisionFactor = 1;
|
|
56
|
-
if (hasExtendedPrecision) {
|
|
57
|
-
const extendedPrecision = binaryReader.readUInt8();
|
|
58
|
-
hasZ = (extendedPrecision & 0x01) === 0x01;
|
|
59
|
-
hasM = (extendedPrecision & 0x02) === 0x02;
|
|
60
|
-
zPrecision = zigZagDecode((extendedPrecision & 0x1c) >> 2);
|
|
61
|
-
zPrecisionFactor = Math.pow(10, zPrecision);
|
|
62
|
-
mPrecision = zigZagDecode((extendedPrecision & 0xe0) >> 5);
|
|
63
|
-
mPrecisionFactor = Math.pow(10, mPrecision);
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
geometryType,
|
|
67
|
-
precision,
|
|
68
|
-
precisionFactor: Math.pow(10, precision),
|
|
69
|
-
hasBoundingBox: Boolean((metadataHeader >> 0) & 1),
|
|
70
|
-
hasSizeAttribute: Boolean((metadataHeader >> 1) & 1),
|
|
71
|
-
hasIdList: Boolean((metadataHeader >> 2) & 1),
|
|
72
|
-
hasExtendedPrecision,
|
|
73
|
-
isEmpty: Boolean((metadataHeader >> 4) & 1),
|
|
74
|
-
hasZ,
|
|
75
|
-
hasM,
|
|
76
|
-
zPrecision,
|
|
77
|
-
zPrecisionFactor,
|
|
78
|
-
mPrecision,
|
|
79
|
-
mPrecisionFactor
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function parseGeometry(binaryReader, context, geometryType) {
|
|
83
|
-
switch (geometryType) {
|
|
84
|
-
case WKBGeometryType.Point:
|
|
85
|
-
return parsePoint(binaryReader, context);
|
|
86
|
-
case WKBGeometryType.LineString:
|
|
87
|
-
return parseLineString(binaryReader, context);
|
|
88
|
-
case WKBGeometryType.Polygon:
|
|
89
|
-
return parsePolygon(binaryReader, context);
|
|
90
|
-
case WKBGeometryType.MultiPoint:
|
|
91
|
-
return parseMultiPoint(binaryReader, context);
|
|
92
|
-
case WKBGeometryType.MultiLineString:
|
|
93
|
-
return parseMultiLineString(binaryReader, context);
|
|
94
|
-
case WKBGeometryType.MultiPolygon:
|
|
95
|
-
return parseMultiPolygon(binaryReader, context);
|
|
96
|
-
case WKBGeometryType.GeometryCollection:
|
|
97
|
-
return parseGeometryCollection(binaryReader, context);
|
|
98
|
-
default:
|
|
99
|
-
throw new Error(`GeometryType ${geometryType} not supported`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// GEOMETRIES
|
|
103
|
-
function parsePoint(reader, context) {
|
|
104
|
-
if (context.isEmpty) {
|
|
105
|
-
return { type: 'Point', coordinates: [] };
|
|
106
|
-
}
|
|
107
|
-
return { type: 'Point', coordinates: readFirstPoint(reader, context) };
|
|
108
|
-
}
|
|
109
|
-
function parseLineString(reader, context) {
|
|
110
|
-
if (context.isEmpty) {
|
|
111
|
-
return { type: 'LineString', coordinates: [] };
|
|
112
|
-
}
|
|
113
|
-
const pointCount = reader.readVarInt();
|
|
114
|
-
const previousPoint = makePreviousPoint(context);
|
|
115
|
-
const points = [];
|
|
116
|
-
for (let i = 0; i < pointCount; i++) {
|
|
117
|
-
points.push(parseNextPoint(reader, context, previousPoint));
|
|
118
|
-
}
|
|
119
|
-
return { type: 'LineString', coordinates: points };
|
|
120
|
-
}
|
|
121
|
-
function parsePolygon(reader, context) {
|
|
122
|
-
if (context.isEmpty) {
|
|
123
|
-
return { type: 'Polygon', coordinates: [] };
|
|
124
|
-
}
|
|
125
|
-
const ringCount = reader.readVarInt();
|
|
126
|
-
const previousPoint = makePreviousPoint(context);
|
|
127
|
-
const exteriorRingLength = reader.readVarInt();
|
|
128
|
-
const exteriorRing = [];
|
|
129
|
-
for (let i = 0; i < exteriorRingLength; i++) {
|
|
130
|
-
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
131
|
-
}
|
|
132
|
-
const polygon = [exteriorRing];
|
|
133
|
-
for (let i = 1; i < ringCount; i++) {
|
|
134
|
-
const interiorRingCount = reader.readVarInt();
|
|
135
|
-
const interiorRing = [];
|
|
136
|
-
for (let j = 0; j < interiorRingCount; j++) {
|
|
137
|
-
interiorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
138
|
-
}
|
|
139
|
-
polygon.push(interiorRing);
|
|
140
|
-
}
|
|
141
|
-
return { type: 'Polygon', coordinates: polygon };
|
|
142
|
-
}
|
|
143
|
-
function parseMultiPoint(reader, context) {
|
|
144
|
-
if (context.isEmpty) {
|
|
145
|
-
return { type: 'MultiPoint', coordinates: [] };
|
|
146
|
-
}
|
|
147
|
-
const previousPoint = makePreviousPoint(context);
|
|
148
|
-
const pointCount = reader.readVarInt();
|
|
149
|
-
const coordinates = [];
|
|
150
|
-
for (let i = 0; i < pointCount; i++) {
|
|
151
|
-
coordinates.push(parseNextPoint(reader, context, previousPoint));
|
|
152
|
-
}
|
|
153
|
-
return { type: 'MultiPoint', coordinates };
|
|
154
|
-
}
|
|
155
|
-
function parseMultiLineString(reader, context) {
|
|
156
|
-
if (context.isEmpty) {
|
|
157
|
-
return { type: 'MultiLineString', coordinates: [] };
|
|
158
|
-
}
|
|
159
|
-
const previousPoint = makePreviousPoint(context);
|
|
160
|
-
const lineStringCount = reader.readVarInt();
|
|
161
|
-
const coordinates = [];
|
|
162
|
-
for (let i = 0; i < lineStringCount; i++) {
|
|
163
|
-
const pointCount = reader.readVarInt();
|
|
164
|
-
const lineString = [];
|
|
165
|
-
for (let j = 0; j < pointCount; j++) {
|
|
166
|
-
lineString.push(parseNextPoint(reader, context, previousPoint));
|
|
167
|
-
}
|
|
168
|
-
coordinates.push(lineString);
|
|
169
|
-
}
|
|
170
|
-
return { type: 'MultiLineString', coordinates };
|
|
171
|
-
}
|
|
172
|
-
function parseMultiPolygon(reader, context) {
|
|
173
|
-
if (context.isEmpty) {
|
|
174
|
-
return { type: 'MultiPolygon', coordinates: [] };
|
|
175
|
-
}
|
|
176
|
-
const previousPoint = makePreviousPoint(context);
|
|
177
|
-
const polygonCount = reader.readVarInt();
|
|
178
|
-
const polygons = [];
|
|
179
|
-
for (let i = 0; i < polygonCount; i++) {
|
|
180
|
-
const ringCount = reader.readVarInt();
|
|
181
|
-
const exteriorPointCount = reader.readVarInt();
|
|
182
|
-
const exteriorRing = [];
|
|
183
|
-
for (let j = 0; j < exteriorPointCount; j++) {
|
|
184
|
-
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
185
|
-
}
|
|
186
|
-
const polygon = exteriorRing ? [exteriorRing] : [];
|
|
187
|
-
for (let j = 1; j < ringCount; j++) {
|
|
188
|
-
const interiorRing = [];
|
|
189
|
-
const interiorRingLength = reader.readVarInt();
|
|
190
|
-
for (let k = 0; k < interiorRingLength; k++) {
|
|
191
|
-
interiorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
192
|
-
}
|
|
193
|
-
polygon.push(interiorRing);
|
|
194
|
-
}
|
|
195
|
-
polygons.push(polygon);
|
|
196
|
-
}
|
|
197
|
-
return { type: 'MultiPolygon', coordinates: polygons };
|
|
198
|
-
}
|
|
199
|
-
/** Geometry collection not yet supported */
|
|
200
|
-
function parseGeometryCollection(reader, context) {
|
|
201
|
-
return { type: 'GeometryCollection', geometries: [] };
|
|
202
|
-
/**
|
|
203
|
-
if (context.isEmpty) {
|
|
204
|
-
return {type: 'GeometryCollection', geometries: []};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const geometryCount = reader.readVarInt();
|
|
208
|
-
|
|
209
|
-
const geometries: Geometry[] = new Array(geometryCount);
|
|
210
|
-
for (let i = 0; i < geometryCount; i++) {
|
|
211
|
-
const geometry = parseGeometry(reader, context, geometryType);
|
|
212
|
-
geometries.push(geometry);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return {type: 'GeometryCollection', geometries: []};
|
|
216
|
-
*/
|
|
217
|
-
}
|
|
218
|
-
// HELPERS
|
|
219
|
-
/**
|
|
220
|
-
* Maps negative values to positive values while going back and
|
|
221
|
-
forth (0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6 ...)
|
|
222
|
-
*/
|
|
223
|
-
function zigZagDecode(value) {
|
|
224
|
-
return (value >> 1) ^ -(value & 1);
|
|
225
|
-
}
|
|
226
|
-
function makePointCoordinates(x, y, z, m) {
|
|
227
|
-
return (z !== undefined ? (m !== undefined ? [x, y, z, m] : [x, y, z]) : [x, y]);
|
|
228
|
-
}
|
|
229
|
-
function makePreviousPoint(context) {
|
|
230
|
-
return makePointCoordinates(0, 0, context.hasZ ? 0 : undefined, context.hasM ? 0 : undefined);
|
|
231
|
-
}
|
|
232
|
-
function readFirstPoint(reader, context) {
|
|
233
|
-
const x = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
234
|
-
const y = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
235
|
-
const z = context.hasZ ? zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor : undefined;
|
|
236
|
-
const m = context.hasM ? zigZagDecode(reader.readVarInt()) / context.mPrecisionFactor : undefined;
|
|
237
|
-
return makePointCoordinates(x, y, z, m);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Modifies previousPoint
|
|
241
|
-
*/
|
|
242
|
-
function parseNextPoint(reader, context, previousPoint) {
|
|
243
|
-
previousPoint[0] += zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
244
|
-
previousPoint[1] += zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
245
|
-
if (context.hasZ) {
|
|
246
|
-
previousPoint[2] += zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor;
|
|
247
|
-
}
|
|
248
|
-
if (context.hasM) {
|
|
249
|
-
previousPoint[3] += zigZagDecode(reader.readVarInt()) / context.mPrecisionFactor;
|
|
250
|
-
}
|
|
251
|
-
// Copy the point
|
|
252
|
-
return previousPoint.slice();
|
|
253
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integer code for geometry types in WKB and related formats
|
|
3
|
-
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
4
|
-
*/
|
|
5
|
-
export declare enum WKBGeometryType {
|
|
6
|
-
Point = 1,
|
|
7
|
-
LineString = 2,
|
|
8
|
-
Polygon = 3,
|
|
9
|
-
MultiPoint = 4,
|
|
10
|
-
MultiLineString = 5,
|
|
11
|
-
MultiPolygon = 6,
|
|
12
|
-
GeometryCollection = 7
|
|
13
|
-
}
|
|
14
|
-
/** Parsed WKB header */
|
|
15
|
-
export type WKBHeader = {
|
|
16
|
-
/** WKB variant */
|
|
17
|
-
type: 'wkb' | 'ewkb' | 'iso-wkb' | 'twkb';
|
|
18
|
-
/** geometry type encoded in this WKB: point, line, polygon etc */
|
|
19
|
-
geometryType: 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
20
|
-
/** Number of dimensions for coordinate data */
|
|
21
|
-
dimensions: 2 | 3 | 4;
|
|
22
|
-
/** Coordinate names, Z and M are controlled by flags */
|
|
23
|
-
coordinates: 'xy' | 'xyz' | 'xym' | 'xyzm';
|
|
24
|
-
srid?: number;
|
|
25
|
-
/** true if binary data is stored as little endian */
|
|
26
|
-
littleEndian: boolean;
|
|
27
|
-
/** Offset to start of geometry */
|
|
28
|
-
byteOffset: number;
|
|
29
|
-
};
|
|
30
|
-
/** Sanity checks that first to 5-9 bytes could represent a supported WKB dialect header */
|
|
31
|
-
export declare function isWKB(arrayBuffer: ArrayBuffer): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Parses header and provides a byteOffset to start of geometry data
|
|
34
|
-
* @param dataView
|
|
35
|
-
* @param target optionally supply a WKBHeader object to avoid creating a new object for every call
|
|
36
|
-
* @returns a header object describing the WKB data
|
|
37
|
-
*/
|
|
38
|
-
export declare function parseWKBHeader(dataView: DataView, target?: WKBHeader): WKBHeader;
|
|
39
|
-
//# sourceMappingURL=parse-wkb-header.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-wkb-header.d.ts","sourceRoot":"","sources":["../../src/lib/parse-wkb-header.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,oBAAY,eAAe;IACzB,KAAK,IAAI;IACT,UAAU,IAAI;IACd,OAAO,IAAI;IACX,UAAU,IAAI;IACd,eAAe,IAAI;IACnB,YAAY,IAAI;IAChB,kBAAkB,IAAI;CACvB;AAED,wBAAwB;AACxB,MAAM,MAAM,SAAS,GAAG;IACtB,kBAAkB;IAClB,IAAI,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IAC1C,kEAAkE;IAClE,YAAY,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,+CAA+C;IAC/C,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACtB,wDAAwD;IACxD,WAAW,EAAE,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,YAAY,EAAE,OAAO,CAAC;IACtB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,2FAA2F;AAC3F,wBAAgB,KAAK,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAkDvD;AAED;;;;;GAKG;AAEH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,CAwEhF"}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
const EWKB_FLAG_Z = 0x80000000;
|
|
5
|
-
const EWKB_FLAG_M = 0x40000000;
|
|
6
|
-
const EWKB_FLAG_SRID = 0x20000000;
|
|
7
|
-
const MAX_SRID = 10000; // TBD: Assume no more than 10K SRIDs are defined
|
|
8
|
-
/**
|
|
9
|
-
* Integer code for geometry types in WKB and related formats
|
|
10
|
-
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
11
|
-
*/
|
|
12
|
-
export var WKBGeometryType;
|
|
13
|
-
(function (WKBGeometryType) {
|
|
14
|
-
WKBGeometryType[WKBGeometryType["Point"] = 1] = "Point";
|
|
15
|
-
WKBGeometryType[WKBGeometryType["LineString"] = 2] = "LineString";
|
|
16
|
-
WKBGeometryType[WKBGeometryType["Polygon"] = 3] = "Polygon";
|
|
17
|
-
WKBGeometryType[WKBGeometryType["MultiPoint"] = 4] = "MultiPoint";
|
|
18
|
-
WKBGeometryType[WKBGeometryType["MultiLineString"] = 5] = "MultiLineString";
|
|
19
|
-
WKBGeometryType[WKBGeometryType["MultiPolygon"] = 6] = "MultiPolygon";
|
|
20
|
-
WKBGeometryType[WKBGeometryType["GeometryCollection"] = 7] = "GeometryCollection";
|
|
21
|
-
})(WKBGeometryType || (WKBGeometryType = {}));
|
|
22
|
-
/** Sanity checks that first to 5-9 bytes could represent a supported WKB dialect header */
|
|
23
|
-
export function isWKB(arrayBuffer) {
|
|
24
|
-
const dataView = new DataView(arrayBuffer);
|
|
25
|
-
let byteOffset = 0;
|
|
26
|
-
const endianness = dataView.getUint8(byteOffset);
|
|
27
|
-
byteOffset += 1;
|
|
28
|
-
// Check valid endianness (only 0 or 1 are allowed)
|
|
29
|
-
if (endianness > 1) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
const littleEndian = endianness === 1;
|
|
33
|
-
const geometry = dataView.getUint32(byteOffset, littleEndian);
|
|
34
|
-
byteOffset += 4;
|
|
35
|
-
// check valid geometry type (we don't support extension geometries)
|
|
36
|
-
const geometryType = geometry & 0x07;
|
|
37
|
-
if (geometryType === 0 || geometryType > 7) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
const geometryFlags = geometry - geometryType;
|
|
41
|
-
// Accept iso-wkb flags
|
|
42
|
-
if (geometryFlags === 0 ||
|
|
43
|
-
geometryFlags === 1000 ||
|
|
44
|
-
geometryFlags === 2000 ||
|
|
45
|
-
geometryFlags === 3000) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
// Accept ewkb flags but reject otherwise
|
|
49
|
-
if ((geometryFlags & ~(EWKB_FLAG_Z | EWKB_FLAG_M | EWKB_FLAG_SRID)) !== 0) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
if (geometryFlags & EWKB_FLAG_SRID) {
|
|
53
|
-
const srid = dataView.getUint32(byteOffset, littleEndian);
|
|
54
|
-
byteOffset += 4;
|
|
55
|
-
if (srid > MAX_SRID) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Parses header and provides a byteOffset to start of geometry data
|
|
63
|
-
* @param dataView
|
|
64
|
-
* @param target optionally supply a WKBHeader object to avoid creating a new object for every call
|
|
65
|
-
* @returns a header object describing the WKB data
|
|
66
|
-
*/
|
|
67
|
-
// eslint-disable-next-line max-statements
|
|
68
|
-
export function parseWKBHeader(dataView, target) {
|
|
69
|
-
const wkbHeader = Object.assign(target || {}, {
|
|
70
|
-
type: 'wkb',
|
|
71
|
-
geometryType: 1,
|
|
72
|
-
dimensions: 2,
|
|
73
|
-
coordinates: 'xy',
|
|
74
|
-
littleEndian: true,
|
|
75
|
-
byteOffset: 0
|
|
76
|
-
});
|
|
77
|
-
// Check endianness of data
|
|
78
|
-
wkbHeader.littleEndian = dataView.getUint8(wkbHeader.byteOffset) === 1;
|
|
79
|
-
wkbHeader.byteOffset++;
|
|
80
|
-
// 4-digit code representing dimension and type of geometry
|
|
81
|
-
const geometryCode = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
82
|
-
wkbHeader.byteOffset += 4;
|
|
83
|
-
wkbHeader.geometryType = (geometryCode & 0x7);
|
|
84
|
-
// Check if iso-wkb variant: iso-wkb adds 1000, 2000 or 3000 to the geometry code
|
|
85
|
-
const isoType = (geometryCode - wkbHeader.geometryType) / 1000;
|
|
86
|
-
switch (isoType) {
|
|
87
|
-
case 0:
|
|
88
|
-
break;
|
|
89
|
-
case 1:
|
|
90
|
-
wkbHeader.type = 'iso-wkb';
|
|
91
|
-
wkbHeader.dimensions = 3;
|
|
92
|
-
wkbHeader.coordinates = 'xyz';
|
|
93
|
-
break;
|
|
94
|
-
case 2:
|
|
95
|
-
wkbHeader.type = 'iso-wkb';
|
|
96
|
-
wkbHeader.dimensions = 3;
|
|
97
|
-
wkbHeader.coordinates = 'xym';
|
|
98
|
-
break;
|
|
99
|
-
case 3:
|
|
100
|
-
wkbHeader.type = 'iso-wkb';
|
|
101
|
-
wkbHeader.dimensions = 4;
|
|
102
|
-
wkbHeader.coordinates = 'xyzm';
|
|
103
|
-
break;
|
|
104
|
-
default:
|
|
105
|
-
throw new Error(`WKB: Unsupported iso-wkb type: ${isoType}`);
|
|
106
|
-
}
|
|
107
|
-
// Check if EWKB variant. Uses bitmasks for Z&M dimensions as well as optional SRID field
|
|
108
|
-
const ewkbZ = geometryCode & EWKB_FLAG_Z;
|
|
109
|
-
const ewkbM = geometryCode & EWKB_FLAG_M;
|
|
110
|
-
const ewkbSRID = geometryCode & EWKB_FLAG_SRID;
|
|
111
|
-
if (ewkbZ && ewkbM) {
|
|
112
|
-
wkbHeader.type = 'ewkb';
|
|
113
|
-
wkbHeader.dimensions = 4;
|
|
114
|
-
wkbHeader.coordinates = 'xyzm';
|
|
115
|
-
}
|
|
116
|
-
else if (ewkbZ) {
|
|
117
|
-
wkbHeader.type = 'ewkb';
|
|
118
|
-
wkbHeader.dimensions = 3;
|
|
119
|
-
wkbHeader.coordinates = 'xyz';
|
|
120
|
-
}
|
|
121
|
-
else if (ewkbM) {
|
|
122
|
-
wkbHeader.type = 'ewkb';
|
|
123
|
-
wkbHeader.dimensions = 3;
|
|
124
|
-
wkbHeader.coordinates = 'xym';
|
|
125
|
-
}
|
|
126
|
-
// If SRID present read four more bytes
|
|
127
|
-
if (ewkbSRID) {
|
|
128
|
-
wkbHeader.type = 'ewkb';
|
|
129
|
-
// 4-digit code representing dimension and type of geometry
|
|
130
|
-
wkbHeader.srid = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
131
|
-
wkbHeader.byteOffset += 4;
|
|
132
|
-
}
|
|
133
|
-
return wkbHeader;
|
|
134
|
-
}
|
package/dist/lib/parse-wkb.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { BinaryGeometry, Geometry } from '@loaders.gl/schema';
|
|
2
|
-
import type { WKBLoaderOptions } from "../wkb-loader.js";
|
|
3
|
-
export declare function parseWKB(arrayBuffer: ArrayBuffer, options?: WKBLoaderOptions): BinaryGeometry | Geometry;
|
|
4
|
-
export declare function parseWKBToBinary(arrayBuffer: ArrayBuffer, options?: WKBLoaderOptions): BinaryGeometry;
|
|
5
|
-
//# sourceMappingURL=parse-wkb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-wkb.d.ts","sourceRoot":"","sources":["../../src/lib/parse-wkb.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,cAAc,EAId,QAAQ,EACT,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAC,gBAAgB,EAAC,yBAAsB;AAIpD,wBAAgB,QAAQ,CACtB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,gBAAgB,GACzB,cAAc,GAAG,QAAQ,CAe3B;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,gBAAgB,GACzB,cAAc,CAoChB"}
|
package/dist/lib/parse-wkb.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { binaryToGeometry } from '@loaders.gl/gis';
|
|
5
|
-
import { parseWKBHeader, WKBGeometryType } from "./parse-wkb-header.js";
|
|
6
|
-
export function parseWKB(arrayBuffer, options) {
|
|
7
|
-
const binaryGeometry = parseWKBToBinary(arrayBuffer, options);
|
|
8
|
-
const shape = options?.wkb?.shape || 'binary-geometry';
|
|
9
|
-
switch (shape) {
|
|
10
|
-
case 'binary-geometry':
|
|
11
|
-
return binaryGeometry;
|
|
12
|
-
case 'geojson-geometry':
|
|
13
|
-
return binaryToGeometry(binaryGeometry);
|
|
14
|
-
case 'geometry':
|
|
15
|
-
// eslint-disable-next-line no-console
|
|
16
|
-
console.error('WKBLoader: "geometry" shape is deprecated, use "binary-geometry" instead');
|
|
17
|
-
return binaryToGeometry(binaryGeometry);
|
|
18
|
-
default:
|
|
19
|
-
throw new Error(shape);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export function parseWKBToBinary(arrayBuffer, options) {
|
|
23
|
-
const dataView = new DataView(arrayBuffer);
|
|
24
|
-
const wkbHeader = parseWKBHeader(dataView);
|
|
25
|
-
const { geometryType, dimensions, littleEndian } = wkbHeader;
|
|
26
|
-
const offset = wkbHeader.byteOffset;
|
|
27
|
-
switch (geometryType) {
|
|
28
|
-
case WKBGeometryType.Point:
|
|
29
|
-
const point = parsePoint(dataView, offset, dimensions, littleEndian);
|
|
30
|
-
return point.geometry;
|
|
31
|
-
case WKBGeometryType.LineString:
|
|
32
|
-
const line = parseLineString(dataView, offset, dimensions, littleEndian);
|
|
33
|
-
return line.geometry;
|
|
34
|
-
case WKBGeometryType.Polygon:
|
|
35
|
-
const polygon = parsePolygon(dataView, offset, dimensions, littleEndian);
|
|
36
|
-
return polygon.geometry;
|
|
37
|
-
case WKBGeometryType.MultiPoint:
|
|
38
|
-
const multiPoint = parseMultiPoint(dataView, offset, dimensions, littleEndian);
|
|
39
|
-
multiPoint.type = 'Point';
|
|
40
|
-
return multiPoint;
|
|
41
|
-
case WKBGeometryType.MultiLineString:
|
|
42
|
-
const multiLine = parseMultiLineString(dataView, offset, dimensions, littleEndian);
|
|
43
|
-
multiLine.type = 'LineString';
|
|
44
|
-
return multiLine;
|
|
45
|
-
case WKBGeometryType.MultiPolygon:
|
|
46
|
-
const multiPolygon = parseMultiPolygon(dataView, offset, dimensions, littleEndian);
|
|
47
|
-
multiPolygon.type = 'Polygon';
|
|
48
|
-
return multiPolygon;
|
|
49
|
-
// case WKBGeometryType.GeometryCollection:
|
|
50
|
-
// TODO: handle GeometryCollections
|
|
51
|
-
// return parseGeometryCollection(dataView, offset, dimensions, littleEndian);
|
|
52
|
-
default:
|
|
53
|
-
throw new Error(`WKB: Unsupported geometry type: ${geometryType}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// Primitives; parse point and linear ring
|
|
57
|
-
function parsePoint(dataView, offset, dimension, littleEndian) {
|
|
58
|
-
const positions = new Float64Array(dimension);
|
|
59
|
-
for (let i = 0; i < dimension; i++) {
|
|
60
|
-
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
61
|
-
offset += 8;
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
geometry: { type: 'Point', positions: { value: positions, size: dimension } },
|
|
65
|
-
offset
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function parseLineString(dataView, offset, dimension, littleEndian) {
|
|
69
|
-
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
70
|
-
offset += 4;
|
|
71
|
-
// Instantiate array
|
|
72
|
-
const positions = new Float64Array(nPoints * dimension);
|
|
73
|
-
for (let i = 0; i < nPoints * dimension; i++) {
|
|
74
|
-
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
75
|
-
offset += 8;
|
|
76
|
-
}
|
|
77
|
-
const pathIndices = [0];
|
|
78
|
-
if (nPoints > 0) {
|
|
79
|
-
pathIndices.push(nPoints);
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
geometry: {
|
|
83
|
-
type: 'LineString',
|
|
84
|
-
positions: { value: positions, size: dimension },
|
|
85
|
-
pathIndices: { value: new Uint32Array(pathIndices), size: 1 }
|
|
86
|
-
},
|
|
87
|
-
offset
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
// https://stackoverflow.com/a/55261098
|
|
91
|
-
const cumulativeSum = (sum) => (value) => (sum += value);
|
|
92
|
-
function parsePolygon(dataView, offset, dimension, littleEndian) {
|
|
93
|
-
const nRings = dataView.getUint32(offset, littleEndian);
|
|
94
|
-
offset += 4;
|
|
95
|
-
const rings = [];
|
|
96
|
-
for (let i = 0; i < nRings; i++) {
|
|
97
|
-
const parsed = parseLineString(dataView, offset, dimension, littleEndian);
|
|
98
|
-
const { positions } = parsed.geometry;
|
|
99
|
-
offset = parsed.offset;
|
|
100
|
-
rings.push(positions.value);
|
|
101
|
-
}
|
|
102
|
-
const concatenatedPositions = new Float64Array(concatTypedArrays(rings).buffer);
|
|
103
|
-
const polygonIndices = [0];
|
|
104
|
-
if (concatenatedPositions.length > 0) {
|
|
105
|
-
polygonIndices.push(concatenatedPositions.length / dimension);
|
|
106
|
-
}
|
|
107
|
-
const primitivePolygonIndices = rings.map((l) => l.length / dimension).map(cumulativeSum(0));
|
|
108
|
-
primitivePolygonIndices.unshift(0);
|
|
109
|
-
return {
|
|
110
|
-
geometry: {
|
|
111
|
-
type: 'Polygon',
|
|
112
|
-
positions: { value: concatenatedPositions, size: dimension },
|
|
113
|
-
polygonIndices: {
|
|
114
|
-
value: new Uint32Array(polygonIndices),
|
|
115
|
-
size: 1
|
|
116
|
-
},
|
|
117
|
-
primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
|
|
118
|
-
},
|
|
119
|
-
offset
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
function parseMultiPoint(dataView, offset, dimension, littleEndian) {
|
|
123
|
-
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
124
|
-
offset += 4;
|
|
125
|
-
const binaryPointGeometries = [];
|
|
126
|
-
for (let i = 0; i < nPoints; i++) {
|
|
127
|
-
// Byte order for point
|
|
128
|
-
const littleEndianPoint = dataView.getUint8(offset) === 1;
|
|
129
|
-
offset++;
|
|
130
|
-
// Assert point type
|
|
131
|
-
if (dataView.getUint32(offset, littleEndianPoint) % 1000 !== 1) {
|
|
132
|
-
throw new Error('WKB: Inner geometries of MultiPoint not of type Point');
|
|
133
|
-
}
|
|
134
|
-
offset += 4;
|
|
135
|
-
const parsed = parsePoint(dataView, offset, dimension, littleEndianPoint);
|
|
136
|
-
offset = parsed.offset;
|
|
137
|
-
binaryPointGeometries.push(parsed.geometry);
|
|
138
|
-
}
|
|
139
|
-
return concatenateBinaryPointGeometries(binaryPointGeometries, dimension);
|
|
140
|
-
}
|
|
141
|
-
function parseMultiLineString(dataView, offset, dimension, littleEndian) {
|
|
142
|
-
const nLines = dataView.getUint32(offset, littleEndian);
|
|
143
|
-
offset += 4;
|
|
144
|
-
const binaryLineGeometries = [];
|
|
145
|
-
for (let i = 0; i < nLines; i++) {
|
|
146
|
-
// Byte order for line
|
|
147
|
-
const littleEndianLine = dataView.getUint8(offset) === 1;
|
|
148
|
-
offset++;
|
|
149
|
-
// Assert type LineString
|
|
150
|
-
if (dataView.getUint32(offset, littleEndianLine) % 1000 !== 2) {
|
|
151
|
-
throw new Error('WKB: Inner geometries of MultiLineString not of type LineString');
|
|
152
|
-
}
|
|
153
|
-
offset += 4;
|
|
154
|
-
const parsed = parseLineString(dataView, offset, dimension, littleEndianLine);
|
|
155
|
-
offset = parsed.offset;
|
|
156
|
-
binaryLineGeometries.push(parsed.geometry);
|
|
157
|
-
}
|
|
158
|
-
return concatenateBinaryLineGeometries(binaryLineGeometries, dimension);
|
|
159
|
-
}
|
|
160
|
-
function parseMultiPolygon(dataView, offset, dimension, littleEndian) {
|
|
161
|
-
const nPolygons = dataView.getUint32(offset, littleEndian);
|
|
162
|
-
offset += 4;
|
|
163
|
-
const binaryPolygonGeometries = [];
|
|
164
|
-
for (let i = 0; i < nPolygons; i++) {
|
|
165
|
-
// Byte order for polygon
|
|
166
|
-
const littleEndianPolygon = dataView.getUint8(offset) === 1;
|
|
167
|
-
offset++;
|
|
168
|
-
// Assert type Polygon
|
|
169
|
-
if (dataView.getUint32(offset, littleEndianPolygon) % 1000 !== 3) {
|
|
170
|
-
throw new Error('WKB: Inner geometries of MultiPolygon not of type Polygon');
|
|
171
|
-
}
|
|
172
|
-
offset += 4;
|
|
173
|
-
const parsed = parsePolygon(dataView, offset, dimension, littleEndianPolygon);
|
|
174
|
-
offset = parsed.offset;
|
|
175
|
-
binaryPolygonGeometries.push(parsed.geometry);
|
|
176
|
-
}
|
|
177
|
-
return concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension);
|
|
178
|
-
}
|
|
179
|
-
// TODO - move to loaders.gl/schema/gis
|
|
180
|
-
function concatenateBinaryPointGeometries(binaryPointGeometries, dimension) {
|
|
181
|
-
const positions = binaryPointGeometries.map((geometry) => geometry.positions.value);
|
|
182
|
-
const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
|
|
183
|
-
return {
|
|
184
|
-
type: 'Point',
|
|
185
|
-
positions: { value: concatenatedPositions, size: dimension }
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
|
|
189
|
-
const lines = binaryLineGeometries.map((geometry) => geometry.positions.value);
|
|
190
|
-
const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
|
|
191
|
-
const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
|
|
192
|
-
pathIndices.unshift(0);
|
|
193
|
-
return {
|
|
194
|
-
type: 'LineString',
|
|
195
|
-
positions: { value: concatenatedPositions, size: dimension },
|
|
196
|
-
pathIndices: { value: new Uint32Array(pathIndices), size: 1 }
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
|
|
200
|
-
const polygons = [];
|
|
201
|
-
const primitivePolygons = [];
|
|
202
|
-
for (const binaryPolygon of binaryPolygonGeometries) {
|
|
203
|
-
const { positions, primitivePolygonIndices } = binaryPolygon;
|
|
204
|
-
polygons.push(positions.value);
|
|
205
|
-
primitivePolygons.push(primitivePolygonIndices.value);
|
|
206
|
-
}
|
|
207
|
-
const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
|
|
208
|
-
const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
|
|
209
|
-
polygonIndices.unshift(0);
|
|
210
|
-
// Combine primitivePolygonIndices from each individual polygon
|
|
211
|
-
const primitivePolygonIndices = [0];
|
|
212
|
-
for (const primitivePolygon of primitivePolygons) {
|
|
213
|
-
primitivePolygonIndices.push(...primitivePolygon
|
|
214
|
-
.filter((x) => x > 0)
|
|
215
|
-
.map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
|
|
216
|
-
}
|
|
217
|
-
return {
|
|
218
|
-
type: 'Polygon',
|
|
219
|
-
positions: { value: concatenatedPositions, size: dimension },
|
|
220
|
-
polygonIndices: { value: new Uint32Array(polygonIndices), size: 1 },
|
|
221
|
-
primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
// TODO: remove copy; import from typed-array-utils
|
|
225
|
-
// modules/math/src/geometry/typed-arrays/typed-array-utils.js
|
|
226
|
-
function concatTypedArrays(arrays) {
|
|
227
|
-
let byteLength = 0;
|
|
228
|
-
for (let i = 0; i < arrays.length; ++i) {
|
|
229
|
-
byteLength += arrays[i].byteLength;
|
|
230
|
-
}
|
|
231
|
-
const buffer = new Uint8Array(byteLength);
|
|
232
|
-
let byteOffset = 0;
|
|
233
|
-
for (let i = 0; i < arrays.length; ++i) {
|
|
234
|
-
const data = new Uint8Array(arrays[i].buffer);
|
|
235
|
-
byteLength = data.length;
|
|
236
|
-
for (let j = 0; j < byteLength; ++j) {
|
|
237
|
-
buffer[byteOffset++] = data[j];
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return buffer;
|
|
241
|
-
}
|