@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/index.cjs
CHANGED
|
@@ -30,117 +30,15 @@ __export(dist_exports, {
|
|
|
30
30
|
WKTCRSWriter: () => WKTCRSWriter,
|
|
31
31
|
WKTLoader: () => WKTLoader,
|
|
32
32
|
WKTWorkerLoader: () => WKTWorkerLoader,
|
|
33
|
-
WKTWriter: () => WKTWriter
|
|
34
|
-
decodeHex: () => decodeHex,
|
|
35
|
-
encodeHex: () => encodeHex,
|
|
36
|
-
isTWKB: () => isTWKB,
|
|
37
|
-
isWKB: () => isWKB,
|
|
38
|
-
isWKT: () => isWKT,
|
|
39
|
-
parseWKBHeader: () => parseWKBHeader
|
|
33
|
+
WKTWriter: () => WKTWriter
|
|
40
34
|
});
|
|
41
35
|
module.exports = __toCommonJS(dist_exports);
|
|
42
36
|
|
|
43
|
-
// dist/
|
|
44
|
-
var
|
|
37
|
+
// dist/wkt-crs-loader.js
|
|
38
|
+
var import_gis = require("@loaders.gl/gis");
|
|
45
39
|
|
|
46
|
-
// dist/lib/
|
|
47
|
-
|
|
48
|
-
if (options == null ? void 0 : options.debug) {
|
|
49
|
-
console.log("[wktcrs] parse starting with\n", wkt);
|
|
50
|
-
}
|
|
51
|
-
wkt = wkt.replace(/[A-Z][A-Z\d_]+\[/gi, (match) => `["${match.substr(0, match.length - 1)}",`);
|
|
52
|
-
wkt = wkt.replace(/, ?([A-Z][A-Z\d_]+[,\]])/gi, (match, p1) => {
|
|
53
|
-
const varname = p1.substr(0, p1.length - 1);
|
|
54
|
-
return `,"${(options == null ? void 0 : options.raw) ? "raw:" : ""}${varname}"${p1[p1.length - 1]}`;
|
|
55
|
-
});
|
|
56
|
-
if (options == null ? void 0 : options.raw) {
|
|
57
|
-
wkt = wkt.replace(/, {0,2}(-?[\.\d]+)(?=,|\])/g, function(match, p1) {
|
|
58
|
-
return `,"${(options == null ? void 0 : options.raw) ? "raw:" : ""}${p1}"`;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (options == null ? void 0 : options.debug) {
|
|
62
|
-
console.log(`[wktcrs] json'd wkt: '${wkt}'`);
|
|
63
|
-
}
|
|
64
|
-
let data;
|
|
65
|
-
try {
|
|
66
|
-
data = JSON.parse(wkt);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error(`[wktcrs] failed to parse '${wkt}'`);
|
|
69
|
-
throw error;
|
|
70
|
-
}
|
|
71
|
-
if (options == null ? void 0 : options.debug) {
|
|
72
|
-
console.log(`[wktcrs] json parsed: '${wkt}'`);
|
|
73
|
-
}
|
|
74
|
-
function process(data2, parent) {
|
|
75
|
-
const kw = data2[0];
|
|
76
|
-
data2.forEach(function(it) {
|
|
77
|
-
if (Array.isArray(it)) {
|
|
78
|
-
process(it, data2);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
const kwarr = `MULTIPLE_${kw}`;
|
|
82
|
-
if (kwarr in parent) {
|
|
83
|
-
parent[kwarr].push(data2);
|
|
84
|
-
} else if (kw in parent) {
|
|
85
|
-
parent[kwarr] = [parent[kw], data2];
|
|
86
|
-
delete parent[kw];
|
|
87
|
-
} else {
|
|
88
|
-
parent[kw] = data2;
|
|
89
|
-
}
|
|
90
|
-
return parent;
|
|
91
|
-
}
|
|
92
|
-
const result = process(data, [data]);
|
|
93
|
-
if (options == null ? void 0 : options.debug) {
|
|
94
|
-
console.log("[wktcrs] parse returning", result);
|
|
95
|
-
}
|
|
96
|
-
if (options == null ? void 0 : options.sort) {
|
|
97
|
-
sort(result, options);
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
function sort(data, options) {
|
|
102
|
-
const keys = Object.keys(data).filter((k) => !/\d+/.test(k));
|
|
103
|
-
const keywords = (options == null ? void 0 : options.keywords) || [];
|
|
104
|
-
if (!(options == null ? void 0 : options.keywords)) {
|
|
105
|
-
const counts = {};
|
|
106
|
-
if (Array.isArray(data)) {
|
|
107
|
-
data.forEach((it) => {
|
|
108
|
-
if (Array.isArray(it) && it.length >= 2 && typeof it[1] === "string") {
|
|
109
|
-
const k = it[0];
|
|
110
|
-
if (!counts[k])
|
|
111
|
-
counts[k] = 0;
|
|
112
|
-
counts[k]++;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
for (const k in counts) {
|
|
116
|
-
if (counts[k] > 0)
|
|
117
|
-
keywords.push(k);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
keys.forEach((key) => {
|
|
122
|
-
data[key] = sort(data[key]);
|
|
123
|
-
});
|
|
124
|
-
keywords.forEach((key) => {
|
|
125
|
-
const indices = [];
|
|
126
|
-
const params = [];
|
|
127
|
-
data.forEach((item, i) => {
|
|
128
|
-
if (Array.isArray(item) && item[0] === key) {
|
|
129
|
-
indices.push(i);
|
|
130
|
-
params.push(item);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
params.sort((a, b) => {
|
|
134
|
-
a = a[1].toString();
|
|
135
|
-
b = b[1].toString();
|
|
136
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
137
|
-
});
|
|
138
|
-
params.forEach((param, i) => {
|
|
139
|
-
data[indices[i]] = param;
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
return data;
|
|
143
|
-
}
|
|
40
|
+
// dist/lib/version.js
|
|
41
|
+
var VERSION = true ? "4.4.0-alpha.1" : "latest";
|
|
144
42
|
|
|
145
43
|
// dist/wkt-crs-loader.js
|
|
146
44
|
var WKTCRSLoader = {
|
|
@@ -158,33 +56,12 @@ var WKTCRSLoader = {
|
|
|
158
56
|
options: {
|
|
159
57
|
"wkt-crs": {}
|
|
160
58
|
},
|
|
161
|
-
parse: async (arrayBuffer, options) => parseWKTCRS(new TextDecoder().decode(arrayBuffer), options == null ? void 0 : options["wkt-crs"]),
|
|
162
|
-
parseTextSync: (string, options) => parseWKTCRS(string, options == null ? void 0 : options["wkt-crs"])
|
|
59
|
+
parse: async (arrayBuffer, options) => (0, import_gis.parseWKTCRS)(new TextDecoder().decode(arrayBuffer), options == null ? void 0 : options["wkt-crs"]),
|
|
60
|
+
parseTextSync: (string, options) => (0, import_gis.parseWKTCRS)(string, options == null ? void 0 : options["wkt-crs"])
|
|
163
61
|
};
|
|
164
62
|
|
|
165
|
-
// dist/lib/encode-wkt-crs.js
|
|
166
|
-
function encodeWKTCRS(wkt, options) {
|
|
167
|
-
if (Array.isArray(wkt) && wkt.length === 1 && Array.isArray(wkt[0])) {
|
|
168
|
-
wkt = wkt[0];
|
|
169
|
-
}
|
|
170
|
-
const [kw, ...attrs] = wkt;
|
|
171
|
-
const str = `${kw}[${attrs.map((attr) => {
|
|
172
|
-
if (Array.isArray(attr)) {
|
|
173
|
-
return encodeWKTCRS(attr, options);
|
|
174
|
-
} else if (typeof attr === "number") {
|
|
175
|
-
return attr.toString();
|
|
176
|
-
} else if (typeof attr === "string") {
|
|
177
|
-
if (attr.startsWith("raw:")) {
|
|
178
|
-
return attr.replace("raw:", "");
|
|
179
|
-
}
|
|
180
|
-
return `"${attr}"`;
|
|
181
|
-
}
|
|
182
|
-
throw new Error(`[wktcrs] unexpected attribute "${attr}"`);
|
|
183
|
-
}).join(",")}]`;
|
|
184
|
-
return str;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
63
|
// dist/wkt-crs-writer.js
|
|
64
|
+
var import_gis2 = require("@loaders.gl/gis");
|
|
188
65
|
var WKTCRSWriter = {
|
|
189
66
|
name: "WKT CRS (Well-Known Text Coordinate Reference System)",
|
|
190
67
|
id: "wkt-crs",
|
|
@@ -198,256 +75,13 @@ var WKTCRSWriter = {
|
|
|
198
75
|
options: {
|
|
199
76
|
"wkt-crs": {}
|
|
200
77
|
},
|
|
201
|
-
encode: async (wktcrs, options) => new TextEncoder().encode(encodeWKTCRS(wktcrs, options == null ? void 0 : options["wkt-crs"])),
|
|
202
|
-
encodeSync: (wktcrs, options) => new TextEncoder().encode(encodeWKTCRS(wktcrs, options == null ? void 0 : options["wkt-crs"])),
|
|
203
|
-
encodeTextSync: (wktcrs, options) => encodeWKTCRS(wktcrs, options == null ? void 0 : options["wkt-crs"])
|
|
78
|
+
encode: async (wktcrs, options) => new TextEncoder().encode((0, import_gis2.encodeWKTCRS)(wktcrs, options == null ? void 0 : options["wkt-crs"])),
|
|
79
|
+
encodeSync: (wktcrs, options) => new TextEncoder().encode((0, import_gis2.encodeWKTCRS)(wktcrs, options == null ? void 0 : options["wkt-crs"])),
|
|
80
|
+
encodeTextSync: (wktcrs, options) => (0, import_gis2.encodeWKTCRS)(wktcrs, options == null ? void 0 : options["wkt-crs"])
|
|
204
81
|
};
|
|
205
82
|
|
|
206
|
-
// dist/lib/parse-wkt.js
|
|
207
|
-
var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
|
|
208
|
-
var tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
|
|
209
|
-
var WKT_MAGIC_STRINGS = [
|
|
210
|
-
"POINT(",
|
|
211
|
-
"LINESTRING(",
|
|
212
|
-
"POLYGON(",
|
|
213
|
-
"MULTIPOINT(",
|
|
214
|
-
"MULTILINESTRING(",
|
|
215
|
-
"MULTIPOLYGON(",
|
|
216
|
-
"GEOMETRYCOLLECTION("
|
|
217
|
-
// We only support this "geojson" subset of the OGC simple features standard
|
|
218
|
-
];
|
|
219
|
-
function isWKT(input) {
|
|
220
|
-
return WKT_MAGIC_STRINGS.some((magicString) => input.startsWith(magicString));
|
|
221
|
-
}
|
|
222
|
-
function parseWKT(input, options) {
|
|
223
|
-
return parseWKTToGeometry(input, options);
|
|
224
|
-
}
|
|
225
|
-
function parseWKTToGeometry(input, options) {
|
|
226
|
-
var _a;
|
|
227
|
-
const parts = input.split(";");
|
|
228
|
-
let _ = parts.pop();
|
|
229
|
-
const srid = (parts.shift() || "").split("=").pop();
|
|
230
|
-
const state = { parts, _, i: 0 };
|
|
231
|
-
const geometry = parseGeometry(state);
|
|
232
|
-
return ((_a = options == null ? void 0 : options.wkt) == null ? void 0 : _a.crs) ? addCRS(geometry, srid) : geometry;
|
|
233
|
-
}
|
|
234
|
-
function parseGeometry(state) {
|
|
235
|
-
return parsePoint(state) || parseLineString(state) || parsePolygon(state) || parseMultiPoint(state) || parseMultiLineString(state) || parseMultiPolygon(state) || parseGeometryCollection(state);
|
|
236
|
-
}
|
|
237
|
-
function addCRS(obj, srid) {
|
|
238
|
-
if (obj && (srid == null ? void 0 : srid.match(/\d+/))) {
|
|
239
|
-
const crs = {
|
|
240
|
-
type: "name",
|
|
241
|
-
properties: {
|
|
242
|
-
name: "urn:ogc:def:crs:EPSG::" + srid
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
obj.crs = crs;
|
|
246
|
-
}
|
|
247
|
-
return obj;
|
|
248
|
-
}
|
|
249
|
-
function parsePoint(state) {
|
|
250
|
-
if (!$(/^(POINT(\sz)?)/i, state)) {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
white(state);
|
|
254
|
-
if (!$(/^(\()/, state)) {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
const c = coords(state);
|
|
258
|
-
if (!c) {
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
white(state);
|
|
262
|
-
if (!$(/^(\))/, state)) {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
return {
|
|
266
|
-
type: "Point",
|
|
267
|
-
coordinates: c[0]
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
function parseMultiPoint(state) {
|
|
271
|
-
var _a, _b;
|
|
272
|
-
if (!$(/^(MULTIPOINT)/i, state)) {
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
white(state);
|
|
276
|
-
const newCoordsFormat = (_b = state._) == null ? void 0 : _b.substring(((_a = state._) == null ? void 0 : _a.indexOf("(")) + 1, state._.length - 1).replace(/\(/g, "").replace(/\)/g, "");
|
|
277
|
-
state._ = "MULTIPOINT (" + newCoordsFormat + ")";
|
|
278
|
-
const c = multicoords(state);
|
|
279
|
-
if (!c) {
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
white(state);
|
|
283
|
-
return {
|
|
284
|
-
type: "MultiPoint",
|
|
285
|
-
coordinates: c
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
function parseLineString(state) {
|
|
289
|
-
if (!$(/^(LINESTRING(\sz)?)/i, state)) {
|
|
290
|
-
return null;
|
|
291
|
-
}
|
|
292
|
-
white(state);
|
|
293
|
-
if (!$(/^(\()/, state)) {
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
const c = coords(state);
|
|
297
|
-
if (!c) {
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
if (!$(/^(\))/, state)) {
|
|
301
|
-
return null;
|
|
302
|
-
}
|
|
303
|
-
return {
|
|
304
|
-
type: "LineString",
|
|
305
|
-
coordinates: c
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
function parseMultiLineString(state) {
|
|
309
|
-
if (!$(/^(MULTILINESTRING)/i, state))
|
|
310
|
-
return null;
|
|
311
|
-
white(state);
|
|
312
|
-
const c = multicoords(state);
|
|
313
|
-
if (!c) {
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
white(state);
|
|
317
|
-
return {
|
|
318
|
-
// @ts-ignore
|
|
319
|
-
type: "MultiLineString",
|
|
320
|
-
// @ts-expect-error
|
|
321
|
-
coordinates: c
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function parsePolygon(state) {
|
|
325
|
-
if (!$(/^(POLYGON(\sz)?)/i, state)) {
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
white(state);
|
|
329
|
-
const c = multicoords(state);
|
|
330
|
-
if (!c) {
|
|
331
|
-
return null;
|
|
332
|
-
}
|
|
333
|
-
return {
|
|
334
|
-
// @ts-ignore
|
|
335
|
-
type: "Polygon",
|
|
336
|
-
// @ts-expect-error
|
|
337
|
-
coordinates: c
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
function parseMultiPolygon(state) {
|
|
341
|
-
if (!$(/^(MULTIPOLYGON)/i, state)) {
|
|
342
|
-
return null;
|
|
343
|
-
}
|
|
344
|
-
white(state);
|
|
345
|
-
const c = multicoords(state);
|
|
346
|
-
if (!c) {
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
return {
|
|
350
|
-
type: "MultiPolygon",
|
|
351
|
-
// @ts-expect-error
|
|
352
|
-
coordinates: c
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function parseGeometryCollection(state) {
|
|
356
|
-
const geometries = [];
|
|
357
|
-
let geometry;
|
|
358
|
-
if (!$(/^(GEOMETRYCOLLECTION)/i, state)) {
|
|
359
|
-
return null;
|
|
360
|
-
}
|
|
361
|
-
white(state);
|
|
362
|
-
if (!$(/^(\()/, state)) {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
while (geometry = parseGeometry(state)) {
|
|
366
|
-
geometries.push(geometry);
|
|
367
|
-
white(state);
|
|
368
|
-
$(/^(,)/, state);
|
|
369
|
-
white(state);
|
|
370
|
-
}
|
|
371
|
-
if (!$(/^(\))/, state)) {
|
|
372
|
-
return null;
|
|
373
|
-
}
|
|
374
|
-
return {
|
|
375
|
-
type: "GeometryCollection",
|
|
376
|
-
geometries
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
function multicoords(state) {
|
|
380
|
-
white(state);
|
|
381
|
-
let depth = 0;
|
|
382
|
-
const rings = [];
|
|
383
|
-
const stack = [rings];
|
|
384
|
-
let pointer = rings;
|
|
385
|
-
let elem;
|
|
386
|
-
while (elem = $(/^(\()/, state) || $(/^(\))/, state) || $(/^(,)/, state) || $(tuples, state)) {
|
|
387
|
-
if (elem === "(") {
|
|
388
|
-
stack.push(pointer);
|
|
389
|
-
pointer = [];
|
|
390
|
-
stack[stack.length - 1].push(pointer);
|
|
391
|
-
depth++;
|
|
392
|
-
} else if (elem === ")") {
|
|
393
|
-
if (pointer.length === 0)
|
|
394
|
-
return null;
|
|
395
|
-
pointer = stack.pop();
|
|
396
|
-
if (!pointer)
|
|
397
|
-
return null;
|
|
398
|
-
depth--;
|
|
399
|
-
if (depth === 0)
|
|
400
|
-
break;
|
|
401
|
-
} else if (elem === ",") {
|
|
402
|
-
pointer = [];
|
|
403
|
-
stack[stack.length - 1].push(pointer);
|
|
404
|
-
} else if (!elem.split(/\s/g).some(isNaN)) {
|
|
405
|
-
Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
|
|
406
|
-
} else {
|
|
407
|
-
return null;
|
|
408
|
-
}
|
|
409
|
-
white(state);
|
|
410
|
-
}
|
|
411
|
-
if (depth !== 0)
|
|
412
|
-
return null;
|
|
413
|
-
return rings;
|
|
414
|
-
}
|
|
415
|
-
function coords(state) {
|
|
416
|
-
const list = [];
|
|
417
|
-
let item;
|
|
418
|
-
let pt;
|
|
419
|
-
while (pt = $(tuples, state) || $(/^(,)/, state)) {
|
|
420
|
-
if (pt === ",") {
|
|
421
|
-
list.push(item);
|
|
422
|
-
item = [];
|
|
423
|
-
} else if (!pt.split(/\s/g).some(isNaN)) {
|
|
424
|
-
if (!item)
|
|
425
|
-
item = [];
|
|
426
|
-
Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
|
|
427
|
-
}
|
|
428
|
-
white(state);
|
|
429
|
-
}
|
|
430
|
-
if (item)
|
|
431
|
-
list.push(item);
|
|
432
|
-
else
|
|
433
|
-
return null;
|
|
434
|
-
return list.length ? list : null;
|
|
435
|
-
}
|
|
436
|
-
function $(regexp, state) {
|
|
437
|
-
var _a;
|
|
438
|
-
const match = (_a = state._) == null ? void 0 : _a.substring(state.i).match(regexp);
|
|
439
|
-
if (!match)
|
|
440
|
-
return null;
|
|
441
|
-
else {
|
|
442
|
-
state.i += match[0].length;
|
|
443
|
-
return match[0];
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
function white(state) {
|
|
447
|
-
$(/^\s*/, state);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
83
|
// dist/wkt-loader.js
|
|
84
|
+
var import_gis3 = require("@loaders.gl/gis");
|
|
451
85
|
var WKTWorkerLoader = {
|
|
452
86
|
dataType: null,
|
|
453
87
|
batchType: null,
|
|
@@ -460,8 +94,8 @@ var WKTWorkerLoader = {
|
|
|
460
94
|
mimeTypes: ["text/plain"],
|
|
461
95
|
category: "geometry",
|
|
462
96
|
text: true,
|
|
463
|
-
tests: WKT_MAGIC_STRINGS,
|
|
464
|
-
testText: isWKT,
|
|
97
|
+
tests: import_gis3.WKT_MAGIC_STRINGS,
|
|
98
|
+
testText: import_gis3.isWKT,
|
|
465
99
|
options: {
|
|
466
100
|
wkt: {
|
|
467
101
|
shape: "geojson-geometry",
|
|
@@ -471,399 +105,35 @@ var WKTWorkerLoader = {
|
|
|
471
105
|
};
|
|
472
106
|
var WKTLoader = {
|
|
473
107
|
...WKTWorkerLoader,
|
|
474
|
-
parse: async (arrayBuffer, options) =>
|
|
475
|
-
parseTextSync: (string, options) =>
|
|
108
|
+
parse: async (arrayBuffer, options) => (0, import_gis3.convertWKTToGeometry)(new TextDecoder().decode(arrayBuffer), options),
|
|
109
|
+
parseTextSync: (string, options) => (0, import_gis3.convertWKTToGeometry)(string, options)
|
|
476
110
|
};
|
|
477
111
|
|
|
478
|
-
// dist/lib/encode-wkt.js
|
|
479
|
-
function encodeWKT(geometry) {
|
|
480
|
-
if (geometry.type === "Feature") {
|
|
481
|
-
geometry = geometry.geometry;
|
|
482
|
-
}
|
|
483
|
-
switch (geometry.type) {
|
|
484
|
-
case "Point":
|
|
485
|
-
return `POINT ${wrapParens(pairWKT(geometry.coordinates))}`;
|
|
486
|
-
case "LineString":
|
|
487
|
-
return `LINESTRING ${wrapParens(ringWKT(geometry.coordinates))}`;
|
|
488
|
-
case "Polygon":
|
|
489
|
-
return `POLYGON ${wrapParens(ringsWKT(geometry.coordinates))}`;
|
|
490
|
-
case "MultiPoint":
|
|
491
|
-
return `MULTIPOINT ${wrapParens(ringWKT(geometry.coordinates))}`;
|
|
492
|
-
case "MultiPolygon":
|
|
493
|
-
return `MULTIPOLYGON ${wrapParens(multiRingsWKT(geometry.coordinates))}`;
|
|
494
|
-
case "MultiLineString":
|
|
495
|
-
return `MULTILINESTRING ${wrapParens(ringsWKT(geometry.coordinates))}`;
|
|
496
|
-
case "GeometryCollection":
|
|
497
|
-
return `GEOMETRYCOLLECTION ${wrapParens(geometry.geometries.map(encodeWKT).join(", "))}`;
|
|
498
|
-
default:
|
|
499
|
-
throw new Error("stringify requires a valid GeoJSON Feature or geometry object as input");
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
function pairWKT(c) {
|
|
503
|
-
return c.join(" ");
|
|
504
|
-
}
|
|
505
|
-
function ringWKT(r) {
|
|
506
|
-
return r.map(pairWKT).join(", ");
|
|
507
|
-
}
|
|
508
|
-
function ringsWKT(r) {
|
|
509
|
-
return r.map(ringWKT).map(wrapParens).join(", ");
|
|
510
|
-
}
|
|
511
|
-
function multiRingsWKT(r) {
|
|
512
|
-
return r.map(ringsWKT).map(wrapParens).join(", ");
|
|
513
|
-
}
|
|
514
|
-
function wrapParens(s) {
|
|
515
|
-
return `(${s})`;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
112
|
// dist/wkt-writer.js
|
|
113
|
+
var import_gis4 = require("@loaders.gl/gis");
|
|
519
114
|
var WKTWriter = {
|
|
520
115
|
name: "WKT (Well Known Text)",
|
|
521
116
|
id: "wkt",
|
|
522
117
|
module: "wkt",
|
|
523
118
|
version: VERSION,
|
|
524
119
|
extensions: ["wkt"],
|
|
120
|
+
mimeTypes: ["application/wkt", "text/plain"],
|
|
525
121
|
text: true,
|
|
526
|
-
encode: async (geometry) =>
|
|
527
|
-
encodeSync:
|
|
528
|
-
encodeTextSync:
|
|
122
|
+
encode: async (geometry) => convertGeometryToWKTSync(geometry),
|
|
123
|
+
encodeSync: convertGeometryToWKTSync,
|
|
124
|
+
encodeTextSync: import_gis4.convertGeometryToWKT,
|
|
529
125
|
options: {
|
|
530
126
|
wkt: {}
|
|
531
127
|
}
|
|
532
128
|
};
|
|
533
|
-
function
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
// dist/lib/parse-wkb.js
|
|
538
|
-
var import_gis = require("@loaders.gl/gis");
|
|
539
|
-
|
|
540
|
-
// dist/lib/parse-wkb-header.js
|
|
541
|
-
var EWKB_FLAG_Z = 2147483648;
|
|
542
|
-
var EWKB_FLAG_M = 1073741824;
|
|
543
|
-
var EWKB_FLAG_SRID = 536870912;
|
|
544
|
-
var MAX_SRID = 1e4;
|
|
545
|
-
var WKBGeometryType;
|
|
546
|
-
(function(WKBGeometryType2) {
|
|
547
|
-
WKBGeometryType2[WKBGeometryType2["Point"] = 1] = "Point";
|
|
548
|
-
WKBGeometryType2[WKBGeometryType2["LineString"] = 2] = "LineString";
|
|
549
|
-
WKBGeometryType2[WKBGeometryType2["Polygon"] = 3] = "Polygon";
|
|
550
|
-
WKBGeometryType2[WKBGeometryType2["MultiPoint"] = 4] = "MultiPoint";
|
|
551
|
-
WKBGeometryType2[WKBGeometryType2["MultiLineString"] = 5] = "MultiLineString";
|
|
552
|
-
WKBGeometryType2[WKBGeometryType2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
553
|
-
WKBGeometryType2[WKBGeometryType2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
554
|
-
})(WKBGeometryType || (WKBGeometryType = {}));
|
|
555
|
-
function isWKB(arrayBuffer) {
|
|
556
|
-
const dataView = new DataView(arrayBuffer);
|
|
557
|
-
let byteOffset = 0;
|
|
558
|
-
const endianness = dataView.getUint8(byteOffset);
|
|
559
|
-
byteOffset += 1;
|
|
560
|
-
if (endianness > 1) {
|
|
561
|
-
return false;
|
|
562
|
-
}
|
|
563
|
-
const littleEndian = endianness === 1;
|
|
564
|
-
const geometry = dataView.getUint32(byteOffset, littleEndian);
|
|
565
|
-
byteOffset += 4;
|
|
566
|
-
const geometryType = geometry & 7;
|
|
567
|
-
if (geometryType === 0 || geometryType > 7) {
|
|
568
|
-
return false;
|
|
569
|
-
}
|
|
570
|
-
const geometryFlags = geometry - geometryType;
|
|
571
|
-
if (geometryFlags === 0 || geometryFlags === 1e3 || geometryFlags === 2e3 || geometryFlags === 3e3) {
|
|
572
|
-
return true;
|
|
573
|
-
}
|
|
574
|
-
if ((geometryFlags & ~(EWKB_FLAG_Z | EWKB_FLAG_M | EWKB_FLAG_SRID)) !== 0) {
|
|
575
|
-
return false;
|
|
576
|
-
}
|
|
577
|
-
if (geometryFlags & EWKB_FLAG_SRID) {
|
|
578
|
-
const srid = dataView.getUint32(byteOffset, littleEndian);
|
|
579
|
-
byteOffset += 4;
|
|
580
|
-
if (srid > MAX_SRID) {
|
|
581
|
-
return false;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
return true;
|
|
585
|
-
}
|
|
586
|
-
function parseWKBHeader(dataView, target) {
|
|
587
|
-
const wkbHeader = Object.assign(target || {}, {
|
|
588
|
-
type: "wkb",
|
|
589
|
-
geometryType: 1,
|
|
590
|
-
dimensions: 2,
|
|
591
|
-
coordinates: "xy",
|
|
592
|
-
littleEndian: true,
|
|
593
|
-
byteOffset: 0
|
|
594
|
-
});
|
|
595
|
-
wkbHeader.littleEndian = dataView.getUint8(wkbHeader.byteOffset) === 1;
|
|
596
|
-
wkbHeader.byteOffset++;
|
|
597
|
-
const geometryCode = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
598
|
-
wkbHeader.byteOffset += 4;
|
|
599
|
-
wkbHeader.geometryType = geometryCode & 7;
|
|
600
|
-
const isoType = (geometryCode - wkbHeader.geometryType) / 1e3;
|
|
601
|
-
switch (isoType) {
|
|
602
|
-
case 0:
|
|
603
|
-
break;
|
|
604
|
-
case 1:
|
|
605
|
-
wkbHeader.type = "iso-wkb";
|
|
606
|
-
wkbHeader.dimensions = 3;
|
|
607
|
-
wkbHeader.coordinates = "xyz";
|
|
608
|
-
break;
|
|
609
|
-
case 2:
|
|
610
|
-
wkbHeader.type = "iso-wkb";
|
|
611
|
-
wkbHeader.dimensions = 3;
|
|
612
|
-
wkbHeader.coordinates = "xym";
|
|
613
|
-
break;
|
|
614
|
-
case 3:
|
|
615
|
-
wkbHeader.type = "iso-wkb";
|
|
616
|
-
wkbHeader.dimensions = 4;
|
|
617
|
-
wkbHeader.coordinates = "xyzm";
|
|
618
|
-
break;
|
|
619
|
-
default:
|
|
620
|
-
throw new Error(`WKB: Unsupported iso-wkb type: ${isoType}`);
|
|
621
|
-
}
|
|
622
|
-
const ewkbZ = geometryCode & EWKB_FLAG_Z;
|
|
623
|
-
const ewkbM = geometryCode & EWKB_FLAG_M;
|
|
624
|
-
const ewkbSRID = geometryCode & EWKB_FLAG_SRID;
|
|
625
|
-
if (ewkbZ && ewkbM) {
|
|
626
|
-
wkbHeader.type = "ewkb";
|
|
627
|
-
wkbHeader.dimensions = 4;
|
|
628
|
-
wkbHeader.coordinates = "xyzm";
|
|
629
|
-
} else if (ewkbZ) {
|
|
630
|
-
wkbHeader.type = "ewkb";
|
|
631
|
-
wkbHeader.dimensions = 3;
|
|
632
|
-
wkbHeader.coordinates = "xyz";
|
|
633
|
-
} else if (ewkbM) {
|
|
634
|
-
wkbHeader.type = "ewkb";
|
|
635
|
-
wkbHeader.dimensions = 3;
|
|
636
|
-
wkbHeader.coordinates = "xym";
|
|
637
|
-
}
|
|
638
|
-
if (ewkbSRID) {
|
|
639
|
-
wkbHeader.type = "ewkb";
|
|
640
|
-
wkbHeader.srid = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
|
|
641
|
-
wkbHeader.byteOffset += 4;
|
|
642
|
-
}
|
|
643
|
-
return wkbHeader;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// dist/lib/parse-wkb.js
|
|
647
|
-
function parseWKB(arrayBuffer, options) {
|
|
648
|
-
var _a;
|
|
649
|
-
const binaryGeometry = parseWKBToBinary(arrayBuffer, options);
|
|
650
|
-
const shape = ((_a = options == null ? void 0 : options.wkb) == null ? void 0 : _a.shape) || "binary-geometry";
|
|
651
|
-
switch (shape) {
|
|
652
|
-
case "binary-geometry":
|
|
653
|
-
return binaryGeometry;
|
|
654
|
-
case "geojson-geometry":
|
|
655
|
-
return (0, import_gis.binaryToGeometry)(binaryGeometry);
|
|
656
|
-
case "geometry":
|
|
657
|
-
console.error('WKBLoader: "geometry" shape is deprecated, use "binary-geometry" instead');
|
|
658
|
-
return (0, import_gis.binaryToGeometry)(binaryGeometry);
|
|
659
|
-
default:
|
|
660
|
-
throw new Error(shape);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
function parseWKBToBinary(arrayBuffer, options) {
|
|
664
|
-
const dataView = new DataView(arrayBuffer);
|
|
665
|
-
const wkbHeader = parseWKBHeader(dataView);
|
|
666
|
-
const { geometryType, dimensions, littleEndian } = wkbHeader;
|
|
667
|
-
const offset = wkbHeader.byteOffset;
|
|
668
|
-
switch (geometryType) {
|
|
669
|
-
case WKBGeometryType.Point:
|
|
670
|
-
const point = parsePoint2(dataView, offset, dimensions, littleEndian);
|
|
671
|
-
return point.geometry;
|
|
672
|
-
case WKBGeometryType.LineString:
|
|
673
|
-
const line = parseLineString2(dataView, offset, dimensions, littleEndian);
|
|
674
|
-
return line.geometry;
|
|
675
|
-
case WKBGeometryType.Polygon:
|
|
676
|
-
const polygon = parsePolygon2(dataView, offset, dimensions, littleEndian);
|
|
677
|
-
return polygon.geometry;
|
|
678
|
-
case WKBGeometryType.MultiPoint:
|
|
679
|
-
const multiPoint = parseMultiPoint2(dataView, offset, dimensions, littleEndian);
|
|
680
|
-
multiPoint.type = "Point";
|
|
681
|
-
return multiPoint;
|
|
682
|
-
case WKBGeometryType.MultiLineString:
|
|
683
|
-
const multiLine = parseMultiLineString2(dataView, offset, dimensions, littleEndian);
|
|
684
|
-
multiLine.type = "LineString";
|
|
685
|
-
return multiLine;
|
|
686
|
-
case WKBGeometryType.MultiPolygon:
|
|
687
|
-
const multiPolygon = parseMultiPolygon2(dataView, offset, dimensions, littleEndian);
|
|
688
|
-
multiPolygon.type = "Polygon";
|
|
689
|
-
return multiPolygon;
|
|
690
|
-
default:
|
|
691
|
-
throw new Error(`WKB: Unsupported geometry type: ${geometryType}`);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
function parsePoint2(dataView, offset, dimension, littleEndian) {
|
|
695
|
-
const positions = new Float64Array(dimension);
|
|
696
|
-
for (let i = 0; i < dimension; i++) {
|
|
697
|
-
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
698
|
-
offset += 8;
|
|
699
|
-
}
|
|
700
|
-
return {
|
|
701
|
-
geometry: { type: "Point", positions: { value: positions, size: dimension } },
|
|
702
|
-
offset
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
function parseLineString2(dataView, offset, dimension, littleEndian) {
|
|
706
|
-
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
707
|
-
offset += 4;
|
|
708
|
-
const positions = new Float64Array(nPoints * dimension);
|
|
709
|
-
for (let i = 0; i < nPoints * dimension; i++) {
|
|
710
|
-
positions[i] = dataView.getFloat64(offset, littleEndian);
|
|
711
|
-
offset += 8;
|
|
712
|
-
}
|
|
713
|
-
const pathIndices = [0];
|
|
714
|
-
if (nPoints > 0) {
|
|
715
|
-
pathIndices.push(nPoints);
|
|
716
|
-
}
|
|
717
|
-
return {
|
|
718
|
-
geometry: {
|
|
719
|
-
type: "LineString",
|
|
720
|
-
positions: { value: positions, size: dimension },
|
|
721
|
-
pathIndices: { value: new Uint32Array(pathIndices), size: 1 }
|
|
722
|
-
},
|
|
723
|
-
offset
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
var cumulativeSum = (sum) => (value) => sum += value;
|
|
727
|
-
function parsePolygon2(dataView, offset, dimension, littleEndian) {
|
|
728
|
-
const nRings = dataView.getUint32(offset, littleEndian);
|
|
729
|
-
offset += 4;
|
|
730
|
-
const rings = [];
|
|
731
|
-
for (let i = 0; i < nRings; i++) {
|
|
732
|
-
const parsed = parseLineString2(dataView, offset, dimension, littleEndian);
|
|
733
|
-
const { positions } = parsed.geometry;
|
|
734
|
-
offset = parsed.offset;
|
|
735
|
-
rings.push(positions.value);
|
|
736
|
-
}
|
|
737
|
-
const concatenatedPositions = new Float64Array(concatTypedArrays(rings).buffer);
|
|
738
|
-
const polygonIndices = [0];
|
|
739
|
-
if (concatenatedPositions.length > 0) {
|
|
740
|
-
polygonIndices.push(concatenatedPositions.length / dimension);
|
|
741
|
-
}
|
|
742
|
-
const primitivePolygonIndices = rings.map((l) => l.length / dimension).map(cumulativeSum(0));
|
|
743
|
-
primitivePolygonIndices.unshift(0);
|
|
744
|
-
return {
|
|
745
|
-
geometry: {
|
|
746
|
-
type: "Polygon",
|
|
747
|
-
positions: { value: concatenatedPositions, size: dimension },
|
|
748
|
-
polygonIndices: {
|
|
749
|
-
value: new Uint32Array(polygonIndices),
|
|
750
|
-
size: 1
|
|
751
|
-
},
|
|
752
|
-
primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
|
|
753
|
-
},
|
|
754
|
-
offset
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
function parseMultiPoint2(dataView, offset, dimension, littleEndian) {
|
|
758
|
-
const nPoints = dataView.getUint32(offset, littleEndian);
|
|
759
|
-
offset += 4;
|
|
760
|
-
const binaryPointGeometries = [];
|
|
761
|
-
for (let i = 0; i < nPoints; i++) {
|
|
762
|
-
const littleEndianPoint = dataView.getUint8(offset) === 1;
|
|
763
|
-
offset++;
|
|
764
|
-
if (dataView.getUint32(offset, littleEndianPoint) % 1e3 !== 1) {
|
|
765
|
-
throw new Error("WKB: Inner geometries of MultiPoint not of type Point");
|
|
766
|
-
}
|
|
767
|
-
offset += 4;
|
|
768
|
-
const parsed = parsePoint2(dataView, offset, dimension, littleEndianPoint);
|
|
769
|
-
offset = parsed.offset;
|
|
770
|
-
binaryPointGeometries.push(parsed.geometry);
|
|
771
|
-
}
|
|
772
|
-
return concatenateBinaryPointGeometries(binaryPointGeometries, dimension);
|
|
773
|
-
}
|
|
774
|
-
function parseMultiLineString2(dataView, offset, dimension, littleEndian) {
|
|
775
|
-
const nLines = dataView.getUint32(offset, littleEndian);
|
|
776
|
-
offset += 4;
|
|
777
|
-
const binaryLineGeometries = [];
|
|
778
|
-
for (let i = 0; i < nLines; i++) {
|
|
779
|
-
const littleEndianLine = dataView.getUint8(offset) === 1;
|
|
780
|
-
offset++;
|
|
781
|
-
if (dataView.getUint32(offset, littleEndianLine) % 1e3 !== 2) {
|
|
782
|
-
throw new Error("WKB: Inner geometries of MultiLineString not of type LineString");
|
|
783
|
-
}
|
|
784
|
-
offset += 4;
|
|
785
|
-
const parsed = parseLineString2(dataView, offset, dimension, littleEndianLine);
|
|
786
|
-
offset = parsed.offset;
|
|
787
|
-
binaryLineGeometries.push(parsed.geometry);
|
|
788
|
-
}
|
|
789
|
-
return concatenateBinaryLineGeometries(binaryLineGeometries, dimension);
|
|
790
|
-
}
|
|
791
|
-
function parseMultiPolygon2(dataView, offset, dimension, littleEndian) {
|
|
792
|
-
const nPolygons = dataView.getUint32(offset, littleEndian);
|
|
793
|
-
offset += 4;
|
|
794
|
-
const binaryPolygonGeometries = [];
|
|
795
|
-
for (let i = 0; i < nPolygons; i++) {
|
|
796
|
-
const littleEndianPolygon = dataView.getUint8(offset) === 1;
|
|
797
|
-
offset++;
|
|
798
|
-
if (dataView.getUint32(offset, littleEndianPolygon) % 1e3 !== 3) {
|
|
799
|
-
throw new Error("WKB: Inner geometries of MultiPolygon not of type Polygon");
|
|
800
|
-
}
|
|
801
|
-
offset += 4;
|
|
802
|
-
const parsed = parsePolygon2(dataView, offset, dimension, littleEndianPolygon);
|
|
803
|
-
offset = parsed.offset;
|
|
804
|
-
binaryPolygonGeometries.push(parsed.geometry);
|
|
805
|
-
}
|
|
806
|
-
return concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension);
|
|
807
|
-
}
|
|
808
|
-
function concatenateBinaryPointGeometries(binaryPointGeometries, dimension) {
|
|
809
|
-
const positions = binaryPointGeometries.map((geometry) => geometry.positions.value);
|
|
810
|
-
const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
|
|
811
|
-
return {
|
|
812
|
-
type: "Point",
|
|
813
|
-
positions: { value: concatenatedPositions, size: dimension }
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
|
|
817
|
-
const lines = binaryLineGeometries.map((geometry) => geometry.positions.value);
|
|
818
|
-
const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
|
|
819
|
-
const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
|
|
820
|
-
pathIndices.unshift(0);
|
|
821
|
-
return {
|
|
822
|
-
type: "LineString",
|
|
823
|
-
positions: { value: concatenatedPositions, size: dimension },
|
|
824
|
-
pathIndices: { value: new Uint32Array(pathIndices), size: 1 }
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
|
|
828
|
-
const polygons = [];
|
|
829
|
-
const primitivePolygons = [];
|
|
830
|
-
for (const binaryPolygon of binaryPolygonGeometries) {
|
|
831
|
-
const { positions, primitivePolygonIndices: primitivePolygonIndices2 } = binaryPolygon;
|
|
832
|
-
polygons.push(positions.value);
|
|
833
|
-
primitivePolygons.push(primitivePolygonIndices2.value);
|
|
834
|
-
}
|
|
835
|
-
const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
|
|
836
|
-
const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
|
|
837
|
-
polygonIndices.unshift(0);
|
|
838
|
-
const primitivePolygonIndices = [0];
|
|
839
|
-
for (const primitivePolygon of primitivePolygons) {
|
|
840
|
-
primitivePolygonIndices.push(...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
|
|
841
|
-
}
|
|
842
|
-
return {
|
|
843
|
-
type: "Polygon",
|
|
844
|
-
positions: { value: concatenatedPositions, size: dimension },
|
|
845
|
-
polygonIndices: { value: new Uint32Array(polygonIndices), size: 1 },
|
|
846
|
-
primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
function concatTypedArrays(arrays) {
|
|
850
|
-
let byteLength = 0;
|
|
851
|
-
for (let i = 0; i < arrays.length; ++i) {
|
|
852
|
-
byteLength += arrays[i].byteLength;
|
|
853
|
-
}
|
|
854
|
-
const buffer = new Uint8Array(byteLength);
|
|
855
|
-
let byteOffset = 0;
|
|
856
|
-
for (let i = 0; i < arrays.length; ++i) {
|
|
857
|
-
const data = new Uint8Array(arrays[i].buffer);
|
|
858
|
-
byteLength = data.length;
|
|
859
|
-
for (let j = 0; j < byteLength; ++j) {
|
|
860
|
-
buffer[byteOffset++] = data[j];
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
return buffer;
|
|
129
|
+
function convertGeometryToWKTSync(geometry) {
|
|
130
|
+
const wktString = (0, import_gis4.convertGeometryToWKT)(geometry);
|
|
131
|
+
const wktTypedArray = new TextEncoder().encode(wktString);
|
|
132
|
+
return wktTypedArray.buffer;
|
|
864
133
|
}
|
|
865
134
|
|
|
866
135
|
// dist/wkb-loader.js
|
|
136
|
+
var import_gis5 = require("@loaders.gl/gis");
|
|
867
137
|
var WKBWorkerLoader = {
|
|
868
138
|
dataType: null,
|
|
869
139
|
batchType: null,
|
|
@@ -876,389 +146,37 @@ var WKBWorkerLoader = {
|
|
|
876
146
|
extensions: ["wkb"],
|
|
877
147
|
mimeTypes: [],
|
|
878
148
|
// TODO can we define static, serializable tests, eg. some binary strings?
|
|
879
|
-
tests: [isWKB],
|
|
149
|
+
tests: [import_gis5.isWKB],
|
|
880
150
|
options: {
|
|
881
151
|
wkb: {
|
|
882
|
-
shape: "
|
|
883
|
-
// 'geojson-geometry'
|
|
152
|
+
shape: "geojson-geometry"
|
|
884
153
|
}
|
|
885
154
|
}
|
|
886
155
|
};
|
|
887
156
|
var WKBLoader = {
|
|
888
157
|
...WKBWorkerLoader,
|
|
889
|
-
parse: async (arrayBuffer) => parseWKB(arrayBuffer),
|
|
890
|
-
parseSync: parseWKB
|
|
891
|
-
};
|
|
892
|
-
|
|
893
|
-
// dist/lib/utils/binary-writer.js
|
|
894
|
-
var LE = true;
|
|
895
|
-
var BE = false;
|
|
896
|
-
var BinaryWriter = class {
|
|
897
|
-
arrayBuffer;
|
|
898
|
-
dataView;
|
|
899
|
-
byteOffset = 0;
|
|
900
|
-
allowResize = false;
|
|
901
|
-
constructor(size, allowResize) {
|
|
902
|
-
this.arrayBuffer = new ArrayBuffer(size);
|
|
903
|
-
this.dataView = new DataView(this.arrayBuffer);
|
|
904
|
-
this.byteOffset = 0;
|
|
905
|
-
this.allowResize = allowResize || false;
|
|
906
|
-
}
|
|
907
|
-
writeUInt8(value) {
|
|
908
|
-
this._ensureSize(1);
|
|
909
|
-
this.dataView.setUint8(this.byteOffset, value);
|
|
910
|
-
this.byteOffset += 1;
|
|
911
|
-
}
|
|
912
|
-
writeUInt16LE(value) {
|
|
913
|
-
this._ensureSize(2);
|
|
914
|
-
this.dataView.setUint16(this.byteOffset, value, LE);
|
|
915
|
-
this.byteOffset += 2;
|
|
916
|
-
}
|
|
917
|
-
writeUInt16BE(value) {
|
|
918
|
-
this._ensureSize(2);
|
|
919
|
-
this.dataView.setUint16(this.byteOffset, value, BE);
|
|
920
|
-
this.byteOffset += 2;
|
|
921
|
-
}
|
|
922
|
-
writeUInt32LE(value) {
|
|
923
|
-
this._ensureSize(4);
|
|
924
|
-
this.dataView.setUint32(this.byteOffset, value, LE);
|
|
925
|
-
this.byteOffset += 4;
|
|
926
|
-
}
|
|
927
|
-
writeUInt32BE(value) {
|
|
928
|
-
this._ensureSize(4);
|
|
929
|
-
this.dataView.setUint32(this.byteOffset, value, BE);
|
|
930
|
-
this.byteOffset += 4;
|
|
931
|
-
}
|
|
932
|
-
writeInt8(value) {
|
|
933
|
-
this._ensureSize(1);
|
|
934
|
-
this.dataView.setInt8(this.byteOffset, value);
|
|
935
|
-
this.byteOffset += 1;
|
|
936
|
-
}
|
|
937
|
-
writeInt16LE(value) {
|
|
938
|
-
this._ensureSize(2);
|
|
939
|
-
this.dataView.setInt16(this.byteOffset, value, LE);
|
|
940
|
-
this.byteOffset += 2;
|
|
941
|
-
}
|
|
942
|
-
writeInt16BE(value) {
|
|
943
|
-
this._ensureSize(2);
|
|
944
|
-
this.dataView.setInt16(this.byteOffset, value, BE);
|
|
945
|
-
this.byteOffset += 2;
|
|
946
|
-
}
|
|
947
|
-
writeInt32LE(value) {
|
|
948
|
-
this._ensureSize(4);
|
|
949
|
-
this.dataView.setInt32(this.byteOffset, value, LE);
|
|
950
|
-
this.byteOffset += 4;
|
|
951
|
-
}
|
|
952
|
-
writeInt32BE(value) {
|
|
953
|
-
this._ensureSize(4);
|
|
954
|
-
this.dataView.setInt32(this.byteOffset, value, BE);
|
|
955
|
-
this.byteOffset += 4;
|
|
956
|
-
}
|
|
957
|
-
writeFloatLE(value) {
|
|
958
|
-
this._ensureSize(4);
|
|
959
|
-
this.dataView.setFloat32(this.byteOffset, value, LE);
|
|
960
|
-
this.byteOffset += 4;
|
|
961
|
-
}
|
|
962
|
-
writeFloatBE(value) {
|
|
963
|
-
this._ensureSize(4);
|
|
964
|
-
this.dataView.setFloat32(this.byteOffset, value, BE);
|
|
965
|
-
this.byteOffset += 4;
|
|
966
|
-
}
|
|
967
|
-
writeDoubleLE(value) {
|
|
968
|
-
this._ensureSize(8);
|
|
969
|
-
this.dataView.setFloat64(this.byteOffset, value, LE);
|
|
970
|
-
this.byteOffset += 8;
|
|
971
|
-
}
|
|
972
|
-
writeDoubleBE(value) {
|
|
973
|
-
this._ensureSize(8);
|
|
974
|
-
this.dataView.setFloat64(this.byteOffset, value, BE);
|
|
975
|
-
this.byteOffset += 8;
|
|
976
|
-
}
|
|
977
|
-
/** A varint uses a variable number of bytes */
|
|
978
|
-
writeVarInt(value) {
|
|
979
|
-
let length = 1;
|
|
980
|
-
while ((value & 4294967168) !== 0) {
|
|
981
|
-
this.writeUInt8(value & 127 | 128);
|
|
982
|
-
value >>>= 7;
|
|
983
|
-
length++;
|
|
984
|
-
}
|
|
985
|
-
this.writeUInt8(value & 127);
|
|
986
|
-
return length;
|
|
987
|
-
}
|
|
988
|
-
/** Append another ArrayBuffer to this ArrayBuffer */
|
|
989
|
-
writeBuffer(arrayBuffer) {
|
|
990
|
-
this._ensureSize(arrayBuffer.byteLength);
|
|
991
|
-
const tempArray = new Uint8Array(this.arrayBuffer);
|
|
992
|
-
tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
|
|
993
|
-
this.byteOffset += arrayBuffer.byteLength;
|
|
994
|
-
}
|
|
995
|
-
/** Resizes this.arrayBuffer if not enough space */
|
|
996
|
-
_ensureSize(size) {
|
|
997
|
-
if (this.arrayBuffer.byteLength < this.byteOffset + size) {
|
|
998
|
-
if (this.allowResize) {
|
|
999
|
-
const newArrayBuffer = new ArrayBuffer(this.byteOffset + size);
|
|
1000
|
-
const tempArray = new Uint8Array(newArrayBuffer);
|
|
1001
|
-
tempArray.set(new Uint8Array(this.arrayBuffer));
|
|
1002
|
-
this.arrayBuffer = newArrayBuffer;
|
|
1003
|
-
} else {
|
|
1004
|
-
throw new Error("BinaryWriter overflow");
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
158
|
+
parse: async (arrayBuffer, options) => parseWKB(arrayBuffer, options == null ? void 0 : options.wkb),
|
|
159
|
+
parseSync: (arrayBuffer, options) => parseWKB(arrayBuffer, options == null ? void 0 : options.wkb)
|
|
1008
160
|
};
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
WKB2[WKB2["LineString"] = 2] = "LineString";
|
|
1015
|
-
WKB2[WKB2["Polygon"] = 3] = "Polygon";
|
|
1016
|
-
WKB2[WKB2["MultiPoint"] = 4] = "MultiPoint";
|
|
1017
|
-
WKB2[WKB2["MultiLineString"] = 5] = "MultiLineString";
|
|
1018
|
-
WKB2[WKB2["MultiPolygon"] = 6] = "MultiPolygon";
|
|
1019
|
-
WKB2[WKB2["GeometryCollection"] = 7] = "GeometryCollection";
|
|
1020
|
-
})(WKB || (WKB = {}));
|
|
1021
|
-
function encodeWKB(geometry, options = {}) {
|
|
1022
|
-
if (geometry.type === "Feature") {
|
|
1023
|
-
geometry = geometry.geometry;
|
|
1024
|
-
}
|
|
1025
|
-
switch (geometry.type) {
|
|
1026
|
-
case "Point":
|
|
1027
|
-
return encodePoint(geometry.coordinates, options);
|
|
1028
|
-
case "LineString":
|
|
1029
|
-
return encodeLineString(geometry.coordinates, options);
|
|
1030
|
-
case "Polygon":
|
|
1031
|
-
return encodePolygon(geometry.coordinates, options);
|
|
1032
|
-
case "MultiPoint":
|
|
1033
|
-
return encodeMultiPoint(geometry, options);
|
|
1034
|
-
case "MultiPolygon":
|
|
1035
|
-
return encodeMultiPolygon(geometry, options);
|
|
1036
|
-
case "MultiLineString":
|
|
1037
|
-
return encodeMultiLineString(geometry, options);
|
|
1038
|
-
case "GeometryCollection":
|
|
1039
|
-
return encodeGeometryCollection(geometry, options);
|
|
1040
|
-
default:
|
|
1041
|
-
const exhaustiveCheck = geometry;
|
|
1042
|
-
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
function getGeometrySize(geometry, options) {
|
|
1046
|
-
switch (geometry.type) {
|
|
1047
|
-
case "Point":
|
|
1048
|
-
return getPointSize(options);
|
|
1049
|
-
case "LineString":
|
|
1050
|
-
return getLineStringSize(geometry.coordinates, options);
|
|
1051
|
-
case "Polygon":
|
|
1052
|
-
return getPolygonSize(geometry.coordinates, options);
|
|
1053
|
-
case "MultiPoint":
|
|
1054
|
-
return getMultiPointSize(geometry, options);
|
|
1055
|
-
case "MultiPolygon":
|
|
1056
|
-
return getMultiPolygonSize(geometry, options);
|
|
1057
|
-
case "MultiLineString":
|
|
1058
|
-
return getMultiLineStringSize(geometry, options);
|
|
1059
|
-
case "GeometryCollection":
|
|
1060
|
-
return getGeometryCollectionSize(geometry, options);
|
|
161
|
+
function parseWKB(arrayBuffer, options) {
|
|
162
|
+
const shape = (options == null ? void 0 : options.shape) || "geojson-geometry";
|
|
163
|
+
switch (shape) {
|
|
164
|
+
case "geojson-geometry":
|
|
165
|
+
return (0, import_gis5.convertWKBToGeometry)(arrayBuffer);
|
|
1061
166
|
default:
|
|
1062
|
-
|
|
1063
|
-
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
function encodePoint(coordinates, options) {
|
|
1067
|
-
const writer = new BinaryWriter(getPointSize(options));
|
|
1068
|
-
writer.writeInt8(1);
|
|
1069
|
-
writeWkbType(writer, WKB.Point, options);
|
|
1070
|
-
if (typeof coordinates[0] === "undefined" && typeof coordinates[1] === "undefined") {
|
|
1071
|
-
writer.writeDoubleLE(NaN);
|
|
1072
|
-
writer.writeDoubleLE(NaN);
|
|
1073
|
-
if (options.hasZ) {
|
|
1074
|
-
writer.writeDoubleLE(NaN);
|
|
1075
|
-
}
|
|
1076
|
-
if (options.hasM) {
|
|
1077
|
-
writer.writeDoubleLE(NaN);
|
|
1078
|
-
}
|
|
1079
|
-
} else {
|
|
1080
|
-
writeCoordinate(writer, coordinates, options);
|
|
1081
|
-
}
|
|
1082
|
-
return writer.arrayBuffer;
|
|
1083
|
-
}
|
|
1084
|
-
function writeCoordinate(writer, coordinate, options) {
|
|
1085
|
-
writer.writeDoubleLE(coordinate[0]);
|
|
1086
|
-
writer.writeDoubleLE(coordinate[1]);
|
|
1087
|
-
if (options.hasZ) {
|
|
1088
|
-
writer.writeDoubleLE(coordinate[2]);
|
|
1089
|
-
}
|
|
1090
|
-
if (options.hasM) {
|
|
1091
|
-
writer.writeDoubleLE(coordinate[3]);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
function getPointSize(options) {
|
|
1095
|
-
const coordinateSize = getCoordinateSize(options);
|
|
1096
|
-
return 1 + 4 + coordinateSize;
|
|
1097
|
-
}
|
|
1098
|
-
function encodeLineString(coordinates, options) {
|
|
1099
|
-
const size = getLineStringSize(coordinates, options);
|
|
1100
|
-
const writer = new BinaryWriter(size);
|
|
1101
|
-
writer.writeInt8(1);
|
|
1102
|
-
writeWkbType(writer, WKB.LineString, options);
|
|
1103
|
-
writer.writeUInt32LE(coordinates.length);
|
|
1104
|
-
for (const coordinate of coordinates) {
|
|
1105
|
-
writeCoordinate(writer, coordinate, options);
|
|
1106
|
-
}
|
|
1107
|
-
return writer.arrayBuffer;
|
|
1108
|
-
}
|
|
1109
|
-
function getLineStringSize(coordinates, options) {
|
|
1110
|
-
const coordinateSize = getCoordinateSize(options);
|
|
1111
|
-
return 1 + 4 + 4 + coordinates.length * coordinateSize;
|
|
1112
|
-
}
|
|
1113
|
-
function encodePolygon(coordinates, options) {
|
|
1114
|
-
const writer = new BinaryWriter(getPolygonSize(coordinates, options));
|
|
1115
|
-
writer.writeInt8(1);
|
|
1116
|
-
writeWkbType(writer, WKB.Polygon, options);
|
|
1117
|
-
const [exteriorRing, ...interiorRings] = coordinates;
|
|
1118
|
-
if (exteriorRing.length > 0) {
|
|
1119
|
-
writer.writeUInt32LE(1 + interiorRings.length);
|
|
1120
|
-
writer.writeUInt32LE(exteriorRing.length);
|
|
1121
|
-
} else {
|
|
1122
|
-
writer.writeUInt32LE(0);
|
|
1123
|
-
}
|
|
1124
|
-
for (const coordinate of exteriorRing) {
|
|
1125
|
-
writeCoordinate(writer, coordinate, options);
|
|
1126
|
-
}
|
|
1127
|
-
for (const interiorRing of interiorRings) {
|
|
1128
|
-
writer.writeUInt32LE(interiorRing.length);
|
|
1129
|
-
for (const coordinate of interiorRing) {
|
|
1130
|
-
writeCoordinate(writer, coordinate, options);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
return writer.arrayBuffer;
|
|
1134
|
-
}
|
|
1135
|
-
function getPolygonSize(coordinates, options) {
|
|
1136
|
-
const coordinateSize = getCoordinateSize(options);
|
|
1137
|
-
const [exteriorRing, ...interiorRings] = coordinates;
|
|
1138
|
-
let size = 1 + 4 + 4;
|
|
1139
|
-
if (exteriorRing.length > 0) {
|
|
1140
|
-
size += 4 + exteriorRing.length * coordinateSize;
|
|
1141
|
-
}
|
|
1142
|
-
for (const interiorRing of interiorRings) {
|
|
1143
|
-
size += 4 + interiorRing.length * coordinateSize;
|
|
1144
|
-
}
|
|
1145
|
-
return size;
|
|
1146
|
-
}
|
|
1147
|
-
function encodeMultiPoint(multiPoint, options) {
|
|
1148
|
-
const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
|
|
1149
|
-
const points = multiPoint.coordinates;
|
|
1150
|
-
writer.writeInt8(1);
|
|
1151
|
-
writeWkbType(writer, WKB.MultiPoint, options);
|
|
1152
|
-
writer.writeUInt32LE(points.length);
|
|
1153
|
-
for (const point of points) {
|
|
1154
|
-
const arrayBuffer = encodePoint(point, options);
|
|
1155
|
-
writer.writeBuffer(arrayBuffer);
|
|
1156
|
-
}
|
|
1157
|
-
return writer.arrayBuffer;
|
|
1158
|
-
}
|
|
1159
|
-
function getMultiPointSize(multiPoint, options) {
|
|
1160
|
-
let coordinateSize = getCoordinateSize(options);
|
|
1161
|
-
const points = multiPoint.coordinates;
|
|
1162
|
-
coordinateSize += 5;
|
|
1163
|
-
return 1 + 4 + 4 + points.length * coordinateSize;
|
|
1164
|
-
}
|
|
1165
|
-
function encodeMultiLineString(multiLineString, options) {
|
|
1166
|
-
const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
|
|
1167
|
-
const lineStrings = multiLineString.coordinates;
|
|
1168
|
-
writer.writeInt8(1);
|
|
1169
|
-
writeWkbType(writer, WKB.MultiLineString, options);
|
|
1170
|
-
writer.writeUInt32LE(lineStrings.length);
|
|
1171
|
-
for (const lineString of lineStrings) {
|
|
1172
|
-
const encodedLineString = encodeLineString(lineString, options);
|
|
1173
|
-
writer.writeBuffer(encodedLineString);
|
|
1174
|
-
}
|
|
1175
|
-
return writer.arrayBuffer;
|
|
1176
|
-
}
|
|
1177
|
-
function getMultiLineStringSize(multiLineString, options) {
|
|
1178
|
-
let size = 1 + 4 + 4;
|
|
1179
|
-
const lineStrings = multiLineString.coordinates;
|
|
1180
|
-
for (const lineString of lineStrings) {
|
|
1181
|
-
size += getLineStringSize(lineString, options);
|
|
1182
|
-
}
|
|
1183
|
-
return size;
|
|
1184
|
-
}
|
|
1185
|
-
function encodeMultiPolygon(multiPolygon, options) {
|
|
1186
|
-
const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
|
|
1187
|
-
const polygons = multiPolygon.coordinates;
|
|
1188
|
-
writer.writeInt8(1);
|
|
1189
|
-
writeWkbType(writer, WKB.MultiPolygon, options);
|
|
1190
|
-
writer.writeUInt32LE(polygons.length);
|
|
1191
|
-
for (const polygon of polygons) {
|
|
1192
|
-
const encodedPolygon = encodePolygon(polygon, options);
|
|
1193
|
-
writer.writeBuffer(encodedPolygon);
|
|
1194
|
-
}
|
|
1195
|
-
return writer.arrayBuffer;
|
|
1196
|
-
}
|
|
1197
|
-
function getMultiPolygonSize(multiPolygon, options) {
|
|
1198
|
-
let size = 1 + 4 + 4;
|
|
1199
|
-
const polygons = multiPolygon.coordinates;
|
|
1200
|
-
for (const polygon of polygons) {
|
|
1201
|
-
size += getPolygonSize(polygon, options);
|
|
1202
|
-
}
|
|
1203
|
-
return size;
|
|
1204
|
-
}
|
|
1205
|
-
function encodeGeometryCollection(collection, options) {
|
|
1206
|
-
const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
|
|
1207
|
-
writer.writeInt8(1);
|
|
1208
|
-
writeWkbType(writer, WKB.GeometryCollection, options);
|
|
1209
|
-
writer.writeUInt32LE(collection.geometries.length);
|
|
1210
|
-
for (const geometry of collection.geometries) {
|
|
1211
|
-
const arrayBuffer = encodeWKB(geometry, options);
|
|
1212
|
-
writer.writeBuffer(arrayBuffer);
|
|
1213
|
-
}
|
|
1214
|
-
return writer.arrayBuffer;
|
|
1215
|
-
}
|
|
1216
|
-
function getGeometryCollectionSize(collection, options) {
|
|
1217
|
-
let size = 1 + 4 + 4;
|
|
1218
|
-
for (const geometry of collection.geometries) {
|
|
1219
|
-
size += getGeometrySize(geometry, options);
|
|
1220
|
-
}
|
|
1221
|
-
return size;
|
|
1222
|
-
}
|
|
1223
|
-
function writeWkbType(writer, geometryType, options) {
|
|
1224
|
-
const { hasZ, hasM, srid } = options;
|
|
1225
|
-
let dimensionType = 0;
|
|
1226
|
-
if (!srid) {
|
|
1227
|
-
if (hasZ && hasM) {
|
|
1228
|
-
dimensionType += 3e3;
|
|
1229
|
-
} else if (hasZ) {
|
|
1230
|
-
dimensionType += 1e3;
|
|
1231
|
-
} else if (hasM) {
|
|
1232
|
-
dimensionType += 2e3;
|
|
1233
|
-
}
|
|
1234
|
-
} else {
|
|
1235
|
-
if (hasZ) {
|
|
1236
|
-
dimensionType |= 2147483648;
|
|
1237
|
-
}
|
|
1238
|
-
if (hasM) {
|
|
1239
|
-
dimensionType |= 1073741824;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
writer.writeUInt32LE(dimensionType + geometryType >>> 0);
|
|
1243
|
-
}
|
|
1244
|
-
function getCoordinateSize(options) {
|
|
1245
|
-
let coordinateSize = 16;
|
|
1246
|
-
if (options.hasZ) {
|
|
1247
|
-
coordinateSize += 8;
|
|
1248
|
-
}
|
|
1249
|
-
if (options.hasM) {
|
|
1250
|
-
coordinateSize += 8;
|
|
167
|
+
throw new Error(shape);
|
|
1251
168
|
}
|
|
1252
|
-
return coordinateSize;
|
|
1253
169
|
}
|
|
1254
170
|
|
|
1255
171
|
// dist/wkb-writer.js
|
|
172
|
+
var import_gis6 = require("@loaders.gl/gis");
|
|
1256
173
|
var WKBWriter = {
|
|
1257
174
|
name: "WKB (Well Known Binary)",
|
|
1258
175
|
id: "wkb",
|
|
1259
176
|
module: "wkt",
|
|
1260
177
|
version: VERSION,
|
|
1261
178
|
extensions: ["wkb"],
|
|
179
|
+
mimeTypes: ["application/wkb", "application/octet-stream"],
|
|
1262
180
|
options: {
|
|
1263
181
|
wkb: {
|
|
1264
182
|
hasZ: false,
|
|
@@ -1266,49 +184,15 @@ var WKBWriter = {
|
|
|
1266
184
|
}
|
|
1267
185
|
},
|
|
1268
186
|
async encode(data, options) {
|
|
1269
|
-
return
|
|
187
|
+
return (0, import_gis6.convertGeometryToWKB)(data);
|
|
1270
188
|
},
|
|
1271
189
|
encodeSync(data, options) {
|
|
1272
|
-
return
|
|
190
|
+
return (0, import_gis6.convertGeometryToWKB)(data);
|
|
1273
191
|
}
|
|
1274
192
|
};
|
|
1275
193
|
|
|
1276
|
-
// dist/lib/utils/hex-transcoder.js
|
|
1277
|
-
var alphabet = "0123456789abcdef";
|
|
1278
|
-
var encodeLookup = [];
|
|
1279
|
-
var decodeLookup = [];
|
|
1280
|
-
for (let i = 0; i < 256; i++) {
|
|
1281
|
-
encodeLookup[i] = alphabet[i >> 4 & 15] + alphabet[i & 15];
|
|
1282
|
-
if (i < 16) {
|
|
1283
|
-
if (i < 10) {
|
|
1284
|
-
decodeLookup[48 + i] = i;
|
|
1285
|
-
} else {
|
|
1286
|
-
decodeLookup[97 - 10 + i] = i;
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
function encodeHex(array) {
|
|
1291
|
-
const length = array.length;
|
|
1292
|
-
let string = "";
|
|
1293
|
-
let i = 0;
|
|
1294
|
-
while (i < length) {
|
|
1295
|
-
string += encodeLookup[array[i++]];
|
|
1296
|
-
}
|
|
1297
|
-
return string;
|
|
1298
|
-
}
|
|
1299
|
-
function decodeHex(string) {
|
|
1300
|
-
const sizeof = string.length >> 1;
|
|
1301
|
-
const length = sizeof << 1;
|
|
1302
|
-
const array = new Uint8Array(sizeof);
|
|
1303
|
-
let n = 0;
|
|
1304
|
-
let i = 0;
|
|
1305
|
-
while (i < length) {
|
|
1306
|
-
array[n++] = decodeLookup[string.charCodeAt(i++)] << 4 | decodeLookup[string.charCodeAt(i++)];
|
|
1307
|
-
}
|
|
1308
|
-
return array;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
194
|
// dist/hex-wkb-loader.js
|
|
195
|
+
var import_gis7 = require("@loaders.gl/gis");
|
|
1312
196
|
var HexWKBLoader = {
|
|
1313
197
|
dataType: null,
|
|
1314
198
|
batchType: null,
|
|
@@ -1328,9 +212,8 @@ var HexWKBLoader = {
|
|
|
1328
212
|
parseTextSync: parseHexWKB
|
|
1329
213
|
};
|
|
1330
214
|
function parseHexWKB(text, options) {
|
|
1331
|
-
|
|
1332
|
-
const
|
|
1333
|
-
const binaryGeometry = (_b = (_a = WKBLoader).parseSync) == null ? void 0 : _b.call(_a, uint8Array.buffer, options);
|
|
215
|
+
const uint8Array = (0, import_gis7.decodeHex)(text);
|
|
216
|
+
const binaryGeometry = (0, import_gis7.convertWKBToGeometry)(uint8Array.buffer);
|
|
1334
217
|
return binaryGeometry;
|
|
1335
218
|
}
|
|
1336
219
|
function isHexWKB(string) {
|
|
@@ -1346,289 +229,8 @@ function isHexWKB(string) {
|
|
|
1346
229
|
return /^[0-9a-fA-F]+$/.test(string.slice(2));
|
|
1347
230
|
}
|
|
1348
231
|
|
|
1349
|
-
// dist/lib/utils/binary-reader.js
|
|
1350
|
-
var BinaryReader = class {
|
|
1351
|
-
arrayBuffer;
|
|
1352
|
-
dataView;
|
|
1353
|
-
byteOffset;
|
|
1354
|
-
littleEndian;
|
|
1355
|
-
constructor(arrayBuffer, isBigEndian = false) {
|
|
1356
|
-
this.arrayBuffer = arrayBuffer;
|
|
1357
|
-
this.dataView = new DataView(arrayBuffer);
|
|
1358
|
-
this.byteOffset = 0;
|
|
1359
|
-
this.littleEndian = !isBigEndian;
|
|
1360
|
-
}
|
|
1361
|
-
readUInt8() {
|
|
1362
|
-
const value = this.dataView.getUint8(this.byteOffset);
|
|
1363
|
-
this.byteOffset += 1;
|
|
1364
|
-
return value;
|
|
1365
|
-
}
|
|
1366
|
-
readUInt16() {
|
|
1367
|
-
const value = this.dataView.getUint16(this.byteOffset, this.littleEndian);
|
|
1368
|
-
this.byteOffset += 2;
|
|
1369
|
-
return value;
|
|
1370
|
-
}
|
|
1371
|
-
readUInt32() {
|
|
1372
|
-
const value = this.dataView.getUint32(this.byteOffset, this.littleEndian);
|
|
1373
|
-
this.byteOffset += 4;
|
|
1374
|
-
return value;
|
|
1375
|
-
}
|
|
1376
|
-
readInt8() {
|
|
1377
|
-
const value = this.dataView.getInt8(this.byteOffset);
|
|
1378
|
-
this.byteOffset += 1;
|
|
1379
|
-
return value;
|
|
1380
|
-
}
|
|
1381
|
-
readInt16() {
|
|
1382
|
-
const value = this.dataView.getInt16(this.byteOffset, this.littleEndian);
|
|
1383
|
-
this.byteOffset += 2;
|
|
1384
|
-
return value;
|
|
1385
|
-
}
|
|
1386
|
-
readInt32() {
|
|
1387
|
-
const value = this.dataView.getInt32(this.byteOffset, this.littleEndian);
|
|
1388
|
-
this.byteOffset += 4;
|
|
1389
|
-
return value;
|
|
1390
|
-
}
|
|
1391
|
-
readFloat() {
|
|
1392
|
-
const value = this.dataView.getFloat32(this.byteOffset, this.littleEndian);
|
|
1393
|
-
this.byteOffset += 4;
|
|
1394
|
-
return value;
|
|
1395
|
-
}
|
|
1396
|
-
readDouble() {
|
|
1397
|
-
const value = this.dataView.getFloat64(this.byteOffset, this.littleEndian);
|
|
1398
|
-
this.byteOffset += 8;
|
|
1399
|
-
return value;
|
|
1400
|
-
}
|
|
1401
|
-
readVarInt() {
|
|
1402
|
-
let result = 0;
|
|
1403
|
-
let bytesRead = 0;
|
|
1404
|
-
let nextByte;
|
|
1405
|
-
do {
|
|
1406
|
-
nextByte = this.dataView.getUint8(this.byteOffset + bytesRead);
|
|
1407
|
-
result += (nextByte & 127) << 7 * bytesRead;
|
|
1408
|
-
bytesRead++;
|
|
1409
|
-
} while (nextByte >= 128);
|
|
1410
|
-
this.byteOffset += bytesRead;
|
|
1411
|
-
return result;
|
|
1412
|
-
}
|
|
1413
|
-
};
|
|
1414
|
-
|
|
1415
|
-
// dist/lib/parse-twkb.js
|
|
1416
|
-
function isTWKB(arrayBuffer) {
|
|
1417
|
-
const binaryReader = new BinaryReader(arrayBuffer);
|
|
1418
|
-
const type = binaryReader.readUInt8();
|
|
1419
|
-
const geometryType = type & 15;
|
|
1420
|
-
if (geometryType < 1 || geometryType > 7) {
|
|
1421
|
-
return false;
|
|
1422
|
-
}
|
|
1423
|
-
return true;
|
|
1424
|
-
}
|
|
1425
|
-
function parseTWKBGeometry(arrayBuffer) {
|
|
1426
|
-
const binaryReader = new BinaryReader(arrayBuffer);
|
|
1427
|
-
const context = parseTWKBHeader(binaryReader);
|
|
1428
|
-
if (context.hasSizeAttribute) {
|
|
1429
|
-
binaryReader.readVarInt();
|
|
1430
|
-
}
|
|
1431
|
-
if (context.hasBoundingBox) {
|
|
1432
|
-
let dimensions = 2;
|
|
1433
|
-
if (context.hasZ) {
|
|
1434
|
-
dimensions++;
|
|
1435
|
-
}
|
|
1436
|
-
if (context.hasM) {
|
|
1437
|
-
dimensions++;
|
|
1438
|
-
}
|
|
1439
|
-
for (let i = 0; i < dimensions; i++) {
|
|
1440
|
-
binaryReader.readVarInt();
|
|
1441
|
-
binaryReader.readVarInt();
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
return parseGeometry2(binaryReader, context, context.geometryType);
|
|
1445
|
-
}
|
|
1446
|
-
function parseTWKBHeader(binaryReader) {
|
|
1447
|
-
const type = binaryReader.readUInt8();
|
|
1448
|
-
const metadataHeader = binaryReader.readUInt8();
|
|
1449
|
-
const geometryType = type & 15;
|
|
1450
|
-
const precision = zigZagDecode(type >> 4);
|
|
1451
|
-
const hasExtendedPrecision = Boolean(metadataHeader >> 3 & 1);
|
|
1452
|
-
let hasZ = false;
|
|
1453
|
-
let hasM = false;
|
|
1454
|
-
let zPrecision = 0;
|
|
1455
|
-
let zPrecisionFactor = 1;
|
|
1456
|
-
let mPrecision = 0;
|
|
1457
|
-
let mPrecisionFactor = 1;
|
|
1458
|
-
if (hasExtendedPrecision) {
|
|
1459
|
-
const extendedPrecision = binaryReader.readUInt8();
|
|
1460
|
-
hasZ = (extendedPrecision & 1) === 1;
|
|
1461
|
-
hasM = (extendedPrecision & 2) === 2;
|
|
1462
|
-
zPrecision = zigZagDecode((extendedPrecision & 28) >> 2);
|
|
1463
|
-
zPrecisionFactor = Math.pow(10, zPrecision);
|
|
1464
|
-
mPrecision = zigZagDecode((extendedPrecision & 224) >> 5);
|
|
1465
|
-
mPrecisionFactor = Math.pow(10, mPrecision);
|
|
1466
|
-
}
|
|
1467
|
-
return {
|
|
1468
|
-
geometryType,
|
|
1469
|
-
precision,
|
|
1470
|
-
precisionFactor: Math.pow(10, precision),
|
|
1471
|
-
hasBoundingBox: Boolean(metadataHeader >> 0 & 1),
|
|
1472
|
-
hasSizeAttribute: Boolean(metadataHeader >> 1 & 1),
|
|
1473
|
-
hasIdList: Boolean(metadataHeader >> 2 & 1),
|
|
1474
|
-
hasExtendedPrecision,
|
|
1475
|
-
isEmpty: Boolean(metadataHeader >> 4 & 1),
|
|
1476
|
-
hasZ,
|
|
1477
|
-
hasM,
|
|
1478
|
-
zPrecision,
|
|
1479
|
-
zPrecisionFactor,
|
|
1480
|
-
mPrecision,
|
|
1481
|
-
mPrecisionFactor
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
function parseGeometry2(binaryReader, context, geometryType) {
|
|
1485
|
-
switch (geometryType) {
|
|
1486
|
-
case WKBGeometryType.Point:
|
|
1487
|
-
return parsePoint3(binaryReader, context);
|
|
1488
|
-
case WKBGeometryType.LineString:
|
|
1489
|
-
return parseLineString3(binaryReader, context);
|
|
1490
|
-
case WKBGeometryType.Polygon:
|
|
1491
|
-
return parsePolygon3(binaryReader, context);
|
|
1492
|
-
case WKBGeometryType.MultiPoint:
|
|
1493
|
-
return parseMultiPoint3(binaryReader, context);
|
|
1494
|
-
case WKBGeometryType.MultiLineString:
|
|
1495
|
-
return parseMultiLineString3(binaryReader, context);
|
|
1496
|
-
case WKBGeometryType.MultiPolygon:
|
|
1497
|
-
return parseMultiPolygon3(binaryReader, context);
|
|
1498
|
-
case WKBGeometryType.GeometryCollection:
|
|
1499
|
-
return parseGeometryCollection2(binaryReader, context);
|
|
1500
|
-
default:
|
|
1501
|
-
throw new Error(`GeometryType ${geometryType} not supported`);
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
function parsePoint3(reader, context) {
|
|
1505
|
-
if (context.isEmpty) {
|
|
1506
|
-
return { type: "Point", coordinates: [] };
|
|
1507
|
-
}
|
|
1508
|
-
return { type: "Point", coordinates: readFirstPoint(reader, context) };
|
|
1509
|
-
}
|
|
1510
|
-
function parseLineString3(reader, context) {
|
|
1511
|
-
if (context.isEmpty) {
|
|
1512
|
-
return { type: "LineString", coordinates: [] };
|
|
1513
|
-
}
|
|
1514
|
-
const pointCount = reader.readVarInt();
|
|
1515
|
-
const previousPoint = makePreviousPoint(context);
|
|
1516
|
-
const points = [];
|
|
1517
|
-
for (let i = 0; i < pointCount; i++) {
|
|
1518
|
-
points.push(parseNextPoint(reader, context, previousPoint));
|
|
1519
|
-
}
|
|
1520
|
-
return { type: "LineString", coordinates: points };
|
|
1521
|
-
}
|
|
1522
|
-
function parsePolygon3(reader, context) {
|
|
1523
|
-
if (context.isEmpty) {
|
|
1524
|
-
return { type: "Polygon", coordinates: [] };
|
|
1525
|
-
}
|
|
1526
|
-
const ringCount = reader.readVarInt();
|
|
1527
|
-
const previousPoint = makePreviousPoint(context);
|
|
1528
|
-
const exteriorRingLength = reader.readVarInt();
|
|
1529
|
-
const exteriorRing = [];
|
|
1530
|
-
for (let i = 0; i < exteriorRingLength; i++) {
|
|
1531
|
-
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
1532
|
-
}
|
|
1533
|
-
const polygon = [exteriorRing];
|
|
1534
|
-
for (let i = 1; i < ringCount; i++) {
|
|
1535
|
-
const interiorRingCount = reader.readVarInt();
|
|
1536
|
-
const interiorRing = [];
|
|
1537
|
-
for (let j = 0; j < interiorRingCount; j++) {
|
|
1538
|
-
interiorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
1539
|
-
}
|
|
1540
|
-
polygon.push(interiorRing);
|
|
1541
|
-
}
|
|
1542
|
-
return { type: "Polygon", coordinates: polygon };
|
|
1543
|
-
}
|
|
1544
|
-
function parseMultiPoint3(reader, context) {
|
|
1545
|
-
if (context.isEmpty) {
|
|
1546
|
-
return { type: "MultiPoint", coordinates: [] };
|
|
1547
|
-
}
|
|
1548
|
-
const previousPoint = makePreviousPoint(context);
|
|
1549
|
-
const pointCount = reader.readVarInt();
|
|
1550
|
-
const coordinates = [];
|
|
1551
|
-
for (let i = 0; i < pointCount; i++) {
|
|
1552
|
-
coordinates.push(parseNextPoint(reader, context, previousPoint));
|
|
1553
|
-
}
|
|
1554
|
-
return { type: "MultiPoint", coordinates };
|
|
1555
|
-
}
|
|
1556
|
-
function parseMultiLineString3(reader, context) {
|
|
1557
|
-
if (context.isEmpty) {
|
|
1558
|
-
return { type: "MultiLineString", coordinates: [] };
|
|
1559
|
-
}
|
|
1560
|
-
const previousPoint = makePreviousPoint(context);
|
|
1561
|
-
const lineStringCount = reader.readVarInt();
|
|
1562
|
-
const coordinates = [];
|
|
1563
|
-
for (let i = 0; i < lineStringCount; i++) {
|
|
1564
|
-
const pointCount = reader.readVarInt();
|
|
1565
|
-
const lineString = [];
|
|
1566
|
-
for (let j = 0; j < pointCount; j++) {
|
|
1567
|
-
lineString.push(parseNextPoint(reader, context, previousPoint));
|
|
1568
|
-
}
|
|
1569
|
-
coordinates.push(lineString);
|
|
1570
|
-
}
|
|
1571
|
-
return { type: "MultiLineString", coordinates };
|
|
1572
|
-
}
|
|
1573
|
-
function parseMultiPolygon3(reader, context) {
|
|
1574
|
-
if (context.isEmpty) {
|
|
1575
|
-
return { type: "MultiPolygon", coordinates: [] };
|
|
1576
|
-
}
|
|
1577
|
-
const previousPoint = makePreviousPoint(context);
|
|
1578
|
-
const polygonCount = reader.readVarInt();
|
|
1579
|
-
const polygons = [];
|
|
1580
|
-
for (let i = 0; i < polygonCount; i++) {
|
|
1581
|
-
const ringCount = reader.readVarInt();
|
|
1582
|
-
const exteriorPointCount = reader.readVarInt();
|
|
1583
|
-
const exteriorRing = [];
|
|
1584
|
-
for (let j = 0; j < exteriorPointCount; j++) {
|
|
1585
|
-
exteriorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
1586
|
-
}
|
|
1587
|
-
const polygon = exteriorRing ? [exteriorRing] : [];
|
|
1588
|
-
for (let j = 1; j < ringCount; j++) {
|
|
1589
|
-
const interiorRing = [];
|
|
1590
|
-
const interiorRingLength = reader.readVarInt();
|
|
1591
|
-
for (let k = 0; k < interiorRingLength; k++) {
|
|
1592
|
-
interiorRing.push(parseNextPoint(reader, context, previousPoint));
|
|
1593
|
-
}
|
|
1594
|
-
polygon.push(interiorRing);
|
|
1595
|
-
}
|
|
1596
|
-
polygons.push(polygon);
|
|
1597
|
-
}
|
|
1598
|
-
return { type: "MultiPolygon", coordinates: polygons };
|
|
1599
|
-
}
|
|
1600
|
-
function parseGeometryCollection2(reader, context) {
|
|
1601
|
-
return { type: "GeometryCollection", geometries: [] };
|
|
1602
|
-
}
|
|
1603
|
-
function zigZagDecode(value) {
|
|
1604
|
-
return value >> 1 ^ -(value & 1);
|
|
1605
|
-
}
|
|
1606
|
-
function makePointCoordinates(x, y, z, m) {
|
|
1607
|
-
return z !== void 0 ? m !== void 0 ? [x, y, z, m] : [x, y, z] : [x, y];
|
|
1608
|
-
}
|
|
1609
|
-
function makePreviousPoint(context) {
|
|
1610
|
-
return makePointCoordinates(0, 0, context.hasZ ? 0 : void 0, context.hasM ? 0 : void 0);
|
|
1611
|
-
}
|
|
1612
|
-
function readFirstPoint(reader, context) {
|
|
1613
|
-
const x = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
1614
|
-
const y = zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
1615
|
-
const z = context.hasZ ? zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor : void 0;
|
|
1616
|
-
const m = context.hasM ? zigZagDecode(reader.readVarInt()) / context.mPrecisionFactor : void 0;
|
|
1617
|
-
return makePointCoordinates(x, y, z, m);
|
|
1618
|
-
}
|
|
1619
|
-
function parseNextPoint(reader, context, previousPoint) {
|
|
1620
|
-
previousPoint[0] += zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
1621
|
-
previousPoint[1] += zigZagDecode(reader.readVarInt()) / context.precisionFactor;
|
|
1622
|
-
if (context.hasZ) {
|
|
1623
|
-
previousPoint[2] += zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor;
|
|
1624
|
-
}
|
|
1625
|
-
if (context.hasM) {
|
|
1626
|
-
previousPoint[3] += zigZagDecode(reader.readVarInt()) / context.mPrecisionFactor;
|
|
1627
|
-
}
|
|
1628
|
-
return previousPoint.slice();
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
232
|
// dist/twkb-loader.js
|
|
233
|
+
var import_gis8 = require("@loaders.gl/gis");
|
|
1632
234
|
var TWKBWorkerLoader = {
|
|
1633
235
|
dataType: null,
|
|
1634
236
|
batchType: null,
|
|
@@ -1641,7 +243,7 @@ var TWKBWorkerLoader = {
|
|
|
1641
243
|
extensions: ["twkb"],
|
|
1642
244
|
mimeTypes: [],
|
|
1643
245
|
// TODO can we define static, serializable tests, eg. some binary strings?
|
|
1644
|
-
tests: [isTWKB],
|
|
246
|
+
tests: [import_gis8.isTWKB],
|
|
1645
247
|
options: {
|
|
1646
248
|
wkb: {
|
|
1647
249
|
shape: "binary-geometry"
|
|
@@ -1651,194 +253,21 @@ var TWKBWorkerLoader = {
|
|
|
1651
253
|
};
|
|
1652
254
|
var TWKBLoader = {
|
|
1653
255
|
...TWKBWorkerLoader,
|
|
1654
|
-
parse: async (arrayBuffer) =>
|
|
1655
|
-
parseSync:
|
|
256
|
+
parse: async (arrayBuffer) => (0, import_gis8.convertTWKBToGeometry)(arrayBuffer),
|
|
257
|
+
parseSync: import_gis8.convertTWKBToGeometry
|
|
1656
258
|
};
|
|
1657
259
|
|
|
1658
|
-
// dist/lib/encode-twkb.js
|
|
1659
|
-
function encodeTWKB(geometry, options) {
|
|
1660
|
-
const writer = new BinaryWriter(0, true);
|
|
1661
|
-
const context = {
|
|
1662
|
-
...getTwkbPrecision(5, 0, 0),
|
|
1663
|
-
hasZ: options == null ? void 0 : options.hasZ,
|
|
1664
|
-
hasM: options == null ? void 0 : options.hasM
|
|
1665
|
-
};
|
|
1666
|
-
encodeGeometry(writer, geometry, context);
|
|
1667
|
-
return writer.arrayBuffer;
|
|
1668
|
-
}
|
|
1669
|
-
function encodeGeometry(writer, geometry, context) {
|
|
1670
|
-
switch (geometry.type) {
|
|
1671
|
-
case "Point":
|
|
1672
|
-
return encodePoint2(writer, context, geometry);
|
|
1673
|
-
case "LineString":
|
|
1674
|
-
return encodeLineString2(writer, context, geometry);
|
|
1675
|
-
case "Polygon":
|
|
1676
|
-
return encodePolygon2(writer, context, geometry);
|
|
1677
|
-
case "MultiPoint":
|
|
1678
|
-
return encodeMultiPoint2(writer, context, geometry);
|
|
1679
|
-
case "MultiLineString":
|
|
1680
|
-
return encodeMultiLineString2(writer, context, geometry);
|
|
1681
|
-
case "MultiPolygon":
|
|
1682
|
-
return encodeMultiPolygon2(writer, context, geometry);
|
|
1683
|
-
case "GeometryCollection":
|
|
1684
|
-
return encodeGeometryCollection2(writer, context, geometry);
|
|
1685
|
-
default:
|
|
1686
|
-
throw new Error("unsupported geometry type");
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
function encodePoint2(writer, context, point) {
|
|
1690
|
-
const isEmpty = point.coordinates.length === 0 || point[0] === "undefined" || point[1] === "undefined";
|
|
1691
|
-
writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
|
|
1692
|
-
if (!isEmpty) {
|
|
1693
|
-
const previousPoint = [0, 0, 0, 0];
|
|
1694
|
-
writeTwkbPoint(writer, context, point.coordinates, previousPoint);
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
function encodeLineString2(writer, context, lineString) {
|
|
1698
|
-
const points = lineString.coordinates;
|
|
1699
|
-
const isEmpty = points.length === 0;
|
|
1700
|
-
writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
|
|
1701
|
-
if (!isEmpty) {
|
|
1702
|
-
writer.writeVarInt(points.length);
|
|
1703
|
-
const previousPoint = [0, 0, 0, 0];
|
|
1704
|
-
for (const point of points) {
|
|
1705
|
-
writeTwkbPoint(writer, context, point, previousPoint);
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
return writer.arrayBuffer;
|
|
1709
|
-
}
|
|
1710
|
-
function encodePolygon2(writer, context, polygon) {
|
|
1711
|
-
const polygonRings = polygon.coordinates;
|
|
1712
|
-
const isEmpty = polygonRings.length === 0;
|
|
1713
|
-
writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
|
|
1714
|
-
if (!isEmpty) {
|
|
1715
|
-
writer.writeVarInt(polygonRings.length);
|
|
1716
|
-
const previousPoint = [0, 0, 0, 0];
|
|
1717
|
-
for (const ring of polygonRings) {
|
|
1718
|
-
writer.writeVarInt(ring.length);
|
|
1719
|
-
for (const point of ring) {
|
|
1720
|
-
writeTwkbPoint(writer, context, previousPoint, point);
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
return writer.arrayBuffer;
|
|
1725
|
-
}
|
|
1726
|
-
function encodeMultiPoint2(writer, context, multiPoint) {
|
|
1727
|
-
const points = multiPoint.coordinates;
|
|
1728
|
-
const isEmpty = points.length === 0;
|
|
1729
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
|
|
1730
|
-
if (!isEmpty) {
|
|
1731
|
-
writer.writeVarInt(points.length);
|
|
1732
|
-
const previousPoint = [0, 0, 0, 0];
|
|
1733
|
-
for (let i = 0; i < points.length; i++) {
|
|
1734
|
-
writeTwkbPoint(writer, context, previousPoint, points[i]);
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
function encodeMultiLineString2(writer, context, multiLineStrings) {
|
|
1739
|
-
const lineStrings = multiLineStrings.coordinates;
|
|
1740
|
-
const isEmpty = lineStrings.length === 0;
|
|
1741
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
|
|
1742
|
-
if (!isEmpty) {
|
|
1743
|
-
writer.writeVarInt(lineStrings.length);
|
|
1744
|
-
const previousPoint = [0, 0, 0, 0];
|
|
1745
|
-
for (const lineString of lineStrings) {
|
|
1746
|
-
writer.writeVarInt(lineString.length);
|
|
1747
|
-
for (const point of lineString) {
|
|
1748
|
-
writeTwkbPoint(writer, context, previousPoint, point);
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
return writer.arrayBuffer;
|
|
1753
|
-
}
|
|
1754
|
-
function encodeMultiPolygon2(writer, context, multiPolygon) {
|
|
1755
|
-
const { coordinates } = multiPolygon;
|
|
1756
|
-
const isEmpty = coordinates.length === 0;
|
|
1757
|
-
writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
|
|
1758
|
-
if (!isEmpty) {
|
|
1759
|
-
const polygons = coordinates;
|
|
1760
|
-
writer.writeVarInt(polygons.length);
|
|
1761
|
-
const previousPoint = [0, 0, 0, 0];
|
|
1762
|
-
for (const polygonRings of polygons) {
|
|
1763
|
-
writer.writeVarInt(polygonRings.length);
|
|
1764
|
-
for (const ring of polygonRings) {
|
|
1765
|
-
writer.writeVarInt(ring.length);
|
|
1766
|
-
for (const point of ring) {
|
|
1767
|
-
writeTwkbPoint(writer, context, previousPoint, point);
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
function encodeGeometryCollection2(writer, context, geometryCollection) {
|
|
1774
|
-
const { geometries } = geometryCollection;
|
|
1775
|
-
const isEmpty = geometries.length === 0;
|
|
1776
|
-
writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
|
|
1777
|
-
if (geometries.length > 0) {
|
|
1778
|
-
writer.writeVarInt(geometries.length);
|
|
1779
|
-
for (const geometry of geometries) {
|
|
1780
|
-
encodeGeometry(writer, geometry, context);
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
function writeTwkbHeader(writer, context, geometryType, isEmpty) {
|
|
1785
|
-
const type = (zigZagEncode(context.xy) << 4) + geometryType;
|
|
1786
|
-
let metadataHeader = context.hasZ || context.hasM ? 1 << 3 : 0;
|
|
1787
|
-
metadataHeader += isEmpty ? 1 << 4 : 0;
|
|
1788
|
-
writer.writeUInt8(type);
|
|
1789
|
-
writer.writeUInt8(metadataHeader);
|
|
1790
|
-
if (context.hasZ || context.hasM) {
|
|
1791
|
-
let extendedPrecision = 0;
|
|
1792
|
-
if (context.hasZ) {
|
|
1793
|
-
extendedPrecision |= 1;
|
|
1794
|
-
}
|
|
1795
|
-
if (context.hasM) {
|
|
1796
|
-
extendedPrecision |= 2;
|
|
1797
|
-
}
|
|
1798
|
-
writer.writeUInt8(extendedPrecision);
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
function writeTwkbPoint(writer, context, point, previousPoint) {
|
|
1802
|
-
const x = point[0] * context.xyFactor;
|
|
1803
|
-
const y = point[1] * context.xyFactor;
|
|
1804
|
-
const z = point[2] * context.zFactor;
|
|
1805
|
-
const m = point[3] * context.mFactor;
|
|
1806
|
-
writer.writeVarInt(zigZagEncode(x - previousPoint[0]));
|
|
1807
|
-
writer.writeVarInt(zigZagEncode(y - previousPoint[1]));
|
|
1808
|
-
if (context.hasZ) {
|
|
1809
|
-
writer.writeVarInt(zigZagEncode(z - previousPoint[2]));
|
|
1810
|
-
}
|
|
1811
|
-
if (context.hasM) {
|
|
1812
|
-
writer.writeVarInt(zigZagEncode(m - previousPoint[3]));
|
|
1813
|
-
}
|
|
1814
|
-
previousPoint[0] = x;
|
|
1815
|
-
previousPoint[1] = y;
|
|
1816
|
-
previousPoint[2] = z;
|
|
1817
|
-
previousPoint[3] = m;
|
|
1818
|
-
}
|
|
1819
|
-
function zigZagEncode(value) {
|
|
1820
|
-
return value << 1 ^ value >> 31;
|
|
1821
|
-
}
|
|
1822
|
-
function getTwkbPrecision(xyPrecision, zPrecision, mPrecision) {
|
|
1823
|
-
return {
|
|
1824
|
-
xy: xyPrecision,
|
|
1825
|
-
z: zPrecision,
|
|
1826
|
-
m: mPrecision,
|
|
1827
|
-
xyFactor: Math.pow(10, xyPrecision),
|
|
1828
|
-
zFactor: Math.pow(10, zPrecision),
|
|
1829
|
-
mFactor: Math.pow(10, mPrecision)
|
|
1830
|
-
};
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
260
|
// dist/twkb-writer.js
|
|
261
|
+
var import_gis9 = require("@loaders.gl/gis");
|
|
1834
262
|
var TWKBWriter = {
|
|
1835
263
|
name: "TWKB (Tiny Well Known Binary)",
|
|
1836
264
|
id: "twkb",
|
|
1837
265
|
module: "wkt",
|
|
1838
266
|
version: VERSION,
|
|
1839
267
|
extensions: ["twkb"],
|
|
1840
|
-
|
|
1841
|
-
|
|
268
|
+
mimeTypes: ["application/text"],
|
|
269
|
+
encode: async (geometry, options) => (0, import_gis9.convertGeometryToTWKB)(geometry, options == null ? void 0 : options.twkb),
|
|
270
|
+
encodeSync: (geometry, options) => (0, import_gis9.convertGeometryToTWKB)(geometry, options == null ? void 0 : options.twkb),
|
|
1842
271
|
options: {
|
|
1843
272
|
twkb: {
|
|
1844
273
|
hasZ: false,
|