@loaders.gl/shapefile 3.0.13 → 3.0.14
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/dbf-worker.js +1 -1
- package/dist/dbf-worker.js.map +1 -1
- package/dist/dist.es5.min.js +1 -1
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/dbf-loader.js +40 -5
- package/dist/es5/dbf-loader.js.map +1 -1
- package/dist/es5/index.js +5 -5
- package/dist/es5/lib/parsers/parse-dbf.js +231 -87
- package/dist/es5/lib/parsers/parse-dbf.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shapefile.js +404 -151
- package/dist/es5/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp-geometry.js +96 -49
- 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 +165 -47
- 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 +172 -99
- package/dist/es5/lib/streaming/binary-chunk-reader.js.map +1 -1
- package/dist/es5/lib/streaming/binary-reader.js +35 -24
- package/dist/es5/lib/streaming/binary-reader.js.map +1 -1
- package/dist/es5/lib/streaming/zip-batch-iterators.js +96 -37
- 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 +41 -6
- package/dist/es5/shp-loader.js.map +1 -1
- package/dist/esm/dbf-loader.js +1 -1
- package/dist/esm/shapefile-loader.js +1 -1
- package/dist/esm/shp-loader.js +1 -1
- package/dist/shp-worker.js +1 -1
- package/dist/shp-worker.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -8,150 +10,347 @@ exports.parseShapefile = parseShapefile;
|
|
|
8
10
|
exports.loadShapefileSidecarFiles = loadShapefileSidecarFiles;
|
|
9
11
|
exports.replaceExtension = replaceExtension;
|
|
10
12
|
|
|
11
|
-
var
|
|
13
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
14
|
|
|
13
|
-
var
|
|
15
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
14
16
|
|
|
15
|
-
var
|
|
17
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
16
18
|
|
|
17
|
-
var
|
|
19
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
20
|
|
|
19
|
-
var
|
|
21
|
+
var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
|
|
20
22
|
|
|
21
|
-
var
|
|
23
|
+
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
22
24
|
|
|
23
|
-
|
|
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
|
-
}
|
|
25
|
+
var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
|
|
44
26
|
|
|
45
|
-
|
|
27
|
+
var _gis = require("@loaders.gl/gis");
|
|
46
28
|
|
|
47
|
-
|
|
48
|
-
shapeHeader = (await shapeIterable.next()).value;
|
|
49
|
-
}
|
|
29
|
+
var _proj = require("@math.gl/proj4");
|
|
50
30
|
|
|
51
|
-
|
|
31
|
+
var _parseShx = require("./parse-shx");
|
|
52
32
|
|
|
53
|
-
|
|
54
|
-
dbfHeader = (await propertyIterable.next()).value;
|
|
33
|
+
var _zipBatchIterators = require("../streaming/zip-batch-iterators");
|
|
55
34
|
|
|
56
|
-
|
|
57
|
-
dbfHeader = (await propertyIterable.next()).value;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
35
|
+
var _shpLoader = require("../../shp-loader");
|
|
60
36
|
|
|
61
|
-
|
|
37
|
+
var _dbfLoader = require("../../dbf-loader");
|
|
62
38
|
|
|
63
|
-
|
|
64
|
-
iterator = (0, _zipBatchIterators.zipBatchIterators)(shapeIterable, propertyIterable);
|
|
65
|
-
} else {
|
|
66
|
-
iterator = shapeIterable;
|
|
67
|
-
}
|
|
39
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
68
40
|
|
|
69
|
-
|
|
70
|
-
let geometries;
|
|
71
|
-
let properties;
|
|
41
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
72
42
|
|
|
73
|
-
|
|
74
|
-
geometries = item;
|
|
75
|
-
} else {
|
|
76
|
-
[geometries, properties] = item;
|
|
77
|
-
}
|
|
43
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
78
44
|
|
|
79
|
-
|
|
80
|
-
let features = joinProperties(geojsonGeometries, properties);
|
|
45
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
81
46
|
|
|
82
|
-
|
|
83
|
-
features = reprojectFeatures(features, prj, _targetCrs);
|
|
84
|
-
}
|
|
47
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
85
48
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
prj,
|
|
89
|
-
shx,
|
|
90
|
-
header: shapeHeader,
|
|
91
|
-
data: features
|
|
92
|
-
};
|
|
93
|
-
}
|
|
49
|
+
function parseShapefileInBatches(_x, _x2, _x3) {
|
|
50
|
+
return _parseShapefileInBatches.apply(this, arguments);
|
|
94
51
|
}
|
|
95
52
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
reproject
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
53
|
+
function _parseShapefileInBatches() {
|
|
54
|
+
_parseShapefileInBatches = (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee(asyncIterator, options, context) {
|
|
55
|
+
var _ref, _ref$reproject, reproject, _ref$_targetCrs, _targetCrs, _yield$_awaitAsyncGen, shx, cpg, prj, shapeIterable, propertyIterable, dbfResponse, shapeHeader, dbfHeader, iterator, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, item, geometries, properties, _item, geojsonGeometries, features;
|
|
56
|
+
|
|
57
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
58
|
+
while (1) {
|
|
59
|
+
switch (_context.prev = _context.next) {
|
|
60
|
+
case 0:
|
|
61
|
+
_ref = (options === null || options === void 0 ? void 0 : options.gis) || {}, _ref$reproject = _ref.reproject, reproject = _ref$reproject === void 0 ? false : _ref$reproject, _ref$_targetCrs = _ref._targetCrs, _targetCrs = _ref$_targetCrs === void 0 ? 'WGS84' : _ref$_targetCrs;
|
|
62
|
+
_context.next = 3;
|
|
63
|
+
return (0, _awaitAsyncGenerator2.default)(loadShapefileSidecarFiles(options, context));
|
|
64
|
+
|
|
65
|
+
case 3:
|
|
66
|
+
_yield$_awaitAsyncGen = _context.sent;
|
|
67
|
+
shx = _yield$_awaitAsyncGen.shx;
|
|
68
|
+
cpg = _yield$_awaitAsyncGen.cpg;
|
|
69
|
+
prj = _yield$_awaitAsyncGen.prj;
|
|
70
|
+
_context.next = 9;
|
|
71
|
+
return (0, _awaitAsyncGenerator2.default)(context.parseInBatches(asyncIterator, _shpLoader.SHPLoader, options));
|
|
72
|
+
|
|
73
|
+
case 9:
|
|
74
|
+
shapeIterable = _context.sent;
|
|
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
|
+
}
|
|
118
244
|
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
245
|
+
}, _callee, null, [[36, 60, 64, 74], [65,, 69, 73]]);
|
|
246
|
+
}));
|
|
247
|
+
return _parseShapefileInBatches.apply(this, arguments);
|
|
248
|
+
}
|
|
123
249
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
250
|
+
function parseShapefile(_x4, _x5, _x6) {
|
|
251
|
+
return _parseShapefile.apply(this, arguments);
|
|
252
|
+
}
|
|
127
253
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
prj,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
254
|
+
function _parseShapefile() {
|
|
255
|
+
_parseShapefile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(arrayBuffer, options, context) {
|
|
256
|
+
var _ref2, _ref2$reproject, reproject, _ref2$_targetCrs, _targetCrs, _yield$loadShapefileS, shx, cpg, prj, _yield$context$parse, header, geometries, geojsonGeometries, properties, dbfResponse, features;
|
|
257
|
+
|
|
258
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
259
|
+
while (1) {
|
|
260
|
+
switch (_context2.prev = _context2.next) {
|
|
261
|
+
case 0:
|
|
262
|
+
_ref2 = (options === null || options === void 0 ? void 0 : options.gis) || {}, _ref2$reproject = _ref2.reproject, reproject = _ref2$reproject === void 0 ? false : _ref2$reproject, _ref2$_targetCrs = _ref2._targetCrs, _targetCrs = _ref2$_targetCrs === void 0 ? 'WGS84' : _ref2$_targetCrs;
|
|
263
|
+
_context2.next = 3;
|
|
264
|
+
return loadShapefileSidecarFiles(options, context);
|
|
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);
|
|
135
324
|
}
|
|
136
325
|
|
|
137
326
|
function parseGeometries(geometries) {
|
|
138
|
-
|
|
327
|
+
var geojsonGeometries = [];
|
|
139
328
|
|
|
140
|
-
|
|
141
|
-
|
|
329
|
+
var _iterator2 = _createForOfIteratorHelper(geometries),
|
|
330
|
+
_step2;
|
|
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();
|
|
142
341
|
}
|
|
143
342
|
|
|
144
343
|
return geojsonGeometries;
|
|
145
344
|
}
|
|
146
345
|
|
|
147
346
|
function joinProperties(geometries, properties) {
|
|
148
|
-
|
|
347
|
+
var features = [];
|
|
149
348
|
|
|
150
|
-
for (
|
|
151
|
-
|
|
152
|
-
|
|
349
|
+
for (var i = 0; i < geometries.length; i++) {
|
|
350
|
+
var geometry = geometries[i];
|
|
351
|
+
var feature = {
|
|
153
352
|
type: 'Feature',
|
|
154
|
-
geometry,
|
|
353
|
+
geometry: geometry,
|
|
155
354
|
properties: properties && properties[i] || {}
|
|
156
355
|
};
|
|
157
356
|
features.push(feature);
|
|
@@ -161,55 +360,109 @@ function joinProperties(geometries, properties) {
|
|
|
161
360
|
}
|
|
162
361
|
|
|
163
362
|
function reprojectFeatures(features, sourceCrs, targetCrs) {
|
|
164
|
-
|
|
363
|
+
var projection = new _proj.Proj4Projection({
|
|
165
364
|
from: sourceCrs || 'WGS84',
|
|
166
365
|
to: targetCrs || 'WGS84'
|
|
167
366
|
});
|
|
168
|
-
return (0, _gis.transformGeoJsonCoords)(features,
|
|
367
|
+
return (0, _gis.transformGeoJsonCoords)(features, function (coord) {
|
|
368
|
+
return projection.project(coord);
|
|
369
|
+
});
|
|
169
370
|
}
|
|
170
371
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
}
|
|
189
|
-
|
|
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
|
-
}
|
|
372
|
+
function loadShapefileSidecarFiles(_x7, _x8) {
|
|
373
|
+
return _loadShapefileSidecarFiles.apply(this, arguments);
|
|
374
|
+
}
|
|
201
375
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
cpg,
|
|
205
|
-
|
|
206
|
-
|
|
376
|
+
function _loadShapefileSidecarFiles() {
|
|
377
|
+
_loadShapefileSidecarFiles = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(options, context) {
|
|
378
|
+
var url, fetch, shxPromise, cpgPromise, prjPromise, shx, cpg, prj, shxResponse, arrayBuffer, cpgResponse, prjResponse;
|
|
379
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
380
|
+
while (1) {
|
|
381
|
+
switch (_context3.prev = _context3.next) {
|
|
382
|
+
case 0:
|
|
383
|
+
url = context.url, fetch = context.fetch;
|
|
384
|
+
shxPromise = fetch(replaceExtension(url, 'shx'));
|
|
385
|
+
cpgPromise = fetch(replaceExtension(url, 'cpg'));
|
|
386
|
+
prjPromise = fetch(replaceExtension(url, 'prj'));
|
|
387
|
+
_context3.next = 6;
|
|
388
|
+
return Promise.all([shxPromise, cpgPromise, prjPromise]);
|
|
389
|
+
|
|
390
|
+
case 6:
|
|
391
|
+
_context3.next = 8;
|
|
392
|
+
return shxPromise;
|
|
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);
|
|
207
460
|
}
|
|
208
461
|
|
|
209
462
|
function replaceExtension(url, newExtension) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
463
|
+
var baseName = basename(url);
|
|
464
|
+
var extension = extname(url);
|
|
465
|
+
var isUpperCase = extension === extension.toUpperCase();
|
|
213
466
|
|
|
214
467
|
if (isUpperCase) {
|
|
215
468
|
newExtension = newExtension.toUpperCase();
|
|
@@ -219,7 +472,7 @@ function replaceExtension(url, newExtension) {
|
|
|
219
472
|
}
|
|
220
473
|
|
|
221
474
|
function basename(url) {
|
|
222
|
-
|
|
475
|
+
var extIndex = url && url.lastIndexOf('.');
|
|
223
476
|
|
|
224
477
|
if (typeof extIndex === 'number') {
|
|
225
478
|
return extIndex >= 0 ? url.substr(0, extIndex) : '';
|
|
@@ -229,7 +482,7 @@ function basename(url) {
|
|
|
229
482
|
}
|
|
230
483
|
|
|
231
484
|
function extname(url) {
|
|
232
|
-
|
|
485
|
+
var extIndex = url && url.lastIndexOf('.');
|
|
233
486
|
|
|
234
487
|
if (typeof extIndex === 'number') {
|
|
235
488
|
return extIndex >= 0 ? url.substr(extIndex + 1) : '';
|