@loaders.gl/shapefile 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 +7554 -0
- package/dist/dbf-loader.d.ts +8 -0
- package/dist/dbf-loader.d.ts.map +1 -0
- package/dist/dbf-loader.js +32 -0
- package/dist/dbf-worker.js +912 -2
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/dbf-loader.js +5 -40
- package/dist/es5/dbf-loader.js.map +1 -1
- package/dist/es5/index.js +5 -5
- package/dist/es5/lib/parsers/parse-dbf.js +86 -232
- package/dist/es5/lib/parsers/parse-dbf.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shapefile.js +151 -404
- package/dist/es5/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp-geometry.js +49 -96
- package/dist/es5/lib/parsers/parse-shp-geometry.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp-header.js +4 -4
- package/dist/es5/lib/parsers/parse-shp-header.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp.js +47 -165
- package/dist/es5/lib/parsers/parse-shp.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shx.js +11 -11
- package/dist/es5/lib/parsers/parse-shx.js.map +1 -1
- package/dist/es5/lib/streaming/binary-chunk-reader.js +99 -172
- package/dist/es5/lib/streaming/binary-chunk-reader.js.map +1 -1
- package/dist/es5/lib/streaming/binary-reader.js +24 -35
- package/dist/es5/lib/streaming/binary-reader.js.map +1 -1
- package/dist/es5/lib/streaming/zip-batch-iterators.js +37 -96
- package/dist/es5/lib/streaming/zip-batch-iterators.js.map +1 -1
- package/dist/es5/shapefile-loader.js +3 -3
- package/dist/es5/shapefile-loader.js.map +1 -1
- package/dist/es5/shp-loader.js +6 -41
- package/dist/es5/shp-loader.js.map +1 -1
- package/dist/es5/workers/dbf-worker.js +7 -3
- package/dist/es5/workers/dbf-worker.js.map +1 -0
- package/dist/es5/workers/shp-worker.js +7 -3
- package/dist/es5/workers/shp-worker.js.map +1 -0
- package/dist/esm/dbf-loader.js +1 -1
- package/dist/esm/dbf-loader.js.map +1 -1
- package/dist/esm/lib/parsers/parse-dbf.js +4 -6
- package/dist/esm/lib/parsers/parse-dbf.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shapefile.js +1 -1
- package/dist/esm/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shp-geometry.js +1 -1
- package/dist/esm/lib/parsers/parse-shp-geometry.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shp-header.js +2 -2
- package/dist/esm/lib/parsers/parse-shp-header.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shp.js +2 -2
- package/dist/esm/lib/parsers/parse-shp.js.map +1 -1
- package/dist/esm/shapefile-loader.js +1 -1
- package/dist/esm/shapefile-loader.js.map +1 -1
- package/dist/esm/shp-loader.js +1 -1
- package/dist/esm/shp-loader.js.map +1 -1
- package/dist/esm/workers/dbf-worker.js +3 -3
- package/dist/esm/workers/dbf-worker.js.map +1 -0
- package/dist/esm/workers/shp-worker.js +3 -3
- package/dist/esm/workers/shp-worker.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/lib/parsers/parse-dbf.d.ts +28 -0
- package/dist/lib/parsers/parse-dbf.d.ts.map +1 -0
- package/dist/lib/parsers/parse-dbf.js +335 -0
- package/dist/lib/parsers/parse-shapefile.d.ts +54 -0
- package/dist/lib/parsers/parse-shapefile.d.ts.map +1 -0
- package/dist/lib/parsers/parse-shapefile.js +245 -0
- package/dist/lib/parsers/parse-shp-geometry.d.ts +11 -0
- package/dist/lib/parsers/parse-shp-geometry.d.ts.map +1 -0
- package/dist/lib/parsers/parse-shp-geometry.js +287 -0
- package/dist/lib/parsers/parse-shp-header.d.ts +26 -0
- package/dist/lib/parsers/parse-shp-header.d.ts.map +1 -0
- package/dist/lib/parsers/parse-shp-header.js +43 -0
- package/dist/lib/parsers/parse-shp.d.ts +9 -0
- package/dist/lib/parsers/parse-shp.d.ts.map +1 -0
- package/dist/lib/parsers/parse-shp.js +170 -0
- package/dist/lib/parsers/parse-shx.d.ts +10 -0
- package/dist/lib/parsers/parse-shx.d.ts.map +1 -0
- package/dist/lib/parsers/parse-shx.js +28 -0
- package/dist/lib/streaming/binary-chunk-reader.d.ts +59 -0
- package/dist/lib/streaming/binary-chunk-reader.d.ts.map +1 -0
- package/dist/lib/streaming/binary-chunk-reader.js +161 -0
- package/dist/lib/streaming/binary-reader.d.ts +32 -0
- package/dist/lib/streaming/binary-reader.d.ts.map +1 -0
- package/dist/lib/streaming/binary-reader.js +52 -0
- package/dist/lib/streaming/zip-batch-iterators.d.ts +8 -0
- package/dist/lib/streaming/zip-batch-iterators.d.ts.map +1 -0
- package/dist/lib/streaming/zip-batch-iterators.js +61 -0
- package/dist/shapefile-loader.d.ts +26 -0
- package/dist/shapefile-loader.d.ts.map +1 -0
- package/dist/shapefile-loader.js +31 -0
- package/dist/shp-loader.d.ts +9 -0
- package/dist/shp-loader.d.ts.map +1 -0
- package/dist/shp-loader.js +35 -0
- package/dist/shp-worker.js +606 -2
- package/dist/workers/dbf-worker.d.ts +2 -0
- package/dist/workers/dbf-worker.d.ts.map +1 -0
- package/dist/workers/dbf-worker.js +5 -0
- package/dist/workers/shp-worker.d.ts +2 -0
- package/dist/workers/shp-worker.d.ts.map +1 -0
- package/dist/workers/shp-worker.js +5 -0
- package/package.json +10 -10
- package/src/lib/parsers/parse-dbf.ts +5 -3
- package/src/lib/parsers/parse-shp-geometry.ts +1 -1
- package/src/workers/{dbf-worker.js → dbf-worker.ts} +0 -0
- package/src/workers/{shp-worker.js → shp-worker.ts} +0 -0
- package/dist/dbf-worker.js.map +0 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/shp-worker.js.map +0 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -10,347 +8,150 @@ exports.parseShapefile = parseShapefile;
|
|
|
10
8
|
exports.loadShapefileSidecarFiles = loadShapefileSidecarFiles;
|
|
11
9
|
exports.replaceExtension = replaceExtension;
|
|
12
10
|
|
|
13
|
-
var
|
|
11
|
+
var _gis = require("@loaders.gl/gis");
|
|
14
12
|
|
|
15
|
-
var
|
|
13
|
+
var _proj = require("@math.gl/proj4");
|
|
16
14
|
|
|
17
|
-
var
|
|
15
|
+
var _parseShx = require("./parse-shx");
|
|
18
16
|
|
|
19
|
-
var
|
|
17
|
+
var _zipBatchIterators = require("../streaming/zip-batch-iterators");
|
|
20
18
|
|
|
21
|
-
var
|
|
19
|
+
var _shpLoader = require("../../shp-loader");
|
|
22
20
|
|
|
23
|
-
var
|
|
21
|
+
var _dbfLoader = require("../../dbf-loader");
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
async function* parseShapefileInBatches(asyncIterator, options, context) {
|
|
24
|
+
const {
|
|
25
|
+
reproject = false,
|
|
26
|
+
_targetCrs = 'WGS84'
|
|
27
|
+
} = (options === null || options === void 0 ? void 0 : options.gis) || {};
|
|
28
|
+
const {
|
|
29
|
+
shx,
|
|
30
|
+
cpg,
|
|
31
|
+
prj
|
|
32
|
+
} = await loadShapefileSidecarFiles(options, context);
|
|
33
|
+
const shapeIterable = await context.parseInBatches(asyncIterator, _shpLoader.SHPLoader, options);
|
|
34
|
+
let propertyIterable;
|
|
35
|
+
const dbfResponse = await context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf'));
|
|
36
|
+
|
|
37
|
+
if (dbfResponse.ok) {
|
|
38
|
+
propertyIterable = await context.parseInBatches(dbfResponse, _dbfLoader.DBFLoader, { ...options,
|
|
39
|
+
dbf: {
|
|
40
|
+
encoding: cpg || 'latin1'
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
26
44
|
|
|
27
|
-
|
|
45
|
+
let shapeHeader = (await shapeIterable.next()).value;
|
|
28
46
|
|
|
29
|
-
|
|
47
|
+
if (shapeHeader && shapeHeader.batchType === 'metadata') {
|
|
48
|
+
shapeHeader = (await shapeIterable.next()).value;
|
|
49
|
+
}
|
|
30
50
|
|
|
31
|
-
|
|
51
|
+
let dbfHeader = {};
|
|
32
52
|
|
|
33
|
-
|
|
53
|
+
if (propertyIterable) {
|
|
54
|
+
dbfHeader = (await propertyIterable.next()).value;
|
|
34
55
|
|
|
35
|
-
|
|
56
|
+
if (dbfHeader && dbfHeader.batchType === 'metadata') {
|
|
57
|
+
dbfHeader = (await propertyIterable.next()).value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
36
60
|
|
|
37
|
-
|
|
61
|
+
let iterator;
|
|
38
62
|
|
|
39
|
-
|
|
63
|
+
if (propertyIterable) {
|
|
64
|
+
iterator = (0, _zipBatchIterators.zipBatchIterators)(shapeIterable, propertyIterable);
|
|
65
|
+
} else {
|
|
66
|
+
iterator = shapeIterable;
|
|
67
|
+
}
|
|
40
68
|
|
|
41
|
-
|
|
69
|
+
for await (const item of iterator) {
|
|
70
|
+
let geometries;
|
|
71
|
+
let properties;
|
|
42
72
|
|
|
43
|
-
|
|
73
|
+
if (!propertyIterable) {
|
|
74
|
+
geometries = item;
|
|
75
|
+
} else {
|
|
76
|
+
[geometries, properties] = item;
|
|
77
|
+
}
|
|
44
78
|
|
|
45
|
-
|
|
79
|
+
const geojsonGeometries = parseGeometries(geometries);
|
|
80
|
+
let features = joinProperties(geojsonGeometries, properties);
|
|
46
81
|
|
|
47
|
-
|
|
82
|
+
if (reproject) {
|
|
83
|
+
features = reprojectFeatures(features, prj, _targetCrs);
|
|
84
|
+
}
|
|
48
85
|
|
|
49
|
-
|
|
50
|
-
|
|
86
|
+
yield {
|
|
87
|
+
encoding: cpg,
|
|
88
|
+
prj,
|
|
89
|
+
shx,
|
|
90
|
+
header: shapeHeader,
|
|
91
|
+
data: features
|
|
92
|
+
};
|
|
93
|
+
}
|
|
51
94
|
}
|
|
52
95
|
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
_context.next = 12;
|
|
76
|
-
return (0, _awaitAsyncGenerator2.default)(context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf')));
|
|
77
|
-
|
|
78
|
-
case 12:
|
|
79
|
-
dbfResponse = _context.sent;
|
|
80
|
-
|
|
81
|
-
if (!dbfResponse.ok) {
|
|
82
|
-
_context.next = 17;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
_context.next = 16;
|
|
87
|
-
return (0, _awaitAsyncGenerator2.default)(context.parseInBatches(dbfResponse, _dbfLoader.DBFLoader, _objectSpread(_objectSpread({}, options), {}, {
|
|
88
|
-
dbf: {
|
|
89
|
-
encoding: cpg || 'latin1'
|
|
90
|
-
}
|
|
91
|
-
})));
|
|
92
|
-
|
|
93
|
-
case 16:
|
|
94
|
-
propertyIterable = _context.sent;
|
|
95
|
-
|
|
96
|
-
case 17:
|
|
97
|
-
_context.next = 19;
|
|
98
|
-
return (0, _awaitAsyncGenerator2.default)(shapeIterable.next());
|
|
99
|
-
|
|
100
|
-
case 19:
|
|
101
|
-
shapeHeader = _context.sent.value;
|
|
102
|
-
|
|
103
|
-
if (!(shapeHeader && shapeHeader.batchType === 'metadata')) {
|
|
104
|
-
_context.next = 24;
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
_context.next = 23;
|
|
109
|
-
return (0, _awaitAsyncGenerator2.default)(shapeIterable.next());
|
|
110
|
-
|
|
111
|
-
case 23:
|
|
112
|
-
shapeHeader = _context.sent.value;
|
|
113
|
-
|
|
114
|
-
case 24:
|
|
115
|
-
dbfHeader = {};
|
|
116
|
-
|
|
117
|
-
if (!propertyIterable) {
|
|
118
|
-
_context.next = 33;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
_context.next = 28;
|
|
123
|
-
return (0, _awaitAsyncGenerator2.default)(propertyIterable.next());
|
|
124
|
-
|
|
125
|
-
case 28:
|
|
126
|
-
dbfHeader = _context.sent.value;
|
|
127
|
-
|
|
128
|
-
if (!(dbfHeader && dbfHeader.batchType === 'metadata')) {
|
|
129
|
-
_context.next = 33;
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
_context.next = 32;
|
|
134
|
-
return (0, _awaitAsyncGenerator2.default)(propertyIterable.next());
|
|
135
|
-
|
|
136
|
-
case 32:
|
|
137
|
-
dbfHeader = _context.sent.value;
|
|
138
|
-
|
|
139
|
-
case 33:
|
|
140
|
-
if (propertyIterable) {
|
|
141
|
-
iterator = (0, _zipBatchIterators.zipBatchIterators)(shapeIterable, propertyIterable);
|
|
142
|
-
} else {
|
|
143
|
-
iterator = shapeIterable;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
_iteratorNormalCompletion = true;
|
|
147
|
-
_didIteratorError = false;
|
|
148
|
-
_context.prev = 36;
|
|
149
|
-
_iterator = (0, _asyncIterator2.default)(iterator);
|
|
150
|
-
|
|
151
|
-
case 38:
|
|
152
|
-
_context.next = 40;
|
|
153
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.next());
|
|
154
|
-
|
|
155
|
-
case 40:
|
|
156
|
-
_step = _context.sent;
|
|
157
|
-
_iteratorNormalCompletion = _step.done;
|
|
158
|
-
_context.next = 44;
|
|
159
|
-
return (0, _awaitAsyncGenerator2.default)(_step.value);
|
|
160
|
-
|
|
161
|
-
case 44:
|
|
162
|
-
_value = _context.sent;
|
|
163
|
-
|
|
164
|
-
if (_iteratorNormalCompletion) {
|
|
165
|
-
_context.next = 58;
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
item = _value;
|
|
170
|
-
geometries = void 0;
|
|
171
|
-
properties = void 0;
|
|
172
|
-
|
|
173
|
-
if (!propertyIterable) {
|
|
174
|
-
geometries = item;
|
|
175
|
-
} else {
|
|
176
|
-
_item = (0, _slicedToArray2.default)(item, 2);
|
|
177
|
-
geometries = _item[0];
|
|
178
|
-
properties = _item[1];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
geojsonGeometries = parseGeometries(geometries);
|
|
182
|
-
features = joinProperties(geojsonGeometries, properties);
|
|
183
|
-
|
|
184
|
-
if (reproject) {
|
|
185
|
-
features = reprojectFeatures(features, prj, _targetCrs);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
_context.next = 55;
|
|
189
|
-
return {
|
|
190
|
-
encoding: cpg,
|
|
191
|
-
prj: prj,
|
|
192
|
-
shx: shx,
|
|
193
|
-
header: shapeHeader,
|
|
194
|
-
data: features
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
case 55:
|
|
198
|
-
_iteratorNormalCompletion = true;
|
|
199
|
-
_context.next = 38;
|
|
200
|
-
break;
|
|
201
|
-
|
|
202
|
-
case 58:
|
|
203
|
-
_context.next = 64;
|
|
204
|
-
break;
|
|
205
|
-
|
|
206
|
-
case 60:
|
|
207
|
-
_context.prev = 60;
|
|
208
|
-
_context.t0 = _context["catch"](36);
|
|
209
|
-
_didIteratorError = true;
|
|
210
|
-
_iteratorError = _context.t0;
|
|
211
|
-
|
|
212
|
-
case 64:
|
|
213
|
-
_context.prev = 64;
|
|
214
|
-
_context.prev = 65;
|
|
215
|
-
|
|
216
|
-
if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
|
|
217
|
-
_context.next = 69;
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
_context.next = 69;
|
|
222
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.return());
|
|
223
|
-
|
|
224
|
-
case 69:
|
|
225
|
-
_context.prev = 69;
|
|
226
|
-
|
|
227
|
-
if (!_didIteratorError) {
|
|
228
|
-
_context.next = 72;
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
throw _iteratorError;
|
|
233
|
-
|
|
234
|
-
case 72:
|
|
235
|
-
return _context.finish(69);
|
|
236
|
-
|
|
237
|
-
case 73:
|
|
238
|
-
return _context.finish(64);
|
|
239
|
-
|
|
240
|
-
case 74:
|
|
241
|
-
case "end":
|
|
242
|
-
return _context.stop();
|
|
243
|
-
}
|
|
96
|
+
async function parseShapefile(arrayBuffer, options, context) {
|
|
97
|
+
const {
|
|
98
|
+
reproject = false,
|
|
99
|
+
_targetCrs = 'WGS84'
|
|
100
|
+
} = (options === null || options === void 0 ? void 0 : options.gis) || {};
|
|
101
|
+
const {
|
|
102
|
+
shx,
|
|
103
|
+
cpg,
|
|
104
|
+
prj
|
|
105
|
+
} = await loadShapefileSidecarFiles(options, context);
|
|
106
|
+
const {
|
|
107
|
+
header,
|
|
108
|
+
geometries
|
|
109
|
+
} = await context.parse(arrayBuffer, _shpLoader.SHPLoader, options);
|
|
110
|
+
const geojsonGeometries = parseGeometries(geometries);
|
|
111
|
+
let properties = [];
|
|
112
|
+
const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));
|
|
113
|
+
|
|
114
|
+
if (dbfResponse.ok) {
|
|
115
|
+
properties = await context.parse(dbfResponse, _dbfLoader.DBFLoader, {
|
|
116
|
+
dbf: {
|
|
117
|
+
encoding: cpg || 'latin1'
|
|
244
118
|
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return _parseShapefileInBatches.apply(this, arguments);
|
|
248
|
-
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
249
121
|
|
|
250
|
-
|
|
251
|
-
return _parseShapefile.apply(this, arguments);
|
|
252
|
-
}
|
|
122
|
+
let features = joinProperties(geojsonGeometries, properties);
|
|
253
123
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
case 3:
|
|
267
|
-
_yield$loadShapefileS = _context2.sent;
|
|
268
|
-
shx = _yield$loadShapefileS.shx;
|
|
269
|
-
cpg = _yield$loadShapefileS.cpg;
|
|
270
|
-
prj = _yield$loadShapefileS.prj;
|
|
271
|
-
_context2.next = 9;
|
|
272
|
-
return context.parse(arrayBuffer, _shpLoader.SHPLoader, options);
|
|
273
|
-
|
|
274
|
-
case 9:
|
|
275
|
-
_yield$context$parse = _context2.sent;
|
|
276
|
-
header = _yield$context$parse.header;
|
|
277
|
-
geometries = _yield$context$parse.geometries;
|
|
278
|
-
geojsonGeometries = parseGeometries(geometries);
|
|
279
|
-
properties = [];
|
|
280
|
-
_context2.next = 16;
|
|
281
|
-
return context.fetch(replaceExtension(context.url, 'dbf'));
|
|
282
|
-
|
|
283
|
-
case 16:
|
|
284
|
-
dbfResponse = _context2.sent;
|
|
285
|
-
|
|
286
|
-
if (!dbfResponse.ok) {
|
|
287
|
-
_context2.next = 21;
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
_context2.next = 20;
|
|
292
|
-
return context.parse(dbfResponse, _dbfLoader.DBFLoader, {
|
|
293
|
-
dbf: {
|
|
294
|
-
encoding: cpg || 'latin1'
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
case 20:
|
|
299
|
-
properties = _context2.sent;
|
|
300
|
-
|
|
301
|
-
case 21:
|
|
302
|
-
features = joinProperties(geojsonGeometries, properties);
|
|
303
|
-
|
|
304
|
-
if (reproject) {
|
|
305
|
-
features = reprojectFeatures(features, prj, _targetCrs);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return _context2.abrupt("return", {
|
|
309
|
-
encoding: cpg,
|
|
310
|
-
prj: prj,
|
|
311
|
-
shx: shx,
|
|
312
|
-
header: header,
|
|
313
|
-
data: features
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
case 24:
|
|
317
|
-
case "end":
|
|
318
|
-
return _context2.stop();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}, _callee2);
|
|
322
|
-
}));
|
|
323
|
-
return _parseShapefile.apply(this, arguments);
|
|
124
|
+
if (reproject) {
|
|
125
|
+
features = reprojectFeatures(features, prj, _targetCrs);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
encoding: cpg,
|
|
130
|
+
prj,
|
|
131
|
+
shx,
|
|
132
|
+
header,
|
|
133
|
+
data: features
|
|
134
|
+
};
|
|
324
135
|
}
|
|
325
136
|
|
|
326
137
|
function parseGeometries(geometries) {
|
|
327
|
-
|
|
138
|
+
const geojsonGeometries = [];
|
|
328
139
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
try {
|
|
333
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
334
|
-
var geom = _step2.value;
|
|
335
|
-
geojsonGeometries.push((0, _gis.binaryToGeometry)(geom));
|
|
336
|
-
}
|
|
337
|
-
} catch (err) {
|
|
338
|
-
_iterator2.e(err);
|
|
339
|
-
} finally {
|
|
340
|
-
_iterator2.f();
|
|
140
|
+
for (const geom of geometries) {
|
|
141
|
+
geojsonGeometries.push((0, _gis.binaryToGeometry)(geom));
|
|
341
142
|
}
|
|
342
143
|
|
|
343
144
|
return geojsonGeometries;
|
|
344
145
|
}
|
|
345
146
|
|
|
346
147
|
function joinProperties(geometries, properties) {
|
|
347
|
-
|
|
148
|
+
const features = [];
|
|
348
149
|
|
|
349
|
-
for (
|
|
350
|
-
|
|
351
|
-
|
|
150
|
+
for (let i = 0; i < geometries.length; i++) {
|
|
151
|
+
const geometry = geometries[i];
|
|
152
|
+
const feature = {
|
|
352
153
|
type: 'Feature',
|
|
353
|
-
geometry
|
|
154
|
+
geometry,
|
|
354
155
|
properties: properties && properties[i] || {}
|
|
355
156
|
};
|
|
356
157
|
features.push(feature);
|
|
@@ -360,109 +161,55 @@ function joinProperties(geometries, properties) {
|
|
|
360
161
|
}
|
|
361
162
|
|
|
362
163
|
function reprojectFeatures(features, sourceCrs, targetCrs) {
|
|
363
|
-
|
|
164
|
+
const projection = new _proj.Proj4Projection({
|
|
364
165
|
from: sourceCrs || 'WGS84',
|
|
365
166
|
to: targetCrs || 'WGS84'
|
|
366
167
|
});
|
|
367
|
-
return (0, _gis.transformGeoJsonCoords)(features,
|
|
368
|
-
return projection.project(coord);
|
|
369
|
-
});
|
|
168
|
+
return (0, _gis.transformGeoJsonCoords)(features, coord => projection.project(coord));
|
|
370
169
|
}
|
|
371
170
|
|
|
372
|
-
function loadShapefileSidecarFiles(
|
|
373
|
-
|
|
374
|
-
|
|
171
|
+
async function loadShapefileSidecarFiles(options, context) {
|
|
172
|
+
const {
|
|
173
|
+
url,
|
|
174
|
+
fetch
|
|
175
|
+
} = context;
|
|
176
|
+
const shxPromise = fetch(replaceExtension(url, 'shx'));
|
|
177
|
+
const cpgPromise = fetch(replaceExtension(url, 'cpg'));
|
|
178
|
+
const prjPromise = fetch(replaceExtension(url, 'prj'));
|
|
179
|
+
await Promise.all([shxPromise, cpgPromise, prjPromise]);
|
|
180
|
+
let shx;
|
|
181
|
+
let cpg;
|
|
182
|
+
let prj;
|
|
183
|
+
const shxResponse = await shxPromise;
|
|
184
|
+
|
|
185
|
+
if (shxResponse.ok) {
|
|
186
|
+
const arrayBuffer = await shxResponse.arrayBuffer();
|
|
187
|
+
shx = (0, _parseShx.parseShx)(arrayBuffer);
|
|
188
|
+
}
|
|
375
189
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
case 8:
|
|
395
|
-
shxResponse = _context3.sent;
|
|
396
|
-
|
|
397
|
-
if (!shxResponse.ok) {
|
|
398
|
-
_context3.next = 14;
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
_context3.next = 12;
|
|
403
|
-
return shxResponse.arrayBuffer();
|
|
404
|
-
|
|
405
|
-
case 12:
|
|
406
|
-
arrayBuffer = _context3.sent;
|
|
407
|
-
shx = (0, _parseShx.parseShx)(arrayBuffer);
|
|
408
|
-
|
|
409
|
-
case 14:
|
|
410
|
-
_context3.next = 16;
|
|
411
|
-
return cpgPromise;
|
|
412
|
-
|
|
413
|
-
case 16:
|
|
414
|
-
cpgResponse = _context3.sent;
|
|
415
|
-
|
|
416
|
-
if (!cpgResponse.ok) {
|
|
417
|
-
_context3.next = 21;
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
_context3.next = 20;
|
|
422
|
-
return cpgResponse.text();
|
|
423
|
-
|
|
424
|
-
case 20:
|
|
425
|
-
cpg = _context3.sent;
|
|
426
|
-
|
|
427
|
-
case 21:
|
|
428
|
-
_context3.next = 23;
|
|
429
|
-
return prjPromise;
|
|
430
|
-
|
|
431
|
-
case 23:
|
|
432
|
-
prjResponse = _context3.sent;
|
|
433
|
-
|
|
434
|
-
if (!prjResponse.ok) {
|
|
435
|
-
_context3.next = 28;
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
_context3.next = 27;
|
|
440
|
-
return prjResponse.text();
|
|
441
|
-
|
|
442
|
-
case 27:
|
|
443
|
-
prj = _context3.sent;
|
|
444
|
-
|
|
445
|
-
case 28:
|
|
446
|
-
return _context3.abrupt("return", {
|
|
447
|
-
shx: shx,
|
|
448
|
-
cpg: cpg,
|
|
449
|
-
prj: prj
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
case 29:
|
|
453
|
-
case "end":
|
|
454
|
-
return _context3.stop();
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}, _callee3);
|
|
458
|
-
}));
|
|
459
|
-
return _loadShapefileSidecarFiles.apply(this, arguments);
|
|
190
|
+
const cpgResponse = await cpgPromise;
|
|
191
|
+
|
|
192
|
+
if (cpgResponse.ok) {
|
|
193
|
+
cpg = await cpgResponse.text();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const prjResponse = await prjPromise;
|
|
197
|
+
|
|
198
|
+
if (prjResponse.ok) {
|
|
199
|
+
prj = await prjResponse.text();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
shx,
|
|
204
|
+
cpg,
|
|
205
|
+
prj
|
|
206
|
+
};
|
|
460
207
|
}
|
|
461
208
|
|
|
462
209
|
function replaceExtension(url, newExtension) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
210
|
+
const baseName = basename(url);
|
|
211
|
+
const extension = extname(url);
|
|
212
|
+
const isUpperCase = extension === extension.toUpperCase();
|
|
466
213
|
|
|
467
214
|
if (isUpperCase) {
|
|
468
215
|
newExtension = newExtension.toUpperCase();
|
|
@@ -472,7 +219,7 @@ function replaceExtension(url, newExtension) {
|
|
|
472
219
|
}
|
|
473
220
|
|
|
474
221
|
function basename(url) {
|
|
475
|
-
|
|
222
|
+
const extIndex = url && url.lastIndexOf('.');
|
|
476
223
|
|
|
477
224
|
if (typeof extIndex === 'number') {
|
|
478
225
|
return extIndex >= 0 ? url.substr(0, extIndex) : '';
|
|
@@ -482,7 +229,7 @@ function basename(url) {
|
|
|
482
229
|
}
|
|
483
230
|
|
|
484
231
|
function extname(url) {
|
|
485
|
-
|
|
232
|
+
const extIndex = url && url.lastIndexOf('.');
|
|
486
233
|
|
|
487
234
|
if (typeof extIndex === 'number') {
|
|
488
235
|
return extIndex >= 0 ? url.substr(extIndex + 1) : '';
|