@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/dist/lib/encode-twkb.js
DELETED
|
@@ -1,195 +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 { BinaryWriter } from "./utils/binary-writer.js";
|
|
6
|
-
import { WKBGeometryType } from "./parse-wkb-header.js";
|
|
7
|
-
export function encodeTWKB(geometry, options) {
|
|
8
|
-
const writer = new BinaryWriter(0, true);
|
|
9
|
-
const context = {
|
|
10
|
-
...getTwkbPrecision(5, 0, 0),
|
|
11
|
-
hasZ: options?.hasZ,
|
|
12
|
-
hasM: options?.hasM
|
|
13
|
-
};
|
|
14
|
-
encodeGeometry(writer, geometry, context);
|
|
15
|
-
// TODO - we need to slice it?
|
|
16
|
-
return writer.arrayBuffer;
|
|
17
|
-
}
|
|
18
|
-
function encodeGeometry(writer, geometry, context) {
|
|
19
|
-
switch (geometry.type) {
|
|
20
|
-
case 'Point':
|
|
21
|
-
return encodePoint(writer, context, geometry);
|
|
22
|
-
case 'LineString':
|
|
23
|
-
return encodeLineString(writer, context, geometry);
|
|
24
|
-
case 'Polygon':
|
|
25
|
-
return encodePolygon(writer, context, geometry);
|
|
26
|
-
case 'MultiPoint':
|
|
27
|
-
return encodeMultiPoint(writer, context, geometry);
|
|
28
|
-
case 'MultiLineString':
|
|
29
|
-
return encodeMultiLineString(writer, context, geometry);
|
|
30
|
-
case 'MultiPolygon':
|
|
31
|
-
return encodeMultiPolygon(writer, context, geometry);
|
|
32
|
-
case 'GeometryCollection':
|
|
33
|
-
return encodeGeometryCollection(writer, context, geometry);
|
|
34
|
-
default:
|
|
35
|
-
throw new Error('unsupported geometry type');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function encodePoint(writer, context, point) {
|
|
39
|
-
const isEmpty = point.coordinates.length === 0 || point[0] === 'undefined' || point[1] === 'undefined';
|
|
40
|
-
writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
|
|
41
|
-
if (!isEmpty) {
|
|
42
|
-
const previousPoint = [0, 0, 0, 0];
|
|
43
|
-
writeTwkbPoint(writer, context, point.coordinates, previousPoint);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function encodeLineString(writer, context, lineString) {
|
|
47
|
-
const points = lineString.coordinates;
|
|
48
|
-
const isEmpty = points.length === 0;
|
|
49
|
-
writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
|
|
50
|
-
if (!isEmpty) {
|
|
51
|
-
writer.writeVarInt(points.length);
|
|
52
|
-
const previousPoint = [0, 0, 0, 0];
|
|
53
|
-
for (const point of points) {
|
|
54
|
-
writeTwkbPoint(writer, context, point, previousPoint);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return writer.arrayBuffer;
|
|
58
|
-
}
|
|
59
|
-
function encodePolygon(writer, context, polygon) {
|
|
60
|
-
const polygonRings = polygon.coordinates;
|
|
61
|
-
const isEmpty = polygonRings.length === 0;
|
|
62
|
-
writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
|
|
63
|
-
if (!isEmpty) {
|
|
64
|
-
writer.writeVarInt(polygonRings.length);
|
|
65
|
-
const previousPoint = [0, 0, 0, 0];
|
|
66
|
-
for (const ring of polygonRings) {
|
|
67
|
-
writer.writeVarInt(ring.length);
|
|
68
|
-
for (const point of ring) {
|
|
69
|
-
writeTwkbPoint(writer, context, previousPoint, point);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return writer.arrayBuffer;
|
|
74
|
-
}
|
|
75
|
-
function encodeMultiPoint(writer, context, multiPoint) {
|
|
76
|
-
const points = multiPoint.coordinates;
|
|
77
|
-
const isEmpty = points.length === 0;
|
|
78
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
|
|
79
|
-
if (!isEmpty) {
|
|
80
|
-
writer.writeVarInt(points.length);
|
|
81
|
-
const previousPoint = [0, 0, 0, 0];
|
|
82
|
-
for (let i = 0; i < points.length; i++) {
|
|
83
|
-
writeTwkbPoint(writer, context, previousPoint, points[i]);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function encodeMultiLineString(writer, context, multiLineStrings) {
|
|
88
|
-
const lineStrings = multiLineStrings.coordinates;
|
|
89
|
-
const isEmpty = lineStrings.length === 0;
|
|
90
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
|
|
91
|
-
if (!isEmpty) {
|
|
92
|
-
writer.writeVarInt(lineStrings.length);
|
|
93
|
-
const previousPoint = [0, 0, 0, 0];
|
|
94
|
-
for (const lineString of lineStrings) {
|
|
95
|
-
writer.writeVarInt(lineString.length);
|
|
96
|
-
for (const point of lineString) {
|
|
97
|
-
writeTwkbPoint(writer, context, previousPoint, point);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return writer.arrayBuffer;
|
|
102
|
-
}
|
|
103
|
-
function encodeMultiPolygon(writer, context, multiPolygon) {
|
|
104
|
-
const { coordinates } = multiPolygon;
|
|
105
|
-
const isEmpty = coordinates.length === 0;
|
|
106
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
|
|
107
|
-
if (!isEmpty) {
|
|
108
|
-
const polygons = coordinates;
|
|
109
|
-
writer.writeVarInt(polygons.length);
|
|
110
|
-
const previousPoint = [0, 0, 0, 0];
|
|
111
|
-
for (const polygonRings of polygons) {
|
|
112
|
-
writer.writeVarInt(polygonRings.length);
|
|
113
|
-
for (const ring of polygonRings) {
|
|
114
|
-
writer.writeVarInt(ring.length);
|
|
115
|
-
for (const point of ring) {
|
|
116
|
-
writeTwkbPoint(writer, context, previousPoint, point);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function encodeGeometryCollection(writer, context, geometryCollection) {
|
|
123
|
-
const { geometries } = geometryCollection;
|
|
124
|
-
const isEmpty = geometries.length === 0;
|
|
125
|
-
writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
|
|
126
|
-
if (geometries.length > 0) {
|
|
127
|
-
writer.writeVarInt(geometries.length);
|
|
128
|
-
for (const geometry of geometries) {
|
|
129
|
-
encodeGeometry(writer, geometry, context);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
*
|
|
135
|
-
* @param writer
|
|
136
|
-
* @param context
|
|
137
|
-
* @param geometryType
|
|
138
|
-
* @param isEmpty
|
|
139
|
-
*/
|
|
140
|
-
function writeTwkbHeader(writer, context, geometryType, isEmpty) {
|
|
141
|
-
const type = (zigZagEncode(context.xy) << 4) + geometryType;
|
|
142
|
-
let metadataHeader = context.hasZ || context.hasM ? 1 << 3 : 0;
|
|
143
|
-
metadataHeader += isEmpty ? 1 << 4 : 0;
|
|
144
|
-
writer.writeUInt8(type);
|
|
145
|
-
writer.writeUInt8(metadataHeader);
|
|
146
|
-
if (context.hasZ || context.hasM) {
|
|
147
|
-
let extendedPrecision = 0;
|
|
148
|
-
if (context.hasZ) {
|
|
149
|
-
extendedPrecision |= 0x1;
|
|
150
|
-
}
|
|
151
|
-
if (context.hasM) {
|
|
152
|
-
extendedPrecision |= 0x2;
|
|
153
|
-
}
|
|
154
|
-
writer.writeUInt8(extendedPrecision);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Write one point to array buffer. ZigZagEncoding the delta fdrom the previous point. Mutates previousPoint.
|
|
159
|
-
* @param writer
|
|
160
|
-
* @param context
|
|
161
|
-
* @param previousPoint - Mutated by this function
|
|
162
|
-
* @param point
|
|
163
|
-
*/
|
|
164
|
-
function writeTwkbPoint(writer, context, point, previousPoint) {
|
|
165
|
-
const x = point[0] * context.xyFactor;
|
|
166
|
-
const y = point[1] * context.xyFactor;
|
|
167
|
-
const z = point[2] * context.zFactor;
|
|
168
|
-
const m = point[3] * context.mFactor;
|
|
169
|
-
writer.writeVarInt(zigZagEncode(x - previousPoint[0]));
|
|
170
|
-
writer.writeVarInt(zigZagEncode(y - previousPoint[1]));
|
|
171
|
-
if (context.hasZ) {
|
|
172
|
-
writer.writeVarInt(zigZagEncode(z - previousPoint[2]));
|
|
173
|
-
}
|
|
174
|
-
if (context.hasM) {
|
|
175
|
-
writer.writeVarInt(zigZagEncode(m - previousPoint[3]));
|
|
176
|
-
}
|
|
177
|
-
previousPoint[0] = x;
|
|
178
|
-
previousPoint[1] = y;
|
|
179
|
-
previousPoint[2] = z;
|
|
180
|
-
previousPoint[3] = m;
|
|
181
|
-
}
|
|
182
|
-
// HELPERS
|
|
183
|
-
function zigZagEncode(value) {
|
|
184
|
-
return (value << 1) ^ (value >> 31);
|
|
185
|
-
}
|
|
186
|
-
function getTwkbPrecision(xyPrecision, zPrecision, mPrecision) {
|
|
187
|
-
return {
|
|
188
|
-
xy: xyPrecision,
|
|
189
|
-
z: zPrecision,
|
|
190
|
-
m: mPrecision,
|
|
191
|
-
xyFactor: Math.pow(10, xyPrecision),
|
|
192
|
-
zFactor: Math.pow(10, zPrecision),
|
|
193
|
-
mFactor: Math.pow(10, mPrecision)
|
|
194
|
-
};
|
|
195
|
-
}
|
package/dist/lib/encode-wkb.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Feature, Geometry } from '@loaders.gl/schema';
|
|
2
|
-
/**
|
|
3
|
-
* Integer code for geometry type
|
|
4
|
-
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
5
|
-
*/
|
|
6
|
-
export declare enum WKB {
|
|
7
|
-
Point = 1,
|
|
8
|
-
LineString = 2,
|
|
9
|
-
Polygon = 3,
|
|
10
|
-
MultiPoint = 4,
|
|
11
|
-
MultiLineString = 5,
|
|
12
|
-
MultiPolygon = 6,
|
|
13
|
-
GeometryCollection = 7
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Options for encodeWKB
|
|
17
|
-
*/
|
|
18
|
-
type WKBOptions = {
|
|
19
|
-
/** Does the GeoJSON input have Z values? */
|
|
20
|
-
hasZ?: boolean;
|
|
21
|
-
/** Does the GeoJSON input have M values? */
|
|
22
|
-
hasM?: boolean;
|
|
23
|
-
/** Spatial reference for input GeoJSON */
|
|
24
|
-
srid?: any;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Encodes a GeoJSON object into WKB
|
|
28
|
-
* @param geojson A GeoJSON Feature or Geometry
|
|
29
|
-
* @returns string
|
|
30
|
-
*/
|
|
31
|
-
export declare function encodeWKB(geometry: Geometry | Feature, options?: WKBOptions): ArrayBuffer;
|
|
32
|
-
export {};
|
|
33
|
-
//# sourceMappingURL=encode-wkb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encode-wkb.d.ts","sourceRoot":"","sources":["../../src/lib/encode-wkb.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EAQT,MAAM,oBAAoB,CAAC;AAI5B;;;GAGG;AACH,oBAAY,GAAG;IACb,KAAK,IAAI;IACT,UAAU,IAAI;IACd,OAAO,IAAI;IACX,UAAU,IAAI;IACd,eAAe,IAAI;IACnB,YAAY,IAAI;IAChB,kBAAkB,IAAI;CACvB;AAED;;GAEG;AACH,KAAK,UAAU,GAAG;IAChB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,4CAA4C;IAC5C,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,0CAA0C;IAC1C,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,EAAE,OAAO,GAAE,UAAe,GAAG,WAAW,CAwB7F"}
|
package/dist/lib/encode-wkb.js
DELETED
|
@@ -1,286 +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
|
-
import { BinaryWriter } from "./utils/binary-writer.js";
|
|
7
|
-
/**
|
|
8
|
-
* Integer code for geometry type
|
|
9
|
-
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
10
|
-
*/
|
|
11
|
-
export var WKB;
|
|
12
|
-
(function (WKB) {
|
|
13
|
-
WKB[WKB["Point"] = 1] = "Point";
|
|
14
|
-
WKB[WKB["LineString"] = 2] = "LineString";
|
|
15
|
-
WKB[WKB["Polygon"] = 3] = "Polygon";
|
|
16
|
-
WKB[WKB["MultiPoint"] = 4] = "MultiPoint";
|
|
17
|
-
WKB[WKB["MultiLineString"] = 5] = "MultiLineString";
|
|
18
|
-
WKB[WKB["MultiPolygon"] = 6] = "MultiPolygon";
|
|
19
|
-
WKB[WKB["GeometryCollection"] = 7] = "GeometryCollection";
|
|
20
|
-
})(WKB || (WKB = {}));
|
|
21
|
-
/**
|
|
22
|
-
* Encodes a GeoJSON object into WKB
|
|
23
|
-
* @param geojson A GeoJSON Feature or Geometry
|
|
24
|
-
* @returns string
|
|
25
|
-
*/
|
|
26
|
-
export function encodeWKB(geometry, options = {}) {
|
|
27
|
-
if (geometry.type === 'Feature') {
|
|
28
|
-
geometry = geometry.geometry;
|
|
29
|
-
}
|
|
30
|
-
switch (geometry.type) {
|
|
31
|
-
case 'Point':
|
|
32
|
-
return encodePoint(geometry.coordinates, options);
|
|
33
|
-
case 'LineString':
|
|
34
|
-
return encodeLineString(geometry.coordinates, options);
|
|
35
|
-
case 'Polygon':
|
|
36
|
-
return encodePolygon(geometry.coordinates, options);
|
|
37
|
-
case 'MultiPoint':
|
|
38
|
-
return encodeMultiPoint(geometry, options);
|
|
39
|
-
case 'MultiPolygon':
|
|
40
|
-
return encodeMultiPolygon(geometry, options);
|
|
41
|
-
case 'MultiLineString':
|
|
42
|
-
return encodeMultiLineString(geometry, options);
|
|
43
|
-
case 'GeometryCollection':
|
|
44
|
-
return encodeGeometryCollection(geometry, options);
|
|
45
|
-
default:
|
|
46
|
-
const exhaustiveCheck = geometry;
|
|
47
|
-
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/** Calculate the binary size (in the WKB encoding) of a specific GeoJSON geometry */
|
|
51
|
-
function getGeometrySize(geometry, options) {
|
|
52
|
-
switch (geometry.type) {
|
|
53
|
-
case 'Point':
|
|
54
|
-
return getPointSize(options);
|
|
55
|
-
case 'LineString':
|
|
56
|
-
return getLineStringSize(geometry.coordinates, options);
|
|
57
|
-
case 'Polygon':
|
|
58
|
-
return getPolygonSize(geometry.coordinates, options);
|
|
59
|
-
case 'MultiPoint':
|
|
60
|
-
return getMultiPointSize(geometry, options);
|
|
61
|
-
case 'MultiPolygon':
|
|
62
|
-
return getMultiPolygonSize(geometry, options);
|
|
63
|
-
case 'MultiLineString':
|
|
64
|
-
return getMultiLineStringSize(geometry, options);
|
|
65
|
-
case 'GeometryCollection':
|
|
66
|
-
return getGeometryCollectionSize(geometry, options);
|
|
67
|
-
default:
|
|
68
|
-
const exhaustiveCheck = geometry;
|
|
69
|
-
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/** Encode Point geometry as WKB ArrayBuffer */
|
|
73
|
-
function encodePoint(coordinates, options) {
|
|
74
|
-
const writer = new BinaryWriter(getPointSize(options));
|
|
75
|
-
writer.writeInt8(1);
|
|
76
|
-
writeWkbType(writer, WKB.Point, options);
|
|
77
|
-
// I believe this special case is to handle writing Point(NaN, NaN) correctly
|
|
78
|
-
if (typeof coordinates[0] === 'undefined' && typeof coordinates[1] === 'undefined') {
|
|
79
|
-
writer.writeDoubleLE(NaN);
|
|
80
|
-
writer.writeDoubleLE(NaN);
|
|
81
|
-
if (options.hasZ) {
|
|
82
|
-
writer.writeDoubleLE(NaN);
|
|
83
|
-
}
|
|
84
|
-
if (options.hasM) {
|
|
85
|
-
writer.writeDoubleLE(NaN);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
writeCoordinate(writer, coordinates, options);
|
|
90
|
-
}
|
|
91
|
-
return writer.arrayBuffer;
|
|
92
|
-
}
|
|
93
|
-
/** Write coordinate to buffer */
|
|
94
|
-
function writeCoordinate(writer, coordinate, options) {
|
|
95
|
-
writer.writeDoubleLE(coordinate[0]);
|
|
96
|
-
writer.writeDoubleLE(coordinate[1]);
|
|
97
|
-
if (options.hasZ) {
|
|
98
|
-
writer.writeDoubleLE(coordinate[2]);
|
|
99
|
-
}
|
|
100
|
-
if (options.hasM) {
|
|
101
|
-
writer.writeDoubleLE(coordinate[3]);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/** Get encoded size of Point geometry */
|
|
105
|
-
function getPointSize(options) {
|
|
106
|
-
const coordinateSize = getCoordinateSize(options);
|
|
107
|
-
return 1 + 4 + coordinateSize;
|
|
108
|
-
}
|
|
109
|
-
/** Encode LineString geometry as WKB ArrayBuffer */
|
|
110
|
-
function encodeLineString(coordinates, options) {
|
|
111
|
-
const size = getLineStringSize(coordinates, options);
|
|
112
|
-
const writer = new BinaryWriter(size);
|
|
113
|
-
writer.writeInt8(1);
|
|
114
|
-
writeWkbType(writer, WKB.LineString, options);
|
|
115
|
-
writer.writeUInt32LE(coordinates.length);
|
|
116
|
-
for (const coordinate of coordinates) {
|
|
117
|
-
writeCoordinate(writer, coordinate, options);
|
|
118
|
-
}
|
|
119
|
-
return writer.arrayBuffer;
|
|
120
|
-
}
|
|
121
|
-
/** Get encoded size of LineString geometry */
|
|
122
|
-
function getLineStringSize(coordinates, options) {
|
|
123
|
-
const coordinateSize = getCoordinateSize(options);
|
|
124
|
-
return 1 + 4 + 4 + coordinates.length * coordinateSize;
|
|
125
|
-
}
|
|
126
|
-
/** Encode Polygon geometry as WKB ArrayBuffer */
|
|
127
|
-
function encodePolygon(coordinates, options) {
|
|
128
|
-
const writer = new BinaryWriter(getPolygonSize(coordinates, options));
|
|
129
|
-
writer.writeInt8(1);
|
|
130
|
-
writeWkbType(writer, WKB.Polygon, options);
|
|
131
|
-
const [exteriorRing, ...interiorRings] = coordinates;
|
|
132
|
-
if (exteriorRing.length > 0) {
|
|
133
|
-
writer.writeUInt32LE(1 + interiorRings.length);
|
|
134
|
-
writer.writeUInt32LE(exteriorRing.length);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
writer.writeUInt32LE(0);
|
|
138
|
-
}
|
|
139
|
-
for (const coordinate of exteriorRing) {
|
|
140
|
-
writeCoordinate(writer, coordinate, options);
|
|
141
|
-
}
|
|
142
|
-
for (const interiorRing of interiorRings) {
|
|
143
|
-
writer.writeUInt32LE(interiorRing.length);
|
|
144
|
-
for (const coordinate of interiorRing) {
|
|
145
|
-
writeCoordinate(writer, coordinate, options);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return writer.arrayBuffer;
|
|
149
|
-
}
|
|
150
|
-
/** Get encoded size of Polygon geometry */
|
|
151
|
-
function getPolygonSize(coordinates, options) {
|
|
152
|
-
const coordinateSize = getCoordinateSize(options);
|
|
153
|
-
const [exteriorRing, ...interiorRings] = coordinates;
|
|
154
|
-
let size = 1 + 4 + 4;
|
|
155
|
-
if (exteriorRing.length > 0) {
|
|
156
|
-
size += 4 + exteriorRing.length * coordinateSize;
|
|
157
|
-
}
|
|
158
|
-
for (const interiorRing of interiorRings) {
|
|
159
|
-
size += 4 + interiorRing.length * coordinateSize;
|
|
160
|
-
}
|
|
161
|
-
return size;
|
|
162
|
-
}
|
|
163
|
-
/** Encode MultiPoint geometry as WKB ArrayBufer */
|
|
164
|
-
function encodeMultiPoint(multiPoint, options) {
|
|
165
|
-
const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
|
|
166
|
-
const points = multiPoint.coordinates;
|
|
167
|
-
writer.writeInt8(1);
|
|
168
|
-
writeWkbType(writer, WKB.MultiPoint, options);
|
|
169
|
-
writer.writeUInt32LE(points.length);
|
|
170
|
-
for (const point of points) {
|
|
171
|
-
// TODO: add srid to this options object? {srid: multiPoint.srid}
|
|
172
|
-
const arrayBuffer = encodePoint(point, options);
|
|
173
|
-
writer.writeBuffer(arrayBuffer);
|
|
174
|
-
}
|
|
175
|
-
return writer.arrayBuffer;
|
|
176
|
-
}
|
|
177
|
-
/** Get encoded size of MultiPoint geometry */
|
|
178
|
-
function getMultiPointSize(multiPoint, options) {
|
|
179
|
-
let coordinateSize = getCoordinateSize(options);
|
|
180
|
-
const points = multiPoint.coordinates;
|
|
181
|
-
// This is because each point has a 5-byte header?
|
|
182
|
-
coordinateSize += 5;
|
|
183
|
-
return 1 + 4 + 4 + points.length * coordinateSize;
|
|
184
|
-
}
|
|
185
|
-
/** Encode MultiLineString geometry as WKB ArrayBufer */
|
|
186
|
-
function encodeMultiLineString(multiLineString, options) {
|
|
187
|
-
const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
|
|
188
|
-
const lineStrings = multiLineString.coordinates;
|
|
189
|
-
writer.writeInt8(1);
|
|
190
|
-
writeWkbType(writer, WKB.MultiLineString, options);
|
|
191
|
-
writer.writeUInt32LE(lineStrings.length);
|
|
192
|
-
for (const lineString of lineStrings) {
|
|
193
|
-
// TODO: Handle srid?
|
|
194
|
-
const encodedLineString = encodeLineString(lineString, options);
|
|
195
|
-
writer.writeBuffer(encodedLineString);
|
|
196
|
-
}
|
|
197
|
-
return writer.arrayBuffer;
|
|
198
|
-
}
|
|
199
|
-
/** Get encoded size of MultiLineString geometry */
|
|
200
|
-
function getMultiLineStringSize(multiLineString, options) {
|
|
201
|
-
let size = 1 + 4 + 4;
|
|
202
|
-
const lineStrings = multiLineString.coordinates;
|
|
203
|
-
for (const lineString of lineStrings) {
|
|
204
|
-
size += getLineStringSize(lineString, options);
|
|
205
|
-
}
|
|
206
|
-
return size;
|
|
207
|
-
}
|
|
208
|
-
function encodeMultiPolygon(multiPolygon, options) {
|
|
209
|
-
const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
|
|
210
|
-
const polygons = multiPolygon.coordinates;
|
|
211
|
-
writer.writeInt8(1);
|
|
212
|
-
writeWkbType(writer, WKB.MultiPolygon, options);
|
|
213
|
-
writer.writeUInt32LE(polygons.length);
|
|
214
|
-
for (const polygon of polygons) {
|
|
215
|
-
const encodedPolygon = encodePolygon(polygon, options);
|
|
216
|
-
writer.writeBuffer(encodedPolygon);
|
|
217
|
-
}
|
|
218
|
-
return writer.arrayBuffer;
|
|
219
|
-
}
|
|
220
|
-
function getMultiPolygonSize(multiPolygon, options) {
|
|
221
|
-
let size = 1 + 4 + 4;
|
|
222
|
-
const polygons = multiPolygon.coordinates;
|
|
223
|
-
for (const polygon of polygons) {
|
|
224
|
-
size += getPolygonSize(polygon, options);
|
|
225
|
-
}
|
|
226
|
-
return size;
|
|
227
|
-
}
|
|
228
|
-
function encodeGeometryCollection(collection, options) {
|
|
229
|
-
const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
|
|
230
|
-
writer.writeInt8(1);
|
|
231
|
-
writeWkbType(writer, WKB.GeometryCollection, options);
|
|
232
|
-
writer.writeUInt32LE(collection.geometries.length);
|
|
233
|
-
for (const geometry of collection.geometries) {
|
|
234
|
-
// TODO: handle srid? {srid: collection.srid}
|
|
235
|
-
const arrayBuffer = encodeWKB(geometry, options);
|
|
236
|
-
writer.writeBuffer(arrayBuffer);
|
|
237
|
-
}
|
|
238
|
-
return writer.arrayBuffer;
|
|
239
|
-
}
|
|
240
|
-
function getGeometryCollectionSize(collection, options) {
|
|
241
|
-
let size = 1 + 4 + 4;
|
|
242
|
-
for (const geometry of collection.geometries) {
|
|
243
|
-
size += getGeometrySize(geometry, options);
|
|
244
|
-
}
|
|
245
|
-
return size;
|
|
246
|
-
}
|
|
247
|
-
// HELPERS
|
|
248
|
-
/**
|
|
249
|
-
* Construct and write WKB integer code
|
|
250
|
-
* Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
|
|
251
|
-
*/
|
|
252
|
-
function writeWkbType(writer, geometryType, options) {
|
|
253
|
-
const { hasZ, hasM, srid } = options;
|
|
254
|
-
let dimensionType = 0;
|
|
255
|
-
if (!srid) {
|
|
256
|
-
if (hasZ && hasM) {
|
|
257
|
-
dimensionType += 3000;
|
|
258
|
-
}
|
|
259
|
-
else if (hasZ) {
|
|
260
|
-
dimensionType += 1000;
|
|
261
|
-
}
|
|
262
|
-
else if (hasM) {
|
|
263
|
-
dimensionType += 2000;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
if (hasZ) {
|
|
268
|
-
dimensionType |= 0x80000000;
|
|
269
|
-
}
|
|
270
|
-
if (hasM) {
|
|
271
|
-
dimensionType |= 0x40000000;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
writer.writeUInt32LE((dimensionType + geometryType) >>> 0);
|
|
275
|
-
}
|
|
276
|
-
/** Get coordinate size given Z/M dimensions */
|
|
277
|
-
function getCoordinateSize(options) {
|
|
278
|
-
let coordinateSize = 16;
|
|
279
|
-
if (options.hasZ) {
|
|
280
|
-
coordinateSize += 8;
|
|
281
|
-
}
|
|
282
|
-
if (options.hasM) {
|
|
283
|
-
coordinateSize += 8;
|
|
284
|
-
}
|
|
285
|
-
return coordinateSize;
|
|
286
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { WKTCRS } from "./parse-wkt-crs.js";
|
|
2
|
-
export type EncodeWKTCRSOptions = {
|
|
3
|
-
debug?: boolean;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* convert JSON representation of Well-Known Text
|
|
7
|
-
* back to standard Well-Known Text
|
|
8
|
-
*/
|
|
9
|
-
export declare function encodeWKTCRS(wkt: WKTCRS, options?: EncodeWKTCRSOptions): string;
|
|
10
|
-
//# sourceMappingURL=encode-wkt-crs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encode-wkt-crs.d.ts","sourceRoot":"","sources":["../../src/lib/encode-wkt-crs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,MAAM,EAAC,2BAAwB;AAE5C,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAyB/E"}
|
|
@@ -1,35 +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
|
-
* convert JSON representation of Well-Known Text
|
|
7
|
-
* back to standard Well-Known Text
|
|
8
|
-
*/
|
|
9
|
-
export function encodeWKTCRS(wkt, options) {
|
|
10
|
-
if (Array.isArray(wkt) && wkt.length === 1 && Array.isArray(wkt[0])) {
|
|
11
|
-
wkt = wkt[0]; // ignore first extra wrapper array
|
|
12
|
-
}
|
|
13
|
-
const [kw, ...attrs] = wkt;
|
|
14
|
-
const str = `${kw}[${attrs
|
|
15
|
-
.map((attr) => {
|
|
16
|
-
if (Array.isArray(attr)) {
|
|
17
|
-
return encodeWKTCRS(attr, options);
|
|
18
|
-
}
|
|
19
|
-
else if (typeof attr === 'number') {
|
|
20
|
-
return attr.toString();
|
|
21
|
-
}
|
|
22
|
-
else if (typeof attr === 'string') {
|
|
23
|
-
// can't automatically convert all caps to varibale
|
|
24
|
-
// because EPSG is string in AUTHORITY["EPSG", ...]
|
|
25
|
-
if (attr.startsWith('raw:')) {
|
|
26
|
-
// convert "raw:NORTH" to NORTH
|
|
27
|
-
return attr.replace('raw:', '');
|
|
28
|
-
}
|
|
29
|
-
return `"${attr}"`;
|
|
30
|
-
}
|
|
31
|
-
throw new Error(`[wktcrs] unexpected attribute "${attr}"`);
|
|
32
|
-
})
|
|
33
|
-
.join(',')}]`;
|
|
34
|
-
return str;
|
|
35
|
-
}
|
package/dist/lib/encode-wkt.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Feature, Geometry } from '@loaders.gl/schema';
|
|
2
|
-
/**
|
|
3
|
-
* Stringifies a GeoJSON object into WKT
|
|
4
|
-
* @param geojson
|
|
5
|
-
* @returns string
|
|
6
|
-
*/
|
|
7
|
-
export declare function encodeWKT(geometry: Geometry | Feature): string;
|
|
8
|
-
//# sourceMappingURL=encode-wkt.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encode-wkt.d.ts","sourceRoot":"","sources":["../../src/lib/encode-wkt.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,CAuB9D"}
|
package/dist/lib/encode-wkt.js
DELETED
|
@@ -1,47 +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
|
-
* Stringifies a GeoJSON object into WKT
|
|
7
|
-
* @param geojson
|
|
8
|
-
* @returns string
|
|
9
|
-
*/
|
|
10
|
-
export function encodeWKT(geometry) {
|
|
11
|
-
if (geometry.type === 'Feature') {
|
|
12
|
-
geometry = geometry.geometry;
|
|
13
|
-
}
|
|
14
|
-
switch (geometry.type) {
|
|
15
|
-
case 'Point':
|
|
16
|
-
return `POINT ${wrapParens(pairWKT(geometry.coordinates))}`;
|
|
17
|
-
case 'LineString':
|
|
18
|
-
return `LINESTRING ${wrapParens(ringWKT(geometry.coordinates))}`;
|
|
19
|
-
case 'Polygon':
|
|
20
|
-
return `POLYGON ${wrapParens(ringsWKT(geometry.coordinates))}`;
|
|
21
|
-
case 'MultiPoint':
|
|
22
|
-
return `MULTIPOINT ${wrapParens(ringWKT(geometry.coordinates))}`;
|
|
23
|
-
case 'MultiPolygon':
|
|
24
|
-
return `MULTIPOLYGON ${wrapParens(multiRingsWKT(geometry.coordinates))}`;
|
|
25
|
-
case 'MultiLineString':
|
|
26
|
-
return `MULTILINESTRING ${wrapParens(ringsWKT(geometry.coordinates))}`;
|
|
27
|
-
case 'GeometryCollection':
|
|
28
|
-
return `GEOMETRYCOLLECTION ${wrapParens(geometry.geometries.map(encodeWKT).join(', '))}`;
|
|
29
|
-
default:
|
|
30
|
-
throw new Error('stringify requires a valid GeoJSON Feature or geometry object as input');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function pairWKT(c) {
|
|
34
|
-
return c.join(' ');
|
|
35
|
-
}
|
|
36
|
-
function ringWKT(r) {
|
|
37
|
-
return r.map(pairWKT).join(', ');
|
|
38
|
-
}
|
|
39
|
-
function ringsWKT(r) {
|
|
40
|
-
return r.map(ringWKT).map(wrapParens).join(', ');
|
|
41
|
-
}
|
|
42
|
-
function multiRingsWKT(r) {
|
|
43
|
-
return r.map(ringsWKT).map(wrapParens).join(', ');
|
|
44
|
-
}
|
|
45
|
-
function wrapParens(s) {
|
|
46
|
-
return `(${s})`;
|
|
47
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=parse-hex-wkb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-hex-wkb.d.ts","sourceRoot":"","sources":["../../src/lib/parse-hex-wkb.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/lib/parse-twkb.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Geometry } from '@loaders.gl/schema';
|
|
2
|
-
/**
|
|
3
|
-
* Check if an array buffer might be a TWKB array buffer
|
|
4
|
-
* @param arrayBuffer The array buffer to check
|
|
5
|
-
* @returns false if this is definitely not a TWKB array buffer, true if it might be a TWKB array buffer
|
|
6
|
-
*/
|
|
7
|
-
export declare function isTWKB(arrayBuffer: ArrayBuffer): boolean;
|
|
8
|
-
export declare function parseTWKBGeometry(arrayBuffer: ArrayBuffer): Geometry;
|
|
9
|
-
//# sourceMappingURL=parse-twkb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-twkb.d.ts","sourceRoot":"","sources":["../../src/lib/parse-twkb.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,QAAQ,EAQT,MAAM,oBAAoB,CAAC;AAI5B;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAYxD;AAwBD,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,QAAQ,CA2BpE"}
|