@loaders.gl/flatgeobuf 3.4.10 → 3.4.12

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.
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader = void 0;
7
- var VERSION = typeof "3.4.10" !== 'undefined' ? "3.4.10" : 'latest';
7
+ var VERSION = typeof "3.4.12" !== 'undefined' ? "3.4.12" : 'latest';
8
8
  var FlatGeobufLoader = {
9
9
  id: 'flatgeobuf',
10
10
  name: 'FlatGeobuf',
@@ -1,4 +1,4 @@
1
- const VERSION = typeof "3.4.10" !== 'undefined' ? "3.4.10" : 'latest';
1
+ const VERSION = typeof "3.4.12" !== 'undefined' ? "3.4.12" : 'latest';
2
2
  export const FlatGeobufLoader = {
3
3
  id: 'flatgeobuf',
4
4
  name: 'FlatGeobuf',
@@ -3441,7 +3441,7 @@
3441
3441
  }
3442
3442
 
3443
3443
  // src/flatgeobuf-loader.ts
3444
- var VERSION = true ? "3.4.10" : "latest";
3444
+ var VERSION = true ? "3.4.12" : "latest";
3445
3445
  var FlatGeobufLoader = {
3446
3446
  id: "flatgeobuf",
3447
3447
  name: "FlatGeobuf",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/flatgeobuf",
3
3
  "description": "Loader for FlatGeobuf",
4
- "version": "3.4.10",
4
+ "version": "3.4.12",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -32,10 +32,10 @@
32
32
  "build-worker": "esbuild src/workers/flatgeobuf-worker.ts --bundle --outfile=dist/flatgeobuf-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
33
33
  },
34
34
  "dependencies": {
35
- "@loaders.gl/gis": "3.4.10",
36
- "@loaders.gl/loader-utils": "3.4.10",
35
+ "@loaders.gl/gis": "3.4.12",
36
+ "@loaders.gl/loader-utils": "3.4.12",
37
37
  "@math.gl/proj4": "^3.3.1",
38
38
  "flatgeobuf": "3.6.5"
39
39
  },
40
- "gitHead": "4568459c96eaf0480a50ab77cace355307f61f04"
40
+ "gitHead": "85254762ae3082f608a863291deef09f2b40c6cf"
41
41
  }
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader = void 0;
4
- // __VERSION__ is injected by babel-plugin-version-inline
5
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
- exports.FlatGeobufLoader = {
8
- id: 'flatgeobuf',
9
- name: 'FlatGeobuf',
10
- module: 'flatgeobuf',
11
- version: VERSION,
12
- worker: true,
13
- extensions: ['fgb'],
14
- mimeTypes: ['application/octet-stream'],
15
- category: 'geometry',
16
- options: {
17
- flatgeobuf: {
18
- // Set to GeoJSON for backwards compatibility
19
- shape: 'geojson'
20
- }
21
- }
22
- };
23
- exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader;
package/dist/index.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader = exports.FlatGeobufWorkerLoader = void 0;
4
- const flatgeobuf_loader_1 = require("./flatgeobuf-loader");
5
- Object.defineProperty(exports, "FlatGeobufWorkerLoader", { enumerable: true, get: function () { return flatgeobuf_loader_1.FlatGeobufLoader; } });
6
- const parse_flatgeobuf_1 = require("./lib/parse-flatgeobuf");
7
- exports.FlatGeobufLoader = {
8
- ...flatgeobuf_loader_1.FlatGeobufLoader,
9
- parse: async (arrayBuffer, options) => (0, parse_flatgeobuf_1.parseFlatGeobuf)(arrayBuffer, options),
10
- parseSync: parse_flatgeobuf_1.parseFlatGeobuf,
11
- parseInBatchesFromStream: parse_flatgeobuf_1.parseFlatGeobufInBatches,
12
- binary: true
13
- };
14
- exports._typecheckFlatGeobufLoader = exports.FlatGeobufLoader;
@@ -1,120 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromGeometry = void 0;
4
- const header_generated_1 = require("flatgeobuf/lib/cjs/header_generated");
5
- // Parse Point to flat array
6
- function parsePoint(geometry) {
7
- const xy = geometry.xyArray();
8
- const z = geometry.zArray();
9
- const positions = blitArrays(xy, z);
10
- return { positions };
11
- }
12
- function parseLines(geometry) {
13
- const xy = geometry.xyArray();
14
- const z = geometry.zArray();
15
- const positions = blitArrays(xy, z);
16
- // If endsArray is null, a single LineString. Otherwise, contains the end
17
- // indices of each part of the MultiLineString. geometry.endsArray() omits the
18
- // initial 0 that we have in our internal format.
19
- const ends = (geometry.endsArray() && Array.from(geometry.endsArray())) || [xy.length / 2];
20
- ends.unshift(0);
21
- const pathIndices = { value: new Uint16Array(ends), size: 1 };
22
- return {
23
- positions,
24
- pathIndices
25
- };
26
- }
27
- function parsePolygons(geometry) {
28
- const xy = geometry.xyArray();
29
- const z = geometry.zArray();
30
- const positions = blitArrays(xy, z);
31
- // If endsArray is null, a simple Polygon with no inner rings. Otherwise,
32
- // contains the end indices of each ring of the Polygon. geometry.endsArray()
33
- // omits the initial 0 that we have in our internal format.
34
- const ends = (geometry.endsArray() && Array.from(geometry.endsArray())) || [xy.length / 2];
35
- ends.unshift(0);
36
- const primitivePolygonIndices = { value: new Uint16Array(ends), size: 1 };
37
- const polygonIndices = { value: new Uint16Array([0, xy.length / 2]), size: 1 };
38
- return {
39
- positions,
40
- primitivePolygonIndices,
41
- polygonIndices
42
- };
43
- }
44
- // eslint-disable-next-line max-statements
45
- function parseMultiPolygons(geometry) {
46
- // Create arrays for each geometry part, then concatenate
47
- const parsedParts = [];
48
- let nPositions = 0;
49
- let nPrimitivePolygonIndices = 1;
50
- let nPolygonIndices = 1;
51
- for (let i = 0; i < geometry.partsLength(); i++) {
52
- const part = geometry.parts(i);
53
- const polygon = parsePolygons(part);
54
- nPositions += polygon.positions.value.length;
55
- nPrimitivePolygonIndices += polygon.primitivePolygonIndices.value.length - 1;
56
- nPolygonIndices += polygon.polygonIndices.value.length - 1;
57
- parsedParts.push(polygon);
58
- }
59
- const concatPositions = new Float64Array(nPositions);
60
- const concatPrimitivePolygonIndices = new Uint32Array(nPrimitivePolygonIndices);
61
- const concatPolygonIndices = new Uint32Array(nPolygonIndices);
62
- let positionCounter = 0;
63
- let primitivePolygonIndicesCounter = 1;
64
- let polygonIndicesCounter = 1;
65
- // Assumes all parts of the multipolygon have the same size
66
- const positionSize = parsedParts[0].positions.size;
67
- for (const parsedPart of parsedParts) {
68
- concatPositions.set(parsedPart.positions.value, positionCounter * positionSize);
69
- // For indices, need to add positionCounter so that position indices are
70
- // correct in the concatenated positions
71
- concatPrimitivePolygonIndices.set(
72
- // eslint-disable-next-line
73
- parsedPart.primitivePolygonIndices.value.subarray(1).map((x) => x + positionCounter), primitivePolygonIndicesCounter);
74
- concatPolygonIndices.set(
75
- // eslint-disable-next-line
76
- parsedPart.polygonIndices.value.subarray(1).map((x) => x + positionCounter), polygonIndicesCounter);
77
- positionCounter += parsedPart.positions.value.length / positionSize;
78
- primitivePolygonIndicesCounter += parsedPart.primitivePolygonIndices.value.length - 1;
79
- polygonIndicesCounter += parsedPart.polygonIndices.value.length - 1;
80
- }
81
- return {
82
- positions: { value: concatPositions, size: positionSize },
83
- primitivePolygonIndices: { value: concatPrimitivePolygonIndices, size: 1 },
84
- polygonIndices: { value: concatPolygonIndices, size: 1 }
85
- };
86
- }
87
- // Combine xy and z arrays
88
- function blitArrays(xy, z) {
89
- if (!z) {
90
- return { value: xy, size: 2 };
91
- }
92
- if (z.length * 2 !== xy.length) {
93
- throw new Error('Z array must be half XY array\'s length');
94
- }
95
- const totalLength = xy.length + z.length;
96
- const xyz = new Float64Array(totalLength);
97
- for (let i = 0; i < xy.length / 2; i++) {
98
- xyz[i * 3 + 0] = xy[i * 2 + 0];
99
- xyz[i * 3 + 1] = xy[i * 2 + 1];
100
- xyz[i * 3 + 2] = z[i];
101
- }
102
- return { value: xyz, size: 3 };
103
- }
104
- function fromGeometry(geometry, type) {
105
- switch (type) {
106
- case header_generated_1.GeometryType.Point:
107
- case header_generated_1.GeometryType.MultiPoint:
108
- return parsePoint(geometry);
109
- case header_generated_1.GeometryType.LineString:
110
- case header_generated_1.GeometryType.MultiLineString:
111
- return parseLines(geometry);
112
- case header_generated_1.GeometryType.Polygon:
113
- return parsePolygons(geometry);
114
- case header_generated_1.GeometryType.MultiPolygon:
115
- return parseMultiPolygons(geometry);
116
- default:
117
- throw new Error(`Unimplemented geometry type: ${type}`);
118
- }
119
- }
120
- exports.fromGeometry = fromGeometry;
@@ -1,128 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseFlatGeobufInBatches = exports.parseFlatGeobuf = void 0;
4
- // @ts-nocheck
5
- const proj4_1 = require("@math.gl/proj4");
6
- const gis_1 = require("@loaders.gl/gis");
7
- const geojson_1 = require("flatgeobuf/lib/cjs/geojson");
8
- const generic_1 = require("flatgeobuf/lib/cjs/generic");
9
- const feature_1 = require("flatgeobuf/lib/cjs/generic/feature");
10
- const binary_geometries_1 = require("./binary-geometries");
11
- // TODO: reproject binary features
12
- function binaryFromFeature(feature, header) {
13
- const geometry = feature.geometry();
14
- // FlatGeobuf files can only hold a single geometry type per file, otherwise
15
- // GeometryType is GeometryCollection
16
- // I believe geometry.type() is null (0) except when the geometry type isn't
17
- // known in the header?
18
- const geometryType = header.geometryType || geometry.type();
19
- const parsedGeometry = (0, binary_geometries_1.fromGeometry)(geometry, geometryType);
20
- parsedGeometry.properties = (0, feature_1.parseProperties)(feature, header.columns);
21
- // TODO: wrap binary data either in points, lines, or polygons key
22
- return parsedGeometry;
23
- }
24
- /*
25
- * Parse FlatGeobuf arrayBuffer and return GeoJSON.
26
- *
27
- * @param arrayBuffer A FlatGeobuf arrayBuffer
28
- * @return A GeoJSON geometry object
29
- */
30
- function parseFlatGeobuf(arrayBuffer, options) {
31
- const shape = options?.gis?.format || options?.flatgeobuf?.shape;
32
- switch (shape) {
33
- case 'geojson-row-table': {
34
- const table = {
35
- shape: 'geojson-row-table',
36
- data: parseFlatGeobufToGeoJSON(arrayBuffer, options)
37
- };
38
- return table;
39
- }
40
- case 'columnar-table': // binary + some JS arrays
41
- return { shape: 'columnar-table', data: parseFlatGeobufToBinary(arrayBuffer, options) };
42
- case 'geojson':
43
- return parseFlatGeobufToGeoJSON(arrayBuffer, options);
44
- case 'binary':
45
- return parseFlatGeobufToBinary(arrayBuffer, options);
46
- default:
47
- throw new Error(shape);
48
- }
49
- }
50
- exports.parseFlatGeobuf = parseFlatGeobuf;
51
- function parseFlatGeobufToBinary(arrayBuffer, options) {
52
- // TODO: reproject binary features
53
- // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};
54
- const array = new Uint8Array(arrayBuffer);
55
- return (0, generic_1.deserialize)(array, binaryFromFeature);
56
- }
57
- function parseFlatGeobufToGeoJSON(arrayBuffer, options) {
58
- if (arrayBuffer.byteLength === 0) {
59
- return [];
60
- }
61
- const { reproject = false, _targetCrs = 'WGS84' } = (options && options.gis) || {};
62
- const arr = new Uint8Array(arrayBuffer);
63
- let headerMeta;
64
- const { features } = (0, geojson_1.deserialize)(arr, false, (header) => {
65
- headerMeta = header;
66
- });
67
- const crs = headerMeta && headerMeta.crs;
68
- let projection;
69
- if (reproject && crs) {
70
- // Constructing the projection may fail for some invalid WKT strings
71
- try {
72
- projection = new proj4_1.Proj4Projection({ from: crs.wkt, to: _targetCrs });
73
- }
74
- catch (e) {
75
- // no op
76
- }
77
- }
78
- if (projection) {
79
- return (0, gis_1.transformGeoJsonCoords)(features, (coords) => projection.project(coords));
80
- }
81
- return features;
82
- }
83
- /*
84
- * Parse FlatGeobuf arrayBuffer and return GeoJSON.
85
- *
86
- * @param {ReadableStream} _ A FlatGeobuf arrayBuffer
87
- * @return A GeoJSON geometry object iterator
88
- */
89
- // eslint-disable-next-line complexity
90
- function parseFlatGeobufInBatches(stream, options) {
91
- if (options && options.gis && options.gis.format === 'binary') {
92
- return parseFlatGeobufInBatchesToBinary(stream, options);
93
- }
94
- return parseFlatGeobufInBatchesToGeoJSON(stream, options);
95
- }
96
- exports.parseFlatGeobufInBatches = parseFlatGeobufInBatches;
97
- function parseFlatGeobufInBatchesToBinary(stream, options) {
98
- // TODO: reproject binary streaming features
99
- // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};
100
- const iterator = (0, generic_1.deserialize)(stream, binaryFromFeature);
101
- return iterator;
102
- }
103
- // eslint-disable-next-line complexity
104
- async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
105
- const { reproject = false, _targetCrs = 'WGS84' } = (options && options.gis) || {};
106
- let headerMeta;
107
- const iterator = (0, geojson_1.deserialize)(stream, false, (header) => {
108
- headerMeta = header;
109
- });
110
- let projection;
111
- let firstRecord = true;
112
- for await (const feature of iterator) {
113
- if (firstRecord) {
114
- const crs = headerMeta && headerMeta.crs;
115
- if (reproject && crs) {
116
- projection = new proj4_1.Proj4Projection({ from: crs.wkt, to: _targetCrs });
117
- }
118
- firstRecord = false;
119
- }
120
- if (reproject && projection) {
121
- // eslint-disable-next-line
122
- yield (0, gis_1.transformGeoJsonCoords)([feature], (coords) => projection.project(coords));
123
- }
124
- else {
125
- yield feature;
126
- }
127
- }
128
- }
package/dist/lib/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader_utils_1 = require("@loaders.gl/loader-utils");
4
- const index_1 = require("../index");
5
- (0, loader_utils_1.createLoaderWorker)(index_1.FlatGeobufLoader);