@loaders.gl/wkt 3.1.0-alpha.4 → 3.1.0-beta.3
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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +596 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +5 -5
- package/dist/es5/lib/encode-wkt.js +2 -2
- package/dist/es5/lib/encode-wkt.js.map +1 -1
- package/dist/es5/lib/parse-wkb.js +78 -113
- package/dist/es5/lib/parse-wkb.js.map +1 -1
- package/dist/es5/lib/parse-wkt.js +24 -24
- package/dist/es5/lib/parse-wkt.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/es5/wkb-loader.js +6 -39
- package/dist/es5/wkb-loader.js.map +1 -1
- package/dist/es5/wkt-loader.js +4 -37
- package/dist/es5/wkt-loader.js.map +1 -1
- package/dist/es5/wkt-writer.js +1 -1
- package/dist/es5/wkt-writer.js.map +1 -1
- package/dist/esm/lib/encode-wkt.js +8 -8
- package/dist/esm/lib/encode-wkt.js.map +1 -1
- package/dist/esm/lib/parse-wkb.js +5 -4
- package/dist/esm/lib/parse-wkb.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/esm/wkb-loader.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/lib/encode-wkt.d.ts +8 -0
- package/dist/lib/encode-wkt.d.ts.map +1 -0
- package/dist/lib/encode-wkt.js +48 -0
- package/dist/lib/parse-wkb.d.ts +3 -0
- package/dist/lib/parse-wkb.d.ts.map +1 -0
- package/dist/lib/parse-wkb.js +236 -0
- package/dist/lib/parse-wkt.d.ts +8 -0
- package/dist/lib/parse-wkt.d.ts.map +1 -0
- package/dist/lib/parse-wkt.js +227 -0
- package/dist/lib/utils/version.d.ts +2 -0
- package/dist/lib/utils/version.d.ts.map +1 -0
- package/dist/lib/utils/version.js +7 -0
- package/dist/wkb-loader.d.ts +39 -0
- package/dist/wkb-loader.d.ts.map +1 -0
- package/dist/wkb-loader.js +34 -0
- package/dist/wkt-loader.d.ts +10 -0
- package/dist/wkt-loader.d.ts.map +1 -0
- package/dist/wkt-loader.js +33 -0
- package/dist/wkt-worker.js +380 -2
- package/dist/wkt-writer.d.ts +6 -0
- package/dist/wkt-writer.d.ts.map +1 -0
- package/dist/wkt-writer.js +23 -0
- package/dist/workers/wkb-worker.d.ts +2 -0
- package/dist/workers/wkb-worker.d.ts.map +1 -0
- package/dist/workers/wkb-worker.js +5 -0
- package/dist/workers/wkt-worker.d.ts +2 -0
- package/dist/workers/wkt-worker.d.ts.map +1 -0
- package/dist/workers/wkt-worker.js +5 -0
- package/package.json +7 -7
- package/src/lib/parse-wkb.ts +35 -19
- package/src/wkb-loader.ts +1 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/wkt-worker.js.map +0 -1
|
@@ -0,0 +1,236 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-wkt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-wkt.ts"],"names":[],"mappings":"AASA;;;;;IAKI;AACJ,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,KAAA,OA8MrC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/version.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,KAA8D,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Loader, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
import parseWKB from './lib/parse-wkb';
|
|
3
|
+
/**
|
|
4
|
+
* Worker loader for WKB (Well-Known Binary)
|
|
5
|
+
*/
|
|
6
|
+
export declare const WKBWorkerLoader: {
|
|
7
|
+
name: string;
|
|
8
|
+
id: string;
|
|
9
|
+
module: string;
|
|
10
|
+
version: any;
|
|
11
|
+
worker: boolean;
|
|
12
|
+
category: string;
|
|
13
|
+
extensions: string[];
|
|
14
|
+
mimeTypes: never[];
|
|
15
|
+
options: {
|
|
16
|
+
wkb: {};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Loader for WKB (Well-Known Binary)
|
|
21
|
+
*/
|
|
22
|
+
export declare const WKBLoader: {
|
|
23
|
+
parse: (arrayBuffer: ArrayBuffer) => Promise<import("@loaders.gl/schema").BinaryGeometry>;
|
|
24
|
+
parseSync: typeof parseWKB;
|
|
25
|
+
name: string;
|
|
26
|
+
id: string;
|
|
27
|
+
module: string;
|
|
28
|
+
version: any;
|
|
29
|
+
worker: boolean;
|
|
30
|
+
category: string;
|
|
31
|
+
extensions: string[];
|
|
32
|
+
mimeTypes: never[];
|
|
33
|
+
options: {
|
|
34
|
+
wkb: {};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare const _typecheckWKBWorkerLoader: Loader;
|
|
38
|
+
export declare const _typecheckWKBLoader: LoaderWithParser;
|
|
39
|
+
//# sourceMappingURL=wkb-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wkb-loader.d.ts","sourceRoot":"","sources":["../src/wkb-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAEvE,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;CAY3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS;yBAEO,WAAW;;;;;;;;;;;;;CAEvC,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,MAAwB,CAAC;AACjE,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Loader, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Well-Known text loader
|
|
4
|
+
*/
|
|
5
|
+
export declare const WKTWorkerLoader: Loader;
|
|
6
|
+
/**
|
|
7
|
+
* Well-Known text loader
|
|
8
|
+
*/
|
|
9
|
+
export declare const WKTLoader: LoaderWithParser;
|
|
10
|
+
//# sourceMappingURL=wkt-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wkt-loader.d.ts","sourceRoot":"","sources":["../src/wkt-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAIvE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAa7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAIvB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
};
|