@loaders.gl/wkt 3.4.11 → 3.4.12

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.
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.VERSION = void 0;
7
- var VERSION = typeof "3.4.11" !== 'undefined' ? "3.4.11" : 'latest';
7
+ var VERSION = typeof "3.4.12" !== 'undefined' ? "3.4.12" : 'latest';
8
8
  exports.VERSION = VERSION;
9
9
  //# sourceMappingURL=version.js.map
@@ -1,2 +1,2 @@
1
- export const VERSION = typeof "3.4.11" !== 'undefined' ? "3.4.11" : 'latest';
1
+ export const VERSION = typeof "3.4.12" !== 'undefined' ? "3.4.12" : 'latest';
2
2
  //# sourceMappingURL=version.js.map
@@ -184,7 +184,7 @@
184
184
  }
185
185
 
186
186
  // src/lib/utils/version.ts
187
- var VERSION = true ? "3.4.11" : "latest";
187
+ var VERSION = true ? "3.4.12" : "latest";
188
188
 
189
189
  // src/lib/parse-wkt.ts
190
190
  var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/wkt",
3
3
  "description": "Loader and Writer for the WKT (Well Known Text) Format",
4
- "version": "3.4.11",
4
+ "version": "3.4.12",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -35,8 +35,8 @@
35
35
  "fuzzer": "^0.2.1"
36
36
  },
37
37
  "dependencies": {
38
- "@loaders.gl/loader-utils": "3.4.11",
39
- "@loaders.gl/schema": "3.4.11"
38
+ "@loaders.gl/loader-utils": "3.4.12",
39
+ "@loaders.gl/schema": "3.4.12"
40
40
  },
