@loaders.gl/wkt 4.3.1 → 4.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/src/lib/encode-wkb.ts
DELETED
|
@@ -1,390 +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
|
-
// Reference: https://www.ogc.org/standards/sfa
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
Feature,
|
|
9
|
-
Geometry,
|
|
10
|
-
Point,
|
|
11
|
-
MultiPoint,
|
|
12
|
-
LineString,
|
|
13
|
-
MultiLineString,
|
|
14
|
-
Polygon,
|
|
15
|
-
MultiPolygon,
|
|
16
|
-
GeometryCollection
|
|
17
|
-
} from '@loaders.gl/schema';
|
|
18
|
-
|
|
19
|
-
import {BinaryWriter} from './utils/binary-writer';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Integer code for geometry type
|
|
23
|
-
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
24
|
-
*/
|
|
25
|
-
export enum WKB {
|
|
26
|
-
Point = 1,
|
|
27
|
-
LineString = 2,
|
|
28
|
-
Polygon = 3,
|
|
29
|
-
MultiPoint = 4,
|
|
30
|
-
MultiLineString = 5,
|
|
31
|
-
MultiPolygon = 6,
|
|
32
|
-
GeometryCollection = 7
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Options for encodeWKB
|
|
37
|
-
*/
|
|
38
|
-
type WKBOptions = {
|
|
39
|
-
/** Does the GeoJSON input have Z values? */
|
|
40
|
-
hasZ?: boolean;
|
|
41
|
-
|
|
42
|
-
/** Does the GeoJSON input have M values? */
|
|
43
|
-
hasM?: boolean;
|
|
44
|
-
|
|
45
|
-
/** Spatial reference for input GeoJSON */
|
|
46
|
-
srid?: any;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Encodes a GeoJSON object into WKB
|
|
51
|
-
* @param geojson A GeoJSON Feature or Geometry
|
|
52
|
-
* @returns string
|
|
53
|
-
*/
|
|
54
|
-
export function encodeWKB(geometry: Geometry | Feature, options: WKBOptions = {}): ArrayBuffer {
|
|
55
|
-
if (geometry.type === 'Feature') {
|
|
56
|
-
geometry = geometry.geometry;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
switch (geometry.type) {
|
|
60
|
-
case 'Point':
|
|
61
|
-
return encodePoint(geometry.coordinates, options);
|
|
62
|
-
case 'LineString':
|
|
63
|
-
return encodeLineString(geometry.coordinates, options);
|
|
64
|
-
case 'Polygon':
|
|
65
|
-
return encodePolygon(geometry.coordinates, options);
|
|
66
|
-
case 'MultiPoint':
|
|
67
|
-
return encodeMultiPoint(geometry, options);
|
|
68
|
-
case 'MultiPolygon':
|
|
69
|
-
return encodeMultiPolygon(geometry, options);
|
|
70
|
-
case 'MultiLineString':
|
|
71
|
-
return encodeMultiLineString(geometry, options);
|
|
72
|
-
case 'GeometryCollection':
|
|
73
|
-
return encodeGeometryCollection(geometry, options);
|
|
74
|
-
default:
|
|
75
|
-
const exhaustiveCheck: never = geometry;
|
|
76
|
-
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Calculate the binary size (in the WKB encoding) of a specific GeoJSON geometry */
|
|
81
|
-
function getGeometrySize(geometry: Geometry, options: WKBOptions): number {
|
|
82
|
-
switch (geometry.type) {
|
|
83
|
-
case 'Point':
|
|
84
|
-
return getPointSize(options);
|
|
85
|
-
case 'LineString':
|
|
86
|
-
return getLineStringSize(geometry.coordinates, options);
|
|
87
|
-
case 'Polygon':
|
|
88
|
-
return getPolygonSize(geometry.coordinates, options);
|
|
89
|
-
case 'MultiPoint':
|
|
90
|
-
return getMultiPointSize(geometry, options);
|
|
91
|
-
case 'MultiPolygon':
|
|
92
|
-
return getMultiPolygonSize(geometry, options);
|
|
93
|
-
case 'MultiLineString':
|
|
94
|
-
return getMultiLineStringSize(geometry, options);
|
|
95
|
-
case 'GeometryCollection':
|
|
96
|
-
return getGeometryCollectionSize(geometry, options);
|
|
97
|
-
default:
|
|
98
|
-
const exhaustiveCheck: never = geometry;
|
|
99
|
-
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Encode Point geometry as WKB ArrayBuffer */
|
|
104
|
-
function encodePoint(coordinates: Point['coordinates'], options: WKBOptions): ArrayBuffer {
|
|
105
|
-
const writer = new BinaryWriter(getPointSize(options));
|
|
106
|
-
|
|
107
|
-
writer.writeInt8(1);
|
|
108
|
-
writeWkbType(writer, WKB.Point, options);
|
|
109
|
-
|
|
110
|
-
// I believe this special case is to handle writing Point(NaN, NaN) correctly
|
|
111
|
-
if (typeof coordinates[0] === 'undefined' && typeof coordinates[1] === 'undefined') {
|
|
112
|
-
writer.writeDoubleLE(NaN);
|
|
113
|
-
writer.writeDoubleLE(NaN);
|
|
114
|
-
|
|
115
|
-
if (options.hasZ) {
|
|
116
|
-
writer.writeDoubleLE(NaN);
|
|
117
|
-
}
|
|
118
|
-
if (options.hasM) {
|
|
119
|
-
writer.writeDoubleLE(NaN);
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
writeCoordinate(writer, coordinates, options);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return writer.arrayBuffer;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Write coordinate to buffer */
|
|
129
|
-
function writeCoordinate(
|
|
130
|
-
writer: BinaryWriter,
|
|
131
|
-
coordinate: Point['coordinates'],
|
|
132
|
-
options: WKBOptions
|
|
133
|
-
): void {
|
|
134
|
-
writer.writeDoubleLE(coordinate[0]);
|
|
135
|
-
writer.writeDoubleLE(coordinate[1]);
|
|
136
|
-
|
|
137
|
-
if (options.hasZ) {
|
|
138
|
-
writer.writeDoubleLE(coordinate[2]);
|
|
139
|
-
}
|
|
140
|
-
if (options.hasM) {
|
|
141
|
-
writer.writeDoubleLE(coordinate[3]);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/** Get encoded size of Point geometry */
|
|
146
|
-
function getPointSize(options: WKBOptions): number {
|
|
147
|
-
const coordinateSize = getCoordinateSize(options);
|
|
148
|
-
return 1 + 4 + coordinateSize;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** Encode LineString geometry as WKB ArrayBuffer */
|
|
152
|
-
function encodeLineString(
|
|
153
|
-
coordinates: LineString['coordinates'],
|
|
154
|
-
options: WKBOptions
|
|
155
|
-
): ArrayBuffer {
|
|
156
|
-
const size = getLineStringSize(coordinates, options);
|
|
157
|
-
|
|
158
|
-
const writer = new BinaryWriter(size);
|
|
159
|
-
|
|
160
|
-
writer.writeInt8(1);
|
|
161
|
-
|
|
162
|
-
writeWkbType(writer, WKB.LineString, options);
|
|
163
|
-
writer.writeUInt32LE(coordinates.length);
|
|
164
|
-
|
|
165
|
-
for (const coordinate of coordinates) {
|
|
166
|
-
writeCoordinate(writer, coordinate, options);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return writer.arrayBuffer;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** Get encoded size of LineString geometry */
|
|
173
|
-
function getLineStringSize(coordinates: LineString['coordinates'], options: WKBOptions): number {
|
|
174
|
-
const coordinateSize = getCoordinateSize(options);
|
|
175
|
-
|
|
176
|
-
return 1 + 4 + 4 + coordinates.length * coordinateSize;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/** Encode Polygon geometry as WKB ArrayBuffer */
|
|
180
|
-
function encodePolygon(coordinates: Polygon['coordinates'], options: WKBOptions): ArrayBuffer {
|
|
181
|
-
const writer = new BinaryWriter(getPolygonSize(coordinates, options));
|
|
182
|
-
|
|
183
|
-
writer.writeInt8(1);
|
|
184
|
-
|
|
185
|
-
writeWkbType(writer, WKB.Polygon, options);
|
|
186
|
-
const [exteriorRing, ...interiorRings] = coordinates;
|
|
187
|
-
|
|
188
|
-
if (exteriorRing.length > 0) {
|
|
189
|
-
writer.writeUInt32LE(1 + interiorRings.length);
|
|
190
|
-
writer.writeUInt32LE(exteriorRing.length);
|
|
191
|
-
} else {
|
|
192
|
-
writer.writeUInt32LE(0);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
for (const coordinate of exteriorRing) {
|
|
196
|
-
writeCoordinate(writer, coordinate, options);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
for (const interiorRing of interiorRings) {
|
|
200
|
-
writer.writeUInt32LE(interiorRing.length);
|
|
201
|
-
|
|
202
|
-
for (const coordinate of interiorRing) {
|
|
203
|
-
writeCoordinate(writer, coordinate, options);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return writer.arrayBuffer;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/** Get encoded size of Polygon geometry */
|
|
211
|
-
function getPolygonSize(coordinates: Polygon['coordinates'], options: WKBOptions): number {
|
|
212
|
-
const coordinateSize = getCoordinateSize(options);
|
|
213
|
-
const [exteriorRing, ...interiorRings] = coordinates;
|
|
214
|
-
|
|
215
|
-
let size = 1 + 4 + 4;
|
|
216
|
-
|
|
217
|
-
if (exteriorRing.length > 0) {
|
|
218
|
-
size += 4 + exteriorRing.length * coordinateSize;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
for (const interiorRing of interiorRings) {
|
|
222
|
-
size += 4 + interiorRing.length * coordinateSize;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return size;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/** Encode MultiPoint geometry as WKB ArrayBufer */
|
|
229
|
-
function encodeMultiPoint(multiPoint: MultiPoint, options: WKBOptions) {
|
|
230
|
-
const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
|
|
231
|
-
const points = multiPoint.coordinates;
|
|
232
|
-
|
|
233
|
-
writer.writeInt8(1);
|
|
234
|
-
|
|
235
|
-
writeWkbType(writer, WKB.MultiPoint, options);
|
|
236
|
-
writer.writeUInt32LE(points.length);
|
|
237
|
-
|
|
238
|
-
for (const point of points) {
|
|
239
|
-
// TODO: add srid to this options object? {srid: multiPoint.srid}
|
|
240
|
-
const arrayBuffer = encodePoint(point, options);
|
|
241
|
-
writer.writeBuffer(arrayBuffer);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return writer.arrayBuffer;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/** Get encoded size of MultiPoint geometry */
|
|
248
|
-
function getMultiPointSize(multiPoint: MultiPoint, options: WKBOptions) {
|
|
249
|
-
let coordinateSize = getCoordinateSize(options);
|
|
250
|
-
const points = multiPoint.coordinates;
|
|
251
|
-
|
|
252
|
-
// This is because each point has a 5-byte header?
|
|
253
|
-
coordinateSize += 5;
|
|
254
|
-
|
|
255
|
-
return 1 + 4 + 4 + points.length * coordinateSize;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** Encode MultiLineString geometry as WKB ArrayBufer */
|
|
259
|
-
function encodeMultiLineString(multiLineString: MultiLineString, options: WKBOptions) {
|
|
260
|
-
const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
|
|
261
|
-
const lineStrings = multiLineString.coordinates;
|
|
262
|
-
|
|
263
|
-
writer.writeInt8(1);
|
|
264
|
-
|
|
265
|
-
writeWkbType(writer, WKB.MultiLineString, options);
|
|
266
|
-
writer.writeUInt32LE(lineStrings.length);
|
|
267
|
-
|
|
268
|
-
for (const lineString of lineStrings) {
|
|
269
|
-
// TODO: Handle srid?
|
|
270
|
-
const encodedLineString = encodeLineString(lineString, options);
|
|
271
|
-
writer.writeBuffer(encodedLineString);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return writer.arrayBuffer;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/** Get encoded size of MultiLineString geometry */
|
|
278
|
-
function getMultiLineStringSize(multiLineString: MultiLineString, options: WKBOptions): number {
|
|
279
|
-
let size = 1 + 4 + 4;
|
|
280
|
-
const lineStrings = multiLineString.coordinates;
|
|
281
|
-
|
|
282
|
-
for (const lineString of lineStrings) {
|
|
283
|
-
size += getLineStringSize(lineString, options);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return size;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
function encodeMultiPolygon(multiPolygon: MultiPolygon, options: WKBOptions): ArrayBuffer {
|
|
290
|
-
const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
|
|
291
|
-
const polygons = multiPolygon.coordinates;
|
|
292
|
-
|
|
293
|
-
writer.writeInt8(1);
|
|
294
|
-
|
|
295
|
-
writeWkbType(writer, WKB.MultiPolygon, options);
|
|
296
|
-
writer.writeUInt32LE(polygons.length);
|
|
297
|
-
|
|
298
|
-
for (const polygon of polygons) {
|
|
299
|
-
const encodedPolygon = encodePolygon(polygon, options);
|
|
300
|
-
writer.writeBuffer(encodedPolygon);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return writer.arrayBuffer;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function getMultiPolygonSize(multiPolygon: MultiPolygon, options: WKBOptions): number {
|
|
307
|
-
let size = 1 + 4 + 4;
|
|
308
|
-
const polygons = multiPolygon.coordinates;
|
|
309
|
-
|
|
310
|
-
for (const polygon of polygons) {
|
|
311
|
-
size += getPolygonSize(polygon, options);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return size;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function encodeGeometryCollection(
|
|
318
|
-
collection: GeometryCollection,
|
|
319
|
-
options: WKBOptions
|
|
320
|
-
): ArrayBuffer {
|
|
321
|
-
const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
|
|
322
|
-
|
|
323
|
-
writer.writeInt8(1);
|
|
324
|
-
|
|
325
|
-
writeWkbType(writer, WKB.GeometryCollection, options);
|
|
326
|
-
writer.writeUInt32LE(collection.geometries.length);
|
|
327
|
-
|
|
328
|
-
for (const geometry of collection.geometries) {
|
|
329
|
-
// TODO: handle srid? {srid: collection.srid}
|
|
330
|
-
const arrayBuffer = encodeWKB(geometry, options);
|
|
331
|
-
writer.writeBuffer(arrayBuffer);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return writer.arrayBuffer;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function getGeometryCollectionSize(collection: GeometryCollection, options: WKBOptions): number {
|
|
338
|
-
let size = 1 + 4 + 4;
|
|
339
|
-
|
|
340
|
-
for (const geometry of collection.geometries) {
|
|
341
|
-
size += getGeometrySize(geometry, options);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return size;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// HELPERS
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Construct and write WKB integer code
|
|
351
|
-
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
352
|
-
*/
|
|
353
|
-
function writeWkbType(writer: BinaryWriter, geometryType: number, options: WKBOptions): void {
|
|
354
|
-
const {hasZ, hasM, srid} = options;
|
|
355
|
-
|
|
356
|
-
let dimensionType = 0;
|
|
357
|
-
|
|
358
|
-
if (!srid) {
|
|
359
|
-
if (hasZ && hasM) {
|
|
360
|
-
dimensionType += 3000;
|
|
361
|
-
} else if (hasZ) {
|
|
362
|
-
dimensionType += 1000;
|
|
363
|
-
} else if (hasM) {
|
|
364
|
-
dimensionType += 2000;
|
|
365
|
-
}
|
|
366
|
-
} else {
|
|
367
|
-
if (hasZ) {
|
|
368
|
-
dimensionType |= 0x80000000;
|
|
369
|
-
}
|
|
370
|
-
if (hasM) {
|
|
371
|
-
dimensionType |= 0x40000000;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
writer.writeUInt32LE((dimensionType + geometryType) >>> 0);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/** Get coordinate size given Z/M dimensions */
|
|
379
|
-
function getCoordinateSize(options: WKBOptions): number {
|
|
380
|
-
let coordinateSize = 16;
|
|
381
|
-
|
|
382
|
-
if (options.hasZ) {
|
|
383
|
-
coordinateSize += 8;
|
|
384
|
-
}
|
|
385
|
-
if (options.hasM) {
|
|
386
|
-
coordinateSize += 8;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
return coordinateSize;
|
|
390
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// parse-wkt-crs was forked from https://github.com/DanielJDufour/wkt-crs under Creative Commons CC0 1.0 license.
|
|
5
|
-
|
|
6
|
-
import type {WKTCRS} from './parse-wkt-crs';
|
|
7
|
-
|
|
8
|
-
export type EncodeWKTCRSOptions = {
|
|
9
|
-
debug?: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* convert JSON representation of Well-Known Text
|
|
14
|
-
* back to standard Well-Known Text
|
|
15
|
-
*/
|
|
16
|
-
export function encodeWKTCRS(wkt: WKTCRS, options?: EncodeWKTCRSOptions): string {
|
|
17
|
-
if (Array.isArray(wkt) && wkt.length === 1 && Array.isArray(wkt[0])) {
|
|
18
|
-
wkt = wkt[0]; // ignore first extra wrapper array
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const [kw, ...attrs] = wkt;
|
|
22
|
-
const str = `${kw}[${attrs
|
|
23
|
-
.map((attr) => {
|
|
24
|
-
if (Array.isArray(attr)) {
|
|
25
|
-
return encodeWKTCRS(attr, options);
|
|
26
|
-
} else if (typeof attr === 'number') {
|
|
27
|
-
return attr.toString();
|
|
28
|
-
} else if (typeof attr === 'string') {
|
|
29
|
-
// can't automatically convert all caps to varibale
|
|
30
|
-
// because EPSG is string in AUTHORITY["EPSG", ...]
|
|
31
|
-
if (attr.startsWith('raw:')) {
|
|
32
|
-
// convert "raw:NORTH" to NORTH
|
|
33
|
-
return attr.replace('raw:', '');
|
|
34
|
-
}
|
|
35
|
-
return `"${attr}"`;
|
|
36
|
-
}
|
|
37
|
-
throw new Error(`[wktcrs] unexpected attribute "${attr}"`);
|
|
38
|
-
})
|
|
39
|
-
.join(',')}]`;
|
|
40
|
-
return str;
|
|
41
|
-
}
|
package/src/lib/encode-wkt.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Fork of https://github.com/mapbox/wellknown under ISC license (MIT/BSD-2-clause equivalent)
|
|
5
|
-
|
|
6
|
-
import type {Feature, Geometry} from '@loaders.gl/schema';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Stringifies a GeoJSON object into WKT
|
|
10
|
-
* @param geojson
|
|
11
|
-
* @returns string
|
|
12
|
-
*/
|
|
13
|
-
export function encodeWKT(geometry: Geometry | Feature): string {
|
|
14
|
-
if (geometry.type === 'Feature') {
|
|
15
|
-
geometry = geometry.geometry;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
switch (geometry.type) {
|
|
19
|
-
case 'Point':
|
|
20
|
-
return `POINT ${wrapParens(pairWKT(geometry.coordinates))}`;
|
|
21
|
-
case 'LineString':
|
|
22
|
-
return `LINESTRING ${wrapParens(ringWKT(geometry.coordinates))}`;
|
|
23
|
-
case 'Polygon':
|
|
24
|
-
return `POLYGON ${wrapParens(ringsWKT(geometry.coordinates))}`;
|
|
25
|
-
case 'MultiPoint':
|
|
26
|
-
return `MULTIPOINT ${wrapParens(ringWKT(geometry.coordinates))}`;
|
|
27
|
-
case 'MultiPolygon':
|
|
28
|
-
return `MULTIPOLYGON ${wrapParens(multiRingsWKT(geometry.coordinates))}`;
|
|
29
|
-
case 'MultiLineString':
|
|
30
|
-
return `MULTILINESTRING ${wrapParens(ringsWKT(geometry.coordinates))}`;
|
|
31
|
-
case 'GeometryCollection':
|
|
32
|
-
return `GEOMETRYCOLLECTION ${wrapParens(geometry.geometries.map(encodeWKT).join(', '))}`;
|
|
33
|
-
default:
|
|
34
|
-
throw new Error('stringify requires a valid GeoJSON Feature or geometry object as input');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function pairWKT(c: number[]): string {
|
|
39
|
-
return c.join(' ');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function ringWKT(r: number[][]): string {
|
|
43
|
-
return r.map(pairWKT).join(', ');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function ringsWKT(r: number[][][]): string {
|
|
47
|
-
return r.map(ringWKT).map(wrapParens).join(', ');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function multiRingsWKT(r: number[][][][]): string {
|
|
51
|
-
return r.map(ringsWKT).map(wrapParens).join(', ');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function wrapParens(s: string): string {
|
|
55
|
-
return `(${s})`;
|
|
56
|
-
}
|
package/src/lib/parse-hex-wkb.ts
DELETED
|
File without changes
|