@loaders.gl/shapefile 3.1.8 → 3.2.0-alpha.3
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 +62 -23
- package/dist/dist.min.js +23 -10
- package/dist/es5/dbf-loader.js +1 -1
- package/dist/es5/dbf-loader.js.map +1 -1
- package/dist/es5/lib/parsers/parse-dbf.js +69 -53
- package/dist/es5/lib/parsers/parse-dbf.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp-geometry.js +2 -1
- package/dist/es5/lib/parsers/parse-shp-geometry.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp.js +10 -2
- package/dist/es5/lib/parsers/parse-shp.js.map +1 -1
- 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.map +1 -1
- package/dist/es5/lib/streaming/zip-batch-iterators.js.map +1 -1
- package/dist/es5/shapefile-loader.js +1 -1
- package/dist/es5/shapefile-loader.js.map +1 -1
- package/dist/es5/shp-loader.js +1 -1
- package/dist/es5/shp-loader.js.map +1 -1
- package/dist/esm/dbf-loader.js +1 -1
- package/dist/esm/dbf-loader.js.map +1 -1
- package/dist/esm/lib/parsers/parse-dbf.js +20 -9
- package/dist/esm/lib/parsers/parse-dbf.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shp-geometry.js +1 -1
- package/dist/esm/lib/parsers/parse-shp-geometry.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shp.js +10 -2
- package/dist/esm/lib/parsers/parse-shp.js.map +1 -1
- 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.map +1 -1
- package/dist/esm/lib/streaming/zip-batch-iterators.js.map +1 -1
- package/dist/esm/shapefile-loader.js +1 -1
- package/dist/esm/shapefile-loader.js.map +1 -1
- package/dist/esm/shp-loader.js +1 -1
- package/dist/esm/shp-loader.js.map +1 -1
- 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 +15 -8
- 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 +0 -4
- 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 +1 -1
- package/dist/lib/parsers/parse-shp.d.ts.map +1 -1
- package/dist/lib/parsers/parse-shp.js +10 -2
- package/dist/lib/parsers/types.d.ts +63 -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/shp-worker.js +57 -19
- package/package.json +5 -5
- package/src/lib/parsers/parse-dbf.ts +37 -58
- 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 +24 -10
- package/src/lib/parsers/types.ts +74 -0
- package/src/lib/streaming/binary-chunk-reader.ts +5 -1
- package/src/lib/streaming/zip-batch-iterators.ts +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {LoaderOptions} from '@loaders.gl/loader-utils';
|
|
2
1
|
import type {BinaryGeometry} from '@loaders.gl/schema';
|
|
3
2
|
import BinaryChunkReader from '../streaming/binary-chunk-reader';
|
|
4
|
-
import {parseSHPHeader} from './parse-shp-header';
|
|
3
|
+
import {parseSHPHeader, SHPHeader} from './parse-shp-header';
|
|
5
4
|
import {parseRecord} from './parse-shp-geometry';
|
|
5
|
+
import {SHPLoaderOptions} from './types';
|
|
6
6
|
|
|
7
7
|
const LITTLE_ENDIAN = true;
|
|
8
8
|
const BIG_ENDIAN = false;
|
|
@@ -20,20 +20,34 @@ const STATE = {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
type SHPResult = {
|
|
23
|
-
geometries: [];
|
|
24
|
-
header?:
|
|
23
|
+
geometries: (BinaryGeometry | null)[];
|
|
24
|
+
header?: SHPHeader;
|
|
25
25
|
error?: string;
|
|
26
|
+
progress: {
|
|
27
|
+
bytesUsed: number;
|
|
28
|
+
bytesTotal: number;
|
|
29
|
+
rows: number;
|
|
30
|
+
};
|
|
31
|
+
currentIndex: number;
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
class SHPParser {
|
|
29
|
-
options?:
|
|
35
|
+
options?: SHPLoaderOptions = {};
|
|
30
36
|
binaryReader = new BinaryChunkReader({maxRewindBytes: SHP_RECORD_HEADER_SIZE});
|
|
31
37
|
state = STATE.EXPECTING_HEADER;
|
|
32
38
|
result: SHPResult = {
|
|
33
|
-
geometries: []
|
|
39
|
+
geometries: [],
|
|
40
|
+
// Initialize with number values to make TS happy
|
|
41
|
+
// These are initialized for real in STATE.EXPECTING_HEADER
|
|
42
|
+
progress: {
|
|
43
|
+
bytesTotal: NaN,
|
|
44
|
+
bytesUsed: NaN,
|
|
45
|
+
rows: NaN
|
|
46
|
+
},
|
|
47
|
+
currentIndex: NaN
|
|
34
48
|
};
|
|
35
49
|
|
|
36
|
-
constructor(options?:
|
|
50
|
+
constructor(options?: SHPLoaderOptions) {
|
|
37
51
|
this.options = options;
|
|
38
52
|
}
|
|
39
53
|
|
|
@@ -109,9 +123,9 @@ export async function* parseSHPInBatches(
|
|
|
109
123
|
/* eslint-disable complexity, max-depth */
|
|
110
124
|
function parseState(
|
|
111
125
|
state: number,
|
|
112
|
-
result:
|
|
126
|
+
result: SHPResult,
|
|
113
127
|
binaryReader: BinaryChunkReader,
|
|
114
|
-
options
|
|
128
|
+
options?: SHPLoaderOptions
|
|
115
129
|
): number {
|
|
116
130
|
// eslint-disable-next-line no-constant-condition
|
|
117
131
|
while (true) {
|
|
@@ -157,7 +171,7 @@ function parseState(
|
|
|
157
171
|
|
|
158
172
|
const invalidRecord =
|
|
159
173
|
recordHeader.byteLength < 4 ||
|
|
160
|
-
recordHeader.type !== result.header
|
|
174
|
+
recordHeader.type !== result.header?.type ||
|
|
161
175
|
recordHeader.recordNumber !== result.currentIndex;
|
|
162
176
|
|
|
163
177
|
// All records must have at least four bytes (for the record shape type)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {Schema, ObjectRowTable} from '@loaders.gl/schema';
|
|
2
|
+
import type {LoaderOptions} from '@loaders.gl/loader-utils';
|
|
3
|
+
|
|
4
|
+
export type SHPLoaderOptions = LoaderOptions & {
|
|
5
|
+
shp?: {
|
|
6
|
+
_maxDimensions?: number;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type DBFLoaderOptions = LoaderOptions & {
|
|
11
|
+
dbf?: {
|
|
12
|
+
encoding?: string;
|
|
13
|
+
shape?: 'rows' | 'table' | 'object-row-table';
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ShapefileLoaderOptions = LoaderOptions &
|
|
18
|
+
SHPLoaderOptions & {
|
|
19
|
+
shapefile?: {
|
|
20
|
+
shape?: 'geojson';
|
|
21
|
+
};
|
|
22
|
+
gis?: {
|
|
23
|
+
reproject?: boolean;
|
|
24
|
+
_targetCrs?: string;
|
|
25
|
+
/** @deprecated. Use options.shapefile.shape */
|
|
26
|
+
format?: 'geojson';
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type DBFRowsOutput = ObjectRowTable['data'];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* DBF Table output. Deprecated in favor of ObjectRowTable
|
|
34
|
+
* @deprecated
|
|
35
|
+
*/
|
|
36
|
+
export interface DBFTableOutput {
|
|
37
|
+
schema?: Schema;
|
|
38
|
+
rows: DBFRowsOutput;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type DBFHeader = {
|
|
42
|
+
// Last updated date
|
|
43
|
+
year: number;
|
|
44
|
+
month: number;
|
|
45
|
+
day: number;
|
|
46
|
+
// Number of records in data file
|
|
47
|
+
nRecords: number;
|
|
48
|
+
// Length of header in bytes
|
|
49
|
+
headerLength: number;
|
|
50
|
+
// Length of each record
|
|
51
|
+
recordLength: number;
|
|
52
|
+
// Not sure if this is usually set
|
|
53
|
+
languageDriver: number;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type DBFField = {
|
|
57
|
+
name: string;
|
|
58
|
+
dataType: string;
|
|
59
|
+
fieldLength: number;
|
|
60
|
+
decimal: number;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type DBFResult = {
|
|
64
|
+
data: {[key: string]: any}[];
|
|
65
|
+
schema?: Schema;
|
|
66
|
+
error?: string;
|
|
67
|
+
dbfHeader?: DBFHeader;
|
|
68
|
+
dbfFields?: DBFField[];
|
|
69
|
+
progress?: {
|
|
70
|
+
bytesUsed: number;
|
|
71
|
+
rowsTotal: number;
|
|
72
|
+
rows: number;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
type BinaryChunkReaderOptions = {
|
|
2
|
+
maxRewindBytes: number;
|
|
3
|
+
};
|
|
4
|
+
|
|
1
5
|
export default class BinaryChunkReader {
|
|
2
6
|
offset: number;
|
|
3
7
|
arrayBuffers: ArrayBuffer[];
|
|
4
8
|
ended: boolean;
|
|
5
9
|
maxRewindBytes: number;
|
|
6
10
|
|
|
7
|
-
constructor(options?:
|
|
11
|
+
constructor(options?: BinaryChunkReaderOptions) {
|
|
8
12
|
const {maxRewindBytes = 0} = options || {};
|
|
9
13
|
|
|
10
14
|
/** current global offset into current array buffer*/
|
|
@@ -8,8 +8,8 @@ export async function* zipBatchIterators(
|
|
|
8
8
|
iterator1: AsyncIterator<any[]>,
|
|
9
9
|
iterator2: AsyncIterator<any[]>
|
|
10
10
|
): AsyncGenerator<number[][], void, unknown> {
|
|
11
|
-
let batch1 = [];
|
|
12
|
-
let batch2 = [];
|
|
11
|
+
let batch1: number[] = [];
|
|
12
|
+
let batch2: number[] = [];
|
|
13
13
|
let iterator1Done: boolean = false;
|
|
14
14
|
let iterator2Done: boolean = false;
|
|
15
15
|
|