@loaders.gl/shapefile 3.4.13 → 3.4.15
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/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/dbf-loader.js +6 -27
- package/dist/es5/dbf-loader.js.map +1 -1
- package/dist/es5/index.js +5 -5
- package/dist/es5/lib/parsers/parse-dbf.js +89 -179
- package/dist/es5/lib/parsers/parse-dbf.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shapefile.js +137 -314
- package/dist/es5/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp-geometry.js +49 -72
- 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 +45 -130
- 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 +82 -146
- package/dist/es5/lib/streaming/binary-chunk-reader.js.map +1 -1
- package/dist/es5/lib/streaming/binary-reader.js +19 -32
- package/dist/es5/lib/streaming/binary-reader.js.map +1 -1
- package/dist/es5/lib/streaming/zip-batch-iterators.js +33 -74
- 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 +7 -28
- 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/package.json +5 -5
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,258 +7,122 @@ exports.loadShapefileSidecarFiles = loadShapefileSidecarFiles;
|
|
|
8
7
|
exports.parseShapefile = parseShapefile;
|
|
9
8
|
exports.parseShapefileInBatches = parseShapefileInBatches;
|
|
10
9
|
exports.replaceExtension = replaceExtension;
|
|
11
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
|
|
16
|
-
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
17
10
|
var _gis = require("@loaders.gl/gis");
|
|
18
11
|
var _proj = require("@math.gl/proj4");
|
|
19
12
|
var _parseShx = require("./parse-shx");
|
|
20
13
|
var _zipBatchIterators = require("../streaming/zip-batch-iterators");
|
|
21
14
|
var _shpLoader = require("../../shp-loader");
|
|
22
15
|
var _dbfLoader = require("../../dbf-loader");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return (0, _awaitAsyncGenerator2.default)(loadShapefileSidecarFiles(options, context));
|
|
42
|
-
case 3:
|
|
43
|
-
_yield$_awaitAsyncGen = _context.sent;
|
|
44
|
-
shx = _yield$_awaitAsyncGen.shx;
|
|
45
|
-
cpg = _yield$_awaitAsyncGen.cpg;
|
|
46
|
-
prj = _yield$_awaitAsyncGen.prj;
|
|
47
|
-
_context.next = 9;
|
|
48
|
-
return (0, _awaitAsyncGenerator2.default)(context.parseInBatches(asyncIterator, _shpLoader.SHPLoader, options));
|
|
49
|
-
case 9:
|
|
50
|
-
shapeIterable = _context.sent;
|
|
51
|
-
_context.next = 12;
|
|
52
|
-
return (0, _awaitAsyncGenerator2.default)(context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf')));
|
|
53
|
-
case 12:
|
|
54
|
-
dbfResponse = _context.sent;
|
|
55
|
-
if (!dbfResponse.ok) {
|
|
56
|
-
_context.next = 17;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
_context.next = 16;
|
|
60
|
-
return (0, _awaitAsyncGenerator2.default)(context.parseInBatches(dbfResponse, _dbfLoader.DBFLoader, _objectSpread(_objectSpread({}, options), {}, {
|
|
61
|
-
dbf: {
|
|
62
|
-
encoding: cpg || 'latin1'
|
|
63
|
-
}
|
|
64
|
-
})));
|
|
65
|
-
case 16:
|
|
66
|
-
propertyIterable = _context.sent;
|
|
67
|
-
case 17:
|
|
68
|
-
_context.next = 19;
|
|
69
|
-
return (0, _awaitAsyncGenerator2.default)(shapeIterable.next());
|
|
70
|
-
case 19:
|
|
71
|
-
shapeHeader = _context.sent.value;
|
|
72
|
-
if (!(shapeHeader && shapeHeader.batchType === 'metadata')) {
|
|
73
|
-
_context.next = 24;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
_context.next = 23;
|
|
77
|
-
return (0, _awaitAsyncGenerator2.default)(shapeIterable.next());
|
|
78
|
-
case 23:
|
|
79
|
-
shapeHeader = _context.sent.value;
|
|
80
|
-
case 24:
|
|
81
|
-
dbfHeader = {};
|
|
82
|
-
if (!propertyIterable) {
|
|
83
|
-
_context.next = 33;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
_context.next = 28;
|
|
87
|
-
return (0, _awaitAsyncGenerator2.default)(propertyIterable.next());
|
|
88
|
-
case 28:
|
|
89
|
-
dbfHeader = _context.sent.value;
|
|
90
|
-
if (!(dbfHeader && dbfHeader.batchType === 'metadata')) {
|
|
91
|
-
_context.next = 33;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
_context.next = 32;
|
|
95
|
-
return (0, _awaitAsyncGenerator2.default)(propertyIterable.next());
|
|
96
|
-
case 32:
|
|
97
|
-
dbfHeader = _context.sent.value;
|
|
98
|
-
case 33:
|
|
99
|
-
if (propertyIterable) {
|
|
100
|
-
iterator = (0, _zipBatchIterators.zipBatchIterators)(shapeIterable, propertyIterable);
|
|
101
|
-
} else {
|
|
102
|
-
iterator = shapeIterable;
|
|
103
|
-
}
|
|
104
|
-
_iteratorAbruptCompletion = false;
|
|
105
|
-
_didIteratorError = false;
|
|
106
|
-
_context.prev = 36;
|
|
107
|
-
_iterator = _asyncIterator(iterator);
|
|
108
|
-
case 38:
|
|
109
|
-
_context.next = 40;
|
|
110
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.next());
|
|
111
|
-
case 40:
|
|
112
|
-
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
113
|
-
_context.next = 53;
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
item = _step.value;
|
|
117
|
-
geometries = void 0;
|
|
118
|
-
properties = void 0;
|
|
119
|
-
if (!propertyIterable) {
|
|
120
|
-
geometries = item;
|
|
121
|
-
} else {
|
|
122
|
-
_item = (0, _slicedToArray2.default)(item, 2);
|
|
123
|
-
geometries = _item[0];
|
|
124
|
-
properties = _item[1];
|
|
125
|
-
}
|
|
126
|
-
geojsonGeometries = parseGeometries(geometries);
|
|
127
|
-
features = joinProperties(geojsonGeometries, properties);
|
|
128
|
-
if (reproject) {
|
|
129
|
-
features = reprojectFeatures(features, prj, _targetCrs);
|
|
130
|
-
}
|
|
131
|
-
_context.next = 50;
|
|
132
|
-
return {
|
|
133
|
-
encoding: cpg,
|
|
134
|
-
prj: prj,
|
|
135
|
-
shx: shx,
|
|
136
|
-
header: shapeHeader,
|
|
137
|
-
data: features
|
|
138
|
-
};
|
|
139
|
-
case 50:
|
|
140
|
-
_iteratorAbruptCompletion = false;
|
|
141
|
-
_context.next = 38;
|
|
142
|
-
break;
|
|
143
|
-
case 53:
|
|
144
|
-
_context.next = 59;
|
|
145
|
-
break;
|
|
146
|
-
case 55:
|
|
147
|
-
_context.prev = 55;
|
|
148
|
-
_context.t0 = _context["catch"](36);
|
|
149
|
-
_didIteratorError = true;
|
|
150
|
-
_iteratorError = _context.t0;
|
|
151
|
-
case 59:
|
|
152
|
-
_context.prev = 59;
|
|
153
|
-
_context.prev = 60;
|
|
154
|
-
if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
|
|
155
|
-
_context.next = 64;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
_context.next = 64;
|
|
159
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.return());
|
|
160
|
-
case 64:
|
|
161
|
-
_context.prev = 64;
|
|
162
|
-
if (!_didIteratorError) {
|
|
163
|
-
_context.next = 67;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
throw _iteratorError;
|
|
167
|
-
case 67:
|
|
168
|
-
return _context.finish(64);
|
|
169
|
-
case 68:
|
|
170
|
-
return _context.finish(59);
|
|
171
|
-
case 69:
|
|
172
|
-
case "end":
|
|
173
|
-
return _context.stop();
|
|
16
|
+
async function* parseShapefileInBatches(asyncIterator, options, context) {
|
|
17
|
+
const {
|
|
18
|
+
reproject = false,
|
|
19
|
+
_targetCrs = 'WGS84'
|
|
20
|
+
} = (options === null || options === void 0 ? void 0 : options.gis) || {};
|
|
21
|
+
const {
|
|
22
|
+
shx,
|
|
23
|
+
cpg,
|
|
24
|
+
prj
|
|
25
|
+
} = await loadShapefileSidecarFiles(options, context);
|
|
26
|
+
const shapeIterable = await context.parseInBatches(asyncIterator, _shpLoader.SHPLoader, options);
|
|
27
|
+
let propertyIterable;
|
|
28
|
+
const dbfResponse = await context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf'));
|
|
29
|
+
if (dbfResponse.ok) {
|
|
30
|
+
propertyIterable = await context.parseInBatches(dbfResponse, _dbfLoader.DBFLoader, {
|
|
31
|
+
...options,
|
|
32
|
+
dbf: {
|
|
33
|
+
encoding: cpg || 'latin1'
|
|
174
34
|
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
let shapeHeader = (await shapeIterable.next()).value;
|
|
38
|
+
if (shapeHeader && shapeHeader.batchType === 'metadata') {
|
|
39
|
+
shapeHeader = (await shapeIterable.next()).value;
|
|
40
|
+
}
|
|
41
|
+
let dbfHeader = {};
|
|
42
|
+
if (propertyIterable) {
|
|
43
|
+
dbfHeader = (await propertyIterable.next()).value;
|
|
44
|
+
if (dbfHeader && dbfHeader.batchType === 'metadata') {
|
|
45
|
+
dbfHeader = (await propertyIterable.next()).value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let iterator;
|
|
49
|
+
if (propertyIterable) {
|
|
50
|
+
iterator = (0, _zipBatchIterators.zipBatchIterators)(shapeIterable, propertyIterable);
|
|
51
|
+
} else {
|
|
52
|
+
iterator = shapeIterable;
|
|
53
|
+
}
|
|
54
|
+
for await (const item of iterator) {
|
|
55
|
+
let geometries;
|
|
56
|
+
let properties;
|
|
57
|
+
if (!propertyIterable) {
|
|
58
|
+
geometries = item;
|
|
59
|
+
} else {
|
|
60
|
+
[geometries, properties] = item;
|
|
61
|
+
}
|
|
62
|
+
const geojsonGeometries = parseGeometries(geometries);
|
|
63
|
+
let features = joinProperties(geojsonGeometries, properties);
|
|
64
|
+
if (reproject) {
|
|
65
|
+
features = reprojectFeatures(features, prj, _targetCrs);
|
|
66
|
+
}
|
|
67
|
+
yield {
|
|
68
|
+
encoding: cpg,
|
|
69
|
+
prj,
|
|
70
|
+
shx,
|
|
71
|
+
header: shapeHeader,
|
|
72
|
+
data: features
|
|
73
|
+
};
|
|
74
|
+
}
|
|
181
75
|
}
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
properties = [];
|
|
204
|
-
_context2.next = 16;
|
|
205
|
-
return context.fetch(replaceExtension(context.url, 'dbf'));
|
|
206
|
-
case 16:
|
|
207
|
-
dbfResponse = _context2.sent;
|
|
208
|
-
if (!dbfResponse.ok) {
|
|
209
|
-
_context2.next = 21;
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
_context2.next = 20;
|
|
213
|
-
return context.parse(dbfResponse, _dbfLoader.DBFLoader, {
|
|
214
|
-
dbf: {
|
|
215
|
-
encoding: cpg || 'latin1'
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
case 20:
|
|
219
|
-
properties = _context2.sent;
|
|
220
|
-
case 21:
|
|
221
|
-
features = joinProperties(geojsonGeometries, properties);
|
|
222
|
-
if (reproject) {
|
|
223
|
-
features = reprojectFeatures(features, prj, _targetCrs);
|
|
224
|
-
}
|
|
225
|
-
return _context2.abrupt("return", {
|
|
226
|
-
encoding: cpg,
|
|
227
|
-
prj: prj,
|
|
228
|
-
shx: shx,
|
|
229
|
-
header: header,
|
|
230
|
-
data: features
|
|
231
|
-
});
|
|
232
|
-
case 24:
|
|
233
|
-
case "end":
|
|
234
|
-
return _context2.stop();
|
|
76
|
+
async function parseShapefile(arrayBuffer, options, context) {
|
|
77
|
+
const {
|
|
78
|
+
reproject = false,
|
|
79
|
+
_targetCrs = 'WGS84'
|
|
80
|
+
} = (options === null || options === void 0 ? void 0 : options.gis) || {};
|
|
81
|
+
const {
|
|
82
|
+
shx,
|
|
83
|
+
cpg,
|
|
84
|
+
prj
|
|
85
|
+
} = await loadShapefileSidecarFiles(options, context);
|
|
86
|
+
const {
|
|
87
|
+
header,
|
|
88
|
+
geometries
|
|
89
|
+
} = await context.parse(arrayBuffer, _shpLoader.SHPLoader, options);
|
|
90
|
+
const geojsonGeometries = parseGeometries(geometries);
|
|
91
|
+
let properties = [];
|
|
92
|
+
const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));
|
|
93
|
+
if (dbfResponse.ok) {
|
|
94
|
+
properties = await context.parse(dbfResponse, _dbfLoader.DBFLoader, {
|
|
95
|
+
dbf: {
|
|
96
|
+
encoding: cpg || 'latin1'
|
|
235
97
|
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
let features = joinProperties(geojsonGeometries, properties);
|
|
101
|
+
if (reproject) {
|
|
102
|
+
features = reprojectFeatures(features, prj, _targetCrs);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
encoding: cpg,
|
|
106
|
+
prj,
|
|
107
|
+
shx,
|
|
108
|
+
header,
|
|
109
|
+
data: features
|
|
110
|
+
};
|
|
239
111
|
}
|
|
240
112
|
function parseGeometries(geometries) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
try {
|
|
245
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
246
|
-
var geom = _step2.value;
|
|
247
|
-
geojsonGeometries.push((0, _gis.binaryToGeometry)(geom));
|
|
248
|
-
}
|
|
249
|
-
} catch (err) {
|
|
250
|
-
_iterator2.e(err);
|
|
251
|
-
} finally {
|
|
252
|
-
_iterator2.f();
|
|
113
|
+
const geojsonGeometries = [];
|
|
114
|
+
for (const geom of geometries) {
|
|
115
|
+
geojsonGeometries.push((0, _gis.binaryToGeometry)(geom));
|
|
253
116
|
}
|
|
254
117
|
return geojsonGeometries;
|
|
255
118
|
}
|
|
256
119
|
function joinProperties(geometries, properties) {
|
|
257
|
-
|
|
258
|
-
for (
|
|
259
|
-
|
|
260
|
-
|
|
120
|
+
const features = [];
|
|
121
|
+
for (let i = 0; i < geometries.length; i++) {
|
|
122
|
+
const geometry = geometries[i];
|
|
123
|
+
const feature = {
|
|
261
124
|
type: 'Feature',
|
|
262
|
-
geometry
|
|
125
|
+
geometry,
|
|
263
126
|
properties: properties && properties[i] || {}
|
|
264
127
|
};
|
|
265
128
|
features.push(feature);
|
|
@@ -270,101 +133,61 @@ function reprojectFeatures(features, sourceCrs, targetCrs) {
|
|
|
270
133
|
if (!sourceCrs && !targetCrs) {
|
|
271
134
|
return features;
|
|
272
135
|
}
|
|
273
|
-
|
|
136
|
+
const projection = new _proj.Proj4Projection({
|
|
274
137
|
from: sourceCrs || 'WGS84',
|
|
275
138
|
to: targetCrs || 'WGS84'
|
|
276
139
|
});
|
|
277
|
-
return (0, _gis.transformGeoJsonCoords)(features,
|
|
278
|
-
return projection.project(coord);
|
|
279
|
-
});
|
|
140
|
+
return (0, _gis.transformGeoJsonCoords)(features, coord => projection.project(coord));
|
|
280
141
|
}
|
|
281
|
-
function loadShapefileSidecarFiles(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
_context3.next = 16;
|
|
312
|
-
return cpgPromise;
|
|
313
|
-
case 16:
|
|
314
|
-
cpgResponse = _context3.sent;
|
|
315
|
-
if (!cpgResponse.ok) {
|
|
316
|
-
_context3.next = 21;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
_context3.next = 20;
|
|
320
|
-
return cpgResponse.text();
|
|
321
|
-
case 20:
|
|
322
|
-
cpg = _context3.sent;
|
|
323
|
-
case 21:
|
|
324
|
-
_context3.next = 23;
|
|
325
|
-
return prjPromise;
|
|
326
|
-
case 23:
|
|
327
|
-
prjResponse = _context3.sent;
|
|
328
|
-
if (!prjResponse.ok) {
|
|
329
|
-
_context3.next = 28;
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
332
|
-
_context3.next = 27;
|
|
333
|
-
return prjResponse.text();
|
|
334
|
-
case 27:
|
|
335
|
-
prj = _context3.sent;
|
|
336
|
-
case 28:
|
|
337
|
-
return _context3.abrupt("return", {
|
|
338
|
-
shx: shx,
|
|
339
|
-
cpg: cpg,
|
|
340
|
-
prj: prj
|
|
341
|
-
});
|
|
342
|
-
case 29:
|
|
343
|
-
case "end":
|
|
344
|
-
return _context3.stop();
|
|
345
|
-
}
|
|
346
|
-
}, _callee3);
|
|
347
|
-
}));
|
|
348
|
-
return _loadShapefileSidecarFiles.apply(this, arguments);
|
|
142
|
+
async function loadShapefileSidecarFiles(options, context) {
|
|
143
|
+
const {
|
|
144
|
+
url,
|
|
145
|
+
fetch
|
|
146
|
+
} = context;
|
|
147
|
+
const shxPromise = fetch(replaceExtension(url, 'shx'));
|
|
148
|
+
const cpgPromise = fetch(replaceExtension(url, 'cpg'));
|
|
149
|
+
const prjPromise = fetch(replaceExtension(url, 'prj'));
|
|
150
|
+
await Promise.all([shxPromise, cpgPromise, prjPromise]);
|
|
151
|
+
let shx;
|
|
152
|
+
let cpg;
|
|
153
|
+
let prj;
|
|
154
|
+
const shxResponse = await shxPromise;
|
|
155
|
+
if (shxResponse.ok) {
|
|
156
|
+
const arrayBuffer = await shxResponse.arrayBuffer();
|
|
157
|
+
shx = (0, _parseShx.parseShx)(arrayBuffer);
|
|
158
|
+
}
|
|
159
|
+
const cpgResponse = await cpgPromise;
|
|
160
|
+
if (cpgResponse.ok) {
|
|
161
|
+
cpg = await cpgResponse.text();
|
|
162
|
+
}
|
|
163
|
+
const prjResponse = await prjPromise;
|
|
164
|
+
if (prjResponse.ok) {
|
|
165
|
+
prj = await prjResponse.text();
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
shx,
|
|
169
|
+
cpg,
|
|
170
|
+
prj
|
|
171
|
+
};
|
|
349
172
|
}
|
|
350
173
|
function replaceExtension(url, newExtension) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
174
|
+
const baseName = basename(url);
|
|
175
|
+
const extension = extname(url);
|
|
176
|
+
const isUpperCase = extension === extension.toUpperCase();
|
|
354
177
|
if (isUpperCase) {
|
|
355
178
|
newExtension = newExtension.toUpperCase();
|
|
356
179
|
}
|
|
357
180
|
return "".concat(baseName, ".").concat(newExtension);
|
|
358
181
|
}
|
|
359
182
|
function basename(url) {
|
|
360
|
-
|
|
183
|
+
const extIndex = url && url.lastIndexOf('.');
|
|
361
184
|
if (typeof extIndex === 'number') {
|
|
362
185
|
return extIndex >= 0 ? url.substr(0, extIndex) : '';
|
|
363
186
|
}
|
|
364
187
|
return extIndex;
|
|
365
188
|
}
|
|
366
189
|
function extname(url) {
|
|
367
|
-
|
|
190
|
+
const extIndex = url && url.lastIndexOf('.');
|
|
368
191
|
if (typeof extIndex === 'number') {
|
|
369
192
|
return extIndex >= 0 ? url.substr(extIndex + 1) : '';
|
|
370
193
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shapefile.js","names":["_gis","require","_proj","_parseShx","_zipBatchIterators","_shpLoader","_dbfLoader","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","arguments","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","_asyncIterator","iterable","method","async","sync","retry","asyncIterator","AsyncFromSyncIterator","AsyncFromSyncIteratorContinuation","r","Promise","reject","resolve","then","_return","ret","throw","_throw","thr","parseShapefileInBatches","_x","_x2","_x3","_parseShapefileInBatches","_wrapAsyncGenerator2","_regenerator","mark","_callee","options","context","_ref","_ref$reproject","reproject","_ref$_targetCrs","_targetCrs","_yield$_awaitAsyncGen","shx","cpg","prj","shapeIterable","propertyIterable","dbfResponse","shapeHeader","dbfHeader","_iteratorAbruptCompletion","_didIteratorError","_iteratorError","_iterator","_step","item","geometries","properties","_item","geojsonGeometries","features","wrap","_callee$","_context","prev","gis","_awaitAsyncGenerator2","loadShapefileSidecarFiles","sent","parseInBatches","SHPLoader","fetch","replaceExtension","url","ok","DBFLoader","dbf","encoding","batchType","zipBatchIterators","_slicedToArray2","parseGeometries","joinProperties","reprojectFeatures","header","data","t0","finish","stop","parseShapefile","_x4","_x5","_x6","_parseShapefile","_asyncToGenerator2","_callee2","arrayBuffer","_ref2","_ref2$reproject","_ref2$_targetCrs","_yield$loadShapefileS","_yield$context$parse","_callee2$","_context2","parse","abrupt","_iterator2","_step2","geom","binaryToGeometry","geometry","feature","type","sourceCrs","targetCrs","projection","Proj4Projection","to","transformGeoJsonCoords","coord","project","_x7","_x8","_loadShapefileSidecarFiles","_callee3","shxPromise","cpgPromise","prjPromise","shxResponse","cpgResponse","prjResponse","_callee3$","_context3","all","parseShx","text","newExtension","baseName","basename","extension","extname","isUpperCase","toUpperCase","concat","extIndex","lastIndexOf","substr"],"sources":["../../../../src/lib/parsers/parse-shapefile.ts"],"sourcesContent":["// import type {Feature} from '@loaders.gl/gis';\nimport type {SHXOutput} from './parse-shx';\nimport type {SHPHeader} from './parse-shp-header';\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport type {ShapefileLoaderOptions} from './types';\n\nimport {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';\nimport {Proj4Projection} from '@math.gl/proj4';\nimport {parseShx} from './parse-shx';\nimport {zipBatchIterators} from '../streaming/zip-batch-iterators';\nimport {SHPLoader} from '../../shp-loader';\nimport {DBFLoader} from '../../dbf-loader';\n\ntype Feature = any;\ninterface ShapefileOutput {\n encoding?: string;\n prj?: string;\n shx?: SHXOutput;\n header: SHPHeader;\n data: object[];\n}\n/**\n * Parsing of file in batches\n */\n// eslint-disable-next-line max-statements, complexity\nexport async function* parseShapefileInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: ShapefileLoaderOptions,\n context?: LoaderContext\n): AsyncIterable<ShapefileOutput> {\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);\n\n // parse geometries\n // @ts-ignore context must be defined\n const shapeIterable: any = await context.parseInBatches(asyncIterator, SHPLoader, options);\n\n // parse properties\n let propertyIterable: any;\n // @ts-ignore context must be defined\n const dbfResponse = await context.fetch(replaceExtension(context?.url || '', 'dbf'));\n if (dbfResponse.ok) {\n // @ts-ignore context must be defined\n propertyIterable = await context.parseInBatches(dbfResponse, DBFLoader, {\n ...options,\n dbf: {encoding: cpg || 'latin1'}\n });\n }\n\n // When `options.metadata` is `true`, there's an extra initial `metadata`\n // object before the iterator starts. zipBatchIterators expects to receive\n // batches of Array objects, and will fail with non-iterable batches, so it's\n // important to skip over the first batch.\n let shapeHeader = (await shapeIterable.next()).value;\n if (shapeHeader && shapeHeader.batchType === 'metadata') {\n shapeHeader = (await shapeIterable.next()).value;\n }\n\n let dbfHeader: {batchType?: string} = {};\n if (propertyIterable) {\n dbfHeader = (await propertyIterable.next()).value;\n if (dbfHeader && dbfHeader.batchType === 'metadata') {\n dbfHeader = (await propertyIterable.next()).value;\n }\n }\n\n let iterator: any;\n if (propertyIterable) {\n iterator = zipBatchIterators(shapeIterable, propertyIterable);\n } else {\n iterator = shapeIterable;\n }\n\n for await (const item of iterator) {\n let geometries: any;\n let properties: any;\n if (!propertyIterable) {\n geometries = item;\n } else {\n [geometries, properties] = item;\n }\n\n const geojsonGeometries = parseGeometries(geometries);\n let features = joinProperties(geojsonGeometries, properties);\n if (reproject) {\n // @ts-ignore\n features = reprojectFeatures(features, prj, _targetCrs);\n }\n yield {\n encoding: cpg,\n prj,\n shx,\n header: shapeHeader,\n data: features\n };\n }\n}\n\n/**\n * Parse shapefile\n *\n * @param arrayBuffer\n * @param options\n * @param context\n * @returns output of shapefile\n */\nexport async function parseShapefile(\n arrayBuffer: ArrayBuffer,\n options?: ShapefileLoaderOptions,\n context?: LoaderContext\n): Promise<ShapefileOutput> {\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);\n\n // parse geometries\n // @ts-ignore context must be defined\n const {header, geometries} = await context.parse(arrayBuffer, SHPLoader, options); // {shp: shx}\n\n const geojsonGeometries = parseGeometries(geometries);\n\n // parse properties\n let properties = [];\n\n // @ts-ignore context must be defined\n const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));\n if (dbfResponse.ok) {\n // @ts-ignore context must be defined\n properties = await context.parse(dbfResponse, DBFLoader, {dbf: {encoding: cpg || 'latin1'}});\n }\n\n let features = joinProperties(geojsonGeometries, properties);\n if (reproject) {\n features = reprojectFeatures(features, prj, _targetCrs);\n }\n\n return {\n encoding: cpg,\n prj,\n shx,\n header,\n data: features\n };\n}\n\n/**\n * Parse geometries\n *\n * @param geometries\n * @returns geometries as an array\n */\nfunction parseGeometries(geometries: any[]): any[] {\n const geojsonGeometries: any[] = [];\n for (const geom of geometries) {\n geojsonGeometries.push(binaryToGeometry(geom));\n }\n return geojsonGeometries;\n}\n\n/**\n * Join properties and geometries into features\n *\n * @param geometries [description]\n * @param properties [description]\n * @return [description]\n */\nfunction joinProperties(geometries: object[], properties: object[]): Feature[] {\n const features: Feature[] = [];\n for (let i = 0; i < geometries.length; i++) {\n const geometry = geometries[i];\n const feature: Feature = {\n type: 'Feature',\n geometry,\n // properties can be undefined if dbfResponse above was empty\n properties: (properties && properties[i]) || {}\n };\n features.push(feature);\n }\n\n return features;\n}\n\n/**\n * Reproject GeoJSON features to output CRS\n *\n * @param features parsed GeoJSON features\n * @param sourceCrs source coordinate reference system\n * @param targetCrs †arget coordinate reference system\n * @return Reprojected Features\n */\nfunction reprojectFeatures(features: Feature[], sourceCrs?: string, targetCrs?: string): Feature[] {\n if (!sourceCrs && !targetCrs) {\n return features;\n }\n\n const projection = new Proj4Projection({from: sourceCrs || 'WGS84', to: targetCrs || 'WGS84'});\n return transformGeoJsonCoords(features, (coord) => projection.project(coord));\n}\n\n/**\n *\n * @param options\n * @param context\n * @returns Promise\n */\n// eslint-disable-next-line max-statements\nexport async function loadShapefileSidecarFiles(\n options?: object,\n context?: LoaderContext\n): Promise<{\n shx?: SHXOutput;\n cpg?: string;\n prj?: string;\n}> {\n // Attempt a parallel load of the small sidecar files\n // @ts-ignore context must be defined\n const {url, fetch} = context;\n const shxPromise = fetch(replaceExtension(url, 'shx'));\n const cpgPromise = fetch(replaceExtension(url, 'cpg'));\n const prjPromise = fetch(replaceExtension(url, 'prj'));\n await Promise.all([shxPromise, cpgPromise, prjPromise]);\n\n let shx: SHXOutput | undefined;\n let cpg: string | undefined;\n let prj: string | undefined;\n\n const shxResponse = await shxPromise;\n if (shxResponse.ok) {\n const arrayBuffer = await shxResponse.arrayBuffer();\n shx = parseShx(arrayBuffer);\n }\n\n const cpgResponse = await cpgPromise;\n if (cpgResponse.ok) {\n cpg = await cpgResponse.text();\n }\n\n const prjResponse = await prjPromise;\n if (prjResponse.ok) {\n prj = await prjResponse.text();\n }\n\n return {\n shx,\n cpg,\n prj\n };\n}\n\n/**\n * Replace the extension at the end of a path.\n *\n * Matches the case of new extension with the case of the original file extension,\n * to increase the chance of finding files without firing off a request storm looking for various case combinations\n *\n * NOTE: Extensions can be both lower and uppercase\n * per spec, extensions should be lower case, but that doesn't mean they always are. See:\n * calvinmetcalf/shapefile-js#64, mapserver/mapserver#4712\n * https://trac.osgeo.org/mapserver/ticket/166\n */\nexport function replaceExtension(url: string, newExtension: string): string {\n const baseName = basename(url);\n const extension = extname(url);\n const isUpperCase = extension === extension.toUpperCase();\n if (isUpperCase) {\n newExtension = newExtension.toUpperCase();\n }\n return `${baseName}.${newExtension}`;\n}\n\n// NOTE - this gives the entire path minus extension (i.e. NOT same as path.basename)\n/**\n * @param url\n * @returns string\n */\nfunction basename(url: string): string {\n const extIndex = url && url.lastIndexOf('.');\n if (typeof extIndex === 'number') {\n return extIndex >= 0 ? url.substr(0, extIndex) : '';\n }\n return extIndex;\n}\n/**\n * @param url\n * @returns string\n */\nfunction extname(url: string): string {\n const extIndex = url && url.lastIndexOf('.');\n if (typeof extIndex === 'number') {\n return extIndex >= 0 ? url.substr(extIndex + 1) : '';\n }\n return extIndex;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAMA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAA2C,SAAAM,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,EAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,cAAA,I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AAC,CAAC,EAAEF,QAAQ,CAAC,GAAG,EAAE;EACrD;EACA,OAAOA,QAAQ;AACjB;AAKA,SAASJ,OAAOA,CAACnE,GAAW,EAAU;EACpC,IAAMuE,QAAQ,GAAGvE,GAAG,IAAIA,GAAG,CAACwE,WAAW,CAAC,GAAG,CAAC;EAC5C,IAAI,OAAOD,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAOA,QAAQ,IAAI,CAAC,GAAGvE,GAAG,CAACyE,MAAM,CAACF,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE;EACtD;EACA,OAAOA,QAAQ;AACjB"}
|
|
1
|
+
{"version":3,"file":"parse-shapefile.js","names":["_gis","require","_proj","_parseShx","_zipBatchIterators","_shpLoader","_dbfLoader","parseShapefileInBatches","asyncIterator","options","context","reproject","_targetCrs","gis","shx","cpg","prj","loadShapefileSidecarFiles","shapeIterable","parseInBatches","SHPLoader","propertyIterable","dbfResponse","fetch","replaceExtension","url","ok","DBFLoader","dbf","encoding","shapeHeader","next","value","batchType","dbfHeader","iterator","zipBatchIterators","item","geometries","properties","geojsonGeometries","parseGeometries","features","joinProperties","reprojectFeatures","header","data","parseShapefile","arrayBuffer","parse","geom","push","binaryToGeometry","i","length","geometry","feature","type","sourceCrs","targetCrs","projection","Proj4Projection","from","to","transformGeoJsonCoords","coord","project","shxPromise","cpgPromise","prjPromise","Promise","all","shxResponse","parseShx","cpgResponse","text","prjResponse","newExtension","baseName","basename","extension","extname","isUpperCase","toUpperCase","concat","extIndex","lastIndexOf","substr"],"sources":["../../../../src/lib/parsers/parse-shapefile.ts"],"sourcesContent":["// import type {Feature} from '@loaders.gl/gis';\nimport type {SHXOutput} from './parse-shx';\nimport type {SHPHeader} from './parse-shp-header';\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport type {ShapefileLoaderOptions} from './types';\n\nimport {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';\nimport {Proj4Projection} from '@math.gl/proj4';\nimport {parseShx} from './parse-shx';\nimport {zipBatchIterators} from '../streaming/zip-batch-iterators';\nimport {SHPLoader} from '../../shp-loader';\nimport {DBFLoader} from '../../dbf-loader';\n\ntype Feature = any;\ninterface ShapefileOutput {\n encoding?: string;\n prj?: string;\n shx?: SHXOutput;\n header: SHPHeader;\n data: object[];\n}\n/**\n * Parsing of file in batches\n */\n// eslint-disable-next-line max-statements, complexity\nexport async function* parseShapefileInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: ShapefileLoaderOptions,\n context?: LoaderContext\n): AsyncIterable<ShapefileOutput> {\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);\n\n // parse geometries\n // @ts-ignore context must be defined\n const shapeIterable: any = await context.parseInBatches(asyncIterator, SHPLoader, options);\n\n // parse properties\n let propertyIterable: any;\n // @ts-ignore context must be defined\n const dbfResponse = await context.fetch(replaceExtension(context?.url || '', 'dbf'));\n if (dbfResponse.ok) {\n // @ts-ignore context must be defined\n propertyIterable = await context.parseInBatches(dbfResponse, DBFLoader, {\n ...options,\n dbf: {encoding: cpg || 'latin1'}\n });\n }\n\n // When `options.metadata` is `true`, there's an extra initial `metadata`\n // object before the iterator starts. zipBatchIterators expects to receive\n // batches of Array objects, and will fail with non-iterable batches, so it's\n // important to skip over the first batch.\n let shapeHeader = (await shapeIterable.next()).value;\n if (shapeHeader && shapeHeader.batchType === 'metadata') {\n shapeHeader = (await shapeIterable.next()).value;\n }\n\n let dbfHeader: {batchType?: string} = {};\n if (propertyIterable) {\n dbfHeader = (await propertyIterable.next()).value;\n if (dbfHeader && dbfHeader.batchType === 'metadata') {\n dbfHeader = (await propertyIterable.next()).value;\n }\n }\n\n let iterator: any;\n if (propertyIterable) {\n iterator = zipBatchIterators(shapeIterable, propertyIterable);\n } else {\n iterator = shapeIterable;\n }\n\n for await (const item of iterator) {\n let geometries: any;\n let properties: any;\n if (!propertyIterable) {\n geometries = item;\n } else {\n [geometries, properties] = item;\n }\n\n const geojsonGeometries = parseGeometries(geometries);\n let features = joinProperties(geojsonGeometries, properties);\n if (reproject) {\n // @ts-ignore\n features = reprojectFeatures(features, prj, _targetCrs);\n }\n yield {\n encoding: cpg,\n prj,\n shx,\n header: shapeHeader,\n data: features\n };\n }\n}\n\n/**\n * Parse shapefile\n *\n * @param arrayBuffer\n * @param options\n * @param context\n * @returns output of shapefile\n */\nexport async function parseShapefile(\n arrayBuffer: ArrayBuffer,\n options?: ShapefileLoaderOptions,\n context?: LoaderContext\n): Promise<ShapefileOutput> {\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);\n\n // parse geometries\n // @ts-ignore context must be defined\n const {header, geometries} = await context.parse(arrayBuffer, SHPLoader, options); // {shp: shx}\n\n const geojsonGeometries = parseGeometries(geometries);\n\n // parse properties\n let properties = [];\n\n // @ts-ignore context must be defined\n const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));\n if (dbfResponse.ok) {\n // @ts-ignore context must be defined\n properties = await context.parse(dbfResponse, DBFLoader, {dbf: {encoding: cpg || 'latin1'}});\n }\n\n let features = joinProperties(geojsonGeometries, properties);\n if (reproject) {\n features = reprojectFeatures(features, prj, _targetCrs);\n }\n\n return {\n encoding: cpg,\n prj,\n shx,\n header,\n data: features\n };\n}\n\n/**\n * Parse geometries\n *\n * @param geometries\n * @returns geometries as an array\n */\nfunction parseGeometries(geometries: any[]): any[] {\n const geojsonGeometries: any[] = [];\n for (const geom of geometries) {\n geojsonGeometries.push(binaryToGeometry(geom));\n }\n return geojsonGeometries;\n}\n\n/**\n * Join properties and geometries into features\n *\n * @param geometries [description]\n * @param properties [description]\n * @return [description]\n */\nfunction joinProperties(geometries: object[], properties: object[]): Feature[] {\n const features: Feature[] = [];\n for (let i = 0; i < geometries.length; i++) {\n const geometry = geometries[i];\n const feature: Feature = {\n type: 'Feature',\n geometry,\n // properties can be undefined if dbfResponse above was empty\n properties: (properties && properties[i]) || {}\n };\n features.push(feature);\n }\n\n return features;\n}\n\n/**\n * Reproject GeoJSON features to output CRS\n *\n * @param features parsed GeoJSON features\n * @param sourceCrs source coordinate reference system\n * @param targetCrs †arget coordinate reference system\n * @return Reprojected Features\n */\nfunction reprojectFeatures(features: Feature[], sourceCrs?: string, targetCrs?: string): Feature[] {\n if (!sourceCrs && !targetCrs) {\n return features;\n }\n\n const projection = new Proj4Projection({from: sourceCrs || 'WGS84', to: targetCrs || 'WGS84'});\n return transformGeoJsonCoords(features, (coord) => projection.project(coord));\n}\n\n/**\n *\n * @param options\n * @param context\n * @returns Promise\n */\n// eslint-disable-next-line max-statements\nexport async function loadShapefileSidecarFiles(\n options?: object,\n context?: LoaderContext\n): Promise<{\n shx?: SHXOutput;\n cpg?: string;\n prj?: string;\n}> {\n // Attempt a parallel load of the small sidecar files\n // @ts-ignore context must be defined\n const {url, fetch} = context;\n const shxPromise = fetch(replaceExtension(url, 'shx'));\n const cpgPromise = fetch(replaceExtension(url, 'cpg'));\n const prjPromise = fetch(replaceExtension(url, 'prj'));\n await Promise.all([shxPromise, cpgPromise, prjPromise]);\n\n let shx: SHXOutput | undefined;\n let cpg: string | undefined;\n let prj: string | undefined;\n\n const shxResponse = await shxPromise;\n if (shxResponse.ok) {\n const arrayBuffer = await shxResponse.arrayBuffer();\n shx = parseShx(arrayBuffer);\n }\n\n const cpgResponse = await cpgPromise;\n if (cpgResponse.ok) {\n cpg = await cpgResponse.text();\n }\n\n const prjResponse = await prjPromise;\n if (prjResponse.ok) {\n prj = await prjResponse.text();\n }\n\n return {\n shx,\n cpg,\n prj\n };\n}\n\n/**\n * Replace the extension at the end of a path.\n *\n * Matches the case of new extension with the case of the original file extension,\n * to increase the chance of finding files without firing off a request storm looking for various case combinations\n *\n * NOTE: Extensions can be both lower and uppercase\n * per spec, extensions should be lower case, but that doesn't mean they always are. See:\n * calvinmetcalf/shapefile-js#64, mapserver/mapserver#4712\n * https://trac.osgeo.org/mapserver/ticket/166\n */\nexport function replaceExtension(url: string, newExtension: string): string {\n const baseName = basename(url);\n const extension = extname(url);\n const isUpperCase = extension === extension.toUpperCase();\n if (isUpperCase) {\n newExtension = newExtension.toUpperCase();\n }\n return `${baseName}.${newExtension}`;\n}\n\n// NOTE - this gives the entire path minus extension (i.e. NOT same as path.basename)\n/**\n * @param url\n * @returns string\n */\nfunction basename(url: string): string {\n const extIndex = url && url.lastIndexOf('.');\n if (typeof extIndex === 'number') {\n return extIndex >= 0 ? url.substr(0, extIndex) : '';\n }\n return extIndex;\n}\n/**\n * @param url\n * @returns string\n */\nfunction extname(url: string): string {\n const extIndex = url && url.lastIndexOf('.');\n if (typeof extIndex === 'number') {\n return extIndex >= 0 ? url.substr(extIndex + 1) : '';\n }\n return extIndex;\n}\n"],"mappings":";;;;;;;;;AAMA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAcO,gBAAgBM,uBAAuBA,CAC5CC,aAAiE,EACjEC,OAAgC,EAChCC,OAAuB,EACS;EAChC,MAAM;IAACC,SAAS,GAAG,KAAK;IAAEC,UAAU,GAAG;EAAO,CAAC,GAAG,CAAAH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEI,GAAG,KAAI,CAAC,CAAC;EACpE,MAAM;IAACC,GAAG;IAAEC,GAAG;IAAEC;EAAG,CAAC,GAAG,MAAMC,yBAAyB,CAACR,OAAO,EAAEC,OAAO,CAAC;EAIzE,MAAMQ,aAAkB,GAAG,MAAMR,OAAO,CAACS,cAAc,CAACX,aAAa,EAAEY,oBAAS,EAAEX,OAAO,CAAC;EAG1F,IAAIY,gBAAqB;EAEzB,MAAMC,WAAW,GAAG,MAAMZ,OAAO,CAACa,KAAK,CAACC,gB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