@loaders.gl/shapefile 4.0.0-alpha.5 → 4.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +2 -2
- package/dist/dbf-loader.js +29 -20
- package/dist/dbf-worker.js +73 -447
- package/dist/dist.min.js +130 -489
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/dbf-loader.js +53 -0
- package/dist/es5/dbf-loader.js.map +1 -0
- package/dist/es5/index.js +39 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/parsers/parse-dbf.js +394 -0
- package/dist/es5/lib/parsers/parse-dbf.js.map +1 -0
- package/dist/es5/lib/parsers/parse-shapefile.js +373 -0
- package/dist/es5/lib/parsers/parse-shapefile.js.map +1 -0
- package/dist/es5/lib/parsers/parse-shp-geometry.js +220 -0
- package/dist/es5/lib/parsers/parse-shp-geometry.js.map +1 -0
- package/dist/es5/lib/parsers/parse-shp-header.js +35 -0
- package/dist/es5/lib/parsers/parse-shp-header.js.map +1 -0
- package/dist/es5/lib/parsers/parse-shp.js +227 -0
- package/dist/es5/lib/parsers/parse-shp.js.map +1 -0
- package/dist/es5/lib/parsers/parse-shx.js +26 -0
- package/dist/es5/lib/parsers/parse-shx.js.map +1 -0
- package/dist/es5/lib/parsers/types.js +2 -0
- package/dist/es5/lib/parsers/types.js.map +1 -0
- package/dist/es5/lib/streaming/binary-chunk-reader.js +178 -0
- package/dist/es5/lib/streaming/binary-chunk-reader.js.map +1 -0
- package/dist/es5/lib/streaming/binary-reader.js +48 -0
- package/dist/es5/lib/streaming/binary-reader.js.map +1 -0
- package/dist/es5/lib/streaming/zip-batch-iterators.js +91 -0
- package/dist/es5/lib/streaming/zip-batch-iterators.js.map +1 -0
- package/dist/es5/shapefile-loader.js +31 -0
- package/dist/es5/shapefile-loader.js.map +1 -0
- package/dist/es5/shp-loader.js +56 -0
- package/dist/es5/shp-loader.js.map +1 -0
- package/dist/es5/workers/dbf-worker.js +6 -0
- package/dist/es5/workers/dbf-worker.js.map +1 -0
- package/dist/es5/workers/shp-worker.js +6 -0
- package/dist/es5/workers/shp-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/dbf-loader.js +24 -0
- package/dist/esm/dbf-loader.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/parsers/parse-dbf.js +296 -0
- package/dist/esm/lib/parsers/parse-dbf.js.map +1 -0
- package/dist/esm/lib/parsers/parse-shapefile.js +187 -0
- package/dist/esm/lib/parsers/parse-shapefile.js.map +1 -0
- package/dist/esm/lib/parsers/parse-shp-geometry.js +191 -0
- package/dist/esm/lib/parsers/parse-shp-geometry.js.map +1 -0
- package/dist/esm/lib/parsers/parse-shp-header.js +29 -0
- package/dist/esm/lib/parsers/parse-shp-header.js.map +1 -0
- package/dist/esm/lib/parsers/parse-shp.js +134 -0
- package/dist/esm/lib/parsers/parse-shp.js.map +1 -0
- package/dist/esm/lib/parsers/parse-shx.js +20 -0
- package/dist/esm/lib/parsers/parse-shx.js.map +1 -0
- package/dist/esm/lib/parsers/types.js +2 -0
- package/dist/esm/lib/parsers/types.js.map +1 -0
- package/dist/esm/lib/streaming/binary-chunk-reader.js +106 -0
- package/dist/esm/lib/streaming/binary-chunk-reader.js.map +1 -0
- package/dist/esm/lib/streaming/binary-reader.js +27 -0
- package/dist/esm/lib/streaming/binary-reader.js.map +1 -0
- package/dist/esm/lib/streaming/zip-batch-iterators.js +44 -0
- package/dist/esm/lib/streaming/zip-batch-iterators.js.map +1 -0
- package/dist/esm/shapefile-loader.js +23 -0
- package/dist/esm/shapefile-loader.js.map +1 -0
- package/dist/esm/shp-loader.js +26 -0
- package/dist/esm/shp-loader.js.map +1 -0
- package/dist/esm/workers/dbf-worker.js +4 -0
- package/dist/esm/workers/dbf-worker.js.map +1 -0
- package/dist/esm/workers/shp-worker.js +4 -0
- package/dist/esm/workers/shp-worker.js.map +1 -0
- package/dist/index.js +11 -4
- package/dist/lib/parsers/parse-dbf.d.ts +4 -18
- package/dist/lib/parsers/parse-dbf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-dbf.js +309 -264
- package/dist/lib/parsers/parse-shapefile.d.ts +3 -8
- package/dist/lib/parsers/parse-shapefile.d.ts.map +1 -1
- package/dist/lib/parsers/parse-shapefile.js +227 -209
- package/dist/lib/parsers/parse-shp-geometry.d.ts +2 -3
- package/dist/lib/parsers/parse-shp-geometry.d.ts.map +1 -1
- package/dist/lib/parsers/parse-shp-geometry.js +265 -212
- package/dist/lib/parsers/parse-shp-header.js +38 -27
- package/dist/lib/parsers/parse-shp.d.ts +3 -2
- package/dist/lib/parsers/parse-shp.d.ts.map +1 -1
- package/dist/lib/parsers/parse-shp.js +160 -136
- package/dist/lib/parsers/parse-shx.js +25 -19
- package/dist/lib/parsers/types.d.ts +68 -0
- package/dist/lib/parsers/types.d.ts.map +1 -0
- package/dist/lib/parsers/types.js +2 -0
- package/dist/lib/streaming/binary-chunk-reader.d.ts +5 -3
- package/dist/lib/streaming/binary-chunk-reader.d.ts.map +1 -1
- package/dist/lib/streaming/binary-chunk-reader.js +152 -128
- package/dist/lib/streaming/binary-reader.js +50 -33
- package/dist/lib/streaming/zip-batch-iterators.js +57 -48
- package/dist/shapefile-loader.js +30 -22
- package/dist/shp-loader.js +32 -22
- package/dist/shp-worker.js +57 -19
- package/dist/workers/dbf-worker.js +5 -4
- package/dist/workers/shp-worker.js +5 -4
- package/package.json +7 -7
- package/src/lib/parsers/parse-dbf.ts +41 -67
- package/src/lib/parsers/parse-shapefile.ts +3 -6
- package/src/lib/parsers/parse-shp-geometry.ts +3 -2
- package/src/lib/parsers/parse-shp.ts +26 -12
- package/src/lib/parsers/types.ts +79 -0
- package/src/lib/streaming/binary-chunk-reader.ts +5 -1
- package/src/lib/streaming/zip-batch-iterators.ts +2 -2
- package/dist/bundle.js.map +0 -1
- package/dist/dbf-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/parsers/parse-dbf.js.map +0 -1
- package/dist/lib/parsers/parse-shapefile.js.map +0 -1
- package/dist/lib/parsers/parse-shp-geometry.js.map +0 -1
- package/dist/lib/parsers/parse-shp-header.js.map +0 -1
- package/dist/lib/parsers/parse-shp.js.map +0 -1
- package/dist/lib/parsers/parse-shx.js.map +0 -1
- package/dist/lib/streaming/binary-chunk-reader.js.map +0 -1
- package/dist/lib/streaming/binary-reader.js.map +0 -1
- package/dist/lib/streaming/zip-batch-iterators.js.map +0 -1
- package/dist/shapefile-loader.js.map +0 -1
- package/dist/shp-loader.js.map +0 -1
- package/dist/workers/dbf-worker.js.map +0 -1
- package/dist/workers/shp-worker.js.map +0 -1
|
@@ -1,226 +1,244 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceExtension = exports.loadShapefileSidecarFiles = exports.parseShapefile = exports.parseShapefileInBatches = void 0;
|
|
4
|
+
const gis_1 = require("@loaders.gl/gis");
|
|
5
|
+
const proj4_1 = require("@math.gl/proj4");
|
|
6
|
+
const parse_shx_1 = require("./parse-shx");
|
|
7
|
+
const zip_batch_iterators_1 = require("../streaming/zip-batch-iterators");
|
|
8
|
+
const shp_loader_1 = require("../../shp-loader");
|
|
9
|
+
const dbf_loader_1 = require("../../dbf-loader");
|
|
10
|
+
/**
|
|
11
|
+
* Parsing of file in batches
|
|
12
|
+
*/
|
|
13
|
+
// eslint-disable-next-line max-statements, complexity
|
|
14
|
+
async function* parseShapefileInBatches(asyncIterator, options, context) {
|
|
15
|
+
const { reproject = false, _targetCrs = 'WGS84' } = options?.gis || {};
|
|
16
|
+
const { shx, cpg, prj } = await loadShapefileSidecarFiles(options, context);
|
|
17
|
+
// parse geometries
|
|
18
|
+
// @ts-ignore context must be defined
|
|
19
|
+
const shapeIterable = await context.parseInBatches(asyncIterator, shp_loader_1.SHPLoader, options);
|
|
20
|
+
// parse properties
|
|
21
|
+
let propertyIterable;
|
|
22
|
+
// @ts-ignore context must be defined
|
|
23
|
+
const dbfResponse = await context.fetch(replaceExtension(context?.url || '', 'dbf'));
|
|
24
|
+
if (dbfResponse.ok) {
|
|
25
|
+
// @ts-ignore context must be defined
|
|
26
|
+
propertyIterable = await context.parseInBatches(dbfResponse, dbf_loader_1.DBFLoader, {
|
|
27
|
+
...options,
|
|
28
|
+
dbf: { encoding: cpg || 'latin1' }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// When `options.metadata` is `true`, there's an extra initial `metadata`
|
|
32
|
+
// object before the iterator starts. zipBatchIterators expects to receive
|
|
33
|
+
// batches of Array objects, and will fail with non-iterable batches, so it's
|
|
34
|
+
// important to skip over the first batch.
|
|
35
|
+
let shapeHeader = (await shapeIterable.next()).value;
|
|
36
|
+
if (shapeHeader && shapeHeader.batchType === 'metadata') {
|
|
37
|
+
shapeHeader = (await shapeIterable.next()).value;
|
|
38
|
+
}
|
|
39
|
+
let dbfHeader = {};
|
|
40
|
+
if (propertyIterable) {
|
|
41
|
+
dbfHeader = (await propertyIterable.next()).value;
|
|
42
|
+
if (dbfHeader && dbfHeader.batchType === 'metadata') {
|
|
43
|
+
dbfHeader = (await propertyIterable.next()).value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
let iterator;
|
|
47
|
+
if (propertyIterable) {
|
|
48
|
+
iterator = (0, zip_batch_iterators_1.zipBatchIterators)(shapeIterable, propertyIterable);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
iterator = shapeIterable;
|
|
52
|
+
}
|
|
53
|
+
for await (const item of iterator) {
|
|
54
|
+
let geometries;
|
|
55
|
+
let properties;
|
|
56
|
+
if (!propertyIterable) {
|
|
57
|
+
geometries = item;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
[geometries, properties] = item;
|
|
61
|
+
}
|
|
62
|
+
const geojsonGeometries = parseGeometries(geometries);
|
|
63
|
+
let features = joinProperties(geojsonGeometries, properties);
|
|
64
|
+
if (reproject) {
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
features = reprojectFeatures(features, prj, _targetCrs);
|
|
67
|
+
}
|
|
68
|
+
yield {
|
|
69
|
+
encoding: cpg,
|
|
70
|
+
prj,
|
|
71
|
+
shx,
|
|
72
|
+
header: shapeHeader,
|
|
73
|
+
data: features
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.parseShapefileInBatches = parseShapefileInBatches;
|
|
78
|
+
/**
|
|
79
|
+
* Parse shapefile
|
|
80
|
+
*
|
|
81
|
+
* @param arrayBuffer
|
|
82
|
+
* @param options
|
|
83
|
+
* @param context
|
|
84
|
+
* @returns output of shapefile
|
|
85
|
+
*/
|
|
86
|
+
async function parseShapefile(arrayBuffer, options, context) {
|
|
87
|
+
const { reproject = false, _targetCrs = 'WGS84' } = options?.gis || {};
|
|
88
|
+
const { shx, cpg, prj } = await loadShapefileSidecarFiles(options, context);
|
|
89
|
+
// parse geometries
|
|
90
|
+
// @ts-ignore context must be defined
|
|
91
|
+
const { header, geometries } = await context.parse(arrayBuffer, shp_loader_1.SHPLoader, options); // {shp: shx}
|
|
63
92
|
const geojsonGeometries = parseGeometries(geometries);
|
|
93
|
+
// parse properties
|
|
94
|
+
let properties = [];
|
|
95
|
+
// @ts-ignore context must be defined
|
|
96
|
+
const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));
|
|
97
|
+
if (dbfResponse.ok) {
|
|
98
|
+
// @ts-ignore context must be defined
|
|
99
|
+
properties = await context.parse(dbfResponse, dbf_loader_1.DBFLoader, { dbf: { encoding: cpg || 'latin1' } });
|
|
100
|
+
}
|
|
64
101
|
let features = joinProperties(geojsonGeometries, properties);
|
|
65
|
-
|
|
66
102
|
if (reproject) {
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
data: features
|
|
103
|
+
features = reprojectFeatures(features, prj, _targetCrs);
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
encoding: cpg,
|
|
107
|
+
prj,
|
|
108
|
+
shx,
|
|
109
|
+
header,
|
|
110
|
+
data: features
|
|
76
111
|
};
|
|
77
|
-
}
|
|
78
112
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
cpg,
|
|
87
|
-
prj
|
|
88
|
-
} = await loadShapefileSidecarFiles(options, context);
|
|
89
|
-
const {
|
|
90
|
-
header,
|
|
91
|
-
geometries
|
|
92
|
-
} = await context.parse(arrayBuffer, SHPLoader, options);
|
|
93
|
-
const geojsonGeometries = parseGeometries(geometries);
|
|
94
|
-
let properties = [];
|
|
95
|
-
const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));
|
|
96
|
-
|
|
97
|
-
if (dbfResponse.ok) {
|
|
98
|
-
properties = await context.parse(dbfResponse, DBFLoader, {
|
|
99
|
-
dbf: {
|
|
100
|
-
encoding: cpg || 'latin1'
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let features = joinProperties(geojsonGeometries, properties);
|
|
106
|
-
|
|
107
|
-
if (reproject) {
|
|
108
|
-
features = reprojectFeatures(features, prj, _targetCrs);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
encoding: cpg,
|
|
113
|
-
prj,
|
|
114
|
-
shx,
|
|
115
|
-
header,
|
|
116
|
-
data: features
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
113
|
+
exports.parseShapefile = parseShapefile;
|
|
114
|
+
/**
|
|
115
|
+
* Parse geometries
|
|
116
|
+
*
|
|
117
|
+
* @param geometries
|
|
118
|
+
* @returns geometries as an array
|
|
119
|
+
*/
|
|
120
120
|
function parseGeometries(geometries) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return geojsonGeometries;
|
|
121
|
+
const geojsonGeometries = [];
|
|
122
|
+
for (const geom of geometries) {
|
|
123
|
+
geojsonGeometries.push((0, gis_1.binaryToGeometry)(geom));
|
|
124
|
+
}
|
|
125
|
+
return geojsonGeometries;
|
|
128
126
|
}
|
|
129
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Join properties and geometries into features
|
|
129
|
+
*
|
|
130
|
+
* @param geometries [description]
|
|
131
|
+
* @param properties [description]
|
|
132
|
+
* @return [description]
|
|
133
|
+
*/
|
|
130
134
|
function joinProperties(geometries, properties) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return features;
|
|
135
|
+
const features = [];
|
|
136
|
+
for (let i = 0; i < geometries.length; i++) {
|
|
137
|
+
const geometry = geometries[i];
|
|
138
|
+
const feature = {
|
|
139
|
+
type: 'Feature',
|
|
140
|
+
geometry,
|
|
141
|
+
// properties can be undefined if dbfResponse above was empty
|
|
142
|
+
properties: (properties && properties[i]) || {}
|
|
143
|
+
};
|
|
144
|
+
features.push(feature);
|
|
145
|
+
}
|
|
146
|
+
return features;
|
|
144
147
|
}
|
|
145
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Reproject GeoJSON features to output CRS
|
|
150
|
+
*
|
|
151
|
+
* @param features parsed GeoJSON features
|
|
152
|
+
* @param sourceCrs source coordinate reference system
|
|
153
|
+
* @param targetCrs †arget coordinate reference system
|
|
154
|
+
* @return Reprojected Features
|
|
155
|
+
*/
|
|
146
156
|
function reprojectFeatures(features, sourceCrs, targetCrs) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
from: sourceCrs || 'WGS84',
|
|
153
|
-
to: targetCrs || 'WGS84'
|
|
154
|
-
});
|
|
155
|
-
return transformGeoJsonCoords(features, coord => projection.project(coord));
|
|
157
|
+
if (!sourceCrs && !targetCrs) {
|
|
158
|
+
return features;
|
|
159
|
+
}
|
|
160
|
+
const projection = new proj4_1.Proj4Projection({ from: sourceCrs || 'WGS84', to: targetCrs || 'WGS84' });
|
|
161
|
+
return (0, gis_1.transformGeoJsonCoords)(features, (coord) => projection.project(coord));
|
|
156
162
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
};
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* @param options
|
|
166
|
+
* @param context
|
|
167
|
+
* @returns Promise
|
|
168
|
+
*/
|
|
169
|
+
// eslint-disable-next-line max-statements
|
|
170
|
+
async function loadShapefileSidecarFiles(options, context) {
|
|
171
|
+
// Attempt a parallel load of the small sidecar files
|
|
172
|
+
// @ts-ignore context must be defined
|
|
173
|
+
const { url, fetch } = context;
|
|
174
|
+
const shxPromise = fetch(replaceExtension(url, 'shx'));
|
|
175
|
+
const cpgPromise = fetch(replaceExtension(url, 'cpg'));
|
|
176
|
+
const prjPromise = fetch(replaceExtension(url, 'prj'));
|
|
177
|
+
await Promise.all([shxPromise, cpgPromise, prjPromise]);
|
|
178
|
+
let shx;
|
|
179
|
+
let cpg;
|
|
180
|
+
let prj;
|
|
181
|
+
const shxResponse = await shxPromise;
|
|
182
|
+
if (shxResponse.ok) {
|
|
183
|
+
const arrayBuffer = await shxResponse.arrayBuffer();
|
|
184
|
+
shx = (0, parse_shx_1.parseShx)(arrayBuffer);
|
|
185
|
+
}
|
|
186
|
+
const cpgResponse = await cpgPromise;
|
|
187
|
+
if (cpgResponse.ok) {
|
|
188
|
+
cpg = await cpgResponse.text();
|
|
189
|
+
}
|
|
190
|
+
const prjResponse = await prjPromise;
|
|
191
|
+
if (prjResponse.ok) {
|
|
192
|
+
prj = await prjResponse.text();
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
shx,
|
|
196
|
+
cpg,
|
|
197
|
+
prj
|
|
198
|
+
};
|
|
194
199
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
exports.loadShapefileSidecarFiles = loadShapefileSidecarFiles;
|
|
201
|
+
/**
|
|
202
|
+
* Replace the extension at the end of a path.
|
|
203
|
+
*
|
|
204
|
+
* Matches the case of new extension with the case of the original file extension,
|
|
205
|
+
* to increase the chance of finding files without firing off a request storm looking for various case combinations
|
|
206
|
+
*
|
|
207
|
+
* NOTE: Extensions can be both lower and uppercase
|
|
208
|
+
* per spec, extensions should be lower case, but that doesn't mean they always are. See:
|
|
209
|
+
* calvinmetcalf/shapefile-js#64, mapserver/mapserver#4712
|
|
210
|
+
* https://trac.osgeo.org/mapserver/ticket/166
|
|
211
|
+
*/
|
|
212
|
+
function replaceExtension(url, newExtension) {
|
|
213
|
+
const baseName = basename(url);
|
|
214
|
+
const extension = extname(url);
|
|
215
|
+
const isUpperCase = extension === extension.toUpperCase();
|
|
216
|
+
if (isUpperCase) {
|
|
217
|
+
newExtension = newExtension.toUpperCase();
|
|
218
|
+
}
|
|
219
|
+
return `${baseName}.${newExtension}`;
|
|
205
220
|
}
|
|
206
|
-
|
|
221
|
+
exports.replaceExtension = replaceExtension;
|
|
222
|
+
// NOTE - this gives the entire path minus extension (i.e. NOT same as path.basename)
|
|
223
|
+
/**
|
|
224
|
+
* @param url
|
|
225
|
+
* @returns string
|
|
226
|
+
*/
|
|
207
227
|
function basename(url) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return extIndex;
|
|
228
|
+
const extIndex = url && url.lastIndexOf('.');
|
|
229
|
+
if (typeof extIndex === 'number') {
|
|
230
|
+
return extIndex >= 0 ? url.substr(0, extIndex) : '';
|
|
231
|
+
}
|
|
232
|
+
return extIndex;
|
|
215
233
|
}
|
|
216
|
-
|
|
234
|
+
/**
|
|
235
|
+
* @param url
|
|
236
|
+
* @returns string
|
|
237
|
+
*/
|
|
217
238
|
function extname(url) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return extIndex;
|
|
239
|
+
const extIndex = url && url.lastIndexOf('.');
|
|
240
|
+
if (typeof extIndex === 'number') {
|
|
241
|
+
return extIndex >= 0 ? url.substr(extIndex + 1) : '';
|
|
242
|
+
}
|
|
243
|
+
return extIndex;
|
|
225
244
|
}
|
|
226
|
-
//# sourceMappingURL=parse-shapefile.js.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { BinaryGeometry } from '@loaders.gl/schema';
|
|
2
|
+
import { SHPLoaderOptions } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Parse individual record
|
|
4
5
|
*
|
|
5
6
|
* @param view Record data
|
|
6
7
|
* @return Binary Geometry Object
|
|
7
8
|
*/
|
|
8
|
-
export declare function parseRecord(view: DataView, options?:
|
|
9
|
-
shp?: any;
|
|
10
|
-
}): BinaryGeometry | null;
|
|
9
|
+
export declare function parseRecord(view: DataView, options?: SHPLoaderOptions): BinaryGeometry | null;
|
|
11
10
|
//# sourceMappingURL=parse-shp-geometry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shp-geometry.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-shp-geometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAqB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"parse-shp-geometry.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-shp-geometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAqB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAIzC;;;;;GAKG;AAEH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,GAAG,IAAI,CAoD7F"}
|