@loaders.gl/shapefile 4.3.2 → 4.4.0-alpha.1
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-arrow-loader.d.ts +52 -0
- package/dist/dbf-arrow-loader.d.ts.map +1 -0
- package/dist/dbf-arrow-loader.js +32 -0
- package/dist/dbf-format.d.ts +10 -0
- package/dist/dbf-format.d.ts.map +1 -0
- package/dist/dbf-format.js +12 -0
- package/dist/dbf-loader.js +1 -1
- package/dist/dbf-worker.js +1 -1
- package/dist/dist.dev.js +12231 -33
- package/dist/dist.min.js +11 -2
- package/dist/index.cjs +277 -10
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/parsers/parse-dbf-to-arrow.d.ts +26 -0
- package/dist/lib/parsers/parse-dbf-to-arrow.d.ts.map +1 -0
- package/dist/lib/parsers/parse-dbf-to-arrow.js +321 -0
- 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-shapefile.js +2 -2
- 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/types.d.ts +1 -1
- package/dist/lib/parsers/types.d.ts.map +1 -1
- package/dist/shapefile-loader.d.ts.map +1 -1
- package/dist/shapefile-loader.js +1 -1
- package/dist/shp-loader.js +1 -1
- package/dist/shp-worker.js +1 -1
- package/package.json +6 -6
- package/src/dbf-arrow-loader.ts +46 -0
- package/src/dbf-format.ts +15 -0
- package/src/index.ts +1 -0
- package/src/lib/parsers/parse-dbf-to-arrow.ts +382 -0
- package/src/lib/parsers/parse-dbf.ts +1 -1
- package/src/lib/parsers/parse-shapefile.ts +2 -2
- package/src/lib/parsers/parse-shp-geometry.ts +1 -1
- package/src/lib/parsers/types.ts +1 -1
- package/src/shapefile-loader.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// dist/index.js
|
|
21
21
|
var dist_exports = {};
|
|
22
22
|
__export(dist_exports, {
|
|
23
|
+
DBFArrowLoader: () => DBFArrowLoader,
|
|
24
|
+
DBFArrowWorkerLoader: () => DBFArrowWorkerLoader,
|
|
23
25
|
DBFLoader: () => DBFLoader,
|
|
24
26
|
DBFWorkerLoader: () => DBFWorkerLoader,
|
|
25
27
|
SHPLoader: () => SHPLoader,
|
|
@@ -516,7 +518,7 @@ function parseState(state, result, binaryReader, options) {
|
|
|
516
518
|
}
|
|
517
519
|
|
|
518
520
|
// dist/shp-loader.js
|
|
519
|
-
var VERSION = true ? "4.
|
|
521
|
+
var VERSION = true ? "4.4.0-alpha.0" : "latest";
|
|
520
522
|
var SHP_MAGIC_NUMBER2 = [0, 0, 39, 10];
|
|
521
523
|
var SHPWorkerLoader = {
|
|
522
524
|
dataType: null,
|
|
@@ -618,12 +620,12 @@ function extractBatchData(batch1, batch2) {
|
|
|
618
620
|
var LITTLE_ENDIAN4 = true;
|
|
619
621
|
var DBF_HEADER_SIZE = 32;
|
|
620
622
|
var STATE2;
|
|
621
|
-
(function(
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
623
|
+
(function(STATE4) {
|
|
624
|
+
STATE4[STATE4["START"] = 0] = "START";
|
|
625
|
+
STATE4[STATE4["FIELD_DESCRIPTORS"] = 1] = "FIELD_DESCRIPTORS";
|
|
626
|
+
STATE4[STATE4["FIELD_PROPERTIES"] = 2] = "FIELD_PROPERTIES";
|
|
627
|
+
STATE4[STATE4["END"] = 3] = "END";
|
|
628
|
+
STATE4[STATE4["ERROR"] = 4] = "ERROR";
|
|
627
629
|
})(STATE2 || (STATE2 = {}));
|
|
628
630
|
var DBFParser = class {
|
|
629
631
|
binaryReader = new BinaryChunkReader();
|
|
@@ -854,7 +856,7 @@ function makeField({ name, dataType, fieldLength, decimal }) {
|
|
|
854
856
|
}
|
|
855
857
|
|
|
856
858
|
// dist/dbf-loader.js
|
|
857
|
-
var VERSION2 = true ? "4.
|
|
859
|
+
var VERSION2 = true ? "4.4.0-alpha.0" : "latest";
|
|
858
860
|
var DBFWorkerLoader = {
|
|
859
861
|
name: "DBF",
|
|
860
862
|
dataType: null,
|
|
@@ -977,7 +979,7 @@ async function parseShapefile(arrayBuffer, options, context) {
|
|
|
977
979
|
function parseGeometries(geometries) {
|
|
978
980
|
const geojsonGeometries = [];
|
|
979
981
|
for (const geom of geometries) {
|
|
980
|
-
geojsonGeometries.push((0, import_gis.
|
|
982
|
+
geojsonGeometries.push((0, import_gis.convertBinaryGeometryToGeometry)(geom));
|
|
981
983
|
}
|
|
982
984
|
return geojsonGeometries;
|
|
983
985
|
}
|
|
@@ -1055,7 +1057,7 @@ function extname(url) {
|
|
|
1055
1057
|
}
|
|
1056
1058
|
|
|
1057
1059
|
// dist/shapefile-loader.js
|
|
1058
|
-
var VERSION3 = true ? "4.
|
|
1060
|
+
var VERSION3 = true ? "4.4.0-alpha.0" : "latest";
|
|
1059
1061
|
var ShapefileLoader = {
|
|
1060
1062
|
name: "Shapefile",
|
|
1061
1063
|
id: "shapefile",
|
|
@@ -1079,6 +1081,271 @@ var ShapefileLoader = {
|
|
|
1079
1081
|
parseInBatches: parseShapefileInBatches
|
|
1080
1082
|
};
|
|
1081
1083
|
|
|
1084
|
+
// dist/lib/parsers/parse-dbf-to-arrow.js
|
|
1085
|
+
var import_schema_utils = require("@loaders.gl/schema-utils");
|
|
1086
|
+
var LITTLE_ENDIAN5 = true;
|
|
1087
|
+
var DBF_HEADER_SIZE2 = 32;
|
|
1088
|
+
var STATE3;
|
|
1089
|
+
(function(STATE4) {
|
|
1090
|
+
STATE4[STATE4["START"] = 0] = "START";
|
|
1091
|
+
STATE4[STATE4["FIELD_DESCRIPTORS"] = 1] = "FIELD_DESCRIPTORS";
|
|
1092
|
+
STATE4[STATE4["FIELD_PROPERTIES"] = 2] = "FIELD_PROPERTIES";
|
|
1093
|
+
STATE4[STATE4["END"] = 3] = "END";
|
|
1094
|
+
STATE4[STATE4["ERROR"] = 4] = "ERROR";
|
|
1095
|
+
})(STATE3 || (STATE3 = {}));
|
|
1096
|
+
var DBFParser2 = class {
|
|
1097
|
+
binaryReader = new BinaryChunkReader();
|
|
1098
|
+
textDecoder;
|
|
1099
|
+
state = STATE3.START;
|
|
1100
|
+
result = {};
|
|
1101
|
+
constructor(options) {
|
|
1102
|
+
this.textDecoder = new TextDecoder(options.encoding);
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* @param arrayBuffer
|
|
1106
|
+
*/
|
|
1107
|
+
write(arrayBuffer) {
|
|
1108
|
+
this.binaryReader.write(arrayBuffer);
|
|
1109
|
+
this.state = parseState3(this.state, this.result, this.binaryReader, this.textDecoder);
|
|
1110
|
+
}
|
|
1111
|
+
end() {
|
|
1112
|
+
this.binaryReader.end();
|
|
1113
|
+
this.state = parseState3(this.state, this.result, this.binaryReader, this.textDecoder);
|
|
1114
|
+
if (this.state !== STATE3.END) {
|
|
1115
|
+
this.state = STATE3.ERROR;
|
|
1116
|
+
this.result.error = "DBF incomplete file";
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
function parseDBF2(arrayBuffer, options = {}) {
|
|
1121
|
+
const { encoding = "latin1" } = options.dbf || {};
|
|
1122
|
+
const dbfParser = new DBFParser2({ encoding });
|
|
1123
|
+
dbfParser.write(arrayBuffer);
|
|
1124
|
+
dbfParser.end();
|
|
1125
|
+
const tableBuilder = dbfParser.result.tableBuilder;
|
|
1126
|
+
const arrowTable = tableBuilder.finishTable();
|
|
1127
|
+
return arrowTable;
|
|
1128
|
+
}
|
|
1129
|
+
async function* parseDBFInBatches2(asyncIterator, options = {}) {
|
|
1130
|
+
const { encoding = "latin1" } = options.dbf || {};
|
|
1131
|
+
const parser = new DBFParser2({ encoding });
|
|
1132
|
+
let headerReturned = false;
|
|
1133
|
+
for await (const arrayBuffer of asyncIterator) {
|
|
1134
|
+
parser.write(arrayBuffer);
|
|
1135
|
+
if (!headerReturned && parser.result.dbfHeader) {
|
|
1136
|
+
headerReturned = true;
|
|
1137
|
+
const tableBuilder3 = parser.result.tableBuilder;
|
|
1138
|
+
const tableBatch3 = tableBuilder3.firstBatch();
|
|
1139
|
+
if (tableBatch3) {
|
|
1140
|
+
yield tableBatch3;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
const tableBuilder2 = parser.result.tableBuilder;
|
|
1144
|
+
const tableBatch2 = tableBuilder2.flushBatch();
|
|
1145
|
+
if (tableBatch2) {
|
|
1146
|
+
yield tableBatch2;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
parser.end();
|
|
1150
|
+
const tableBuilder = parser.result.tableBuilder;
|
|
1151
|
+
const tableBatch = tableBuilder.finishBatch();
|
|
1152
|
+
if (tableBatch) {
|
|
1153
|
+
yield tableBatch;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
function parseState3(state, result, binaryReader, textDecoder) {
|
|
1157
|
+
while (true) {
|
|
1158
|
+
try {
|
|
1159
|
+
switch (state) {
|
|
1160
|
+
case STATE3.ERROR:
|
|
1161
|
+
case STATE3.END:
|
|
1162
|
+
return state;
|
|
1163
|
+
case STATE3.START:
|
|
1164
|
+
const dataView = binaryReader.getDataView(DBF_HEADER_SIZE2);
|
|
1165
|
+
if (!dataView) {
|
|
1166
|
+
return state;
|
|
1167
|
+
}
|
|
1168
|
+
result.dbfHeader = parseDBFHeader2(dataView);
|
|
1169
|
+
result.progress = {
|
|
1170
|
+
bytesUsed: 0,
|
|
1171
|
+
rowsTotal: result.dbfHeader.nRecords,
|
|
1172
|
+
rows: 0
|
|
1173
|
+
};
|
|
1174
|
+
state = STATE3.FIELD_DESCRIPTORS;
|
|
1175
|
+
break;
|
|
1176
|
+
case STATE3.FIELD_DESCRIPTORS:
|
|
1177
|
+
const fieldDescriptorView = binaryReader.getDataView(
|
|
1178
|
+
// @ts-ignore
|
|
1179
|
+
result.dbfHeader.headerLength - DBF_HEADER_SIZE2
|
|
1180
|
+
);
|
|
1181
|
+
if (!fieldDescriptorView) {
|
|
1182
|
+
return state;
|
|
1183
|
+
}
|
|
1184
|
+
result.dbfFields = parseFieldDescriptors2(fieldDescriptorView, textDecoder);
|
|
1185
|
+
const schema = {
|
|
1186
|
+
fields: result.dbfFields.map((dbfField) => makeField2(dbfField)),
|
|
1187
|
+
metadata: {}
|
|
1188
|
+
};
|
|
1189
|
+
result.tableBuilder = new import_schema_utils.ArrowTableBuilder(schema);
|
|
1190
|
+
state = STATE3.FIELD_PROPERTIES;
|
|
1191
|
+
binaryReader.skip(1);
|
|
1192
|
+
break;
|
|
1193
|
+
case STATE3.FIELD_PROPERTIES:
|
|
1194
|
+
const { recordLength = 0, nRecords = 0 } = (result == null ? void 0 : result.dbfHeader) || {};
|
|
1195
|
+
let rowCount = 0;
|
|
1196
|
+
while (rowCount < nRecords) {
|
|
1197
|
+
rowCount++;
|
|
1198
|
+
const recordView = binaryReader.getDataView(recordLength - 1);
|
|
1199
|
+
if (!recordView) {
|
|
1200
|
+
return state;
|
|
1201
|
+
}
|
|
1202
|
+
binaryReader.skip(1);
|
|
1203
|
+
const row = parseRow2(recordView, result.dbfFields, textDecoder);
|
|
1204
|
+
result.tableBuilder.addObjectRow(row);
|
|
1205
|
+
}
|
|
1206
|
+
state = STATE3.END;
|
|
1207
|
+
break;
|
|
1208
|
+
default:
|
|
1209
|
+
state = STATE3.ERROR;
|
|
1210
|
+
result.error = `illegal parser state ${state}`;
|
|
1211
|
+
return state;
|
|
1212
|
+
}
|
|
1213
|
+
} catch (error) {
|
|
1214
|
+
state = STATE3.ERROR;
|
|
1215
|
+
result.error = `DBF parsing failed: ${error.message}`;
|
|
1216
|
+
return state;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
function parseDBFHeader2(headerView) {
|
|
1221
|
+
return {
|
|
1222
|
+
// Last updated date
|
|
1223
|
+
year: headerView.getUint8(1) + 1900,
|
|
1224
|
+
month: headerView.getUint8(2),
|
|
1225
|
+
day: headerView.getUint8(3),
|
|
1226
|
+
// Number of records in data file
|
|
1227
|
+
nRecords: headerView.getUint32(4, LITTLE_ENDIAN5),
|
|
1228
|
+
// Length of header in bytes
|
|
1229
|
+
headerLength: headerView.getUint16(8, LITTLE_ENDIAN5),
|
|
1230
|
+
// Length of each record
|
|
1231
|
+
recordLength: headerView.getUint16(10, LITTLE_ENDIAN5),
|
|
1232
|
+
// Not sure if this is usually set
|
|
1233
|
+
languageDriver: headerView.getUint8(29)
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
function parseFieldDescriptors2(view, textDecoder) {
|
|
1237
|
+
const nFields = (view.byteLength - 1) / 32;
|
|
1238
|
+
const fields = [];
|
|
1239
|
+
let offset = 0;
|
|
1240
|
+
for (let i = 0; i < nFields; i++) {
|
|
1241
|
+
const name = textDecoder.decode(new Uint8Array(view.buffer, view.byteOffset + offset, 11)).replace(/\u0000/g, "");
|
|
1242
|
+
fields.push({
|
|
1243
|
+
name,
|
|
1244
|
+
dataType: String.fromCharCode(view.getUint8(offset + 11)),
|
|
1245
|
+
fieldLength: view.getUint8(offset + 16),
|
|
1246
|
+
decimal: view.getUint8(offset + 17)
|
|
1247
|
+
});
|
|
1248
|
+
offset += 32;
|
|
1249
|
+
}
|
|
1250
|
+
return fields;
|
|
1251
|
+
}
|
|
1252
|
+
function parseRow2(view, fields, textDecoder) {
|
|
1253
|
+
const out = {};
|
|
1254
|
+
let offset = 0;
|
|
1255
|
+
for (const field of fields) {
|
|
1256
|
+
const text = textDecoder.decode(new Uint8Array(view.buffer, view.byteOffset + offset, field.fieldLength));
|
|
1257
|
+
out[field.name] = parseField2(text, field.dataType);
|
|
1258
|
+
offset += field.fieldLength;
|
|
1259
|
+
}
|
|
1260
|
+
return out;
|
|
1261
|
+
}
|
|
1262
|
+
function parseField2(text, dataType) {
|
|
1263
|
+
switch (dataType) {
|
|
1264
|
+
case "B":
|
|
1265
|
+
return parseNumber2(text);
|
|
1266
|
+
case "C":
|
|
1267
|
+
return parseCharacter2(text);
|
|
1268
|
+
case "F":
|
|
1269
|
+
return parseNumber2(text);
|
|
1270
|
+
case "N":
|
|
1271
|
+
return parseNumber2(text);
|
|
1272
|
+
case "O":
|
|
1273
|
+
return parseNumber2(text);
|
|
1274
|
+
case "D":
|
|
1275
|
+
return parseDate2(text);
|
|
1276
|
+
case "L":
|
|
1277
|
+
return parseBoolean2(text);
|
|
1278
|
+
default:
|
|
1279
|
+
throw new Error("Unsupported data type");
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
function parseDate2(str) {
|
|
1283
|
+
return Date.UTC(str.slice(0, 4), parseInt(str.slice(4, 6), 10) - 1, str.slice(6, 8));
|
|
1284
|
+
}
|
|
1285
|
+
function parseBoolean2(value) {
|
|
1286
|
+
return /^[nf]$/i.test(value) ? false : /^[yt]$/i.test(value) ? true : null;
|
|
1287
|
+
}
|
|
1288
|
+
function parseNumber2(text) {
|
|
1289
|
+
const number = parseFloat(text);
|
|
1290
|
+
return isNaN(number) ? null : number;
|
|
1291
|
+
}
|
|
1292
|
+
function parseCharacter2(text) {
|
|
1293
|
+
return text.trim() || null;
|
|
1294
|
+
}
|
|
1295
|
+
function makeField2({ name, dataType, fieldLength, decimal }) {
|
|
1296
|
+
switch (dataType) {
|
|
1297
|
+
case "B":
|
|
1298
|
+
return { name, type: "float64", nullable: true, metadata: {} };
|
|
1299
|
+
case "C":
|
|
1300
|
+
return { name, type: "utf8", nullable: true, metadata: {} };
|
|
1301
|
+
case "F":
|
|
1302
|
+
return { name, type: "float64", nullable: true, metadata: {} };
|
|
1303
|
+
case "N":
|
|
1304
|
+
return { name, type: "float64", nullable: true, metadata: {} };
|
|
1305
|
+
case "O":
|
|
1306
|
+
return { name, type: "float64", nullable: true, metadata: {} };
|
|
1307
|
+
case "D":
|
|
1308
|
+
return { name, type: "timestamp-millisecond", nullable: true, metadata: {} };
|
|
1309
|
+
case "L":
|
|
1310
|
+
return { name, type: "bool", nullable: true, metadata: {} };
|
|
1311
|
+
default:
|
|
1312
|
+
throw new Error("Unsupported data type");
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// dist/dbf-format.js
|
|
1317
|
+
var DBFFormat = {
|
|
1318
|
+
name: "DBF",
|
|
1319
|
+
id: "dbf",
|
|
1320
|
+
module: "shapefile",
|
|
1321
|
+
category: "table",
|
|
1322
|
+
extensions: ["dbf"],
|
|
1323
|
+
mimeTypes: ["application/x-dbf"]
|
|
1324
|
+
};
|
|
1325
|
+
|
|
1326
|
+
// dist/dbf-arrow-loader.js
|
|
1327
|
+
var VERSION4 = true ? "4.4.0-alpha.0" : "latest";
|
|
1328
|
+
var DBFArrowWorkerLoader = {
|
|
1329
|
+
...DBFFormat,
|
|
1330
|
+
dataType: null,
|
|
1331
|
+
batchType: null,
|
|
1332
|
+
version: VERSION4,
|
|
1333
|
+
worker: true,
|
|
1334
|
+
options: {
|
|
1335
|
+
dbf: {
|
|
1336
|
+
encoding: "latin1"
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
var DBFArrowLoader = {
|
|
1341
|
+
...DBFArrowWorkerLoader,
|
|
1342
|
+
parse: async (arrayBuffer, options) => parseDBF2(arrayBuffer, options),
|
|
1343
|
+
parseSync: parseDBF2,
|
|
1344
|
+
parseInBatches(arrayBufferIterator, options) {
|
|
1345
|
+
return parseDBFInBatches2(arrayBufferIterator, options);
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1082
1349
|
// dist/lib/streaming/binary-reader.js
|
|
1083
1350
|
var BinaryReader = class {
|
|
1084
1351
|
offset;
|