@loaders.gl/shapefile 4.4.0-alpha.2 → 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.
Files changed (72) hide show
  1. package/dist/dbf-arrow-loader.d.ts +3 -3
  2. package/dist/dbf-arrow-loader.d.ts.map +1 -1
  3. package/dist/dbf-arrow-loader.js +2 -1
  4. package/dist/dbf-arrow-loader.js.map +1 -0
  5. package/dist/dbf-format.js +1 -0
  6. package/dist/dbf-format.js.map +1 -0
  7. package/dist/dbf-loader.d.ts +3 -2
  8. package/dist/dbf-loader.d.ts.map +1 -1
  9. package/dist/dbf-loader.js +2 -1
  10. package/dist/dbf-loader.js.map +1 -0
  11. package/dist/dbf-worker.js +227 -201
  12. package/dist/dist.dev.js +51 -22
  13. package/dist/dist.min.js +5 -5
  14. package/dist/index.cjs +29 -13
  15. package/dist/index.cjs.map +4 -4
  16. package/dist/index.js +1 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/lib/parsers/parse-dbf-to-arrow.d.ts +1 -1
  19. package/dist/lib/parsers/parse-dbf-to-arrow.d.ts.map +1 -1
  20. package/dist/lib/parsers/parse-dbf-to-arrow.js +3 -1
  21. package/dist/lib/parsers/parse-dbf-to-arrow.js.map +1 -0
  22. package/dist/lib/parsers/parse-dbf.d.ts +1 -1
  23. package/dist/lib/parsers/parse-dbf.d.ts.map +1 -1
  24. package/dist/lib/parsers/parse-dbf.js +3 -1
  25. package/dist/lib/parsers/parse-dbf.js.map +1 -0
  26. package/dist/lib/parsers/parse-shapefile.d.ts +1 -1
  27. package/dist/lib/parsers/parse-shapefile.d.ts.map +1 -1
  28. package/dist/lib/parsers/parse-shapefile.js +16 -4
  29. package/dist/lib/parsers/parse-shapefile.js.map +1 -0
  30. package/dist/lib/parsers/parse-shp-geometry.js +1 -0
  31. package/dist/lib/parsers/parse-shp-geometry.js.map +1 -0
  32. package/dist/lib/parsers/parse-shp-header.js +1 -0
  33. package/dist/lib/parsers/parse-shp-header.js.map +1 -0
  34. package/dist/lib/parsers/parse-shp.d.ts +1 -1
  35. package/dist/lib/parsers/parse-shp.d.ts.map +1 -1
  36. package/dist/lib/parsers/parse-shp.js +3 -1
  37. package/dist/lib/parsers/parse-shp.js.map +1 -0
  38. package/dist/lib/parsers/parse-shx.js +1 -0
  39. package/dist/lib/parsers/parse-shx.js.map +1 -0
  40. package/dist/lib/parsers/types.d.ts +9 -5
  41. package/dist/lib/parsers/types.d.ts.map +1 -1
  42. package/dist/lib/parsers/types.js +1 -0
  43. package/dist/lib/parsers/types.js.map +1 -0
  44. package/dist/lib/streaming/binary-chunk-reader.js +1 -0
  45. package/dist/lib/streaming/binary-chunk-reader.js.map +1 -0
  46. package/dist/lib/streaming/binary-reader.js +1 -0
  47. package/dist/lib/streaming/binary-reader.js.map +1 -0
  48. package/dist/lib/streaming/zip-batch-iterators.js +1 -0
  49. package/dist/lib/streaming/zip-batch-iterators.js.map +1 -0
  50. package/dist/shapefile-loader.d.ts +8 -2
  51. package/dist/shapefile-loader.d.ts.map +1 -1
  52. package/dist/shapefile-loader.js +2 -1
  53. package/dist/shapefile-loader.js.map +1 -0
  54. package/dist/shp-loader.d.ts +3 -3
  55. package/dist/shp-loader.d.ts.map +1 -1
  56. package/dist/shp-loader.js +2 -1
  57. package/dist/shp-loader.js.map +1 -0
  58. package/dist/shp-worker.js +227 -201
  59. package/dist/workers/dbf-worker.js +1 -0
  60. package/dist/workers/dbf-worker.js.map +1 -0
  61. package/dist/workers/shp-worker.js +1 -0
  62. package/dist/workers/shp-worker.js.map +1 -0
  63. package/package.json +11 -5
  64. package/src/dbf-arrow-loader.ts +8 -3
  65. package/src/dbf-loader.ts +9 -3
  66. package/src/lib/parsers/parse-dbf-to-arrow.ts +5 -2
  67. package/src/lib/parsers/parse-dbf.ts +5 -2
  68. package/src/lib/parsers/parse-shapefile.ts +23 -10
  69. package/src/lib/parsers/parse-shp.ts +5 -2
  70. package/src/lib/parsers/types.ts +11 -6
  71. package/src/shapefile-loader.ts +15 -8
  72. package/src/shp-loader.ts +6 -4
