@loaders.gl/flatgeobuf 4.0.0-alpha.8 → 4.0.0-beta.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/dist.min.js +19 -16
- package/dist/es5/flatgeobuf-loader.js +6 -5
- package/dist/es5/flatgeobuf-loader.js.map +1 -1
- package/dist/es5/index.js +0 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/parse-flatgeobuf.js +14 -10
- package/dist/es5/lib/parse-flatgeobuf.js.map +1 -1
- package/dist/esm/flatgeobuf-loader.js +5 -3
- package/dist/esm/flatgeobuf-loader.js.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/parse-flatgeobuf.js +14 -10
- package/dist/esm/lib/parse-flatgeobuf.js.map +1 -1
- package/dist/flatgeobuf-loader.d.ts +11 -15
- package/dist/flatgeobuf-loader.d.ts.map +1 -1
- package/dist/flatgeobuf-worker.js +26 -16
- package/dist/index.d.ts +2 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/parse-flatgeobuf.d.ts +3 -6
- package/dist/lib/parse-flatgeobuf.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/flatgeobuf-loader.ts +18 -6
- package/src/index.ts +3 -3
- package/src/lib/parse-flatgeobuf.ts +30 -15
- package/dist/bundle.js +0 -5
- package/dist/es5/lib/types.js +0 -2
- package/dist/es5/lib/types.js.map +0 -1
- package/dist/esm/lib/types.js +0 -2
- package/dist/esm/lib/types.js.map +0 -1
- package/dist/flatgeobuf-loader.js +0 -23
- package/dist/index.js +0 -14
- package/dist/lib/binary-geometries.js +0 -120
- package/dist/lib/parse-flatgeobuf.js +0 -128
- package/dist/lib/types.d.ts +0 -13
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/types.js +0 -2
- package/dist/workers/flatgeobuf-worker.js +0 -5
- package/src/lib/types.ts +0 -13
|
@@ -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.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
-
export type FlatGeobufLoaderOptions = LoaderOptions & {
|
|
3
|
-
flatgeobuf?: {
|
|
4
|
-
shape?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary';
|
|
5
|
-
};
|
|
6
|
-
gis?: {
|
|
7
|
-
reproject?: boolean;
|
|
8
|
-
_targetCrs?: string;
|
|
9
|
-
/** @deprecated Use options.flatgeobuf.shape */
|
|
10
|
-
format?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary';
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/lib/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE5D,MAAM,MAAM,uBAAuB,GAAG,aAAa,GAAG;IACpD,UAAU,CAAC,EAAE;QACX,KAAK,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,CAAC;KACvE,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,+CAA+C;QAC/C,MAAM,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,CAAC;KACxE,CAAC;CACH,CAAC"}
|
package/dist/lib/types.js
DELETED
package/src/lib/types.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type {LoaderOptions} from '@loaders.gl/loader-utils';
|
|
2
|
-
|
|
3
|
-
export type FlatGeobufLoaderOptions = LoaderOptions & {
|
|
4
|
-
flatgeobuf?: {
|
|
5
|
-
shape?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary';
|
|
6
|
-
};
|
|
7
|
-
gis?: {
|
|
8
|
-
reproject?: boolean;
|
|
9
|
-
_targetCrs?: string;
|
|
10
|
-
/** @deprecated Use options.flatgeobuf.shape */
|
|
11
|
-
format?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary';
|
|
12
|
-
};
|
|
13
|
-
};
|