@loaders.gl/wkt 3.1.1 → 3.1.5

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.
Files changed (46) hide show
  1. package/dist/bundle.js +5 -596
  2. package/dist/dist.min.js +983 -0
  3. package/dist/es5/index.js +8 -0
  4. package/dist/es5/index.js.map +1 -1
  5. package/dist/es5/lib/encode-wkb.js +468 -0
  6. package/dist/es5/lib/encode-wkb.js.map +1 -0
  7. package/dist/es5/lib/encode-wkt.js +32 -34
  8. package/dist/es5/lib/encode-wkt.js.map +1 -1
  9. package/dist/es5/lib/utils/binary-writer.js +186 -0
  10. package/dist/es5/lib/utils/binary-writer.js.map +1 -0
  11. package/dist/es5/lib/utils/version.js +1 -1
  12. package/dist/es5/wkb-writer.js +26 -0
  13. package/dist/es5/wkb-writer.js.map +1 -0
  14. package/dist/esm/index.js +1 -0
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/lib/encode-wkb.js +323 -0
  17. package/dist/esm/lib/encode-wkb.js.map +1 -0
  18. package/dist/esm/lib/encode-wkt.js +32 -34
  19. package/dist/esm/lib/encode-wkt.js.map +1 -1
  20. package/dist/esm/lib/utils/binary-writer.js +153 -0
  21. package/dist/esm/lib/utils/binary-writer.js.map +1 -0
  22. package/dist/esm/lib/utils/version.js +1 -1
  23. package/dist/esm/wkb-writer.js +14 -0
  24. package/dist/esm/wkb-writer.js.map +1 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +3 -1
  28. package/dist/lib/encode-wkb.d.ts +17 -0
  29. package/dist/lib/encode-wkb.d.ts.map +1 -0
  30. package/dist/lib/encode-wkb.js +290 -0
  31. package/dist/lib/encode-wkt.d.ts +2 -2
  32. package/dist/lib/encode-wkt.d.ts.map +1 -1
  33. package/dist/lib/encode-wkt.js +27 -29
  34. package/dist/lib/utils/binary-writer.d.ts +28 -0
  35. package/dist/lib/utils/binary-writer.d.ts.map +1 -0
  36. package/dist/lib/utils/binary-writer.js +120 -0
  37. package/dist/wkb-writer.d.ts +6 -0
  38. package/dist/wkb-writer.d.ts.map +1 -0
  39. package/dist/wkb-writer.js +23 -0
  40. package/dist/wkt-worker.js +1 -1
  41. package/package.json +6 -6
  42. package/src/index.ts +1 -0
  43. package/src/lib/encode-wkb.ts +386 -0
  44. package/src/lib/encode-wkt.ts +34 -36
  45. package/src/lib/utils/binary-writer.ts +125 -0
  46. package/src/wkb-writer.ts +19 -0