@@ -3,7 +3,12 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  // import type {Feature} from '@loaders.gl/gis';
6
- import {LoaderContext, parseInBatchesFromContext, parseFromContext} from '@loaders.gl/loader-utils';
6
+ import {
7
+ LoaderContext,
8
+ parseInBatchesFromContext,
9
+ parseFromContext,
10
+ toArrayBufferIterator
11
+ } from '@loaders.gl/loader-utils';
7
12
  import {convertBinaryGeometryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';
8
13
  import type {
9
14
  BinaryGeometry,
@@ -34,7 +39,9 @@ interface ShapefileOutput {
34
39
  */
35
40
  // eslint-disable-next-line max-statements, complexity
36
41
  export async function* parseShapefileInBatches(
37
- asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
42
+ asyncIterator:
43
+ | AsyncIterable<ArrayBufferLike | ArrayBufferView>
44
+ | Iterable<ArrayBufferLike | ArrayBufferView>,
38
45
  options?: ShapefileLoaderOptions,
39
46
  context?: LoaderContext
40
47
  ): AsyncIterable<ShapefileOutput> {
@@ -43,7 +50,7 @@ export async function* parseShapefileInBatches(
43
50
 
44
51
  // parse geometries
45
52
  const shapeIterable = await parseInBatchesFromContext(
46
- asyncIterator,
53
+ toArrayBufferIterator(asyncIterator),
47
54
  SHPLoader,
48
55
  options,
49
56
  context!
@@ -61,7 +68,10 @@ export async function* parseShapefileInBatches(
61
68
  DBFLoader,
62
69
  {
63
70
  ...options,
64
- dbf: {encoding: cpg || 'latin1'}
71
+ dbf: {
72
+ ...options?.dbf,
73
+ encoding: cpg || 'latin1'
74
+ }
65
75
  },
66
76
  context!
67
77
  );
@@ -147,12 +157,15 @@ export async function parseShapefile(
147
157
 
148
158
  const dbfResponse = await context?.fetch(replaceExtension(context?.url!, 'dbf'));
149
159
  if (dbfResponse?.ok) {
150
- propertyTable = await parseFromContext(
151
- dbfResponse as any,
152
- DBFLoader,
153
- {dbf: {shape: 'object-row-table', encoding: cpg || 'latin1'}},
154
- context!
155
- );
160
+ const dbfOptions = {
161
+ ...options,
162
+ dbf: {
163
+ ...options?.dbf,
164
+ shape: 'object-row-table',
165
+ encoding: cpg || 'latin1'
166
+ }
167
+ };
168
+ propertyTable = await parseFromContext(dbfResponse as any, DBFLoader, dbfOptions, context!);
156
169
  }
157
170
 
158
171
  let features = joinProperties(geojsonGeometries, propertyTable?.data || []);
@@ -3,6 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {BinaryGeometry} from '@loaders.gl/schema';
6
+ import {toArrayBufferIterator} from '@loaders.gl/loader-utils';
6
7
  import {BinaryChunkReader} from '../streaming/binary-chunk-reader';
7
8
  import {parseSHPHeader, SHPHeader} from './parse-shp-header';
8
9
  import {parseRecord} from './parse-shp-geometry';
@@ -86,12 +87,14 @@ export function parseSHP(arrayBuffer: ArrayBuffer, options?: SHPLoaderOptions):
86
87
  * @returns
87
88
  */
88
89
  export async function* parseSHPInBatches(
89
- asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
90
+ asyncIterator:
91
+ | AsyncIterable<ArrayBufferLike | ArrayBufferView>
92
+ | Iterable<ArrayBufferLike | ArrayBufferView>,
90
93
  options?: SHPLoaderOptions
91
94
  ): AsyncGenerator<BinaryGeometry | object> {
92
95
  const parser = new SHPParser(options);
93
96
  let headerReturned = false;
94
- for await (const arrayBuffer of asyncIterator) {
97
+ for await (const arrayBuffer of toArrayBufferIterator(asyncIterator)) {
95
98
  parser.write(arrayBuffer);
96
99
  if (!headerReturned && parser.result.header) {
97
100
  headerReturned = true;
@@ -3,25 +3,30 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Schema, ObjectRowTable} from '@loaders.gl/schema';
6
- import type {LoaderOptions} from '@loaders.gl/loader-utils';
6
+ import type {StrictLoaderOptions} from '@loaders.gl/loader-utils';
7
7
 
8
- export type SHPLoaderOptions = LoaderOptions & {
8
+ export type SHPLoaderOptions = StrictLoaderOptions & {
9
9
  shp?: {
10
10
  _maxDimensions?: number;
11
+ /** Override the URL to the worker bundle (by default loads from unpkg.com) */
12
+ workerUrl?: string;
11
13
  };
12
14
  };
13
15
 
14
- export type DBFLoaderOptions = LoaderOptions & {
16
+ export type DBFLoaderOptions = StrictLoaderOptions & {
15
17
  dbf?: {
16
18
  encoding?: string;
17
19
  shape?: 'rows' | 'table' | 'object-row-table';
20
+ /** Override the URL to the worker bundle (by default loads from unpkg.com) */
21
+ workerUrl?: string;
18
22
  };
19
23
  };
20
24
 
21
- export type ShapefileLoaderOptions = LoaderOptions &
22
- SHPLoaderOptions & {
25
+ export type ShapefileLoaderOptions = StrictLoaderOptions &
26
+ SHPLoaderOptions &
27
+ DBFLoaderOptions & {
23
28
  shapefile?: {
24
- shape?: 'geojson-table';
29
+ shape?: 'geojson-table' | 'v3';
25
30
  };
26
31
  gis?: {
27
32
  reproject?: boolean;
@@ -2,22 +2,29 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
5
+ import type {StrictLoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
6
6
  import type {Batch, GeoJSONTable} from '@loaders.gl/schema';
7
- import {SHP_MAGIC_NUMBER} from './shp-loader';
7
+ import {SHP_MAGIC_NUMBER, SHPLoaderOptions} from './shp-loader';
8
8
  import {parseShapefile, parseShapefileInBatches} from './lib/parsers/parse-shapefile';
9
+ import {DBFLoaderOptions} from './dbf-loader';
9
10
 
10
11
  // __VERSION__ is injected by babel-plugin-version-inline
11
12
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
12
13
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
13
14
 
14
- export type ShapefileLoaderOptions = LoaderOptions & {
15
- shapefile?: {
16
- shape?: 'geojson-table' | 'v3';
17
- /** @deprecated Worker URLs must be specified with .dbf.workerUrl * .shp.workerUrl */
18
- workerUrl?: never;
15
+ export type ShapefileLoaderOptions = StrictLoaderOptions &
16
+ SHPLoaderOptions &
17
+ DBFLoaderOptions & {
18
+ shapefile?: {
19
+ shape?: 'geojson-table' | 'v3';
20
+ /** @deprecated Worker URLs must be specified with .dbf.workerUrl * .shp.workerUrl */
21
+ workerUrl?: never;
22
+ };
23
+ gis?: {
24
+ reproject?: boolean;
25
+ _targetCrs?: string;
26
+ };
19
27
  };
20
- };
21
28
 
22
29
  /**
23
30
  * Shapefile loader
package/src/shp-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, LoaderOptions} from '@loaders.gl/loader-utils';
5
+ import type {Loader, LoaderWithParser, StrictLoaderOptions} from '@loaders.gl/loader-utils';
6
6
  import {parseSHP, parseSHPInBatches} from './lib/parsers/parse-shp';
7
7
 
8
8
  // __VERSION__ is injected by babel-plugin-version-inline
@@ -12,8 +12,8 @@ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
12
12
  export const SHP_MAGIC_NUMBER = [0x00, 0x00, 0x27, 0x0a];
13
13
 
14
14
  /** SHPLoader */
15
- export type SHPLoaderOptions = LoaderOptions & {
16
- dbf?: {
15
+ export type SHPLoaderOptions = StrictLoaderOptions & {
16
+ shp?: {
17
17
  _maxDimensions?: number;
18
18
  /** Override the URL to the worker bundle (by default loads from unpkg.com) */
19
19
  workerUrl?: string;
@@ -50,7 +50,9 @@ export const SHPLoader: LoaderWithParser = {
50
50
  parse: async (arrayBuffer, options?) => parseSHP(arrayBuffer, options),
51
51
  parseSync: parseSHP,
52
52
  parseInBatches: (
53
- arrayBufferIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
53
+ arrayBufferIterator:
54
+ | AsyncIterable<ArrayBufferLike | ArrayBufferView>
55
+ | Iterable<ArrayBufferLike | ArrayBufferView>,
54
56
  options
55
57
  ) => parseSHPInBatches(arrayBufferIterator, options)
56
58
  };