@loaders.gl/shapefile 4.0.0-alpha.21 → 4.0.0-alpha.23
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 +9 -4
- package/dist/dist.min.js +36 -13
- package/dist/es5/dbf-loader.js +1 -1
- package/dist/es5/lib/parsers/parse-shapefile.js +15 -14
- package/dist/es5/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/es5/shapefile-loader.js +2 -4
- package/dist/es5/shapefile-loader.js.map +1 -1
- package/dist/es5/shp-loader.js +1 -1
- package/dist/esm/dbf-loader.js +1 -1
- package/dist/esm/lib/parsers/parse-shapefile.js +11 -10
- package/dist/esm/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/esm/shapefile-loader.js +1 -2
- package/dist/esm/shapefile-loader.js.map +1 -1
- package/dist/esm/shp-loader.js +1 -1
- package/dist/lib/parsers/parse-shapefile.d.ts +1 -1
- package/dist/lib/parsers/parse-shapefile.d.ts.map +1 -1
- package/dist/lib/parsers/parse-shapefile.js +11 -15
- package/dist/shapefile-loader.d.ts +2 -21
- package/dist/shapefile-loader.d.ts.map +1 -1
- package/dist/shapefile-loader.js +1 -2
- package/dist/shp-worker.js +9 -4
- package/package.json +5 -5
- package/src/lib/parsers/parse-shapefile.ts +30 -21
- package/src/shapefile-loader.ts +2 -4
package/dist/dbf-worker.js
CHANGED
|
@@ -326,7 +326,7 @@
|
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
// src/dbf-loader.ts
|
|
329
|
-
var VERSION = true ? "4.0.0-alpha.
|
|
329
|
+
var VERSION = true ? "4.0.0-alpha.23" : "latest";
|
|
330
330
|
var DBFWorkerLoader = {
|
|
331
331
|
name: "DBF",
|
|
332
332
|
id: "dbf",
|
|
@@ -475,7 +475,7 @@
|
|
|
475
475
|
options,
|
|
476
476
|
context: {
|
|
477
477
|
...context,
|
|
478
|
-
|
|
478
|
+
_parse: parseOnMainThread
|
|
479
479
|
}
|
|
480
480
|
});
|
|
481
481
|
WorkerBody.postMessage("done", { result });
|
|
@@ -488,7 +488,7 @@
|
|
|
488
488
|
}
|
|
489
489
|
};
|
|
490
490
|
}
|
|
491
|
-
function parseOnMainThread(arrayBuffer, options) {
|
|
491
|
+
function parseOnMainThread(arrayBuffer, loader, options, context) {
|
|
492
492
|
return new Promise((resolve, reject) => {
|
|
493
493
|
const id = requestId++;
|
|
494
494
|
const onMessage = (type, payload2) => {
|
|
@@ -512,7 +512,12 @@
|
|
|
512
512
|
WorkerBody.postMessage("process", payload);
|
|
513
513
|
});
|
|
514
514
|
}
|
|
515
|
-
async function parseData({
|
|
515
|
+
async function parseData({
|
|
516
|
+
loader,
|
|
517
|
+
arrayBuffer,
|
|
518
|
+
options,
|
|
519
|
+
context
|
|
520
|
+
}) {
|
|
516
521
|
let data;
|
|
517
522
|
let parser;
|
|
518
523
|
if (loader.parseSync || loader.parse) {
|
package/dist/dist.min.js
CHANGED
|
@@ -498,6 +498,21 @@
|
|
|
498
498
|
}
|
|
499
499
|
});
|
|
500
500
|
|
|
501
|
+
// ../loader-utils/src/loader-types.ts
|
|
502
|
+
async function parseFromContext(data, loaders, options, context) {
|
|
503
|
+
return context._parse(data, loaders, options, context);
|
|
504
|
+
}
|
|
505
|
+
async function parseInBatchesFromContext(data, loader, options, context) {
|
|
506
|
+
if (!context._parseInBatches) {
|
|
507
|
+
throw new Error("parseInBatches");
|
|
508
|
+
}
|
|
509
|
+
return context._parseInBatches(data, loader, options, context);
|
|
510
|
+
}
|
|
511
|
+
var init_loader_types = __esm({
|
|
512
|
+
"../loader-utils/src/loader-types.ts"() {
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
|
|
501
516
|
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
502
517
|
function _typeof(obj) {
|
|
503
518
|
"@babel/helpers - typeof";
|
|
@@ -564,6 +579,13 @@
|
|
|
564
579
|
}
|
|
565
580
|
});
|
|
566
581
|
|
|
582
|
+
// ../loader-utils/src/index.ts
|
|
583
|
+
var init_src = __esm({
|
|
584
|
+
"../loader-utils/src/index.ts"() {
|
|
585
|
+
init_loader_types();
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
|
|
567
589
|
// ../gis/src/lib/binary-to-geojson.ts
|
|
568
590
|
function binaryToGeometry(data, startIndex, endIndex) {
|
|
569
591
|
switch (data.type) {
|
|
@@ -660,7 +682,7 @@
|
|
|
660
682
|
});
|
|
661
683
|
}
|
|
662
684
|
function isCoord(array) {
|
|
663
|
-
return Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
685
|
+
return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
664
686
|
}
|
|
665
687
|
var init_transform = __esm({
|
|
666
688
|
"../gis/src/lib/transform.ts"() {
|
|
@@ -668,7 +690,7 @@
|
|
|
668
690
|
});
|
|
669
691
|
|
|
670
692
|
// ../gis/src/index.ts
|
|
671
|
-
var
|
|
693
|
+
var init_src2 = __esm({
|
|
672
694
|
"../gis/src/index.ts"() {
|
|
673
695
|
init_binary_to_geojson();
|
|
674
696
|
init_transform();
|
|
@@ -6982,14 +7004,14 @@
|
|
|
6982
7004
|
async function* parseShapefileInBatches(asyncIterator, options, context) {
|
|
6983
7005
|
const { reproject = false, _targetCrs = "WGS84" } = options?.gis || {};
|
|
6984
7006
|
const { shx, cpg, prj } = await loadShapefileSidecarFiles(options, context);
|
|
6985
|
-
const shapeIterable = await
|
|
7007
|
+
const shapeIterable = await parseInBatchesFromContext(asyncIterator, SHPLoader, options, context);
|
|
6986
7008
|
let propertyIterable;
|
|
6987
|
-
const dbfResponse = await context
|
|
6988
|
-
if (dbfResponse
|
|
6989
|
-
propertyIterable = await
|
|
7009
|
+
const dbfResponse = await context?.fetch(replaceExtension(context?.url || "", "dbf"));
|
|
7010
|
+
if (dbfResponse?.ok) {
|
|
7011
|
+
propertyIterable = await parseInBatchesFromContext(dbfResponse, DBFLoader, {
|
|
6990
7012
|
...options,
|
|
6991
7013
|
dbf: { encoding: cpg || "latin1" }
|
|
6992
|
-
});
|
|
7014
|
+
}, context);
|
|
6993
7015
|
}
|
|
6994
7016
|
let shapeHeader = (await shapeIterable.next()).value;
|
|
6995
7017
|
if (shapeHeader && shapeHeader.batchType === "metadata") {
|
|
@@ -7033,12 +7055,12 @@
|
|
|
7033
7055
|
async function parseShapefile(arrayBuffer, options, context) {
|
|
7034
7056
|
const { reproject = false, _targetCrs = "WGS84" } = options?.gis || {};
|
|
7035
7057
|
const { shx, cpg, prj } = await loadShapefileSidecarFiles(options, context);
|
|
7036
|
-
const { header, geometries } = await
|
|
7058
|
+
const { header, geometries } = await parseFromContext(arrayBuffer, SHPLoader, options, context);
|
|
7037
7059
|
const geojsonGeometries = parseGeometries(geometries);
|
|
7038
7060
|
let properties = [];
|
|
7039
|
-
const dbfResponse = await context
|
|
7040
|
-
if (dbfResponse
|
|
7041
|
-
properties = await
|
|
7061
|
+
const dbfResponse = await context?.fetch(replaceExtension(context?.url, "dbf"));
|
|
7062
|
+
if (dbfResponse?.ok) {
|
|
7063
|
+
properties = await parseFromContext(dbfResponse, DBFLoader, { dbf: { encoding: cpg || "latin1" } }, context);
|
|
7042
7064
|
}
|
|
7043
7065
|
let features = joinProperties(geojsonGeometries, properties);
|
|
7044
7066
|
if (reproject) {
|
|
@@ -7133,6 +7155,7 @@
|
|
|
7133
7155
|
var init_parse_shapefile = __esm({
|
|
7134
7156
|
"src/lib/parsers/parse-shapefile.ts"() {
|
|
7135
7157
|
init_src();
|
|
7158
|
+
init_src2();
|
|
7136
7159
|
init_esm();
|
|
7137
7160
|
init_parse_shx();
|
|
7138
7161
|
init_zip_batch_iterators();
|
|
@@ -7178,7 +7201,7 @@
|
|
|
7178
7201
|
SHPWorkerLoader: () => SHPWorkerLoader,
|
|
7179
7202
|
ShapefileLoader: () => ShapefileLoader
|
|
7180
7203
|
});
|
|
7181
|
-
var
|
|
7204
|
+
var init_src3 = __esm({
|
|
7182
7205
|
"src/index.ts"() {
|
|
7183
7206
|
init_shapefile_loader();
|
|
7184
7207
|
init_dbf_loader();
|
|
@@ -7189,7 +7212,7 @@
|
|
|
7189
7212
|
// src/bundle.ts
|
|
7190
7213
|
var require_bundle = __commonJS({
|
|
7191
7214
|
"src/bundle.ts"(exports4, module) {
|
|
7192
|
-
var moduleExports = (
|
|
7215
|
+
var moduleExports = (init_src3(), src_exports);
|
|
7193
7216
|
globalThis.loaders = globalThis.loaders || {};
|
|
7194
7217
|
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
7195
7218
|
}
|
package/dist/es5/dbf-loader.js
CHANGED
|
@@ -11,7 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
11
11
|
var _parseDbf = require("./lib/parsers/parse-dbf");
|
|
12
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
14
|
+
var VERSION = typeof "4.0.0-alpha.23" !== 'undefined' ? "4.0.0-alpha.23" : 'latest';
|
|
15
15
|
var DBFWorkerLoader = {
|
|
16
16
|
name: 'DBF',
|
|
17
17
|
id: 'dbf',
|
|
@@ -14,6 +14,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
14
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
15
|
var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
|
|
16
16
|
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
17
|
+
var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
17
18
|
var _gis = require("@loaders.gl/gis");
|
|
18
19
|
var _proj = require("@math.gl/proj4");
|
|
19
20
|
var _parseShx = require("./parse-shx");
|
|
@@ -45,23 +46,23 @@ function _parseShapefileInBatches() {
|
|
|
45
46
|
cpg = _yield$_awaitAsyncGen.cpg;
|
|
46
47
|
prj = _yield$_awaitAsyncGen.prj;
|
|
47
48
|
_context.next = 9;
|
|
48
|
-
return (0, _awaitAsyncGenerator2.default)(
|
|
49
|
+
return (0, _awaitAsyncGenerator2.default)((0, _loaderUtils.parseInBatchesFromContext)(asyncIterator, _shpLoader.SHPLoader, options, context));
|
|
49
50
|
case 9:
|
|
50
51
|
shapeIterable = _context.sent;
|
|
51
52
|
_context.next = 12;
|
|
52
|
-
return (0, _awaitAsyncGenerator2.default)(context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf')));
|
|
53
|
+
return (0, _awaitAsyncGenerator2.default)(context === null || context === void 0 ? void 0 : context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf')));
|
|
53
54
|
case 12:
|
|
54
55
|
dbfResponse = _context.sent;
|
|
55
|
-
if (!dbfResponse.ok) {
|
|
56
|
+
if (!(dbfResponse !== null && dbfResponse !== void 0 && dbfResponse.ok)) {
|
|
56
57
|
_context.next = 17;
|
|
57
58
|
break;
|
|
58
59
|
}
|
|
59
60
|
_context.next = 16;
|
|
60
|
-
return (0, _awaitAsyncGenerator2.default)(
|
|
61
|
+
return (0, _awaitAsyncGenerator2.default)((0, _loaderUtils.parseInBatchesFromContext)(dbfResponse, _dbfLoader.DBFLoader, _objectSpread(_objectSpread({}, options), {}, {
|
|
61
62
|
dbf: {
|
|
62
63
|
encoding: cpg || 'latin1'
|
|
63
64
|
}
|
|
64
|
-
})));
|
|
65
|
+
}), context));
|
|
65
66
|
case 16:
|
|
66
67
|
propertyIterable = _context.sent;
|
|
67
68
|
case 17:
|
|
@@ -181,7 +182,7 @@ function parseShapefile(_x4, _x5, _x6) {
|
|
|
181
182
|
}
|
|
182
183
|
function _parseShapefile() {
|
|
183
184
|
_parseShapefile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(arrayBuffer, options, context) {
|
|
184
|
-
var _ref2, _ref2$reproject, reproject, _ref2$_targetCrs, _targetCrs, _yield$loadShapefileS, shx, cpg, prj, _yield$
|
|
185
|
+
var _ref2, _ref2$reproject, reproject, _ref2$_targetCrs, _targetCrs, _yield$loadShapefileS, shx, cpg, prj, _yield$parseFromConte, header, geometries, geojsonGeometries, properties, dbfResponse, features;
|
|
185
186
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
186
187
|
while (1) switch (_context2.prev = _context2.next) {
|
|
187
188
|
case 0:
|
|
@@ -194,27 +195,27 @@ function _parseShapefile() {
|
|
|
194
195
|
cpg = _yield$loadShapefileS.cpg;
|
|
195
196
|
prj = _yield$loadShapefileS.prj;
|
|
196
197
|
_context2.next = 9;
|
|
197
|
-
return
|
|
198
|
+
return (0, _loaderUtils.parseFromContext)(arrayBuffer, _shpLoader.SHPLoader, options, context);
|
|
198
199
|
case 9:
|
|
199
|
-
_yield$
|
|
200
|
-
header = _yield$
|
|
201
|
-
geometries = _yield$
|
|
200
|
+
_yield$parseFromConte = _context2.sent;
|
|
201
|
+
header = _yield$parseFromConte.header;
|
|
202
|
+
geometries = _yield$parseFromConte.geometries;
|
|
202
203
|
geojsonGeometries = parseGeometries(geometries);
|
|
203
204
|
properties = [];
|
|
204
205
|
_context2.next = 16;
|
|
205
|
-
return context.fetch(replaceExtension(context.url, 'dbf'));
|
|
206
|
+
return context === null || context === void 0 ? void 0 : context.fetch(replaceExtension(context === null || context === void 0 ? void 0 : context.url, 'dbf'));
|
|
206
207
|
case 16:
|
|
207
208
|
dbfResponse = _context2.sent;
|
|
208
|
-
if (!dbfResponse.ok) {
|
|
209
|
+
if (!(dbfResponse !== null && dbfResponse !== void 0 && dbfResponse.ok)) {
|
|
209
210
|
_context2.next = 21;
|
|
210
211
|
break;
|
|
211
212
|
}
|
|
212
213
|
_context2.next = 20;
|
|
213
|
-
return
|
|
214
|
+
return (0, _loaderUtils.parseFromContext)(dbfResponse, _dbfLoader.DBFLoader, {
|
|
214
215
|
dbf: {
|
|
215
216
|
encoding: cpg || 'latin1'
|
|
216
217
|
}
|
|
217
|
-
});
|
|
218
|
+
}, context);
|
|
218
219
|
case 20:
|
|
219
220
|
properties = _context2.sent;
|
|
220
221
|
case 21:
|
|
@@ -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,IAAAD,CAAA,WAAAA,CAAA,CAAAQ,MAAA,qBAAAN,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAO,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAT,CAAA,CAAAQ,MAAA,WAAAK,IAAA,mBAAAA,IAAA,SAAAC,KAAA,EAAAd,CAAA,CAAAS,CAAA,UAAAM,CAAA,WAAAA,EAAAC,EAAA,UAAAA,EAAA,KAAAC,CAAA,EAAAP,CAAA,gBAAAQ,SAAA,iJAAAC,gBAAA,SAAAC,MAAA,UAAAC,GAAA,WAAAV,CAAA,WAAAA,EAAA,IAAAT,EAAA,GAAAA,EAAA,CAAAoB,IAAA,CAAAtB,CAAA,MAAAY,CAAA,WAAAA,EAAA,QAAA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A;MAAA;IAAA,GAAAoC,QAAA;EAAA,CACF;EAAA,OAAAD,0BAAA,CAAAjI,KAAA,OAAAG,SAAA;AAAA;AAaM,SAAS2E,gBAAgBA,CAACC,GAAW,EAAE+D,YAAoB,EAAU;EAC1E,IAAMC,QAAQ,GAAGC,QAAQ,CAACjE,GAAG,CAAC;EAC9B,IAAMkE,SAAS,GAAGC,OAAO,CAACnE,GAAG,CAAC;EAC9B,IAAMoE,WAAW,GAAGF,SAAS,KAAKA,SAAS,CAACG,WAAW,CAAC,CAAC;EACzD,IAAID,WAAW,EAAE;IACfL,YAAY,GAAGA,YAAY,CAACM,WAAW,CAAC,CAAC;EAC3C;EACA,UAAAC,MAAA,CAAUN,QAAQ,OAAAM,MAAA,CAAIP,YAAY;AACpC;AAOA,SAASE,QAAQA,CAACjE,GAAW,EAAU;EACrC,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,CAAC,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":["_loaderUtils","require","_gis","_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","parseInBatchesFromContext","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$parseFromConte","_callee2$","_context2","parseFromContext","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 {LoaderContext, parseInBatchesFromContext, parseFromContext} from '@loaders.gl/loader-utils';\nimport {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';\nimport {Proj4Projection} from '@math.gl/proj4';\n\nimport type {SHXOutput} from './parse-shx';\nimport type {SHPHeader} from './parse-shp-header';\nimport type {ShapefileLoaderOptions} from './types';\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 const shapeIterable: any = await parseInBatchesFromContext(\n asyncIterator,\n SHPLoader,\n options,\n context!\n );\n\n // parse properties\n let propertyIterable: any;\n const dbfResponse = await context?.fetch(replaceExtension(context?.url || '', 'dbf'));\n if (dbfResponse?.ok) {\n propertyIterable = await parseInBatchesFromContext(\n dbfResponse as any,\n DBFLoader,\n {\n ...options,\n dbf: {encoding: cpg || 'latin1'}\n },\n context!\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 const {header, geometries} = await parseFromContext(arrayBuffer, SHPLoader, options, context!); // {shp: shx}\n\n const geojsonGeometries = parseGeometries(geometries);\n\n // parse properties\n let properties = [];\n\n const dbfResponse = await context?.fetch(replaceExtension(context?.url!, 'dbf'));\n if (dbfResponse?.ok) {\n properties = await parseFromContext(\n dbfResponse as any,\n DBFLoader,\n {dbf: {encoding: cpg || 'latin1'}},\n context!\n );\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":";;;;;;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAKA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AAA2C,SAAAO,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,G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,EAAU;EACrC,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,CAAC,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"}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.ShapefileLoader = void 0;
|
|
7
7
|
var _shpLoader = require("./shp-loader");
|
|
8
8
|
var _parseShapefile = require("./lib/parsers/parse-shapefile");
|
|
9
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
9
|
+
var VERSION = typeof "4.0.0-alpha.23" !== 'undefined' ? "4.0.0-alpha.23" : 'latest';
|
|
10
10
|
var ShapefileLoader = {
|
|
11
11
|
name: 'Shapefile',
|
|
12
12
|
id: 'shapefile',
|
|
@@ -26,6 +26,4 @@ var ShapefileLoader = {
|
|
|
26
26
|
parseInBatches: _parseShapefile.parseShapefileInBatches
|
|
27
27
|
};
|
|
28
28
|
exports.ShapefileLoader = ShapefileLoader;
|
|
29
|
-
var _typecheckShapefileLoader = ShapefileLoader;
|
|
30
|
-
exports._typecheckShapefileLoader = _typecheckShapefileLoader;
|
|
31
29
|
//# sourceMappingURL=shapefile-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapefile-loader.js","names":["_shpLoader","require","_parseShapefile","VERSION","ShapefileLoader","name","id","module","version","category","extensions","mimeTypes","tests","Uint8Array","SHP_MAGIC_NUMBER","buffer","options","shapefile","shp","_maxDimensions","parse","parseShapefile","parseInBatches","parseShapefileInBatches","exports"
|
|
1
|
+
{"version":3,"file":"shapefile-loader.js","names":["_shpLoader","require","_parseShapefile","VERSION","ShapefileLoader","name","id","module","version","category","extensions","mimeTypes","tests","Uint8Array","SHP_MAGIC_NUMBER","buffer","options","shapefile","shp","_maxDimensions","parse","parseShapefile","parseInBatches","parseShapefileInBatches","exports"],"sources":["../../src/shapefile-loader.ts"],"sourcesContent":["import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {SHP_MAGIC_NUMBER} from './shp-loader';\nimport {parseShapefile, parseShapefileInBatches} from './lib/parsers/parse-shapefile';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Shapefile loader\n * @note Shapefile is multifile format and requires providing additional files\n */\nexport const ShapefileLoader: LoaderWithParser<any, any, LoaderOptions> = {\n name: 'Shapefile',\n id: 'shapefile',\n module: 'shapefile',\n version: VERSION,\n category: 'geometry',\n extensions: ['shp'],\n mimeTypes: ['application/octet-stream'],\n tests: [new Uint8Array(SHP_MAGIC_NUMBER).buffer],\n options: {\n shapefile: {},\n shp: {\n _maxDimensions: 4\n }\n },\n parse: parseShapefile,\n parseInBatches: parseShapefileInBatches\n};\n"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAIA,IAAME,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAMpE,IAAMC,eAA0D,GAAG;EACxEC,IAAI,EAAE,WAAW;EACjBC,EAAE,EAAE,WAAW;EACfC,MAAM,EAAE,WAAW;EACnBC,OAAO,EAAEL,OAAO;EAChBM,QAAQ,EAAE,UAAU;EACpBC,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,0BAA0B,CAAC;EACvCC,KAAK,EAAE,CAAC,IAAIC,UAAU,CAACC,2BAAgB,CAAC,CAACC,MAAM,CAAC;EAChDC,OAAO,EAAE;IACPC,SAAS,EAAE,CAAC,CAAC;IACbC,GAAG,EAAE;MACHC,cAAc,EAAE;IAClB;EACF,CAAC;EACDC,KAAK,EAAEC,8BAAc;EACrBC,cAAc,EAAEC;AAClB,CAAC;AAACC,OAAA,CAAApB,eAAA,GAAAA,eAAA"}
|
package/dist/es5/shp-loader.js
CHANGED
|
@@ -11,7 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
11
11
|
var _parseShp = require("./lib/parsers/parse-shp");
|
|
12
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
14
|
+
var VERSION = typeof "4.0.0-alpha.23" !== 'undefined' ? "4.0.0-alpha.23" : 'latest';
|
|
15
15
|
var SHP_MAGIC_NUMBER = [0x00, 0x00, 0x27, 0x0a];
|
|
16
16
|
exports.SHP_MAGIC_NUMBER = SHP_MAGIC_NUMBER;
|
|
17
17
|
var SHPWorkerLoader = {
|
package/dist/esm/dbf-loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseDBF, parseDBFInBatches } from './lib/parsers/parse-dbf';
|
|
2
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
2
|
+
const VERSION = typeof "4.0.0-alpha.23" !== 'undefined' ? "4.0.0-alpha.23" : 'latest';
|
|
3
3
|
export const DBFWorkerLoader = {
|
|
4
4
|
name: 'DBF',
|
|
5
5
|
id: 'dbf',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseInBatchesFromContext, parseFromContext } from '@loaders.gl/loader-utils';
|
|
1
2
|
import { binaryToGeometry, transformGeoJsonCoords } from '@loaders.gl/gis';
|
|
2
3
|
import { Proj4Projection } from '@math.gl/proj4';
|
|
3
4
|
import { parseShx } from './parse-shx';
|
|
@@ -14,16 +15,16 @@ export async function* parseShapefileInBatches(asyncIterator, options, context)
|
|
|
14
15
|
cpg,
|
|
15
16
|
prj
|
|
16
17
|
} = await loadShapefileSidecarFiles(options, context);
|
|
17
|
-
const shapeIterable = await
|
|
18
|
+
const shapeIterable = await parseInBatchesFromContext(asyncIterator, SHPLoader, options, context);
|
|
18
19
|
let propertyIterable;
|
|
19
|
-
const dbfResponse = await context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf'));
|
|
20
|
-
if (dbfResponse.ok) {
|
|
21
|
-
propertyIterable = await
|
|
20
|
+
const dbfResponse = await (context === null || context === void 0 ? void 0 : context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf')));
|
|
21
|
+
if (dbfResponse !== null && dbfResponse !== void 0 && dbfResponse.ok) {
|
|
22
|
+
propertyIterable = await parseInBatchesFromContext(dbfResponse, DBFLoader, {
|
|
22
23
|
...options,
|
|
23
24
|
dbf: {
|
|
24
25
|
encoding: cpg || 'latin1'
|
|
25
26
|
}
|
|
26
|
-
});
|
|
27
|
+
}, context);
|
|
27
28
|
}
|
|
28
29
|
let shapeHeader = (await shapeIterable.next()).value;
|
|
29
30
|
if (shapeHeader && shapeHeader.batchType === 'metadata') {
|
|
@@ -77,16 +78,16 @@ export async function parseShapefile(arrayBuffer, options, context) {
|
|
|
77
78
|
const {
|
|
78
79
|
header,
|
|
79
80
|
geometries
|
|
80
|
-
} = await
|
|
81
|
+
} = await parseFromContext(arrayBuffer, SHPLoader, options, context);
|
|
81
82
|
const geojsonGeometries = parseGeometries(geometries);
|
|
82
83
|
let properties = [];
|
|
83
|
-
const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));
|
|
84
|
-
if (dbfResponse.ok) {
|
|
85
|
-
properties = await
|
|
84
|
+
const dbfResponse = await (context === null || context === void 0 ? void 0 : context.fetch(replaceExtension(context === null || context === void 0 ? void 0 : context.url, 'dbf')));
|
|
85
|
+
if (dbfResponse !== null && dbfResponse !== void 0 && dbfResponse.ok) {
|
|
86
|
+
properties = await parseFromContext(dbfResponse, DBFLoader, {
|
|
86
87
|
dbf: {
|
|
87
88
|
encoding: cpg || 'latin1'
|
|
88
89
|
}
|
|
89
|
-
});
|
|
90
|
+
}, context);
|
|
90
91
|
}
|
|
91
92
|
let features = joinProperties(geojsonGeometries, properties);
|
|
92
93
|
if (reproject) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shapefile.js","names":["binaryToGeometry","transformGeoJsonCoords","Proj4Projection","parseShx","zipBatchIterators","SHPLoader","DBFLoader","parseShapefileInBatches","asyncIterator","options","context","reproject","_targetCrs","gis","shx","cpg","prj","loadShapefileSidecarFiles","shapeIterable","parseInBatches","propertyIterable","dbfResponse","fetch","replaceExtension","url","ok","dbf","encoding","shapeHeader","next","value","batchType","dbfHeader","iterator","item","geometries","properties","geojsonGeometries","parseGeometries","features","joinProperties","reprojectFeatures","header","data","parseShapefile","arrayBuffer","parse","geom","push","i","length","geometry","feature","type","sourceCrs","targetCrs","projection","from","to","coord","project","shxPromise","cpgPromise","prjPromise","Promise","all","shxResponse","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,SAAQA,gBAAgB,EAAEC,sBAAsB,QAAO,iBAAiB;AACxE,SAAQC,eAAe,QAAO,gBAAgB;AAC9C,SAAQC,QAAQ,QAAO,aAAa;AACpC,SAAQC,iBAAiB,QAAO,kCAAkC;AAClE,SAAQC,SAAS,QAAO,kBAAkB;AAC1C,SAAQC,SAAS,QAAO,kBAAkB;AAc1C,OAAO,gBAAgBC,uBAAuBA,CAC5CC,a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uD,WAAW,CAAC,GAAG,CAAC;EAC5C,IAAI,OAAOD,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAOA,QAAQ,IAAI,CAAC,GAAGtD,GAAG,CAACwD,MAAM,CAACF,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE;EACtD;EACA,OAAOA,QAAQ;AACjB"}
|
|
1
|
+
{"version":3,"file":"parse-shapefile.js","names":["parseInBatchesFromContext","parseFromContext","binaryToGeometry","transformGeoJsonCoords","Proj4Projection","parseShx","zipBatchIterators","SHPLoader","DBFLoader","parseShapefileInBatches","asyncIterator","options","context","reproject","_targetCrs","gis","shx","cpg","prj","loadShapefileSidecarFiles","shapeIterable","propertyIterable","dbfResponse","fetch","replaceExtension","url","ok","dbf","encoding","shapeHeader","next","value","batchType","dbfHeader","iterator","item","geometries","properties","geojsonGeometries","parseGeometries","features","joinProperties","reprojectFeatures","header","data","parseShapefile","arrayBuffer","geom","push","i","length","geometry","feature","type","sourceCrs","targetCrs","projection","from","to","coord","project","shxPromise","cpgPromise","prjPromise","Promise","all","shxResponse","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 {LoaderContext, parseInBatchesFromContext, parseFromContext} from '@loaders.gl/loader-utils';\nimport {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';\nimport {Proj4Projection} from '@math.gl/proj4';\n\nimport type {SHXOutput} from './parse-shx';\nimport type {SHPHeader} from './parse-shp-header';\nimport type {ShapefileLoaderOptions} from './types';\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 const shapeIterable: any = await parseInBatchesFromContext(\n asyncIterator,\n SHPLoader,\n options,\n context!\n );\n\n // parse properties\n let propertyIterable: any;\n const dbfResponse = await context?.fetch(replaceExtension(context?.url || '', 'dbf'));\n if (dbfResponse?.ok) {\n propertyIterable = await parseInBatchesFromContext(\n dbfResponse as any,\n DBFLoader,\n {\n ...options,\n dbf: {encoding: cpg || 'latin1'}\n },\n context!\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 const {header, geometries} = await parseFromContext(arrayBuffer, SHPLoader, options, context!); // {shp: shx}\n\n const geojsonGeometries = parseGeometries(geometries);\n\n // parse properties\n let properties = [];\n\n const dbfResponse = await context?.fetch(replaceExtension(context?.url!, 'dbf'));\n if (dbfResponse?.ok) {\n properties = await parseFromContext(\n dbfResponse as any,\n DBFLoader,\n {dbf: {encoding: cpg || 'latin1'}},\n context!\n );\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":"AACA,SAAuBA,yBAAyB,EAAEC,gBAAgB,QAAO,0BAA0B;AACnG,SAAQC,gBAAgB,EAAEC,sBAAsB,QAAO,iBAAiB;AACxE,SAAQC,eAAe,QAAO,gBAAgB;AAK9C,SAAQC,QAAQ,QAAO,aAAa;AACpC,SAAQC,iBAAiB,QAAO,kCAAkC;AAClE,SAAQC,SAAS,QAAO,kBAAkB;AAC1C,SAAQC,SAAS,QAAO,kBAAkB;AAc1C,OAAO,gBAAgBC,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;EAGzE,MAAMQ,aAAkB,GAAG,MAAMpB,yBAAyB,CACxDU,aAAa,EACbH,SAAS,EACTI,OAAO,EACPC,OACF,CAAC;EAGD,IAAIS,gBAAqB;EACzB,MAAMC,WAAW,GAAG,OAAMV,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEW,KAAK,CAACC,gBAAgB,CAAC,CAAAZ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEa,GAAG,KAAI,EAAE,EAAE,KAAK,CAAC,CAAC;EACrF,I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A,CAACC,GAAW,EAAE6C,YAAoB,EAAU;EAC1E,MAAMC,QAAQ,GAAGC,QAAQ,CAAC/C,GAAG,CAAC;EAC9B,MAAMgD,SAAS,GAAGC,OAAO,CAACjD,GAAG,CAAC;EAC9B,MAAMkD,WAAW,GAAGF,SAAS,KAAKA,SAAS,CAACG,WAAW,CAAC,CAAC;EACzD,IAAID,WAAW,EAAE;IACfL,YAAY,GAAGA,YAAY,CAACM,WAAW,CAAC,CAAC;EAC3C;EACA,UAAAC,MAAA,CAAUN,QAAQ,OAAAM,MAAA,CAAIP,YAAY;AACpC;AAOA,SAASE,QAAQA,CAAC/C,GAAW,EAAU;EACrC,MAAMqD,QAAQ,GAAGrD,GAAG,IAAIA,GAAG,CAACsD,WAAW,CAAC,GAAG,CAAC;EAC5C,IAAI,OAAOD,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAOA,QAAQ,IAAI,CAAC,GAAGrD,GAAG,CAACuD,MAAM,CAAC,CAAC,EAAEF,QAAQ,CAAC,GAAG,EAAE;EACrD;EACA,OAAOA,QAAQ;AACjB;AAKA,SAASJ,OAAOA,CAACjD,GAAW,EAAU;EACpC,MAAMqD,QAAQ,GAAGrD,GAAG,IAAIA,GAAG,CAACsD,WAAW,CAAC,GAAG,CAAC;EAC5C,IAAI,OAAOD,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAOA,QAAQ,IAAI,CAAC,GAAGrD,GAAG,CAACuD,MAAM,CAACF,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE;EACtD;EACA,OAAOA,QAAQ;AACjB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SHP_MAGIC_NUMBER } from './shp-loader';
|
|
2
2
|
import { parseShapefile, parseShapefileInBatches } from './lib/parsers/parse-shapefile';
|
|
3
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
3
|
+
const VERSION = typeof "4.0.0-alpha.23" !== 'undefined' ? "4.0.0-alpha.23" : 'latest';
|
|
4
4
|
export const ShapefileLoader = {
|
|
5
5
|
name: 'Shapefile',
|
|
6
6
|
id: 'shapefile',
|
|
@@ -19,5 +19,4 @@ export const ShapefileLoader = {
|
|
|
19
19
|
parse: parseShapefile,
|
|
20
20
|
parseInBatches: parseShapefileInBatches
|
|
21
21
|
};
|
|
22
|
-
export const _typecheckShapefileLoader = ShapefileLoader;
|
|
23
22
|
//# sourceMappingURL=shapefile-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapefile-loader.js","names":["SHP_MAGIC_NUMBER","parseShapefile","parseShapefileInBatches","VERSION","ShapefileLoader","name","id","module","version","category","extensions","mimeTypes","tests","Uint8Array","buffer","options","shapefile","shp","_maxDimensions","parse","parseInBatches"
|
|
1
|
+
{"version":3,"file":"shapefile-loader.js","names":["SHP_MAGIC_NUMBER","parseShapefile","parseShapefileInBatches","VERSION","ShapefileLoader","name","id","module","version","category","extensions","mimeTypes","tests","Uint8Array","buffer","options","shapefile","shp","_maxDimensions","parse","parseInBatches"],"sources":["../../src/shapefile-loader.ts"],"sourcesContent":["import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {SHP_MAGIC_NUMBER} from './shp-loader';\nimport {parseShapefile, parseShapefileInBatches} from './lib/parsers/parse-shapefile';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Shapefile loader\n * @note Shapefile is multifile format and requires providing additional files\n */\nexport const ShapefileLoader: LoaderWithParser<any, any, LoaderOptions> = {\n name: 'Shapefile',\n id: 'shapefile',\n module: 'shapefile',\n version: VERSION,\n category: 'geometry',\n extensions: ['shp'],\n mimeTypes: ['application/octet-stream'],\n tests: [new Uint8Array(SHP_MAGIC_NUMBER).buffer],\n options: {\n shapefile: {},\n shp: {\n _maxDimensions: 4\n }\n },\n parse: parseShapefile,\n parseInBatches: parseShapefileInBatches\n};\n"],"mappings":"AACA,SAAQA,gBAAgB,QAAO,cAAc;AAC7C,SAAQC,cAAc,EAAEC,uBAAuB,QAAO,+BAA+B;AAIrF,MAAMC,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAM3E,OAAO,MAAMC,eAA0D,GAAG;EACxEC,IAAI,EAAE,WAAW;EACjBC,EAAE,EAAE,WAAW;EACfC,MAAM,EAAE,WAAW;EACnBC,OAAO,EAAEL,OAAO;EAChBM,QAAQ,EAAE,UAAU;EACpBC,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,0BAA0B,CAAC;EACvCC,KAAK,EAAE,CAAC,IAAIC,UAAU,CAACb,gBAAgB,CAAC,CAACc,MAAM,CAAC;EAChDC,OAAO,EAAE;IACPC,SAAS,EAAE,CAAC,CAAC;IACbC,GAAG,EAAE;MACHC,cAAc,EAAE;IAClB;EACF,CAAC;EACDC,KAAK,EAAElB,cAAc;EACrBmB,cAAc,EAAElB;AAClB,CAAC"}
|
package/dist/esm/shp-loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseSHP, parseSHPInBatches } from './lib/parsers/parse-shp';
|
|
2
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
2
|
+
const VERSION = typeof "4.0.0-alpha.23" !== 'undefined' ? "4.0.0-alpha.23" : 'latest';
|
|
3
3
|
export const SHP_MAGIC_NUMBER = [0x00, 0x00, 0x27, 0x0a];
|
|
4
4
|
export const SHPWorkerLoader = {
|
|
5
5
|
name: 'SHP',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { LoaderContext } from '@loaders.gl/loader-utils';
|
|
1
2
|
import type { SHXOutput } from './parse-shx';
|
|
2
3
|
import type { SHPHeader } from './parse-shp-header';
|
|
3
|
-
import type { LoaderContext } from '@loaders.gl/loader-utils';
|
|
4
4
|
import type { ShapefileLoaderOptions } from './types';
|
|
5
5
|
interface ShapefileOutput {
|
|
6
6
|
encoding?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shapefile.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-shapefile.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"parse-shapefile.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-shapefile.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAA8C,MAAM,0BAA0B,CAAC;AAIpG,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAC,sBAAsB,EAAC,MAAM,SAAS,CAAC;AAOpD,UAAU,eAAe;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AACD;;GAEG;AAEH,wBAAuB,uBAAuB,CAC5C,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,OAAO,CAAC,EAAE,sBAAsB,EAChC,OAAO,CAAC,EAAE,aAAa,GACtB,aAAa,CAAC,eAAe,CAAC,CA0EhC;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,sBAAsB,EAChC,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,eAAe,CAAC,CAkC1B;AAwDD;;;;;GAKG;AAEH,wBAAsB,yBAAyB,CAC7C,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC;IACT,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC,CAkCD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAQ1E"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.replaceExtension = exports.loadShapefileSidecarFiles = exports.parseShapefile = exports.parseShapefileInBatches = void 0;
|
|
4
|
+
// import type {Feature} from '@loaders.gl/gis';
|
|
5
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
4
6
|
const gis_1 = require("@loaders.gl/gis");
|
|
5
7
|
const proj4_1 = require("@math.gl/proj4");
|
|
6
8
|
const parse_shx_1 = require("./parse-shx");
|
|
@@ -15,18 +17,15 @@ async function* parseShapefileInBatches(asyncIterator, options, context) {
|
|
|
15
17
|
const { reproject = false, _targetCrs = 'WGS84' } = options?.gis || {};
|
|
16
18
|
const { shx, cpg, prj } = await loadShapefileSidecarFiles(options, context);
|
|
17
19
|
// parse geometries
|
|
18
|
-
|
|
19
|
-
const shapeIterable = await context.parseInBatches(asyncIterator, shp_loader_1.SHPLoader, options);
|
|
20
|
+
const shapeIterable = await (0, loader_utils_1.parseInBatchesFromContext)(asyncIterator, shp_loader_1.SHPLoader, options, context);
|
|
20
21
|
// parse properties
|
|
21
22
|
let propertyIterable;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// @ts-ignore context must be defined
|
|
26
|
-
propertyIterable = await context.parseInBatches(dbfResponse, dbf_loader_1.DBFLoader, {
|
|
23
|
+
const dbfResponse = await context?.fetch(replaceExtension(context?.url || '', 'dbf'));
|
|
24
|
+
if (dbfResponse?.ok) {
|
|
25
|
+
propertyIterable = await (0, loader_utils_1.parseInBatchesFromContext)(dbfResponse, dbf_loader_1.DBFLoader, {
|
|
27
26
|
...options,
|
|
28
27
|
dbf: { encoding: cpg || 'latin1' }
|
|
29
|
-
});
|
|
28
|
+
}, context);
|
|
30
29
|
}
|
|
31
30
|
// When `options.metadata` is `true`, there's an extra initial `metadata`
|
|
32
31
|
// object before the iterator starts. zipBatchIterators expects to receive
|
|
@@ -87,16 +86,13 @@ async function parseShapefile(arrayBuffer, options, context) {
|
|
|
87
86
|
const { reproject = false, _targetCrs = 'WGS84' } = options?.gis || {};
|
|
88
87
|
const { shx, cpg, prj } = await loadShapefileSidecarFiles(options, context);
|
|
89
88
|
// parse geometries
|
|
90
|
-
|
|
91
|
-
const { header, geometries } = await context.parse(arrayBuffer, shp_loader_1.SHPLoader, options); // {shp: shx}
|
|
89
|
+
const { header, geometries } = await (0, loader_utils_1.parseFromContext)(arrayBuffer, shp_loader_1.SHPLoader, options, context); // {shp: shx}
|
|
92
90
|
const geojsonGeometries = parseGeometries(geometries);
|
|
93
91
|
// parse properties
|
|
94
92
|
let properties = [];
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// @ts-ignore context must be defined
|
|
99
|
-
properties = await context.parse(dbfResponse, dbf_loader_1.DBFLoader, { dbf: { encoding: cpg || 'latin1' } });
|
|
93
|
+
const dbfResponse = await context?.fetch(replaceExtension(context?.url, 'dbf'));
|
|
94
|
+
if (dbfResponse?.ok) {
|
|
95
|
+
properties = await (0, loader_utils_1.parseFromContext)(dbfResponse, dbf_loader_1.DBFLoader, { dbf: { encoding: cpg || 'latin1' } }, context);
|
|
100
96
|
}
|
|
101
97
|
let features = joinProperties(geojsonGeometries, properties);
|
|
102
98
|
if (reproject) {
|
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
import type { LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
-
import { parseShapefile, parseShapefileInBatches } from './lib/parsers/parse-shapefile';
|
|
1
|
+
import type { LoaderOptions, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
3
2
|
/**
|
|
4
3
|
* Shapefile loader
|
|
5
4
|
* @note Shapefile is multifile format and requires providing additional files
|
|
6
5
|
*/
|
|
7
|
-
export declare const ShapefileLoader:
|
|
8
|
-
name: string;
|
|
9
|
-
id: string;
|
|
10
|
-
module: string;
|
|
11
|
-
version: any;
|
|
12
|
-
category: string;
|
|
13
|
-
extensions: string[];
|
|
14
|
-
mimeTypes: string[];
|
|
15
|
-
tests: ArrayBufferLike[];
|
|
16
|
-
options: {
|
|
17
|
-
shapefile: {};
|
|
18
|
-
shp: {
|
|
19
|
-
_maxDimensions: number;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
parse: typeof parseShapefile;
|
|
23
|
-
parseInBatches: typeof parseShapefileInBatches;
|
|
24
|
-
};
|
|
25
|
-
export declare const _typecheckShapefileLoader: LoaderWithParser;
|
|
6
|
+
export declare const ShapefileLoader: LoaderWithParser<any, any, LoaderOptions>;
|
|
26
7
|
//# sourceMappingURL=shapefile-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapefile-loader.d.ts","sourceRoot":"","sources":["../src/shapefile-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"shapefile-loader.d.ts","sourceRoot":"","sources":["../src/shapefile-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAQ9E;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,aAAa,CAiBrE,CAAC"}
|
package/dist/shapefile-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ShapefileLoader = void 0;
|
|
4
4
|
const shp_loader_1 = require("./shp-loader");
|
|
5
5
|
const parse_shapefile_1 = require("./lib/parsers/parse-shapefile");
|
|
6
6
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
@@ -28,4 +28,3 @@ exports.ShapefileLoader = {
|
|
|
28
28
|
parse: parse_shapefile_1.parseShapefile,
|
|
29
29
|
parseInBatches: parse_shapefile_1.parseShapefileInBatches
|
|
30
30
|
};
|
|
31
|
-
exports._typecheckShapefileLoader = exports.ShapefileLoader;
|
package/dist/shp-worker.js
CHANGED
|
@@ -430,7 +430,7 @@
|
|
|
430
430
|
}
|
|
431
431
|
|
|
432
432
|
// src/shp-loader.ts
|
|
433
|
-
var VERSION = true ? "4.0.0-alpha.
|
|
433
|
+
var VERSION = true ? "4.0.0-alpha.23" : "latest";
|
|
434
434
|
var SHP_MAGIC_NUMBER2 = [0, 0, 39, 10];
|
|
435
435
|
var SHPWorkerLoader = {
|
|
436
436
|
name: "SHP",
|
|
@@ -581,7 +581,7 @@
|
|
|
581
581
|
options,
|
|
582
582
|
context: {
|
|
583
583
|
...context,
|
|
584
|
-
|
|
584
|
+
_parse: parseOnMainThread
|
|
585
585
|
}
|
|
586
586
|
});
|
|
587
587
|
WorkerBody.postMessage("done", { result });
|
|
@@ -594,7 +594,7 @@
|
|
|
594
594
|
}
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
|
-
function parseOnMainThread(arrayBuffer, options) {
|
|
597
|
+
function parseOnMainThread(arrayBuffer, loader, options, context) {
|
|
598
598
|
return new Promise((resolve, reject) => {
|
|
599
599
|
const id = requestId++;
|
|
600
600
|
const onMessage = (type, payload2) => {
|
|
@@ -618,7 +618,12 @@
|
|
|
618
618
|
WorkerBody.postMessage("process", payload);
|
|
619
619
|
});
|
|
620
620
|
}
|
|
621
|
-
async function parseData({
|
|
621
|
+
async function parseData({
|
|
622
|
+
loader,
|
|
623
|
+
arrayBuffer,
|
|
624
|
+
options,
|
|
625
|
+
context
|
|
626
|
+
}) {
|
|
622
627
|
let data;
|
|
623
628
|
let parser;
|
|
624
629
|
if (loader.parseSync || loader.parse) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/shapefile",
|
|
3
3
|
"description": "Loader for the Shapefile Format",
|
|
4
|
-
"version": "4.0.0-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.23",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"build-worker-dbf": "esbuild src/workers/dbf-worker.ts --bundle --outfile=dist/dbf-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@loaders.gl/gis": "4.0.0-alpha.
|
|
41
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
42
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
40
|
+
"@loaders.gl/gis": "4.0.0-alpha.23",
|
|
41
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.23",
|
|
42
|
+
"@loaders.gl/schema": "4.0.0-alpha.23",
|
|
43
43
|
"@math.gl/proj4": "^3.5.1"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e212f2a0c0e342f7cb65ce84fa2ff39f64b7d94b"
|
|
46
46
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// import type {Feature} from '@loaders.gl/gis';
|
|
2
|
+
import {LoaderContext, parseInBatchesFromContext, parseFromContext} from '@loaders.gl/loader-utils';
|
|
3
|
+
import {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';
|
|
4
|
+
import {Proj4Projection} from '@math.gl/proj4';
|
|
5
|
+
|
|
2
6
|
import type {SHXOutput} from './parse-shx';
|
|
3
7
|
import type {SHPHeader} from './parse-shp-header';
|
|
4
|
-
import type {LoaderContext} from '@loaders.gl/loader-utils';
|
|
5
8
|
import type {ShapefileLoaderOptions} from './types';
|
|
6
|
-
|
|
7
|
-
import {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';
|
|
8
|
-
import {Proj4Projection} from '@math.gl/proj4';
|
|
9
9
|
import {parseShx} from './parse-shx';
|
|
10
10
|
import {zipBatchIterators} from '../streaming/zip-batch-iterators';
|
|
11
11
|
import {SHPLoader} from '../../shp-loader';
|
|
@@ -32,19 +32,26 @@ export async function* parseShapefileInBatches(
|
|
|
32
32
|
const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);
|
|
33
33
|
|
|
34
34
|
// parse geometries
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const shapeIterable: any = await parseInBatchesFromContext(
|
|
36
|
+
asyncIterator,
|
|
37
|
+
SHPLoader,
|
|
38
|
+
options,
|
|
39
|
+
context!
|
|
40
|
+
);
|
|
37
41
|
|
|
38
42
|
// parse properties
|
|
39
43
|
let propertyIterable: any;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const dbfResponse = await context?.fetch(replaceExtension(context?.url || '', 'dbf'));
|
|
45
|
+
if (dbfResponse?.ok) {
|
|
46
|
+
propertyIterable = await parseInBatchesFromContext(
|
|
47
|
+
dbfResponse as any,
|
|
48
|
+
DBFLoader,
|
|
49
|
+
{
|
|
50
|
+
...options,
|
|
51
|
+
dbf: {encoding: cpg || 'latin1'}
|
|
52
|
+
},
|
|
53
|
+
context!
|
|
54
|
+
);
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
// When `options.metadata` is `true`, there's an extra initial `metadata`
|
|
@@ -113,19 +120,21 @@ export async function parseShapefile(
|
|
|
113
120
|
const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);
|
|
114
121
|
|
|
115
122
|
// parse geometries
|
|
116
|
-
|
|
117
|
-
const {header, geometries} = await context.parse(arrayBuffer, SHPLoader, options); // {shp: shx}
|
|
123
|
+
const {header, geometries} = await parseFromContext(arrayBuffer, SHPLoader, options, context!); // {shp: shx}
|
|
118
124
|
|
|
119
125
|
const geojsonGeometries = parseGeometries(geometries);
|
|
120
126
|
|
|
121
127
|
// parse properties
|
|
122
128
|
let properties = [];
|
|
123
129
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
const dbfResponse = await context?.fetch(replaceExtension(context?.url!, 'dbf'));
|
|
131
|
+
if (dbfResponse?.ok) {
|
|
132
|
+
properties = await parseFromContext(
|
|
133
|
+
dbfResponse as any,
|
|
134
|
+
DBFLoader,
|
|
135
|
+
{dbf: {encoding: cpg || 'latin1'}},
|
|
136
|
+
context!
|
|
137
|
+
);
|
|
129
138
|
}
|
|
130
139
|
|
|
131
140
|
let features = joinProperties(geojsonGeometries, properties);
|
package/src/shapefile-loader.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
1
|
+
import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {SHP_MAGIC_NUMBER} from './shp-loader';
|
|
3
3
|
import {parseShapefile, parseShapefileInBatches} from './lib/parsers/parse-shapefile';
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
|
10
10
|
* Shapefile loader
|
|
11
11
|
* @note Shapefile is multifile format and requires providing additional files
|
|
12
12
|
*/
|
|
13
|
-
export const ShapefileLoader = {
|
|
13
|
+
export const ShapefileLoader: LoaderWithParser<any, any, LoaderOptions> = {
|
|
14
14
|
name: 'Shapefile',
|
|
15
15
|
id: 'shapefile',
|
|
16
16
|
module: 'shapefile',
|
|
@@ -28,5 +28,3 @@ export const ShapefileLoader = {
|
|
|
28
28
|
parse: parseShapefile,
|
|
29
29
|
parseInBatches: parseShapefileInBatches
|
|
30
30
|
};
|
|
31
|
-
|
|
32
|
-
export const _typecheckShapefileLoader: LoaderWithParser = ShapefileLoader;
|