@loaders.gl/shapefile 4.2.0-alpha.4 → 4.2.0-alpha.5
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-loader.js +24 -19
- package/dist/dist.dev.js +227 -247
- package/dist/dist.min.js +12 -0
- package/dist/index.cjs +49 -57
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/parsers/parse-dbf.d.ts +1 -1
- package/dist/lib/parsers/parse-dbf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-dbf.js +300 -259
- package/dist/lib/parsers/parse-shapefile.d.ts +3 -3
- package/dist/lib/parsers/parse-shapefile.d.ts.map +1 -1
- package/dist/lib/parsers/parse-shapefile.js +225 -184
- package/dist/lib/parsers/parse-shp-geometry.d.ts +1 -1
- package/dist/lib/parsers/parse-shp-geometry.d.ts.map +1 -1
- package/dist/lib/parsers/parse-shp-geometry.js +260 -168
- package/dist/lib/parsers/parse-shp-header.js +33 -23
- package/dist/lib/parsers/parse-shp.d.ts +1 -1
- package/dist/lib/parsers/parse-shp.d.ts.map +1 -1
- package/dist/lib/parsers/parse-shp.js +147 -110
- package/dist/lib/parsers/parse-shx.js +19 -15
- package/dist/lib/parsers/types.js +0 -1
- package/dist/lib/streaming/binary-chunk-reader.js +150 -95
- package/dist/lib/streaming/binary-reader.js +49 -23
- package/dist/lib/streaming/zip-batch-iterators.js +61 -45
- package/dist/shapefile-loader.js +25 -18
- package/dist/shp-loader.js +24 -18
- package/dist/workers/dbf-worker.js +0 -1
- package/dist/workers/shp-worker.js +0 -1
- package/package.json +11 -7
- 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/parsers/types.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,295 +1,336 @@
|
|
|
1
1
|
import { BinaryChunkReader } from "../streaming/binary-chunk-reader.js";
|
|
2
2
|
const LITTLE_ENDIAN = true;
|
|
3
3
|
const DBF_HEADER_SIZE = 32;
|
|
4
|
-
var STATE
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}(STATE || {});
|
|
4
|
+
var STATE;
|
|
5
|
+
(function (STATE) {
|
|
6
|
+
STATE[STATE["START"] = 0] = "START";
|
|
7
|
+
STATE[STATE["FIELD_DESCRIPTORS"] = 1] = "FIELD_DESCRIPTORS";
|
|
8
|
+
STATE[STATE["FIELD_PROPERTIES"] = 2] = "FIELD_PROPERTIES";
|
|
9
|
+
STATE[STATE["END"] = 3] = "END";
|
|
10
|
+
STATE[STATE["ERROR"] = 4] = "ERROR";
|
|
11
|
+
})(STATE || (STATE = {}));
|
|
12
12
|
class DBFParser {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.binaryReader = new BinaryChunkReader();
|
|
15
|
+
this.state = STATE.START;
|
|
16
|
+
this.result = {
|
|
17
|
+
data: []
|
|
18
|
+
};
|
|
19
|
+
this.textDecoder = new TextDecoder(options.encoding);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @param arrayBuffer
|
|
23
|
+
*/
|
|
24
|
+
write(arrayBuffer) {
|
|
25
|
+
this.binaryReader.write(arrayBuffer);
|
|
26
|
+
this.state = parseState(this.state, this.result, this.binaryReader, this.textDecoder);
|
|
27
|
+
// this.result.progress.bytesUsed = this.binaryReader.bytesUsed();
|
|
28
|
+
// important events:
|
|
29
|
+
// - schema available
|
|
30
|
+
// - first rows available
|
|
31
|
+
// - all rows available
|
|
32
|
+
}
|
|
33
|
+
end() {
|
|
34
|
+
this.binaryReader.end();
|
|
35
|
+
this.state = parseState(this.state, this.result, this.binaryReader, this.textDecoder);
|
|
36
|
+
// this.result.progress.bytesUsed = this.binaryReader.bytesUsed();
|
|
37
|
+
if (this.state !== STATE.END) {
|
|
38
|
+
this.state = STATE.ERROR;
|
|
39
|
+
this.result.error = 'DBF incomplete file';
|
|
40
|
+
}
|
|
32
41
|
}
|
|
33
|
-
}
|
|
34
42
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
encoding
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
schema,
|
|
64
|
-
rows: data
|
|
65
|
-
};
|
|
66
|
-
case 'rows':
|
|
67
|
-
default:
|
|
68
|
-
return data;
|
|
69
|
-
}
|
|
43
|
+
/**
|
|
44
|
+
* @param arrayBuffer
|
|
45
|
+
* @param options
|
|
46
|
+
* @returns DBFTable or rows
|
|
47
|
+
*/
|
|
48
|
+
export function parseDBF(arrayBuffer, options = {}) {
|
|
49
|
+
const { encoding = 'latin1' } = options.dbf || {};
|
|
50
|
+
const dbfParser = new DBFParser({ encoding });
|
|
51
|
+
dbfParser.write(arrayBuffer);
|
|
52
|
+
dbfParser.end();
|
|
53
|
+
const { data, schema } = dbfParser.result;
|
|
54
|
+
const shape = options?.dbf?.shape;
|
|
55
|
+
switch (shape) {
|
|
56
|
+
case 'object-row-table': {
|
|
57
|
+
const table = {
|
|
58
|
+
shape: 'object-row-table',
|
|
59
|
+
schema,
|
|
60
|
+
data
|
|
61
|
+
};
|
|
62
|
+
return table;
|
|
63
|
+
}
|
|
64
|
+
case 'table':
|
|
65
|
+
return { schema, rows: data };
|
|
66
|
+
case 'rows':
|
|
67
|
+
default:
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
let headerReturned = false;
|
|
82
|
-
for await (const arrayBuffer of asyncIterator) {
|
|
71
|
+
/**
|
|
72
|
+
* @param asyncIterator
|
|
73
|
+
* @param options
|
|
74
|
+
*/
|
|
75
|
+
export async function* parseDBFInBatches(asyncIterator, options = {}) {
|
|
76
|
+
const { encoding = 'latin1' } = options.dbf || {};
|
|
77
|
+
const parser = new DBFParser({ encoding });
|
|
78
|
+
let headerReturned = false;
|
|
79
|
+
for await (const arrayBuffer of asyncIterator) {
|
|
83
80
|
parser.write(arrayBuffer);
|
|
84
81
|
if (!headerReturned && parser.result.dbfHeader) {
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
headerReturned = true;
|
|
83
|
+
yield parser.result.dbfHeader;
|
|
87
84
|
}
|
|
88
85
|
if (parser.result.data.length > 0) {
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
yield parser.result.data;
|
|
87
|
+
parser.result.data = [];
|
|
91
88
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
}
|
|
90
|
+
parser.end();
|
|
91
|
+
if (parser.result.data.length > 0) {
|
|
95
92
|
yield parser.result.data;
|
|
96
|
-
|
|
97
|
-
}();
|
|
98
|
-
} catch (e) {
|
|
99
|
-
return Promise.reject(e);
|
|
100
|
-
}
|
|
93
|
+
}
|
|
101
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm
|
|
97
|
+
* @param state
|
|
98
|
+
* @param result
|
|
99
|
+
* @param binaryReader
|
|
100
|
+
* @param textDecoder
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
/* eslint-disable complexity, max-depth */
|
|
102
104
|
function parseState(state, result, binaryReader, textDecoder) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
105
|
+
// eslint-disable-next-line no-constant-condition
|
|
106
|
+
while (true) {
|
|
107
|
+
try {
|
|
108
|
+
switch (state) {
|
|
109
|
+
case STATE.ERROR:
|
|
110
|
+
case STATE.END:
|
|
111
|
+
return state;
|
|
112
|
+
case STATE.START:
|
|
113
|
+
// Parse initial file header
|
|
114
|
+
// DBF Header
|
|
115
|
+
const dataView = binaryReader.getDataView(DBF_HEADER_SIZE);
|
|
116
|
+
if (!dataView) {
|
|
117
|
+
return state;
|
|
118
|
+
}
|
|
119
|
+
result.dbfHeader = parseDBFHeader(dataView);
|
|
120
|
+
result.progress = {
|
|
121
|
+
bytesUsed: 0,
|
|
122
|
+
rowsTotal: result.dbfHeader.nRecords,
|
|
123
|
+
rows: 0
|
|
124
|
+
};
|
|
125
|
+
state = STATE.FIELD_DESCRIPTORS;
|
|
126
|
+
break;
|
|
127
|
+
case STATE.FIELD_DESCRIPTORS:
|
|
128
|
+
// Parse DBF field descriptors (schema)
|
|
129
|
+
const fieldDescriptorView = binaryReader.getDataView(
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
result.dbfHeader.headerLength - DBF_HEADER_SIZE);
|
|
132
|
+
if (!fieldDescriptorView) {
|
|
133
|
+
return state;
|
|
134
|
+
}
|
|
135
|
+
result.dbfFields = parseFieldDescriptors(fieldDescriptorView, textDecoder);
|
|
136
|
+
result.schema = {
|
|
137
|
+
fields: result.dbfFields.map((dbfField) => makeField(dbfField)),
|
|
138
|
+
metadata: {}
|
|
139
|
+
};
|
|
140
|
+
state = STATE.FIELD_PROPERTIES;
|
|
141
|
+
// TODO(kyle) Not exactly sure why start offset needs to be headerLength + 1?
|
|
142
|
+
// parsedbf uses ((fields.length + 1) << 5) + 2;
|
|
143
|
+
binaryReader.skip(1);
|
|
144
|
+
break;
|
|
145
|
+
case STATE.FIELD_PROPERTIES:
|
|
146
|
+
const { recordLength = 0, nRecords = 0 } = result?.dbfHeader || {};
|
|
147
|
+
while (result.data.length < nRecords) {
|
|
148
|
+
const recordView = binaryReader.getDataView(recordLength - 1);
|
|
149
|
+
if (!recordView) {
|
|
150
|
+
return state;
|
|
151
|
+
}
|
|
152
|
+
// Note: Avoid actually reading the last byte, which may not be present
|
|
153
|
+
binaryReader.skip(1);
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
const row = parseRow(recordView, result.dbfFields, textDecoder);
|
|
156
|
+
result.data.push(row);
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
result.progress.rows = result.data.length;
|
|
159
|
+
}
|
|
160
|
+
state = STATE.END;
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
state = STATE.ERROR;
|
|
164
|
+
result.error = `illegal parser state ${state}`;
|
|
165
|
+
return state;
|
|
144
166
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
result.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
break;
|
|
152
|
-
default:
|
|
153
|
-
state = STATE.ERROR;
|
|
154
|
-
result.error = `illegal parser state ${state}`;
|
|
155
|
-
return state;
|
|
156
|
-
}
|
|
157
|
-
} catch (error) {
|
|
158
|
-
state = STATE.ERROR;
|
|
159
|
-
result.error = `DBF parsing failed: ${error.message}`;
|
|
160
|
-
return state;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
state = STATE.ERROR;
|
|
170
|
+
result.error = `DBF parsing failed: ${error.message}`;
|
|
171
|
+
return state;
|
|
172
|
+
}
|
|
161
173
|
}
|
|
162
|
-
}
|
|
163
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* @param headerView
|
|
177
|
+
*/
|
|
164
178
|
function parseDBFHeader(headerView) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
return {
|
|
180
|
+
// Last updated date
|
|
181
|
+
year: headerView.getUint8(1) + 1900,
|
|
182
|
+
month: headerView.getUint8(2),
|
|
183
|
+
day: headerView.getUint8(3),
|
|
184
|
+
// Number of records in data file
|
|
185
|
+
nRecords: headerView.getUint32(4, LITTLE_ENDIAN),
|
|
186
|
+
// Length of header in bytes
|
|
187
|
+
headerLength: headerView.getUint16(8, LITTLE_ENDIAN),
|
|
188
|
+
// Length of each record
|
|
189
|
+
recordLength: headerView.getUint16(10, LITTLE_ENDIAN),
|
|
190
|
+
// Not sure if this is usually set
|
|
191
|
+
languageDriver: headerView.getUint8(29)
|
|
192
|
+
};
|
|
174
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* @param view
|
|
196
|
+
*/
|
|
175
197
|
function parseFieldDescriptors(view, textDecoder) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
198
|
+
// NOTE: this might overestimate the number of fields if the "Database
|
|
199
|
+
// Container" container exists and is included in the headerLength
|
|
200
|
+
const nFields = (view.byteLength - 1) / 32;
|
|
201
|
+
const fields = [];
|
|
202
|
+
let offset = 0;
|
|
203
|
+
for (let i = 0; i < nFields; i++) {
|
|
204
|
+
const name = textDecoder
|
|
205
|
+
.decode(new Uint8Array(view.buffer, view.byteOffset + offset, 11))
|
|
206
|
+
// eslint-disable-next-line no-control-regex
|
|
207
|
+
.replace(/\u0000/g, '');
|
|
208
|
+
fields.push({
|
|
209
|
+
name,
|
|
210
|
+
dataType: String.fromCharCode(view.getUint8(offset + 11)),
|
|
211
|
+
fieldLength: view.getUint8(offset + 16),
|
|
212
|
+
decimal: view.getUint8(offset + 17)
|
|
213
|
+
});
|
|
214
|
+
offset += 32;
|
|
215
|
+
}
|
|
216
|
+
return fields;
|
|
217
|
+
}
|
|
218
|
+
/*
|
|
219
|
+
* @param {BinaryChunkReader} binaryReader
|
|
220
|
+
function parseRows(binaryReader, fields, nRecords, recordLength, textDecoder) {
|
|
221
|
+
const rows = [];
|
|
222
|
+
for (let i = 0; i < nRecords; i++) {
|
|
223
|
+
const recordView = binaryReader.getDataView(recordLength - 1);
|
|
224
|
+
binaryReader.skip(1);
|
|
225
|
+
// @ts-ignore
|
|
226
|
+
rows.push(parseRow(recordView, fields, textDecoder));
|
|
188
227
|
}
|
|
189
|
-
return
|
|
228
|
+
return rows;
|
|
190
229
|
}
|
|
230
|
+
*/
|
|
231
|
+
/**
|
|
232
|
+
*
|
|
233
|
+
* @param view
|
|
234
|
+
* @param fields
|
|
235
|
+
* @param textDecoder
|
|
236
|
+
* @returns
|
|
237
|
+
*/
|
|
191
238
|
function parseRow(view, fields, textDecoder) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
239
|
+
const out = {};
|
|
240
|
+
let offset = 0;
|
|
241
|
+
for (const field of fields) {
|
|
242
|
+
const text = textDecoder.decode(new Uint8Array(view.buffer, view.byteOffset + offset, field.fieldLength));
|
|
243
|
+
out[field.name] = parseField(text, field.dataType);
|
|
244
|
+
offset += field.fieldLength;
|
|
245
|
+
}
|
|
246
|
+
return out;
|
|
200
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Should NaN be coerced to null?
|
|
250
|
+
* @param text
|
|
251
|
+
* @param dataType
|
|
252
|
+
* @returns Field depends on a type of the data
|
|
253
|
+
*/
|
|
201
254
|
function parseField(text, dataType) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
255
|
+
switch (dataType) {
|
|
256
|
+
case 'B':
|
|
257
|
+
return parseNumber(text);
|
|
258
|
+
case 'C':
|
|
259
|
+
return parseCharacter(text);
|
|
260
|
+
case 'F':
|
|
261
|
+
return parseNumber(text);
|
|
262
|
+
case 'N':
|
|
263
|
+
return parseNumber(text);
|
|
264
|
+
case 'O':
|
|
265
|
+
return parseNumber(text);
|
|
266
|
+
case 'D':
|
|
267
|
+
return parseDate(text);
|
|
268
|
+
case 'L':
|
|
269
|
+
return parseBoolean(text);
|
|
270
|
+
default:
|
|
271
|
+
throw new Error('Unsupported data type');
|
|
272
|
+
}
|
|
220
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Parse YYYYMMDD to date in milliseconds
|
|
276
|
+
* @param str YYYYMMDD
|
|
277
|
+
* @returns new Date as a number
|
|
278
|
+
*/
|
|
221
279
|
function parseDate(str) {
|
|
222
|
-
|
|
280
|
+
return Date.UTC(str.slice(0, 4), parseInt(str.slice(4, 6), 10) - 1, str.slice(6, 8));
|
|
223
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Read boolean value
|
|
284
|
+
* any of Y, y, T, t coerce to true
|
|
285
|
+
* any of N, n, F, f coerce to false
|
|
286
|
+
* otherwise null
|
|
287
|
+
* @param value
|
|
288
|
+
* @returns boolean | null
|
|
289
|
+
*/
|
|
224
290
|
function parseBoolean(value) {
|
|
225
|
-
|
|
291
|
+
return /^[nf]$/i.test(value) ? false : /^[yt]$/i.test(value) ? true : null;
|
|
226
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Return null instead of NaN
|
|
295
|
+
* @param text
|
|
296
|
+
* @returns number | null
|
|
297
|
+
*/
|
|
227
298
|
function parseNumber(text) {
|
|
228
|
-
|
|
229
|
-
|
|
299
|
+
const number = parseFloat(text);
|
|
300
|
+
return isNaN(number) ? null : number;
|
|
230
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
*
|
|
304
|
+
* @param text
|
|
305
|
+
* @returns string | null
|
|
306
|
+
*/
|
|
231
307
|
function parseCharacter(text) {
|
|
232
|
-
|
|
308
|
+
return text.trim() || null;
|
|
233
309
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
nullable: true,
|
|
261
|
-
metadata: {}
|
|
262
|
-
};
|
|
263
|
-
case 'N':
|
|
264
|
-
return {
|
|
265
|
-
name,
|
|
266
|
-
type: 'float64',
|
|
267
|
-
nullable: true,
|
|
268
|
-
metadata: {}
|
|
269
|
-
};
|
|
270
|
-
case 'O':
|
|
271
|
-
return {
|
|
272
|
-
name,
|
|
273
|
-
type: 'float64',
|
|
274
|
-
nullable: true,
|
|
275
|
-
metadata: {}
|
|
276
|
-
};
|
|
277
|
-
case 'D':
|
|
278
|
-
return {
|
|
279
|
-
name,
|
|
280
|
-
type: 'timestamp-millisecond',
|
|
281
|
-
nullable: true,
|
|
282
|
-
metadata: {}
|
|
283
|
-
};
|
|
284
|
-
case 'L':
|
|
285
|
-
return {
|
|
286
|
-
name,
|
|
287
|
-
type: 'bool',
|
|
288
|
-
nullable: true,
|
|
289
|
-
metadata: {}
|
|
290
|
-
};
|
|
291
|
-
default:
|
|
292
|
-
throw new Error('Unsupported data type');
|
|
293
|
-
}
|
|
310
|
+
/**
|
|
311
|
+
* Create a standard Arrow-style `Field` from field descriptor.
|
|
312
|
+
* TODO - use `fieldLength` and `decimal` to generate smaller types?
|
|
313
|
+
* @param param0
|
|
314
|
+
* @returns Field
|
|
315
|
+
*/
|
|
316
|
+
// eslint-disable
|
|
317
|
+
function makeField({ name, dataType, fieldLength, decimal }) {
|
|
318
|
+
switch (dataType) {
|
|
319
|
+
case 'B':
|
|
320
|
+
return { name, type: 'float64', nullable: true, metadata: {} };
|
|
321
|
+
case 'C':
|
|
322
|
+
return { name, type: 'utf8', nullable: true, metadata: {} };
|
|
323
|
+
case 'F':
|
|
324
|
+
return { name, type: 'float64', nullable: true, metadata: {} };
|
|
325
|
+
case 'N':
|
|
326
|
+
return { name, type: 'float64', nullable: true, metadata: {} };
|
|
327
|
+
case 'O':
|
|
328
|
+
return { name, type: 'float64', nullable: true, metadata: {} };
|
|
329
|
+
case 'D':
|
|
330
|
+
return { name, type: 'timestamp-millisecond', nullable: true, metadata: {} };
|
|
331
|
+
case 'L':
|
|
332
|
+
return { name, type: 'bool', nullable: true, metadata: {} };
|
|
333
|
+
default:
|
|
334
|
+
throw new Error('Unsupported data type');
|
|
335
|
+
}
|
|
294
336
|
}
|
|
295
|
-
//# sourceMappingURL=parse-dbf.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LoaderContext } from '@loaders.gl/loader-utils';
|
|
2
|
-
import type { SHXOutput } from
|
|
3
|
-
import type { SHPHeader } from
|
|
4
|
-
import type { ShapefileLoaderOptions } from
|
|
2
|
+
import type { SHXOutput } from "./parse-shx.js";
|
|
3
|
+
import type { SHPHeader } from "./parse-shp-header.js";
|
|
4
|
+
import type { ShapefileLoaderOptions } from "./types.js";
|
|
5
5
|
interface ShapefileOutput {
|
|
6
6
|
encoding?: string;
|
|
7
7
|
prj?: string;
|
|
@@ -1 +1 @@
|
|
|
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;AAUpG,OAAO,KAAK,EAAC,SAAS,EAAC,
|
|
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;AAUpG,OAAO,KAAK,EAAC,SAAS,EAAC,uBAAoB;AAC3C,OAAO,KAAK,EAAC,SAAS,EAAC,8BAA2B;AAClD,OAAO,KAAK,EAAC,sBAAsB,EAAC,mBAAgB;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,CAkFhC;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,sBAAsB,EAChC,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,eAAe,CAAC,CAiD1B;AAwDD;;;;;GAKG;AAEH,wBAAsB,yBAAyB,CAC7C,OAAO,CAAC,EAAE,sBAAsB,EAChC,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"}
|