package/dist/bundle.js CHANGED
@@ -1,596 +1,5 @@
1
- (() => {
2
- var __defProp = Object.defineProperty;
3
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
4
- var __esm = (fn, res) => function __init() {
5
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
6
- };
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __export = (target, all) => {
11
- __markAsModule(target);
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
-
16
- // src/lib/utils/version.ts
17
- var VERSION;
18
- var init_version = __esm({
19
- "src/lib/utils/version.ts"() {
20
- VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
21
- }
22
- });
23
-
24
- // src/lib/parse-wkb.ts
25
- function parseWKB(arrayBuffer) {
26
- const view = new DataView(arrayBuffer);
27
- let offset = 0;
28
- const littleEndian = view.getUint8(offset) === 1;
29
- offset++;
30
- const geometryCode = view.getUint32(offset, littleEndian);
31
- offset += 4;
32
- const geometryType = geometryCode % 1e3;
33
- const type = (geometryCode - geometryType) / 1e3;
34
- const dimension = NUM_DIMENSIONS[type];
35
- switch (geometryType) {
36
- case 1:
37
- const point = parsePoint(view, offset, dimension, littleEndian);
38
- return point.geometry;
39
- case 2:
40
- const line = parseLineString(view, offset, dimension, littleEndian);
41
- return line.geometry;
42
- case 3:
43
- const polygon = parsePolygon(view, offset, dimension, littleEndian);
44
- return polygon.geometry;
45
- case 4:
46
- const multiPoint = parseMultiPoint(view, offset, dimension, littleEndian);
47
- multiPoint.type = "Point";
48
- return multiPoint;
49
- case 5:
50
- const multiLine = parseMultiLineString(view, offset, dimension, littleEndian);
51
- multiLine.type = "LineString";
52
- return multiLine;
53
- case 6:
54
- const multiPolygon = parseMultiPolygon(view, offset, dimension, littleEndian);
55
- multiPolygon.type = "Polygon";
56
- return multiPolygon;
57
- default:
58
- throw new Error(`WKB: Unsupported geometry type: ${geometryType}`);
59
- }
60
- }
61
- function parsePoint(view, offset, dimension, littleEndian) {
62
- const positions = new Float64Array(dimension);
63
- for (let i = 0; i < dimension; i++) {
64
- positions[i] = view.getFloat64(offset, littleEndian);
65
- offset += 8;
66
- }
67
- return {
68
- geometry: { type: "Point", positions: { value: positions, size: dimension } },
69
- offset
70
- };
71
- }
72
- function parseLineString(view, offset, dimension, littleEndian) {
73
- const nPoints = view.getUint32(offset, littleEndian);
74
- offset += 4;
75
- const positions = new Float64Array(nPoints * dimension);
76
- for (let i = 0; i < nPoints * dimension; i++) {
77
- positions[i] = view.getFloat64(offset, littleEndian);
78
- offset += 8;
79
- }
80
- const pathIndices = [0];
81
- if (nPoints > 0) {
82
- pathIndices.push(nPoints);
83
- }
84
- return {
85
- geometry: {
86
- type: "LineString",
87
- positions: { value: positions, size: dimension },
88
- pathIndices: { value: new Uint16Array(pathIndices), size: 1 }
89
- },
90
- offset
91
- };
92
- }
93
- function parsePolygon(view, offset, dimension, littleEndian) {
94
- const nRings = view.getUint32(offset, littleEndian);
95
- offset += 4;
96
- const rings = [];
97
- for (let i = 0; i < nRings; i++) {
98
- const parsed = parseLineString(view, offset, dimension, littleEndian);
99
- const { positions } = parsed.geometry;
100
- offset = parsed.offset;
101
- rings.push(positions.value);
102
- }
103
- const concatenatedPositions = new Float64Array(concatTypedArrays(rings).buffer);
104
- const polygonIndices = [0];
105
- if (concatenatedPositions.length > 0) {
106
- polygonIndices.push(concatenatedPositions.length / dimension);
107
- }
108
- const primitivePolygonIndices = rings.map((l) => l.length / dimension).map(cumulativeSum(0));
109
- primitivePolygonIndices.unshift(0);
110
- return {
111
- geometry: {
112
- type: "Polygon",
113
- positions: { value: concatenatedPositions, size: dimension },
114
- polygonIndices: {
115
- value: new Uint16Array(polygonIndices),
116
- size: 1
117
- },
118
- primitivePolygonIndices: { value: new Uint16Array(primitivePolygonIndices), size: 1 }
119
- },
120
- offset
121
- };
122
- }
123
- function parseMultiPoint(view, offset, dimension, littleEndian) {
124
- const nPoints = view.getUint32(offset, littleEndian);
125
- offset += 4;
126
- const binaryPointGeometries = [];
127
- for (let i = 0; i < nPoints; i++) {
128
- const littleEndianPoint = view.getUint8(offset) === 1;
129
- offset++;
130
- if (view.getUint32(offset, littleEndianPoint) % 1e3 !== 1) {
131
- throw new Error("WKB: Inner geometries of MultiPoint not of type Point");
132
- }
133
- offset += 4;
134
- const parsed = parsePoint(view, offset, dimension, littleEndianPoint);
135
- offset = parsed.offset;
136
- binaryPointGeometries.push(parsed.geometry);
137
- }
138
- return concatenateBinaryPointGeometries(binaryPointGeometries, dimension);
139
- }
140
- function parseMultiLineString(view, offset, dimension, littleEndian) {
141
- const nLines = view.getUint32(offset, littleEndian);
142
- offset += 4;
143
- const binaryLineGeometries = [];
144
- for (let i = 0; i < nLines; i++) {
145
- const littleEndianLine = view.getUint8(offset) === 1;
146
- offset++;
147
- if (view.getUint32(offset, littleEndianLine) % 1e3 !== 2) {
148
- throw new Error("WKB: Inner geometries of MultiLineString not of type LineString");
149
- }
150
- offset += 4;
151
- const parsed = parseLineString(view, offset, dimension, littleEndianLine);
152
- offset = parsed.offset;
153
- binaryLineGeometries.push(parsed.geometry);
154
- }
155
- return concatenateBinaryLineGeometries(binaryLineGeometries, dimension);
156
- }
157
- function parseMultiPolygon(view, offset, dimension, littleEndian) {
158
- const nPolygons = view.getUint32(offset, littleEndian);
159
- offset += 4;
160
- const binaryPolygonGeometries = [];
161
- for (let i = 0; i < nPolygons; i++) {
162
- const littleEndianPolygon = view.getUint8(offset) === 1;
163
- offset++;
164
- if (view.getUint32(offset, littleEndianPolygon) % 1e3 !== 3) {
165
- throw new Error("WKB: Inner geometries of MultiPolygon not of type Polygon");
166
- }
167
- offset += 4;
168
- const parsed = parsePolygon(view, offset, dimension, littleEndianPolygon);
169
- offset = parsed.offset;
170
- binaryPolygonGeometries.push(parsed.geometry);
171
- }
172
- return concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension);
173
- }
174
- function concatenateBinaryPointGeometries(binaryPointGeometries, dimension) {
175
- const positions = binaryPointGeometries.map((geometry) => geometry.positions.value);
176
- const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
177
- return {
178
- type: "Point",
179
- positions: { value: concatenatedPositions, size: dimension }
180
- };
181
- }
182
- function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
183
- const lines = binaryLineGeometries.map((geometry) => geometry.positions.value);
184
- const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
185
- const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
186
- pathIndices.unshift(0);
187
- return {
188
- type: "LineString",
189
- positions: { value: concatenatedPositions, size: dimension },
190
- pathIndices: { value: new Uint16Array(pathIndices), size: 1 }
191
- };
192
- }
193
- function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
194
- const polygons = [];
195
- const primitivePolygons = [];
196
- for (const binaryPolygon of binaryPolygonGeometries) {
197
- const { positions, primitivePolygonIndices: primitivePolygonIndices2 } = binaryPolygon;
198
- polygons.push(positions.value);
199
- primitivePolygons.push(primitivePolygonIndices2.value);
200
- }
201
- const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
202
- const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
203
- polygonIndices.unshift(0);
204
- const primitivePolygonIndices = [0];
205
- for (const primitivePolygon of primitivePolygons) {
206
- primitivePolygonIndices.push(...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
207
- }
208
- return {
209
- type: "Polygon",
210
- positions: { value: concatenatedPositions, size: dimension },
211
- polygonIndices: { value: new Uint16Array(polygonIndices), size: 1 },
212
- primitivePolygonIndices: { value: new Uint16Array(primitivePolygonIndices), size: 1 }
213
- };
214
- }
215
- function concatTypedArrays(arrays) {
216
- let byteLength = 0;
217
- for (let i = 0; i < arrays.length; ++i) {
218
- byteLength += arrays[i].byteLength;
219
- }
220
- const buffer = new Uint8Array(byteLength);
221
- let byteOffset = 0;
222
- for (let i = 0; i < arrays.length; ++i) {
223
- const data = new Uint8Array(arrays[i].buffer);
224
- byteLength = data.length;
225
- for (let j = 0; j < byteLength; ++j) {
226
- buffer[byteOffset++] = data[j];
227
- }
228
- }
229
- return buffer;
230
- }
231
- var NUM_DIMENSIONS, cumulativeSum;
232
- var init_parse_wkb = __esm({
233
- "src/lib/parse-wkb.ts"() {
234
- NUM_DIMENSIONS = {
235
- 0: 2,
236
- 1: 3,
237
- 2: 3,
238
- 3: 4
239
- };
240
- cumulativeSum = (sum) => (value) => sum += value;
241
- }
242
- });
243
-
244
- // src/wkb-loader.ts
245
- var WKBWorkerLoader, WKBLoader;
246
- var init_wkb_loader = __esm({
247
- "src/wkb-loader.ts"() {
248
- init_version();
249
- init_parse_wkb();
250
- WKBWorkerLoader = {
251
- name: "WKB",
252
- id: "wkb",
253
- module: "wkt",
254
- version: VERSION,
255
- worker: true,
256
- category: "geometry",
257
- extensions: ["wkb"],
258
- mimeTypes: [],
259
- options: {
260
- wkb: {}
261
- }
262
- };
263
- WKBLoader = {
264
- ...WKBWorkerLoader,
265
- parse: async (arrayBuffer) => parseWKB(arrayBuffer),
266
- parseSync: parseWKB
267
- };
268
- }
269
- });
270
-
271
- // src/lib/parse-wkt.ts
272
- function parseWKT(input) {
273
- const parts = input.split(";");
274
- let _ = parts.pop();
275
- const srid = (parts.shift() || "").split("=").pop();
276
- let i = 0;
277
- function $(re) {
278
- const match = _.substring(i).match(re);
279
- if (!match)
280
- return null;
281
- else {
282
- i += match[0].length;
283
- return match[0];
284
- }
285
- }
286
- function crs(obj) {
287
- if (obj && srid.match(/\d+/)) {
288
- obj.crs = {
289
- type: "name",
290
- properties: {
291
- name: "urn:ogc:def:crs:EPSG::" + srid
292
- }
293
- };
294
- }
295
- return obj;
296
- }
297
- function white() {
298
- $(/^\s*/);
299
- }
300
- function multicoords() {
301
- white();
302
- let depth = 0;
303
- const rings = [];
304
- const stack = [rings];
305
- let pointer = rings;
306
- let elem;
307
- while (elem = $(/^(\()/) || $(/^(\))/) || $(/^(,)/) || $(tuples)) {
308
- if (elem === "(") {
309
- stack.push(pointer);
310
- pointer = [];
311
- stack[stack.length - 1].push(pointer);
312
- depth++;
313
- } else if (elem === ")") {
314
- if (pointer.length === 0)
315
- return null;
316
- pointer = stack.pop();
317
- if (!pointer)
318
- return null;
319
- depth--;
320
- if (depth === 0)
321
- break;
322
- } else if (elem === ",") {
323
- pointer = [];
324
- stack[stack.length - 1].push(pointer);
325
- } else if (!elem.split(/\s/g).some(isNaN)) {
326
- Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
327
- } else {
328
- return null;
329
- }
330
- white();
331
- }
332
- if (depth !== 0)
333
- return null;
334
- return rings;
335
- }
336
- function coords() {
337
- const list = [];
338
- let item;
339
- let pt;
340
- while (pt = $(tuples) || $(/^(,)/)) {
341
- if (pt === ",") {
342
- list.push(item);
343
- item = [];
344
- } else if (!pt.split(/\s/g).some(isNaN)) {
345
- if (!item)
346
- item = [];
347
- Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
348
- }
349
- white();
350
- }
351
- if (item)
352
- list.push(item);
353
- else
354
- return null;
355
- return list.length ? list : null;
356
- }
357
- function point() {
358
- if (!$(/^(point(\sz)?)/i))
359
- return null;
360
- white();
361
- if (!$(/^(\()/))
362
- return null;
363
- const c = coords();
364
- if (!c)
365
- return null;
366
- white();
367
- if (!$(/^(\))/))
368
- return null;
369
- return {
370
- type: "Point",
371
- coordinates: c[0]
372
- };
373
- }
374
- function multipoint() {
375
- if (!$(/^(multipoint)/i))
376
- return null;
377
- white();
378
- const newCoordsFormat = _.substring(_.indexOf("(") + 1, _.length - 1).replace(/\(/g, "").replace(/\)/g, "");
379
- _ = "MULTIPOINT (" + newCoordsFormat + ")";
380
- const c = multicoords();
381
- if (!c)
382
- return null;
383
- white();
384
- return {
385
- type: "MultiPoint",
386
- coordinates: c
387
- };
388
- }
389
- function multilinestring() {
390
- if (!$(/^(multilinestring)/i))
391
- return null;
392
- white();
393
- const c = multicoords();
394
- if (!c)
395
- return null;
396
- white();
397
- return {
398
- type: "MultiLineString",
399
- coordinates: c
400
- };
401
- }
402
- function linestring() {
403
- if (!$(/^(linestring(\sz)?)/i))
404
- return null;
405
- white();
406
- if (!$(/^(\()/))
407
- return null;
408
- const c = coords();
409
- if (!c)
410
- return null;
411
- if (!$(/^(\))/))
412
- return null;
413
- return {
414
- type: "LineString",
415
- coordinates: c
416
- };
417
- }
418
- function polygon() {
419
- if (!$(/^(polygon(\sz)?)/i))
420
- return null;
421
- white();
422
- const c = multicoords();
423
- if (!c)
424
- return null;
425
- return {
426
- type: "Polygon",
427
- coordinates: c
428
- };
429
- }
430
- function multipolygon() {
431
- if (!$(/^(multipolygon)/i))
432
- return null;
433
- white();
434
- const c = multicoords();
435
- if (!c)
436
- return null;
437
- return {
438
- type: "MultiPolygon",
439
- coordinates: c
440
- };
441
- }
442
- function geometrycollection() {
443
- const geometries = [];
444
- let geometry;
445
- if (!$(/^(geometrycollection)/i))
446
- return null;
447
- white();
448
- if (!$(/^(\()/))
449
- return null;
450
- while (geometry = root()) {
451
- geometries.push(geometry);
452
- white();
453
- $(/^(,)/);
454
- white();
455
- }
456
- if (!$(/^(\))/))
457
- return null;
458
- return {
459
- type: "GeometryCollection",
460
- geometries
461
- };
462
- }
463
- function root() {
464
- return point() || linestring() || polygon() || multipoint() || multilinestring() || multipolygon() || geometrycollection();
465
- }
466
- return crs(root());
467
- }
468
- var numberRegexp, tuples;
469
- var init_parse_wkt = __esm({
470
- "src/lib/parse-wkt.ts"() {
471
- numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
472
- tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
473
- }
474
- });
475
-
476
- // src/wkt-loader.ts
477
- var WKTWorkerLoader, WKTLoader;
478
- var init_wkt_loader = __esm({
479
- "src/wkt-loader.ts"() {
480
- init_version();
481
- init_parse_wkt();
482
- WKTWorkerLoader = {
483
- name: "WKT (Well-Known Text)",
484
- id: "wkt",
485
- module: "wkt",
486
- version: VERSION,
487
- worker: true,
488
- extensions: ["wkt"],
489
- mimeTypes: ["text/plain"],
490
- category: "geometry",
491
- text: true,
492
- options: {
493
- wkt: {}
494
- }
495
- };
496
- WKTLoader = {
497
- ...WKTWorkerLoader,
498
- parse: async (arrayBuffer) => parseWKT(new TextDecoder().decode(arrayBuffer)),
499
- parseTextSync: parseWKT
500
- };
501
- }
502
- });
503
-
504
- // src/lib/encode-wkt.ts
505
- function encodeWKT(gj) {
506
- if (gj.type === "Feature") {
507
- gj = gj.geometry;
508
- }
509
- function pairWKT(c) {
510
- return c.join(" ");
511
- }
512
- function ringWKT(r) {
513
- return r.map(pairWKT).join(", ");
514
- }
515
- function ringsWKT(r) {
516
- return r.map(ringWKT).map(wrapParens).join(", ");
517
- }
518
- function multiRingsWKT(r) {
519
- return r.map(ringsWKT).map(wrapParens).join(", ");
520
- }
521
- function wrapParens(s) {
522
- return `(${s})`;
523
- }
524
- switch (gj.type) {
525
- case "Point":
526
- return `POINT ${wrapParens(pairWKT(gj.coordinates))}`;
527
- case "LineString":
528
- return `LINESTRING ${wrapParens(ringWKT(gj.coordinates))}`;
529
- case "Polygon":
530
- return `POLYGON ${wrapParens(ringsWKT(gj.coordinates))}`;
531
- case "MultiPoint":
532
- return `MULTIPOINT ${wrapParens(ringWKT(gj.coordinates))}`;
533
- case "MultiPolygon":
534
- return `MULTIPOLYGON ${wrapParens(multiRingsWKT(gj.coordinates))}`;
535
- case "MultiLineString":
536
- return `MULTILINESTRING ${wrapParens(ringsWKT(gj.coordinates))}`;
537
- case "GeometryCollection":
538
- return `GEOMETRYCOLLECTION ${wrapParens(gj.geometries.map(encodeWKT).join(", "))}`;
539
- default:
540
- return ((_x) => {
541
- throw new Error("stringify requires a valid GeoJSON Feature or geometry object as input");
542
- })(gj);
543
- }
544
- }
545
- var init_encode_wkt = __esm({
546
- "src/lib/encode-wkt.ts"() {
547
- }
548
- });
549
-
550
- // src/wkt-writer.ts
551
- var WKTWriter;
552
- var init_wkt_writer = __esm({
553
- "src/wkt-writer.ts"() {
554
- init_version();
555
- init_encode_wkt();
556
- WKTWriter = {
557
- name: "WKT (Well Known Text)",
558
- id: "wkt",
559
- module: "wkt",
560
- version: VERSION,
561
- extensions: ["wkt"],
562
- encode: encodeWKT,
563
- options: {
564
- wkt: {}
565
- }
566
- };
567
- }
568
- });
569
-
570
- // src/index.ts
571
- var src_exports = {};
572
- __export(src_exports, {
573
- WKBLoader: () => WKBLoader,
574
- WKBWorkerLoader: () => WKBWorkerLoader,
575
- WKTLoader: () => WKTLoader,
576
- WKTWorkerLoader: () => WKTWorkerLoader,
577
- WKTWriter: () => WKTWriter
578
- });
579
- var init_src = __esm({
580
- "src/index.ts"() {
581
- init_wkb_loader();
582
- init_wkt_loader();
583
- init_wkt_writer();
584
- }
585
- });
586
-
587
- // src/bundle.ts
588
- var require_bundle = __commonJS({
589
- "src/bundle.ts"(exports, module) {
590
- var moduleExports = (init_src(), src_exports);
591
- globalThis.loaders = globalThis.loaders || {};
592
- module.exports = Object.assign(globalThis.loaders, moduleExports);
593
- }
594
- });
595
- require_bundle();
596
- })();
1
+ "use strict";
2
+ // @ts-nocheck
3
+ const moduleExports = require('./index');
4
+ globalThis.loaders = globalThis.loaders || {};
5
+ module.exports = Object.assign(globalThis.loaders, moduleExports);