41
- "gitHead": "2b8d490d2372e70dd89eef8f6b215a5205c16621"
41
+ "gitHead": "85254762ae3082f608a863291deef09f2b40c6cf"
42
42
  }
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
package/dist/index.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WKBWriter = exports.WKTWriter = exports.WKTWorkerLoader = exports.WKTLoader = exports.WKBWorkerLoader = exports.WKBLoader = void 0;
4
- var wkb_loader_1 = require("./wkb-loader");
5
- Object.defineProperty(exports, "WKBLoader", { enumerable: true, get: function () { return wkb_loader_1.WKBLoader; } });
6
- Object.defineProperty(exports, "WKBWorkerLoader", { enumerable: true, get: function () { return wkb_loader_1.WKBWorkerLoader; } });
7
- var wkt_loader_1 = require("./wkt-loader");
8
- Object.defineProperty(exports, "WKTLoader", { enumerable: true, get: function () { return wkt_loader_1.WKTLoader; } });
9
- Object.defineProperty(exports, "WKTWorkerLoader", { enumerable: true, get: function () { return wkt_loader_1.WKTWorkerLoader; } });
10
- var wkt_writer_1 = require("./wkt-writer");
11
- Object.defineProperty(exports, "WKTWriter", { enumerable: true, get: function () { return wkt_writer_1.WKTWriter; } });
12
- var wkb_writer_1 = require("./wkb-writer");
13
- Object.defineProperty(exports, "WKBWriter", { enumerable: true, get: function () { return wkb_writer_1.WKBWriter; } });
@@ -1,295 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- // Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
4
- // Reference: https://www.ogc.org/standards/sfa
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const binary_writer_1 = __importDefault(require("./utils/binary-writer"));
10
- /**
11
- * Integer code for geometry type
12
- * Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
13
- */
14
- var WKB;
15
- (function (WKB) {
16
- WKB[WKB["Point"] = 1] = "Point";
17
- WKB[WKB["LineString"] = 2] = "LineString";
18
- WKB[WKB["Polygon"] = 3] = "Polygon";
19
- WKB[WKB["MultiPoint"] = 4] = "MultiPoint";
20
- WKB[WKB["MultiLineString"] = 5] = "MultiLineString";
21
- WKB[WKB["MultiPolygon"] = 6] = "MultiPolygon";
22
- WKB[WKB["GeometryCollection"] = 7] = "GeometryCollection";
23
- })(WKB || (WKB = {}));
24
- /**
25
- * Encodes a GeoJSON object into WKB
26
- * @param geojson A GeoJSON Feature or Geometry
27
- * @returns string
28
- */
29
- function encodeWKB(geometry, options = {}) {
30
- if (geometry.type === 'Feature') {
31
- geometry = geometry.geometry;
32
- }
33
- // Options should be wrapped in a `wkb` key, but we allow top-level options here for backwards
34
- // compatibility
35
- if ('wkb' in options) {
36
- options = options.wkb;
37
- }
38
- switch (geometry.type) {
39
- case 'Point':
40
- return encodePoint(geometry.coordinates, options);
41
- case 'LineString':
42
- return encodeLineString(geometry.coordinates, options);
43
- case 'Polygon':
44
- return encodePolygon(geometry.coordinates, options);
45
- case 'MultiPoint':
46
- return encodeMultiPoint(geometry, options);
47
- case 'MultiPolygon':
48
- return encodeMultiPolygon(geometry, options);
49
- case 'MultiLineString':
50
- return encodeMultiLineString(geometry, options);
51
- case 'GeometryCollection':
52
- return encodeGeometryCollection(geometry, options);
53
- default:
54
- const exhaustiveCheck = geometry;
55
- throw new Error(`Unhandled case: ${exhaustiveCheck}`);
56
- }
57
- }
58
- exports.default = encodeWKB;
59
- /** Calculate the binary size (in the WKB encoding) of a specific GeoJSON geometry */
60
- function getGeometrySize(geometry, options) {
61
- switch (geometry.type) {
62
- case 'Point':
63
- return getPointSize(options);
64
- case 'LineString':
65
- return getLineStringSize(geometry.coordinates, options);
66
- case 'Polygon':
67
- return getPolygonSize(geometry.coordinates, options);
68
- case 'MultiPoint':
69
- return getMultiPointSize(geometry, options);
70
- case 'MultiPolygon':
71
- return getMultiPolygonSize(geometry, options);
72
- case 'MultiLineString':
73
- return getMultiLineStringSize(geometry, options);
74
- case 'GeometryCollection':
75
- return getGeometryCollectionSize(geometry, options);
76
- default:
77
- const exhaustiveCheck = geometry;
78
- throw new Error(`Unhandled case: ${exhaustiveCheck}`);
79
- }
80
- }
81
- /** Encode Point geometry as WKB ArrayBuffer */
82
- function encodePoint(coordinates, options) {
83
- const writer = new binary_writer_1.default(getPointSize(options));
84
- writer.writeInt8(1);
85
- writeWkbType(writer, WKB.Point, options);
86
- // I believe this special case is to handle writing Point(NaN, NaN) correctly
87
- if (typeof coordinates[0] === 'undefined' && typeof coordinates[1] === 'undefined') {
88
- writer.writeDoubleLE(NaN);
89
- writer.writeDoubleLE(NaN);
90
- if (options.hasZ) {
91
- writer.writeDoubleLE(NaN);
92
- }
93
- if (options.hasM) {
94
- writer.writeDoubleLE(NaN);
95
- }
96
- }
97
- else {
98
- writeCoordinate(writer, coordinates, options);
99
- }
100
- return writer.arrayBuffer;
101
- }
102
- /** Write coordinate to buffer */
103
- function writeCoordinate(writer, coordinate, options) {
104
- writer.writeDoubleLE(coordinate[0]);
105
- writer.writeDoubleLE(coordinate[1]);
106
- if (options.hasZ) {
107
- writer.writeDoubleLE(coordinate[2]);
108
- }
109
- if (options.hasM) {
110
- writer.writeDoubleLE(coordinate[3]);
111
- }
112
- }
113
- /** Get encoded size of Point geometry */
114
- function getPointSize(options) {
115
- const coordinateSize = getCoordinateSize(options);
116
- return 1 + 4 + coordinateSize;
117
- }
118
- /** Encode LineString geometry as WKB ArrayBuffer */
119
- function encodeLineString(coordinates, options) {
120
- const size = getLineStringSize(coordinates, options);
121
- const writer = new binary_writer_1.default(size);
122
- writer.writeInt8(1);
123
- writeWkbType(writer, WKB.LineString, options);
124
- writer.writeUInt32LE(coordinates.length);
125
- for (const coordinate of coordinates) {
126
- writeCoordinate(writer, coordinate, options);
127
- }
128
- return writer.arrayBuffer;
129
- }
130
- /** Get encoded size of LineString geometry */
131
- function getLineStringSize(coordinates, options) {
132
- const coordinateSize = getCoordinateSize(options);
133
- return 1 + 4 + 4 + coordinates.length * coordinateSize;
134
- }
135
- /** Encode Polygon geometry as WKB ArrayBuffer */
136
- function encodePolygon(coordinates, options) {
137
- const writer = new binary_writer_1.default(getPolygonSize(coordinates, options));
138
- writer.writeInt8(1);
139
- writeWkbType(writer, WKB.Polygon, options);
140
- const [exteriorRing, ...interiorRings] = coordinates;
141
- if (exteriorRing.length > 0) {
142
- writer.writeUInt32LE(1 + interiorRings.length);
143
- writer.writeUInt32LE(exteriorRing.length);
144
- }
145
- else {
146
- writer.writeUInt32LE(0);
147
- }
148
- for (const coordinate of exteriorRing) {
149
- writeCoordinate(writer, coordinate, options);
150
- }
151
- for (const interiorRing of interiorRings) {
152
- writer.writeUInt32LE(interiorRing.length);
153
- for (const coordinate of interiorRing) {
154
- writeCoordinate(writer, coordinate, options);
155
- }
156
- }
157
- return writer.arrayBuffer;
158
- }
159
- /** Get encoded size of Polygon geometry */
160
- function getPolygonSize(coordinates, options) {
161
- const coordinateSize = getCoordinateSize(options);
162
- const [exteriorRing, ...interiorRings] = coordinates;
163
- let size = 1 + 4 + 4;
164
- if (exteriorRing.length > 0) {
165
- size += 4 + exteriorRing.length * coordinateSize;
166
- }
167
- for (const interiorRing of interiorRings) {
168
- size += 4 + interiorRing.length * coordinateSize;
169
- }
170
- return size;
171
- }
172
- /** Encode MultiPoint geometry as WKB ArrayBufer */
173
- function encodeMultiPoint(multiPoint, options) {
174
- const writer = new binary_writer_1.default(getMultiPointSize(multiPoint, options));
175
- const points = multiPoint.coordinates;
176
- writer.writeInt8(1);
177
- writeWkbType(writer, WKB.MultiPoint, options);
178
- writer.writeUInt32LE(points.length);
179
- for (const point of points) {
180
- // TODO: add srid to this options object? {srid: multiPoint.srid}
181
- const arrayBuffer = encodePoint(point, options);
182
- writer.writeBuffer(arrayBuffer);
183
- }
184
- return writer.arrayBuffer;
185
- }
186
- /** Get encoded size of MultiPoint geometry */
187
- function getMultiPointSize(multiPoint, options) {
188
- let coordinateSize = getCoordinateSize(options);
189
- const points = multiPoint.coordinates;
190
- // This is because each point has a 5-byte header?
191
- coordinateSize += 5;
192
- return 1 + 4 + 4 + points.length * coordinateSize;
193
- }
194
- /** Encode MultiLineString geometry as WKB ArrayBufer */
195
- function encodeMultiLineString(multiLineString, options) {
196
- const writer = new binary_writer_1.default(getMultiLineStringSize(multiLineString, options));
197
- const lineStrings = multiLineString.coordinates;
198
- writer.writeInt8(1);
199
- writeWkbType(writer, WKB.MultiLineString, options);
200
- writer.writeUInt32LE(lineStrings.length);
201
- for (const lineString of lineStrings) {
202
- // TODO: Handle srid?
203
- const encodedLineString = encodeLineString(lineString, options);
204
- writer.writeBuffer(encodedLineString);
205
- }
206
- return writer.arrayBuffer;
207
- }
208
- /** Get encoded size of MultiLineString geometry */
209
- function getMultiLineStringSize(multiLineString, options) {
210
- let size = 1 + 4 + 4;
211
- const lineStrings = multiLineString.coordinates;
212
- for (const lineString of lineStrings) {
213
- size += getLineStringSize(lineString, options);
214
- }
215
- return size;
216
- }
217
- function encodeMultiPolygon(multiPolygon, options) {
218
- const writer = new binary_writer_1.default(getMultiPolygonSize(multiPolygon, options));
219
- const polygons = multiPolygon.coordinates;
220
- writer.writeInt8(1);
221
- writeWkbType(writer, WKB.MultiPolygon, options);
222
- writer.writeUInt32LE(polygons.length);
223
- for (const polygon of polygons) {
224
- const encodedPolygon = encodePolygon(polygon, options);
225
- writer.writeBuffer(encodedPolygon);
226
- }
227
- return writer.arrayBuffer;
228
- }
229
- function getMultiPolygonSize(multiPolygon, options) {
230
- let size = 1 + 4 + 4;
231
- const polygons = multiPolygon.coordinates;
232
- for (const polygon of polygons) {
233
- size += getPolygonSize(polygon, options);
234
- }
235
- return size;
236
- }
237
- function encodeGeometryCollection(collection, options) {
238
- const writer = new binary_writer_1.default(getGeometryCollectionSize(collection, options));
239
- writer.writeInt8(1);
240
- writeWkbType(writer, WKB.GeometryCollection, options);
241
- writer.writeUInt32LE(collection.geometries.length);
242
- for (const geometry of collection.geometries) {
243
- // TODO: handle srid? {srid: collection.srid}
244
- const arrayBuffer = encodeWKB(geometry, options);
245
- writer.writeBuffer(arrayBuffer);
246
- }
247
- return writer.arrayBuffer;
248
- }
249
- function getGeometryCollectionSize(collection, options) {
250
- let size = 1 + 4 + 4;
251
- for (const geometry of collection.geometries) {
252
- size += getGeometrySize(geometry, options);
253
- }
254
- return size;
255
- }
256
- // HELPERS
257
- /**
258
- * Construct and write WKB integer code
259
- * Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary
260
- */
261
- function writeWkbType(writer, geometryType, options) {
262
- const { hasZ, hasM, srid } = options;
263
- let dimensionType = 0;
264
- if (!srid) {
265
- if (hasZ && hasM) {
266
- dimensionType += 3000;
267
- }
268
- else if (hasZ) {
269
- dimensionType += 1000;
270
- }
271
- else if (hasM) {
272
- dimensionType += 2000;
273
- }
274
- }
275
- else {
276
- if (hasZ) {
277
- dimensionType |= 0x80000000;
278
- }
279
- if (hasM) {
280
- dimensionType |= 0x40000000;
281
- }
282
- }
283
- writer.writeUInt32LE((dimensionType + geometryType) >>> 0);
284
- }
285
- /** Get coordinate size given Z/M dimensions */
286
- function getCoordinateSize(options) {
287
- let coordinateSize = 16;
288
- if (options.hasZ) {
289
- coordinateSize += 8;
290
- }
291
- if (options.hasM) {
292
- coordinateSize += 8;
293
- }
294
- return coordinateSize;
295
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Stringifies a GeoJSON object into WKT
5
- * @param geojson
6
- * @returns string
7
- */
8
- function encodeWKT(geometry) {
9
- if (geometry.type === 'Feature') {
10
- geometry = geometry.geometry;
11
- }
12
- switch (geometry.type) {
13
- case 'Point':
14
- return `POINT ${wrapParens(pairWKT(geometry.coordinates))}`;
15
- case 'LineString':
16
- return `LINESTRING ${wrapParens(ringWKT(geometry.coordinates))}`;
17
- case 'Polygon':
18
- return `POLYGON ${wrapParens(ringsWKT(geometry.coordinates))}`;
19
- case 'MultiPoint':
20
- return `MULTIPOINT ${wrapParens(ringWKT(geometry.coordinates))}`;
21
- case 'MultiPolygon':
22
- return `MULTIPOLYGON ${wrapParens(multiRingsWKT(geometry.coordinates))}`;
23
- case 'MultiLineString':
24
- return `MULTILINESTRING ${wrapParens(ringsWKT(geometry.coordinates))}`;
25
- case 'GeometryCollection':
26
- return `GEOMETRYCOLLECTION ${wrapParens(geometry.geometries.map(encodeWKT).join(', '))}`;
27
- default:
28
- throw new Error('stringify requires a valid GeoJSON Feature or geometry object as input');
29
- }
30
- }
31
- exports.default = encodeWKT;
32
- function pairWKT(c) {
33
- return c.join(' ');
34
- }
35
- function ringWKT(r) {
36
- return r.map(pairWKT).join(', ');
37
- }
38
- function ringsWKT(r) {
39
- return r.map(ringWKT).map(wrapParens).join(', ');
40
- }
41
- function multiRingsWKT(r) {
42
- return r.map(ringsWKT).map(wrapParens).join(', ');
43
- }
44
- function wrapParens(s) {
45
- return `(${s})`;
46
- }
@@ -1,236 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const NUM_DIMENSIONS = {
4
- 0: 2,
5
- 1: 3,
6
- 2: 3,
7
- 3: 4 // 4D (ZM)
8
- };
9
- function parseWKB(arrayBuffer) {
10
- const view = new DataView(arrayBuffer);
11
- let offset = 0;
12
- // Check endianness of data
13
- const littleEndian = view.getUint8(offset) === 1;
14
- offset++;
15
- // 4-digit code representing dimension and type of geometry
16
- const geometryCode = view.getUint32(offset, littleEndian);
17
- offset += 4;
18
- const geometryType = geometryCode % 1000;
19
- const type = ((geometryCode - geometryType) / 1000);
20
- const dimension = NUM_DIMENSIONS[type];
21
- switch (geometryType) {
22
- case 1:
23
- const point = parsePoint(view, offset, dimension, littleEndian);
24
- return point.geometry;
25
- case 2:
26
- const line = parseLineString(view, offset, dimension, littleEndian);
27
- return line.geometry;
28
- case 3:
29
- const polygon = parsePolygon(view, offset, dimension, littleEndian);
30
- return polygon.geometry;
31
- case 4:
32
- const multiPoint = parseMultiPoint(view, offset, dimension, littleEndian);
33
- multiPoint.type = 'Point';
34
- return multiPoint;
35
- case 5:
36
- const multiLine = parseMultiLineString(view, offset, dimension, littleEndian);
37
- multiLine.type = 'LineString';
38
- return multiLine;
39
- case 6:
40
- const multiPolygon = parseMultiPolygon(view, offset, dimension, littleEndian);
41
- multiPolygon.type = 'Polygon';
42
- return multiPolygon;
43
- // case 7:
44
- // TODO: handle GeometryCollections
45
- // return parseGeometryCollection(view, offset, dimension, littleEndian);
46
- default:
47
- throw new Error(`WKB: Unsupported geometry type: ${geometryType}`);
48
- }
49
- }
50
- exports.default = parseWKB;
51
- // Primitives; parse point and linear ring
52
- function parsePoint(view, offset, dimension, littleEndian) {
53
- const positions = new Float64Array(dimension);
54
- for (let i = 0; i < dimension; i++) {
55
- positions[i] = view.getFloat64(offset, littleEndian);
56
- offset += 8;
57
- }
58
- return {
59
- geometry: { type: 'Point', positions: { value: positions, size: dimension } },
60
- offset
61
- };
62
- }
63
- function parseLineString(view, offset, dimension, littleEndian) {
64
- const nPoints = view.getUint32(offset, littleEndian);
65
- offset += 4;
66
- // Instantiate array
67
- const positions = new Float64Array(nPoints * dimension);
68
- for (let i = 0; i < nPoints * dimension; i++) {
69
- positions[i] = view.getFloat64(offset, littleEndian);
70
- offset += 8;
71
- }
72
- const pathIndices = [0];
73
- if (nPoints > 0) {
74
- pathIndices.push(nPoints);
75
- }
76
- return {
77
- geometry: {
78
- type: 'LineString',
79
- positions: { value: positions, size: dimension },
80
- pathIndices: { value: new Uint16Array(pathIndices), size: 1 }
81
- },
82
- offset
83
- };
84
- }
85
- // https://stackoverflow.com/a/55261098
86
- const cumulativeSum = (sum) => (value) => (sum += value);
87
- function parsePolygon(view, offset, dimension, littleEndian) {
88
- const nRings = view.getUint32(offset, littleEndian);
89
- offset += 4;
90
- const rings = [];
91
- for (let i = 0; i < nRings; i++) {
92
- const parsed = parseLineString(view, offset, dimension, littleEndian);
93
- const { positions } = parsed.geometry;
94
- offset = parsed.offset;
95
- rings.push(positions.value);
96
- }
97
- const concatenatedPositions = new Float64Array(concatTypedArrays(rings).buffer);
98
- const polygonIndices = [0];
99
- if (concatenatedPositions.length > 0) {
100
- polygonIndices.push(concatenatedPositions.length / dimension);
101
- }
102
- const primitivePolygonIndices = rings.map((l) => l.length / dimension).map(cumulativeSum(0));
103
- primitivePolygonIndices.unshift(0);
104
- return {
105
- geometry: {
106
- type: 'Polygon',
107
- positions: { value: concatenatedPositions, size: dimension },
108
- polygonIndices: {
109
- value: new Uint16Array(polygonIndices),
110
- size: 1
111
- },
112
- primitivePolygonIndices: { value: new Uint16Array(primitivePolygonIndices), size: 1 }
113
- },
114
- offset
115
- };
116
- }
117
- function parseMultiPoint(view, offset, dimension, littleEndian) {
118
- const nPoints = view.getUint32(offset, littleEndian);
119
- offset += 4;
120
- const binaryPointGeometries = [];
121
- for (let i = 0; i < nPoints; i++) {
122
- // Byte order for point
123
- const littleEndianPoint = view.getUint8(offset) === 1;
124
- offset++;
125
- // Assert point type
126
- if (view.getUint32(offset, littleEndianPoint) % 1000 !== 1) {
127
- throw new Error('WKB: Inner geometries of MultiPoint not of type Point');
128
- }
129
- offset += 4;
130
- const parsed = parsePoint(view, offset, dimension, littleEndianPoint);
131
- offset = parsed.offset;
132
- binaryPointGeometries.push(parsed.geometry);
133
- }
134
- return concatenateBinaryPointGeometries(binaryPointGeometries, dimension);
135
- }
136
- function parseMultiLineString(view, offset, dimension, littleEndian) {
137
- const nLines = view.getUint32(offset, littleEndian);
138
- offset += 4;
139
- const binaryLineGeometries = [];
140
- for (let i = 0; i < nLines; i++) {
141
- // Byte order for line
142
- const littleEndianLine = view.getUint8(offset) === 1;
143
- offset++;
144
- // Assert type LineString
145
- if (view.getUint32(offset, littleEndianLine) % 1000 !== 2) {
146
- throw new Error('WKB: Inner geometries of MultiLineString not of type LineString');
147
- }
148
- offset += 4;
149
- const parsed = parseLineString(view, offset, dimension, littleEndianLine);
150
- offset = parsed.offset;
151
- binaryLineGeometries.push(parsed.geometry);
152
- }
153
- return concatenateBinaryLineGeometries(binaryLineGeometries, dimension);
154
- }
155
- function parseMultiPolygon(view, offset, dimension, littleEndian) {
156
- const nPolygons = view.getUint32(offset, littleEndian);
157
- offset += 4;
158
- const binaryPolygonGeometries = [];
159
- for (let i = 0; i < nPolygons; i++) {
160
- // Byte order for polygon
161
- const littleEndianPolygon = view.getUint8(offset) === 1;
162
- offset++;
163
- // Assert type Polygon
164
- if (view.getUint32(offset, littleEndianPolygon) % 1000 !== 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
- // TODO - move to loaders.gl/schema/gis
175
- function concatenateBinaryPointGeometries(binaryPointGeometries, dimension) {
176
- const positions = binaryPointGeometries.map((geometry) => geometry.positions.value);
177
- const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
178
- return {
179
- type: 'Point',
180
- positions: { value: concatenatedPositions, size: dimension }
181
- };
182
- }
183
- function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
184
- const lines = binaryLineGeometries.map((geometry) => geometry.positions.value);
185
- const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
186
- const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
187
- pathIndices.unshift(0);
188
- return {
189
- type: 'LineString',
190
- positions: { value: concatenatedPositions, size: dimension },
191
- pathIndices: { value: new Uint16Array(pathIndices), size: 1 }
192
- };
193
- }
194
- function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
195
- const polygons = [];
196
- const primitivePolygons = [];
197
- for (const binaryPolygon of binaryPolygonGeometries) {
198
- const { positions, primitivePolygonIndices } = binaryPolygon;
199
- polygons.push(positions.value);
200
- primitivePolygons.push(primitivePolygonIndices.value);
201
- }
202
- const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
203
- const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
204
- polygonIndices.unshift(0);
205
- // Combine primitivePolygonIndices from each individual polygon
206
- const primitivePolygonIndices = [0];
207
- for (const primitivePolygon of primitivePolygons) {
208
- primitivePolygonIndices.push(...primitivePolygon
209
- .filter((x) => x > 0)
210
- .map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
211
- }
212
- return {
213
- type: 'Polygon',
214
- positions: { value: concatenatedPositions, size: dimension },
215
- polygonIndices: { value: new Uint16Array(polygonIndices), size: 1 },
216
- primitivePolygonIndices: { value: new Uint16Array(primitivePolygonIndices), size: 1 }
217
- };
218
- }
219
- // TODO: remove copy; import from typed-array-utils
220
- // modules/math/src/geometry/typed-arrays/typed-array-utils.js
221
- function concatTypedArrays(arrays) {
222
- let byteLength = 0;
223
- for (let i = 0; i < arrays.length; ++i) {
224
- byteLength += arrays[i].byteLength;
225
- }
226
- const buffer = new Uint8Array(byteLength);
227
- let byteOffset = 0;
228
- for (let i = 0; i < arrays.length; ++i) {
229
- const data = new Uint8Array(arrays[i].buffer);
230
- byteLength = data.length;
231
- for (let j = 0; j < byteLength; ++j) {
232
- buffer[byteOffset++] = data[j];
233
- }
234
- }
235
- return buffer;
236
- }
@@ -1,227 +0,0 @@
1
- "use strict";
2
- // Fork of https://github.com/mapbox/wellknown under ISC license (MIT/BSD-2-clause equivalent)
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /* eslint-disable */
5
- // @ts-nocheck
6
- const numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
7
- // Matches sequences like '100 100' or '100 100 100'.
8
- const tuples = new RegExp('^' + numberRegexp.source + '(\\s' + numberRegexp.source + '){1,}');
9
- /**
10
- * Parse WKT and return GeoJSON.
11
- *
12
- * @param {string} _ A WKT geometry
13
- * @return {?Object} A GeoJSON geometry object
14
- **/
15
- function parseWKT(input) {
16
- const parts = input.split(';');
17
- let _ = parts.pop();
18
- const srid = (parts.shift() || '').split('=').pop();
19
- let i = 0;
20
- function $(re) {
21
- const match = _.substring(i).match(re);
22
- if (!match)
23
- return null;
24
- else {
25
- i += match[0].length;
26
- return match[0];
27
- }
28
- }
29
- function crs(obj) {
30
- if (obj && srid.match(/\d+/)) {
31
- obj.crs = {
32
- type: 'name',
33
- properties: {
34
- name: 'urn:ogc:def:crs:EPSG::' + srid
35
- }
36
- };
37
- }
38
- return obj;
39
- }
40
- function white() {
41
- $(/^\s*/);
42
- }
43
- function multicoords() {
44
- white();
45
- let depth = 0;
46
- const rings = [];
47
- const stack = [rings];
48
- let pointer = rings;
49
- let elem;
50
- while ((elem = $(/^(\()/) || $(/^(\))/) || $(/^(,)/) || $(tuples))) {
51
- if (elem === '(') {
52
- stack.push(pointer);
53
- pointer = [];
54
- stack[stack.length - 1].push(pointer);
55
- depth++;
56
- }
57
- else if (elem === ')') {
58
- // For the case: Polygon(), ...
59
- if (pointer.length === 0)
60
- return null;
61
- // @ts-ignore
62
- pointer = stack.pop();
63
- // the stack was empty, input was malformed
64
- if (!pointer)
65
- return null;
66
- depth--;
67
- if (depth === 0)
68
- break;
69
- }
70
- else if (elem === ',') {
71
- pointer = [];
72
- stack[stack.length - 1].push(pointer);
73
- }
74
- else if (!elem.split(/\s/g).some(isNaN)) {
75
- Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
76
- }
77
- else {
78
- return null;
79
- }
80
- white();
81
- }
82
- if (depth !== 0)
83
- return null;
84
- return rings;
85
- }
86
- function coords() {
87
- const list = [];
88
- let item;
89
- let pt;
90
- while ((pt = $(tuples) || $(/^(,)/))) {
91
- if (pt === ',') {
92
- list.push(item);
93
- item = [];
94
- }
95
- else if (!pt.split(/\s/g).some(isNaN)) {
96
- if (!item)
97
- item = [];
98
- Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
99
- }
100
- white();
101
- }
102
- if (item)
103
- list.push(item);
104
- else
105
- return null;
106
- return list.length ? list : null;
107
- }
108
- function point() {
109
- if (!$(/^(point(\sz)?)/i))
110
- return null;
111
- white();
112
- if (!$(/^(\()/))
113
- return null;
114
- const c = coords();
115
- if (!c)
116
- return null;
117
- white();
118
- if (!$(/^(\))/))
119
- return null;
120
- return {
121
- type: 'Point',
122
- coordinates: c[0]
123
- };
124
- }
125
- function multipoint() {
126
- if (!$(/^(multipoint)/i))
127
- return null;
128
- white();
129
- const newCoordsFormat = _.substring(_.indexOf('(') + 1, _.length - 1)
130
- .replace(/\(/g, '')
131
- .replace(/\)/g, '');
132
- _ = 'MULTIPOINT (' + newCoordsFormat + ')';
133
- const c = multicoords();
134
- if (!c)
135
- return null;
136
- white();
137
- return {
138
- type: 'MultiPoint',
139
- coordinates: c
140
- };
141
- }
142
- function multilinestring() {
143
- if (!$(/^(multilinestring)/i))
144
- return null;
145
- white();
146
- const c = multicoords();
147
- if (!c)
148
- return null;
149
- white();
150
- return {
151
- type: 'MultiLineString',
152
- coordinates: c
153
- };
154
- }
155
- function linestring() {
156
- if (!$(/^(linestring(\sz)?)/i))
157
- return null;
158
- white();
159
- if (!$(/^(\()/))
160
- return null;
161
- const c = coords();
162
- if (!c)
163
- return null;
164
- if (!$(/^(\))/))
165
- return null;
166
- return {
167
- type: 'LineString',
168
- coordinates: c
169
- };
170
- }
171
- function polygon() {
172
- if (!$(/^(polygon(\sz)?)/i))
173
- return null;
174
- white();
175
- const c = multicoords();
176
- if (!c)
177
- return null;
178
- return {
179
- type: 'Polygon',
180
- coordinates: c
181
- };
182
- }
183
- function multipolygon() {
184
- if (!$(/^(multipolygon)/i))
185
- return null;
186
- white();
187
- const c = multicoords();
188
- if (!c)
189
- return null;
190
- return {
191
- type: 'MultiPolygon',
192
- coordinates: c
193
- };
194
- }
195
- function geometrycollection() {
196
- const geometries = [];
197
- let geometry;
198
- if (!$(/^(geometrycollection)/i))
199
- return null;
200
- white();
201
- if (!$(/^(\()/))
202
- return null;
203
- while ((geometry = root())) {
204
- geometries.push(geometry);
205
- white();
206
- $(/^(,)/);
207
- white();
208
- }
209
- if (!$(/^(\))/))
210
- return null;
211
- return {
212
- type: 'GeometryCollection',
213
- geometries: geometries
214
- };
215
- }
216
- function root() {
217
- return (point() ||
218
- linestring() ||
219
- polygon() ||
220
- multipoint() ||
221
- multilinestring() ||
222
- multipolygon() ||
223
- geometrycollection());
224
- }
225
- return crs(root());
226
- }
227
- exports.default = parseWKT;
@@ -1,120 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- // Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- const LE = true;
6
- const BE = false;
7
- class BinaryWriter {
8
- constructor(size, allowResize) {
9
- this.byteOffset = 0;
10
- this.allowResize = false;
11
- this.arrayBuffer = new ArrayBuffer(size);
12
- this.dataView = new DataView(this.arrayBuffer);
13
- this.byteOffset = 0;
14
- this.allowResize = allowResize || false;
15
- }
16
- writeUInt8(value) {
17
- this._ensureSize(1);
18
- this.dataView.setUint8(this.byteOffset, value);
19
- this.byteOffset += 1;
20
- }
21
- writeUInt16LE(value) {
22
- this._ensureSize(2);
23
- this.dataView.setUint16(this.byteOffset, value, LE);
24
- this.byteOffset += 2;
25
- }
26
- writeUInt16BE(value) {
27
- this._ensureSize(2);
28
- this.dataView.setUint16(this.byteOffset, value, BE);
29
- this.byteOffset += 2;
30
- }
31
- writeUInt32LE(value) {
32
- this._ensureSize(4);
33
- this.dataView.setUint32(this.byteOffset, value, LE);
34
- this.byteOffset += 4;
35
- }
36
- writeUInt32BE(value) {
37
- this._ensureSize(4);
38
- this.dataView.setUint32(this.byteOffset, value, BE);
39
- this.byteOffset += 4;
40
- }
41
- writeInt8(value) {
42
- this._ensureSize(1);
43
- this.dataView.setInt8(this.byteOffset, value);
44
- this.byteOffset += 1;
45
- }
46
- writeInt16LE(value) {
47
- this._ensureSize(2);
48
- this.dataView.setInt16(this.byteOffset, value, LE);
49
- this.byteOffset += 2;
50
- }
51
- writeInt16BE(value) {
52
- this._ensureSize(2);
53
- this.dataView.setInt16(this.byteOffset, value, BE);
54
- this.byteOffset += 2;
55
- }
56
- writeInt32LE(value) {
57
- this._ensureSize(4);
58
- this.dataView.setInt32(this.byteOffset, value, LE);
59
- this.byteOffset += 4;
60
- }
61
- writeInt32BE(value) {
62
- this._ensureSize(4);
63
- this.dataView.setInt32(this.byteOffset, value, BE);
64
- this.byteOffset += 4;
65
- }
66
- writeFloatLE(value) {
67
- this._ensureSize(4);
68
- this.dataView.setFloat32(this.byteOffset, value, LE);
69
- this.byteOffset += 4;
70
- }
71
- writeFloatBE(value) {
72
- this._ensureSize(4);
73
- this.dataView.setFloat32(this.byteOffset, value, BE);
74
- this.byteOffset += 4;
75
- }
76
- writeDoubleLE(value) {
77
- this._ensureSize(8);
78
- this.dataView.setFloat64(this.byteOffset, value, LE);
79
- this.byteOffset += 8;
80
- }
81
- writeDoubleBE(value) {
82
- this._ensureSize(8);
83
- this.dataView.setFloat64(this.byteOffset, value, BE);
84
- this.byteOffset += 8;
85
- }
86
- /** A varint uses a variable number of bytes */
87
- writeVarInt(value) {
88
- // TODO - ensure size?
89
- let length = 1;
90
- while ((value & 0xffffff80) !== 0) {
91
- this.writeUInt8((value & 0x7f) | 0x80);
92
- value >>>= 7;
93
- length++;
94
- }
95
- this.writeUInt8(value & 0x7f);
96
- return length;
97
- }
98
- /** Append another ArrayBuffer to this ArrayBuffer */
99
- writeBuffer(arrayBuffer) {
100
- this._ensureSize(arrayBuffer.byteLength);
101
- const tempArray = new Uint8Array(this.arrayBuffer);
102
- tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
103
- this.byteOffset += arrayBuffer.byteLength;
104
- }
105
- /** Resizes this.arrayBuffer if not enough space */
106
- _ensureSize(size) {
107
- if (this.arrayBuffer.byteLength < this.byteOffset + size) {
108
- if (this.allowResize) {
109
- const newArrayBuffer = new ArrayBuffer(this.byteOffset + size);
110
- const tempArray = new Uint8Array(newArrayBuffer);
111
- tempArray.set(new Uint8Array(this.arrayBuffer));
112
- this.arrayBuffer = newArrayBuffer;
113
- }
114
- else {
115
- throw new Error('BinaryWriter overflow');
116
- }
117
- }
118
- }
119
- }
120
- exports.default = BinaryWriter;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERSION = void 0;
4
- // Version constant cannot be imported, it needs to correspond to the build version of **this** module.
5
- // __VERSION__ is injected by babel-plugin-version-inline
6
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
- exports.VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._typecheckWKBLoader = exports._typecheckWKBWorkerLoader = exports.WKBLoader = exports.WKBWorkerLoader = void 0;
7
- const version_1 = require("./lib/utils/version");
8
- const parse_wkb_1 = __importDefault(require("./lib/parse-wkb"));
9
- /**
10
- * Worker loader for WKB (Well-Known Binary)
11
- */
12
- exports.WKBWorkerLoader = {
13
- name: 'WKB',
14
- id: 'wkb',
15
- module: 'wkt',
16
- version: version_1.VERSION,
17
- worker: true,
18
- category: 'geometry',
19
- extensions: ['wkb'],
20
- mimeTypes: [],
21
- options: {
22
- wkb: {}
23
- }
24
- };
25
- /**
26
- * Loader for WKB (Well-Known Binary)
27
- */
28
- exports.WKBLoader = {
29
- ...exports.WKBWorkerLoader,
30
- parse: async (arrayBuffer) => (0, parse_wkb_1.default)(arrayBuffer),
31
- parseSync: parse_wkb_1.default
32
- };
33
- exports._typecheckWKBWorkerLoader = exports.WKBWorkerLoader;
34
- exports._typecheckWKBLoader = exports.WKBLoader;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WKBWriter = void 0;
7
- const version_1 = require("./lib/utils/version");
8
- const encode_wkb_1 = __importDefault(require("./lib/encode-wkb"));
9
- /**
10
- * WKB exporter
11
- */
12
- exports.WKBWriter = {
13
- name: 'WKB (Well Known Binary)',
14
- id: 'wkb',
15
- module: 'wkt',
16
- version: version_1.VERSION,
17
- extensions: ['wkb'],
18
- // @ts-ignore
19
- encodeSync: encode_wkb_1.default,
20
- options: {
21
- wkb: {
22
- hasZ: false,
23
- hasM: false
24
- }
25
- }
26
- };
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WKTLoader = exports.WKTWorkerLoader = void 0;
7
- const version_1 = require("./lib/utils/version");
8
- const parse_wkt_1 = __importDefault(require("./lib/parse-wkt"));
9
- /**
10
- * Well-Known text loader
11
- */
12
- exports.WKTWorkerLoader = {
13
- name: 'WKT (Well-Known Text)',
14
- id: 'wkt',
15
- module: 'wkt',
16
- version: version_1.VERSION,
17
- worker: true,
18
- extensions: ['wkt'],
19
- mimeTypes: ['text/plain'],
20
- category: 'geometry',
21
- text: true,
22
- options: {
23
- wkt: {}
24
- }
25
- };
26
- /**
27
- * Well-Known text loader
28
- */
29
- exports.WKTLoader = {
30
- ...exports.WKTWorkerLoader,
31
- parse: async (arrayBuffer) => (0, parse_wkt_1.default)(new TextDecoder().decode(arrayBuffer)),
32
- parseTextSync: parse_wkt_1.default
33
- };
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WKTWriter = void 0;
7
- const version_1 = require("./lib/utils/version");
8
- const encode_wkt_1 = __importDefault(require("./lib/encode-wkt"));
9
- /**
10
- * WKT exporter
11
- */
12
- exports.WKTWriter = {
13
- name: 'WKT (Well Known Text)',
14
- id: 'wkt',
15
- module: 'wkt',
16
- version: version_1.VERSION,
17
- extensions: ['wkt'],
18
- // @ts-ignore
19
- encode: encode_wkt_1.default,
20
- options: {
21
- wkt: {}
22
- }
23
- };
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader_utils_1 = require("@loaders.gl/loader-utils");
4
- const wkb_loader_1 = require("../wkb-loader");
5
- (0, loader_utils_1.createLoaderWorker)(wkb_loader_1.WKBLoader);
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader_utils_1 = require("@loaders.gl/loader-utils");
4
- const wkt_loader_1 = require("../wkt-loader");
5
- (0, loader_utils_1.createLoaderWorker)(wkt_loader_1.WKTLoader);