@loaders.gl/shapefile 4.4.0-alpha.1 → 4.4.0-alpha.9
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 +3 -3
- package/dist/dbf-arrow-loader.d.ts.map +1 -1
- package/dist/dbf-arrow-loader.js +2 -1
- package/dist/dbf-arrow-loader.js.map +1 -0
- package/dist/dbf-format.js +1 -0
- package/dist/dbf-format.js.map +1 -0
- package/dist/dbf-loader.d.ts +3 -2
- package/dist/dbf-loader.d.ts.map +1 -1
- package/dist/dbf-loader.js +2 -1
- package/dist/dbf-loader.js.map +1 -0
- package/dist/dbf-worker.js +227 -201
- package/dist/dist.dev.js +51 -22
- package/dist/dist.min.js +5 -5
- package/dist/index.cjs +29 -13
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/parsers/parse-dbf-to-arrow.d.ts +1 -1
- package/dist/lib/parsers/parse-dbf-to-arrow.d.ts.map +1 -1
- package/dist/lib/parsers/parse-dbf-to-arrow.js +3 -1
- package/dist/lib/parsers/parse-dbf-to-arrow.js.map +1 -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-dbf.js +3 -1
- package/dist/lib/parsers/parse-dbf.js.map +1 -0
- 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 +16 -4
- package/dist/lib/parsers/parse-shapefile.js.map +1 -0
- package/dist/lib/parsers/parse-shp-geometry.js +1 -0
- package/dist/lib/parsers/parse-shp-geometry.js.map +1 -0
- package/dist/lib/parsers/parse-shp-header.js +1 -0
- package/dist/lib/parsers/parse-shp-header.js.map +1 -0
- 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 +3 -1
- package/dist/lib/parsers/parse-shp.js.map +1 -0
- package/dist/lib/parsers/parse-shx.js +1 -0
- package/dist/lib/parsers/parse-shx.js.map +1 -0
- package/dist/lib/parsers/types.d.ts +9 -5
- package/dist/lib/parsers/types.d.ts.map +1 -1
- package/dist/lib/parsers/types.js +1 -0
- package/dist/lib/parsers/types.js.map +1 -0
- package/dist/lib/streaming/binary-chunk-reader.js +1 -0
- package/dist/lib/streaming/binary-chunk-reader.js.map +1 -0
- package/dist/lib/streaming/binary-reader.js +1 -0
- package/dist/lib/streaming/binary-reader.js.map +1 -0
- package/dist/lib/streaming/zip-batch-iterators.js +1 -0
- package/dist/lib/streaming/zip-batch-iterators.js.map +1 -0
- package/dist/shapefile-loader.d.ts +8 -2
- package/dist/shapefile-loader.d.ts.map +1 -1
- package/dist/shapefile-loader.js +2 -1
- package/dist/shapefile-loader.js.map +1 -0
- package/dist/shp-loader.d.ts +3 -3
- package/dist/shp-loader.d.ts.map +1 -1
- package/dist/shp-loader.js +2 -1
- package/dist/shp-loader.js.map +1 -0
- package/dist/shp-worker.js +227 -201
- package/dist/workers/dbf-worker.js +1 -0
- package/dist/workers/dbf-worker.js.map +1 -0
- package/dist/workers/shp-worker.js +1 -0
- package/dist/workers/shp-worker.js.map +1 -0
- package/package.json +12 -6
- package/src/dbf-arrow-loader.ts +8 -3
- package/src/dbf-loader.ts +9 -3
- package/src/lib/parsers/parse-dbf-to-arrow.ts +5 -2
- package/src/lib/parsers/parse-dbf.ts +5 -2
- package/src/lib/parsers/parse-shapefile.ts +23 -10
- package/src/lib/parsers/parse-shp.ts +5 -2
- package/src/lib/parsers/types.ts +11 -6
- package/src/shapefile-loader.ts +15 -8
- package/src/shp-loader.ts +6 -4
package/dist/shp-worker.js
CHANGED
|
@@ -1,5 +1,230 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
+
// ../worker-utils/src/lib/node/worker_threads-browser.ts
|
|
4
|
+
var parentPort = null;
|
|
5
|
+
|
|
6
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
7
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
8
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
9
|
+
if (!object) {
|
|
10
|
+
} else if (isTransferable(object)) {
|
|
11
|
+
transfersSet.add(object);
|
|
12
|
+
} else if (isTransferable(object.buffer)) {
|
|
13
|
+
transfersSet.add(object.buffer);
|
|
14
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
15
|
+
} else if (recursive && typeof object === "object") {
|
|
16
|
+
for (const key in object) {
|
|
17
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
21
|
+
}
|
|
22
|
+
function isTransferable(object) {
|
|
23
|
+
if (!object) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (object instanceof ArrayBuffer) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ../worker-utils/src/lib/worker-farm/worker-body.ts
|
|
42
|
+
async function getParentPort() {
|
|
43
|
+
return parentPort;
|
|
44
|
+
}
|
|
45
|
+
var onMessageWrapperMap = /* @__PURE__ */ new Map();
|
|
46
|
+
var WorkerBody = class {
|
|
47
|
+
/** Check that we are actually in a worker thread */
|
|
48
|
+
static async inWorkerThread() {
|
|
49
|
+
return typeof self !== "undefined" || Boolean(await getParentPort());
|
|
50
|
+
}
|
|
51
|
+
/*
|
|
52
|
+
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any
|
|
53
|
+
*/
|
|
54
|
+
static set onmessage(onMessage) {
|
|
55
|
+
async function handleMessage(message) {
|
|
56
|
+
const parentPort2 = await getParentPort();
|
|
57
|
+
const { type, payload } = parentPort2 ? message : message.data;
|
|
58
|
+
onMessage(type, payload);
|
|
59
|
+
}
|
|
60
|
+
getParentPort().then((parentPort2) => {
|
|
61
|
+
if (parentPort2) {
|
|
62
|
+
parentPort2.on("message", (message) => {
|
|
63
|
+
handleMessage(message);
|
|
64
|
+
});
|
|
65
|
+
parentPort2.on("exit", () => console.debug("Node worker closing"));
|
|
66
|
+
} else {
|
|
67
|
+
globalThis.onmessage = handleMessage;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
static async addEventListener(onMessage) {
|
|
72
|
+
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
73
|
+
if (!onMessageWrapper) {
|
|
74
|
+
onMessageWrapper = async (message) => {
|
|
75
|
+
if (!isKnownMessage(message)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const parentPort3 = await getParentPort();
|
|
79
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
80
|
+
onMessage(type, payload);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const parentPort2 = await getParentPort();
|
|
84
|
+
if (parentPort2) {
|
|
85
|
+
console.error("not implemented");
|
|
86
|
+
} else {
|
|
87
|
+
globalThis.addEventListener("message", onMessageWrapper);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
static async removeEventListener(onMessage) {
|
|
91
|
+
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
92
|
+
onMessageWrapperMap.delete(onMessage);
|
|
93
|
+
const parentPort2 = await getParentPort();
|
|
94
|
+
if (parentPort2) {
|
|
95
|
+
console.error("not implemented");
|
|
96
|
+
} else {
|
|
97
|
+
globalThis.removeEventListener("message", onMessageWrapper);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Send a message from a worker to creating thread (main thread)
|
|
102
|
+
* @param type
|
|
103
|
+
* @param payload
|
|
104
|
+
*/
|
|
105
|
+
static async postMessage(type, payload) {
|
|
106
|
+
const data = { source: "loaders.gl", type, payload };
|
|
107
|
+
const transferList = getTransferList(payload);
|
|
108
|
+
const parentPort2 = await getParentPort();
|
|
109
|
+
if (parentPort2) {
|
|
110
|
+
parentPort2.postMessage(data, transferList);
|
|
111
|
+
} else {
|
|
112
|
+
globalThis.postMessage(data, transferList);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
function isKnownMessage(message) {
|
|
117
|
+
const { type, data } = message;
|
|
118
|
+
return type === "message" && data && typeof data.source === "string" && data.source.startsWith("loaders.gl");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
|
|
122
|
+
var requestId = 0;
|
|
123
|
+
async function createLoaderWorker(loader) {
|
|
124
|
+
if (!await WorkerBody.inWorkerThread()) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
WorkerBody.onmessage = async (type, payload) => {
|
|
128
|
+
switch (type) {
|
|
129
|
+
case "process":
|
|
130
|
+
try {
|
|
131
|
+
const { input, options = {}, context = {} } = payload;
|
|
132
|
+
const result = await parseData({
|
|
133
|
+
loader,
|
|
134
|
+
arrayBuffer: input,
|
|
135
|
+
options,
|
|
136
|
+
// @ts-expect-error fetch missing
|
|
137
|
+
context: {
|
|
138
|
+
...context,
|
|
139
|
+
_parse: parseOnMainThread
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
WorkerBody.postMessage("done", { result });
|
|
143
|
+
} catch (error) {
|
|
144
|
+
const message = error instanceof Error ? error.message : "";
|
|
145
|
+
WorkerBody.postMessage("error", { error: message });
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function parseOnMainThread(arrayBuffer, loader, options, context) {
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
const id = requestId++;
|
|
155
|
+
const onMessage = (type, payload2) => {
|
|
156
|
+
if (payload2.id !== id) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
switch (type) {
|
|
160
|
+
case "done":
|
|
161
|
+
WorkerBody.removeEventListener(onMessage);
|
|
162
|
+
resolve(payload2.result);
|
|
163
|
+
break;
|
|
164
|
+
case "error":
|
|
165
|
+
WorkerBody.removeEventListener(onMessage);
|
|
166
|
+
reject(payload2.error);
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
WorkerBody.addEventListener(onMessage);
|
|
172
|
+
const payload = { id, input: arrayBuffer, options };
|
|
173
|
+
WorkerBody.postMessage("process", payload);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
async function parseData({
|
|
177
|
+
loader,
|
|
178
|
+
arrayBuffer,
|
|
179
|
+
options,
|
|
180
|
+
context
|
|
181
|
+
}) {
|
|
182
|
+
let data;
|
|
183
|
+
let parser;
|
|
184
|
+
if (loader.parseSync || loader.parse) {
|
|
185
|
+
data = arrayBuffer;
|
|
186
|
+
parser = loader.parseSync || loader.parse;
|
|
187
|
+
} else if (loader.parseTextSync) {
|
|
188
|
+
const textDecoder = new TextDecoder();
|
|
189
|
+
data = textDecoder.decode(arrayBuffer);
|
|
190
|
+
parser = loader.parseTextSync;
|
|
191
|
+
} else {
|
|
192
|
+
throw new Error(`Could not load data with ${loader.name} loader`);
|
|
193
|
+
}
|
|
194
|
+
options = {
|
|
195
|
+
...options,
|
|
196
|
+
modules: loader && loader.options && loader.options.modules || {},
|
|
197
|
+
core: {
|
|
198
|
+
...options.core,
|
|
199
|
+
worker: false
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
return await parser(data, { ...options }, context, loader);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
206
|
+
async function* toArrayBufferIterator(asyncIterator) {
|
|
207
|
+
for await (const chunk of asyncIterator) {
|
|
208
|
+
yield copyToArrayBuffer(chunk);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function copyToArrayBuffer(chunk) {
|
|
212
|
+
if (chunk instanceof ArrayBuffer) {
|
|
213
|
+
return chunk;
|
|
214
|
+
}
|
|
215
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
216
|
+
const { buffer, byteOffset, byteLength } = chunk;
|
|
217
|
+
return copyFromBuffer(buffer, byteOffset, byteLength);
|
|
218
|
+
}
|
|
219
|
+
return copyFromBuffer(chunk);
|
|
220
|
+
}
|
|
221
|
+
function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
222
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
223
|
+
const copy = new Uint8Array(view.length);
|
|
224
|
+
copy.set(view);
|
|
225
|
+
return copy.buffer;
|
|
226
|
+
}
|
|
227
|
+
|
|
3
228
|
// src/lib/streaming/binary-chunk-reader.ts
|
|
4
229
|
var BinaryChunkReader = class {
|
|
5
230
|
offset;
|
|
@@ -402,7 +627,7 @@
|
|
|
402
627
|
async function* parseSHPInBatches(asyncIterator, options) {
|
|
403
628
|
const parser = new SHPParser(options);
|
|
404
629
|
let headerReturned = false;
|
|
405
|
-
for await (const arrayBuffer of asyncIterator) {
|
|
630
|
+
for await (const arrayBuffer of toArrayBufferIterator(asyncIterator)) {
|
|
406
631
|
parser.write(arrayBuffer);
|
|
407
632
|
if (!headerReturned && parser.result.header) {
|
|
408
633
|
headerReturned = true;
|
|
@@ -484,7 +709,7 @@
|
|
|
484
709
|
}
|
|
485
710
|
|
|
486
711
|
// src/shp-loader.ts
|
|
487
|
-
var VERSION = true ? "4.4.0-alpha.
|
|
712
|
+
var VERSION = true ? "4.4.0-alpha.9" : "latest";
|
|
488
713
|
var SHP_MAGIC_NUMBER2 = [0, 0, 39, 10];
|
|
489
714
|
var SHPWorkerLoader = {
|
|
490
715
|
dataType: null,
|
|
@@ -512,205 +737,6 @@
|
|
|
512
737
|
parseInBatches: (arrayBufferIterator, options) => parseSHPInBatches(arrayBufferIterator, options)
|
|
513
738
|
};
|
|
514
739
|
|
|
515
|
-
// ../worker-utils/src/lib/node/worker_threads-browser.ts
|
|
516
|
-
var parentPort = null;
|
|
517
|
-
|
|
518
|
-
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
519
|
-
function getTransferList(object, recursive = true, transfers) {
|
|
520
|
-
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
521
|
-
if (!object) {
|
|
522
|
-
} else if (isTransferable(object)) {
|
|
523
|
-
transfersSet.add(object);
|
|
524
|
-
} else if (isTransferable(object.buffer)) {
|
|
525
|
-
transfersSet.add(object.buffer);
|
|
526
|
-
} else if (ArrayBuffer.isView(object)) {
|
|
527
|
-
} else if (recursive && typeof object === "object") {
|
|
528
|
-
for (const key in object) {
|
|
529
|
-
getTransferList(object[key], recursive, transfersSet);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
533
|
-
}
|
|
534
|
-
function isTransferable(object) {
|
|
535
|
-
if (!object) {
|
|
536
|
-
return false;
|
|
537
|
-
}
|
|
538
|
-
if (object instanceof ArrayBuffer) {
|
|
539
|
-
return true;
|
|
540
|
-
}
|
|
541
|
-
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
542
|
-
return true;
|
|
543
|
-
}
|
|
544
|
-
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
545
|
-
return true;
|
|
546
|
-
}
|
|
547
|
-
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
548
|
-
return true;
|
|
549
|
-
}
|
|
550
|
-
return false;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
// ../worker-utils/src/lib/worker-farm/worker-body.ts
|
|
554
|
-
async function getParentPort() {
|
|
555
|
-
return parentPort;
|
|
556
|
-
}
|
|
557
|
-
var onMessageWrapperMap = /* @__PURE__ */ new Map();
|
|
558
|
-
var WorkerBody = class {
|
|
559
|
-
/** Check that we are actually in a worker thread */
|
|
560
|
-
static async inWorkerThread() {
|
|
561
|
-
return typeof self !== "undefined" || Boolean(await getParentPort());
|
|
562
|
-
}
|
|
563
|
-
/*
|
|
564
|
-
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any
|
|
565
|
-
*/
|
|
566
|
-
static set onmessage(onMessage) {
|
|
567
|
-
async function handleMessage(message) {
|
|
568
|
-
const parentPort2 = await getParentPort();
|
|
569
|
-
const { type, payload } = parentPort2 ? message : message.data;
|
|
570
|
-
onMessage(type, payload);
|
|
571
|
-
}
|
|
572
|
-
getParentPort().then((parentPort2) => {
|
|
573
|
-
if (parentPort2) {
|
|
574
|
-
parentPort2.on("message", (message) => {
|
|
575
|
-
handleMessage(message);
|
|
576
|
-
});
|
|
577
|
-
parentPort2.on("exit", () => console.debug("Node worker closing"));
|
|
578
|
-
} else {
|
|
579
|
-
globalThis.onmessage = handleMessage;
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
static async addEventListener(onMessage) {
|
|
584
|
-
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
585
|
-
if (!onMessageWrapper) {
|
|
586
|
-
onMessageWrapper = async (message) => {
|
|
587
|
-
if (!isKnownMessage(message)) {
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
const parentPort3 = await getParentPort();
|
|
591
|
-
const { type, payload } = parentPort3 ? message : message.data;
|
|
592
|
-
onMessage(type, payload);
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
const parentPort2 = await getParentPort();
|
|
596
|
-
if (parentPort2) {
|
|
597
|
-
console.error("not implemented");
|
|
598
|
-
} else {
|
|
599
|
-
globalThis.addEventListener("message", onMessageWrapper);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
static async removeEventListener(onMessage) {
|
|
603
|
-
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
604
|
-
onMessageWrapperMap.delete(onMessage);
|
|
605
|
-
const parentPort2 = await getParentPort();
|
|
606
|
-
if (parentPort2) {
|
|
607
|
-
console.error("not implemented");
|
|
608
|
-
} else {
|
|
609
|
-
globalThis.removeEventListener("message", onMessageWrapper);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Send a message from a worker to creating thread (main thread)
|
|
614
|
-
* @param type
|
|
615
|
-
* @param payload
|
|
616
|
-
*/
|
|
617
|
-
static async postMessage(type, payload) {
|
|
618
|
-
const data = { source: "loaders.gl", type, payload };
|
|
619
|
-
const transferList = getTransferList(payload);
|
|
620
|
-
const parentPort2 = await getParentPort();
|
|
621
|
-
if (parentPort2) {
|
|
622
|
-
parentPort2.postMessage(data, transferList);
|
|
623
|
-
} else {
|
|
624
|
-
globalThis.postMessage(data, transferList);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
function isKnownMessage(message) {
|
|
629
|
-
const { type, data } = message;
|
|
630
|
-
return type === "message" && data && typeof data.source === "string" && data.source.startsWith("loaders.gl");
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
// ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
|
|
634
|
-
var requestId = 0;
|
|
635
|
-
async function createLoaderWorker(loader) {
|
|
636
|
-
if (!await WorkerBody.inWorkerThread()) {
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
WorkerBody.onmessage = async (type, payload) => {
|
|
640
|
-
switch (type) {
|
|
641
|
-
case "process":
|
|
642
|
-
try {
|
|
643
|
-
const { input, options = {}, context = {} } = payload;
|
|
644
|
-
const result = await parseData({
|
|
645
|
-
loader,
|
|
646
|
-
arrayBuffer: input,
|
|
647
|
-
options,
|
|
648
|
-
// @ts-expect-error fetch missing
|
|
649
|
-
context: {
|
|
650
|
-
...context,
|
|
651
|
-
_parse: parseOnMainThread
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
WorkerBody.postMessage("done", { result });
|
|
655
|
-
} catch (error) {
|
|
656
|
-
const message = error instanceof Error ? error.message : "";
|
|
657
|
-
WorkerBody.postMessage("error", { error: message });
|
|
658
|
-
}
|
|
659
|
-
break;
|
|
660
|
-
default:
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
function parseOnMainThread(arrayBuffer, loader, options, context) {
|
|
665
|
-
return new Promise((resolve, reject) => {
|
|
666
|
-
const id = requestId++;
|
|
667
|
-
const onMessage = (type, payload2) => {
|
|
668
|
-
if (payload2.id !== id) {
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
switch (type) {
|
|
672
|
-
case "done":
|
|
673
|
-
WorkerBody.removeEventListener(onMessage);
|
|
674
|
-
resolve(payload2.result);
|
|
675
|
-
break;
|
|
676
|
-
case "error":
|
|
677
|
-
WorkerBody.removeEventListener(onMessage);
|
|
678
|
-
reject(payload2.error);
|
|
679
|
-
break;
|
|
680
|
-
default:
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
WorkerBody.addEventListener(onMessage);
|
|
684
|
-
const payload = { id, input: arrayBuffer, options };
|
|
685
|
-
WorkerBody.postMessage("process", payload);
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
async function parseData({
|
|
689
|
-
loader,
|
|
690
|
-
arrayBuffer,
|
|
691
|
-
options,
|
|
692
|
-
context
|
|
693
|
-
}) {
|
|
694
|
-
let data;
|
|
695
|
-
let parser;
|
|
696
|
-
if (loader.parseSync || loader.parse) {
|
|
697
|
-
data = arrayBuffer;
|
|
698
|
-
parser = loader.parseSync || loader.parse;
|
|
699
|
-
} else if (loader.parseTextSync) {
|
|
700
|
-
const textDecoder = new TextDecoder();
|
|
701
|
-
data = textDecoder.decode(arrayBuffer);
|
|
702
|
-
parser = loader.parseTextSync;
|
|
703
|
-
} else {
|
|
704
|
-
throw new Error(`Could not load data with ${loader.name} loader`);
|
|
705
|
-
}
|
|
706
|
-
options = {
|
|
707
|
-
...options,
|
|
708
|
-
modules: loader && loader.options && loader.options.modules || {},
|
|
709
|
-
worker: false
|
|
710
|
-
};
|
|
711
|
-
return await parser(data, { ...options }, context, loader);
|
|
712
|
-
}
|
|
713
|
-
|
|
714
740
|
// src/workers/shp-worker.ts
|
|
715
741
|
createLoaderWorker(SHPLoader);
|
|
716
742
|
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbf-worker.js","sourceRoot":"","sources":["../../src/workers/dbf-worker.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,SAAS,EAAC,yBAAsB;AACxC,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAE5D,kBAAkB,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shp-worker.js","sourceRoot":"","sources":["../../src/workers/shp-worker.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,SAAS,EAAC,yBAAsB;AACxC,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAE5D,kBAAkB,CAAC,SAAS,CAAC,CAAC"}
|
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.4.0-alpha.
|
|
4
|
+
"version": "4.4.0-alpha.9",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -26,6 +26,12 @@
|
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
27
|
"import": "./dist/index.js",
|
|
28
28
|
"require": "./dist/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./shp-worker.js": {
|
|
31
|
+
"import": "./dist/shp-worker.js"
|
|
32
|
+
},
|
|
33
|
+
"./dbf-worker.js": {
|
|
34
|
+
"import": "./dist/dbf-worker.js"
|
|
29
35
|
}
|
|
30
36
|
},
|
|
31
37
|
"sideEffects": false,
|
|
@@ -45,13 +51,13 @@
|
|
|
45
51
|
"build-worker-dbf": "esbuild src/workers/dbf-worker.ts --bundle --outfile=dist/dbf-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
46
52
|
},
|
|
47
53
|
"dependencies": {
|
|
48
|
-
"@loaders.gl/gis": "4.4.0-alpha.
|
|
49
|
-
"@loaders.gl/loader-utils": "4.4.0-alpha.
|
|
50
|
-
"@loaders.gl/schema": "4.4.0-alpha.
|
|
54
|
+
"@loaders.gl/gis": "4.4.0-alpha.9",
|
|
55
|
+
"@loaders.gl/loader-utils": "4.4.0-alpha.9",
|
|
56
|
+
"@loaders.gl/schema": "4.4.0-alpha.9",
|
|
51
57
|
"@math.gl/proj4": "^4.1.0"
|
|
52
58
|
},
|
|
53
59
|
"peerDependencies": {
|
|
54
|
-
"@loaders.gl/core": "4.4.0-alpha.
|
|
60
|
+
"@loaders.gl/core": "4.4.0-alpha.1"
|
|
55
61
|
},
|
|
56
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "e9e6710379718c7663e97eba868c76e15de4cb84"
|
|
57
63
|
}
|
package/src/dbf-arrow-loader.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {Loader, LoaderWithParser,
|
|
5
|
+
import type {Loader, LoaderWithParser, StrictLoaderOptions} from '@loaders.gl/loader-utils';
|
|
6
6
|
import type {ArrowTable, ArrowTableBatch} from '@loaders.gl/schema';
|
|
7
7
|
import {parseDBF, parseDBFInBatches} from './lib/parsers/parse-dbf-to-arrow';
|
|
8
8
|
import {DBFFormat} from './dbf-format';
|
|
@@ -11,7 +11,7 @@ import {DBFFormat} from './dbf-format';
|
|
|
11
11
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
12
12
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
13
13
|
|
|
14
|
-
export type DBFLoaderOptions =
|
|
14
|
+
export type DBFLoaderOptions = StrictLoaderOptions & {
|
|
15
15
|
dbf?: {
|
|
16
16
|
encoding?: string;
|
|
17
17
|
/** Override the URL to the worker bundle (by default loads from unpkg.com) */
|
|
@@ -40,7 +40,12 @@ export const DBFArrowLoader = {
|
|
|
40
40
|
...DBFArrowWorkerLoader,
|
|
41
41
|
parse: async (arrayBuffer, options) => parseDBF(arrayBuffer, options),
|
|
42
42
|
parseSync: parseDBF,
|
|
43
|
-
parseInBatches(
|
|
43
|
+
parseInBatches(
|
|
44
|
+
arrayBufferIterator:
|
|
45
|
+
| AsyncIterable<ArrayBufferLike | ArrayBufferView>
|
|
46
|
+
| Iterable<ArrayBufferLike | ArrayBufferView>,
|
|
47
|
+
options
|
|
48
|
+
) {
|
|
44
49
|
return parseDBFInBatches(arrayBufferIterator, options);
|
|
45
50
|
}
|
|
46
51
|
} as const satisfies LoaderWithParser<ArrowTable, ArrowTableBatch, DBFLoaderOptions>;
|
package/src/dbf-loader.ts
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {Loader, LoaderWithParser,
|
|
5
|
+
import type {Loader, LoaderWithParser, StrictLoaderOptions} from '@loaders.gl/loader-utils';
|
|
6
6
|
import {parseDBF, parseDBFInBatches} from './lib/parsers/parse-dbf';
|
|
7
7
|
|
|
8
8
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
9
9
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
10
10
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
11
11
|
|
|
12
|
-
export type DBFLoaderOptions =
|
|
12
|
+
export type DBFLoaderOptions = StrictLoaderOptions & {
|
|
13
13
|
dbf?: {
|
|
14
14
|
encoding?: string;
|
|
15
|
+
shape?: 'rows' | 'table' | 'object-row-table';
|
|
15
16
|
/** Override the URL to the worker bundle (by default loads from unpkg.com) */
|
|
16
17
|
workerUrl?: string;
|
|
17
18
|
};
|
|
@@ -44,7 +45,12 @@ export const DBFLoader: LoaderWithParser = {
|
|
|
44
45
|
...DBFWorkerLoader,
|
|
45
46
|
parse: async (arrayBuffer, options) => parseDBF(arrayBuffer, options),
|
|
46
47
|
parseSync: parseDBF,
|
|
47
|
-
parseInBatches(
|
|
48
|
+
parseInBatches(
|
|
49
|
+
arrayBufferIterator:
|
|
50
|
+
| AsyncIterable<ArrayBufferLike | ArrayBufferView>
|
|
51
|
+
| Iterable<ArrayBufferLike | ArrayBufferView>,
|
|
52
|
+
options
|
|
53
|
+
) {
|
|
48
54
|
return parseDBFInBatches(arrayBufferIterator, options);
|
|
49
55
|
}
|
|
50
56
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {Schema, Field, ArrowTable, ArrowTableBatch} from '@loaders.gl/schema';
|
|
6
|
+
import {toArrayBufferIterator} from '@loaders.gl/loader-utils';
|
|
6
7
|
import {ArrowTableBuilder} from '@loaders.gl/schema-utils';
|
|
7
8
|
import {BinaryChunkReader} from '../streaming/binary-chunk-reader';
|
|
8
9
|
import {DBFLoaderOptions, DBFHeader, DBFField} from './types';
|
|
@@ -87,14 +88,16 @@ export function parseDBF(arrayBuffer: ArrayBuffer, options: DBFLoaderOptions = {
|
|
|
87
88
|
* @param options
|
|
88
89
|
*/
|
|
89
90
|
export async function* parseDBFInBatches(
|
|
90
|
-
asyncIterator:
|
|
91
|
+
asyncIterator:
|
|
92
|
+
| AsyncIterable<ArrayBufferLike | ArrayBufferView>
|
|
93
|
+
| Iterable<ArrayBufferLike | ArrayBufferView>,
|
|
91
94
|
options: DBFLoaderOptions = {}
|
|
92
95
|
): AsyncIterable<ArrowTableBatch> {
|
|
93
96
|
const {encoding = 'latin1'} = options.dbf || {};
|
|
94
97
|
|
|
95
98
|
const parser = new DBFParser({encoding});
|
|
96
99
|
let headerReturned = false;
|
|
97
|
-
for await (const arrayBuffer of asyncIterator) {
|
|
100
|
+
for await (const arrayBuffer of toArrayBufferIterator(asyncIterator)) {
|
|
98
101
|
parser.write(arrayBuffer);
|
|
99
102
|
if (!headerReturned && parser.result.dbfHeader) {
|
|
100
103
|
headerReturned = true;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {Field, ObjectRowTable} from '@loaders.gl/schema';
|
|
6
|
+
import {toArrayBufferIterator} from '@loaders.gl/loader-utils';
|
|
6
7
|
import {BinaryChunkReader} from '../streaming/binary-chunk-reader';
|
|
7
8
|
import {
|
|
8
9
|
DBFLoaderOptions,
|
|
@@ -99,14 +100,16 @@ export function parseDBF(
|
|
|
99
100
|
* @param options
|
|
100
101
|
*/
|
|
101
102
|
export async function* parseDBFInBatches(
|
|
102
|
-
asyncIterator:
|
|
103
|
+
asyncIterator:
|
|
104
|
+
| AsyncIterable<ArrayBufferLike | ArrayBufferView>
|
|
105
|
+
| Iterable<ArrayBufferLike | ArrayBufferView>,
|
|
103
106
|
options: DBFLoaderOptions = {}
|
|
104
107
|
): AsyncIterable<DBFHeader | DBFRowsOutput | DBFTableOutput> {
|
|
105
108
|
const {encoding = 'latin1'} = options.dbf || {};
|
|
106
109
|
|
|
107
110
|
const parser = new DBFParser({encoding});
|
|
108
111
|
let headerReturned = false;
|
|
109
|
-
for await (const arrayBuffer of asyncIterator) {
|
|
112
|
+
for await (const arrayBuffer of toArrayBufferIterator(asyncIterator)) {
|
|
110
113
|
parser.write(arrayBuffer);
|
|
111
114
|
if (!headerReturned && parser.result.dbfHeader) {
|
|
112
115
|
headerReturned = true;
|