@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
|
@@ -3336,7 +3336,7 @@
|
|
|
3336
3336
|
options,
|
|
3337
3337
|
context: {
|
|
3338
3338
|
...context,
|
|
3339
|
-
|
|
3339
|
+
_parse: parseOnMainThread
|
|
3340
3340
|
}
|
|
3341
3341
|
});
|
|
3342
3342
|
WorkerBody.postMessage("done", { result });
|
|
@@ -3349,7 +3349,7 @@
|
|
|
3349
3349
|
}
|
|
3350
3350
|
};
|
|
3351
3351
|
}
|
|
3352
|
-
function parseOnMainThread(arrayBuffer, options) {
|
|
3352
|
+
function parseOnMainThread(arrayBuffer, loader, options, context) {
|
|
3353
3353
|
return new Promise((resolve, reject) => {
|
|
3354
3354
|
const id = requestId++;
|
|
3355
3355
|
const onMessage = (type, payload2) => {
|
|
@@ -3373,7 +3373,12 @@
|
|
|
3373
3373
|
WorkerBody.postMessage("process", payload);
|
|
3374
3374
|
});
|
|
3375
3375
|
}
|
|
3376
|
-
async function parseData({
|
|
3376
|
+
async function parseData({
|
|
3377
|
+
loader,
|
|
3378
|
+
arrayBuffer,
|
|
3379
|
+
options,
|
|
3380
|
+
context
|
|
3381
|
+
}) {
|
|
3377
3382
|
let data;
|
|
3378
3383
|
let parser;
|
|
3379
3384
|
if (loader.parseSync || loader.parse) {
|
|
@@ -3441,7 +3446,7 @@
|
|
|
3441
3446
|
}
|
|
3442
3447
|
|
|
3443
3448
|
// src/flatgeobuf-loader.ts
|
|
3444
|
-
var VERSION = true ? "4.0.0-
|
|
3449
|
+
var VERSION = true ? "4.0.0-beta.1" : "latest";
|
|
3445
3450
|
var FlatGeobufLoader = {
|
|
3446
3451
|
id: "flatgeobuf",
|
|
3447
3452
|
name: "FlatGeobuf",
|
|
@@ -3453,7 +3458,10 @@
|
|
|
3453
3458
|
category: "geometry",
|
|
3454
3459
|
options: {
|
|
3455
3460
|
flatgeobuf: {
|
|
3456
|
-
shape: "geojson"
|
|
3461
|
+
shape: "geojson-table"
|
|
3462
|
+
},
|
|
3463
|
+
gis: {
|
|
3464
|
+
reproject: false
|
|
3457
3465
|
}
|
|
3458
3466
|
}
|
|
3459
3467
|
};
|
|
@@ -8826,7 +8834,7 @@
|
|
|
8826
8834
|
});
|
|
8827
8835
|
}
|
|
8828
8836
|
function isCoord(array) {
|
|
8829
|
-
return Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
8837
|
+
return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
8830
8838
|
}
|
|
8831
8839
|
|
|
8832
8840
|
// src/lib/parse-flatgeobuf.ts
|
|
@@ -8946,35 +8954,37 @@
|
|
|
8946
8954
|
function parseFlatGeobuf(arrayBuffer, options) {
|
|
8947
8955
|
const shape = options?.gis?.format || options?.flatgeobuf?.shape;
|
|
8948
8956
|
switch (shape) {
|
|
8949
|
-
case "geojson
|
|
8957
|
+
case "geojson":
|
|
8958
|
+
case "geojson-table": {
|
|
8959
|
+
const features = parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
8950
8960
|
const table = {
|
|
8951
|
-
shape: "geojson-
|
|
8952
|
-
|
|
8961
|
+
shape: "geojson-table",
|
|
8962
|
+
type: "FeatureCollection",
|
|
8963
|
+
features
|
|
8953
8964
|
};
|
|
8954
8965
|
return table;
|
|
8955
8966
|
}
|
|
8956
8967
|
case "columnar-table":
|
|
8957
|
-
|
|
8958
|
-
|
|
8959
|
-
return parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
8968
|
+
const binary = parseFlatGeobufToBinary(arrayBuffer, options);
|
|
8969
|
+
return { shape: "columnar-table", data: binary };
|
|
8960
8970
|
case "binary":
|
|
8961
8971
|
return parseFlatGeobufToBinary(arrayBuffer, options);
|
|
8962
8972
|
default:
|
|
8963
8973
|
throw new Error(shape);
|
|
8964
8974
|
}
|
|
8965
8975
|
}
|
|
8966
|
-
function parseFlatGeobufToBinary(arrayBuffer, options) {
|
|
8976
|
+
function parseFlatGeobufToBinary(arrayBuffer, options = {}) {
|
|
8967
8977
|
const array = new Uint8Array(arrayBuffer);
|
|
8968
8978
|
return (0, import_generic.deserialize)(array, binaryFromFeature);
|
|
8969
8979
|
}
|
|
8970
|
-
function parseFlatGeobufToGeoJSON(arrayBuffer, options) {
|
|
8980
|
+
function parseFlatGeobufToGeoJSON(arrayBuffer, options = {}) {
|
|
8971
8981
|
if (arrayBuffer.byteLength === 0) {
|
|
8972
8982
|
return [];
|
|
8973
8983
|
}
|
|
8974
8984
|
const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
|
|
8975
8985
|
const arr = new Uint8Array(arrayBuffer);
|
|
8976
8986
|
let headerMeta;
|
|
8977
|
-
const { features } = (0, import_geojson.deserialize)(arr,
|
|
8987
|
+
const { features } = (0, import_geojson.deserialize)(arr, void 0, (header) => {
|
|
8978
8988
|
headerMeta = header;
|
|
8979
8989
|
});
|
|
8980
8990
|
const crs = headerMeta && headerMeta.crs;
|
|
@@ -9003,7 +9013,7 @@
|
|
|
9003
9013
|
async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
|
|
9004
9014
|
const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
|
|
9005
9015
|
let headerMeta;
|
|
9006
|
-
const iterator = (0, import_geojson.deserialize)(stream,
|
|
9016
|
+
const iterator = (0, import_geojson.deserialize)(stream, void 0, (header) => {
|
|
9007
9017
|
headerMeta = header;
|
|
9008
9018
|
});
|
|
9009
9019
|
let projection;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
import type { LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { FlatGeobufLoaderOptions } from './flatgeobuf-loader';
|
|
2
3
|
import { FlatGeobufLoader as FlatGeobufWorkerLoader } from './flatgeobuf-loader';
|
|
3
|
-
import { parseFlatGeobuf, parseFlatGeobufInBatches } from './lib/parse-flatgeobuf';
|
|
4
4
|
export { FlatGeobufWorkerLoader };
|
|
5
|
-
export declare const FlatGeobufLoader:
|
|
6
|
-
parse: (arrayBuffer: any, options: any) => Promise<any[] | import("@loaders.gl/schema").GeoJSONRowTable | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown> | {
|
|
7
|
-
shape: string;
|
|
8
|
-
data: any[] | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown>;
|
|
9
|
-
}>;
|
|
10
|
-
parseSync: typeof parseFlatGeobuf;
|
|
11
|
-
parseInBatchesFromStream: typeof parseFlatGeobufInBatches;
|
|
12
|
-
binary: boolean;
|
|
13
|
-
id: string;
|
|
14
|
-
name: string;
|
|
15
|
-
module: string;
|
|
16
|
-
version: any;
|
|
17
|
-
worker: boolean;
|
|
18
|
-
extensions: string[];
|
|
19
|
-
mimeTypes: string[];
|
|
20
|
-
category: string;
|
|
21
|
-
options: {
|
|
22
|
-
flatgeobuf: {
|
|
23
|
-
shape: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export declare const _typecheckFlatGeobufLoader: LoaderWithParser;
|
|
5
|
+
export declare const FlatGeobufLoader: LoaderWithParser<any, any, FlatGeobufLoaderOptions>;
|
|
28
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAC,gBAAgB,IAAI,sBAAsB,EAAC,MAAM,qBAAqB,CAAC;AAG/E,OAAO,EAAC,sBAAsB,EAAC,CAAC;AAEhC,eAAO,MAAM,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,uBAAuB,CAOhF,CAAC"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { FlatGeobufLoaderOptions } from '
|
|
2
|
-
import {
|
|
3
|
-
export declare function parseFlatGeobuf(arrayBuffer: ArrayBuffer, options?: FlatGeobufLoaderOptions):
|
|
4
|
-
shape: string;
|
|
5
|
-
data: any[] | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown>;
|
|
6
|
-
};
|
|
1
|
+
import type { FlatGeobufLoaderOptions } from '../flatgeobuf-loader';
|
|
2
|
+
import type { Table } from '@loaders.gl/schema';
|
|
3
|
+
export declare function parseFlatGeobuf(arrayBuffer: ArrayBuffer, options?: FlatGeobufLoaderOptions): Table;
|
|
7
4
|
export declare function parseFlatGeobufInBatches(stream: any, options: FlatGeobufLoaderOptions): any[] | AsyncGenerator<import("flatgeobuf/lib/cjs/generic/feature").IFeature, any, unknown> | AsyncGenerator<any, void, unknown>;
|
|
8
5
|
//# sourceMappingURL=parse-flatgeobuf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-flatgeobuf.d.ts","sourceRoot":"","sources":["../../src/lib/parse-flatgeobuf.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-flatgeobuf.d.ts","sourceRoot":"","sources":["../../src/lib/parse-flatgeobuf.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAwB,KAAK,EAAC,MAAM,oBAAoB,CAAC;AA2BrE,wBAAgB,eAAe,CAC7B,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,uBAAuB,GAChC,KAAK,CA2BP;AAsDD,wBAAgB,wBAAwB,CAAC,MAAM,KAAA,EAAE,OAAO,EAAE,uBAAuB,oIAMhF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/flatgeobuf",
|
|
3
3
|
"description": "Loader for FlatGeobuf",
|
|
4
|
-
"version": "4.0.0-
|
|
4
|
+
"version": "4.0.0-beta.1",
|
|
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": "4.0.0-
|
|
36
|
-
"@loaders.gl/loader-utils": "4.0.0-
|
|
35
|
+
"@loaders.gl/gis": "4.0.0-beta.1",
|
|
36
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.1",
|
|
37
37
|
"@math.gl/proj4": "^3.3.1",
|
|
38
38
|
"flatgeobuf": "3.6.5"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "35c625e67132b0784e597d9ddabae8aefea29ff2"
|
|
41
41
|
}
|
package/src/flatgeobuf-loader.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import type {Loader} from '@loaders.gl/loader-utils';
|
|
1
|
+
import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
2
2
|
|
|
3
3
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
4
4
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
5
5
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export type FlatGeobufLoaderOptions = LoaderOptions & {
|
|
8
|
+
flatgeobuf?: {
|
|
9
|
+
shape?: 'geojson-table' | 'columnar-table' | 'geojson-table' | 'geojson' | 'binary';
|
|
10
|
+
};
|
|
11
|
+
gis?: {
|
|
12
|
+
reproject?: boolean;
|
|
13
|
+
_targetCrs?: string;
|
|
14
|
+
/** @deprecated Use options.flatgeobuf.shape */
|
|
15
|
+
format?: never;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const FlatGeobufLoader: Loader<any, any, FlatGeobufLoaderOptions> = {
|
|
8
20
|
id: 'flatgeobuf',
|
|
9
21
|
name: 'FlatGeobuf',
|
|
10
22
|
module: 'flatgeobuf',
|
|
@@ -15,10 +27,10 @@ export const FlatGeobufLoader = {
|
|
|
15
27
|
category: 'geometry',
|
|
16
28
|
options: {
|
|
17
29
|
flatgeobuf: {
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
shape: 'geojson-table'
|
|
31
|
+
},
|
|
32
|
+
gis: {
|
|
33
|
+
reproject: false
|
|
20
34
|
}
|
|
21
35
|
}
|
|
22
36
|
};
|
|
23
|
-
|
|
24
|
-
export const _typecheckFlatGeobufLoader: Loader = FlatGeobufLoader;
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type {LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
2
|
+
import type {FlatGeobufLoaderOptions} from './flatgeobuf-loader';
|
|
2
3
|
import {FlatGeobufLoader as FlatGeobufWorkerLoader} from './flatgeobuf-loader';
|
|
3
4
|
import {parseFlatGeobuf, parseFlatGeobufInBatches} from './lib/parse-flatgeobuf';
|
|
4
5
|
|
|
5
6
|
export {FlatGeobufWorkerLoader};
|
|
6
7
|
|
|
7
|
-
export const FlatGeobufLoader = {
|
|
8
|
+
export const FlatGeobufLoader: LoaderWithParser<any, any, FlatGeobufLoaderOptions> = {
|
|
8
9
|
...FlatGeobufWorkerLoader,
|
|
9
10
|
parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),
|
|
10
11
|
parseSync: parseFlatGeobuf,
|
|
12
|
+
// @ts-expect-error this is a stream parser not an async iterator parser
|
|
11
13
|
parseInBatchesFromStream: parseFlatGeobufInBatches,
|
|
12
14
|
binary: true
|
|
13
15
|
};
|
|
14
|
-
|
|
15
|
-
export const _typecheckFlatGeobufLoader: LoaderWithParser = FlatGeobufLoader;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
import {Proj4Projection} from '@math.gl/proj4';
|
|
3
2
|
import {transformGeoJsonCoords} from '@loaders.gl/gis';
|
|
4
3
|
|
|
@@ -6,9 +5,10 @@ import {deserialize as deserializeGeoJson} from 'flatgeobuf/lib/cjs/geojson';
|
|
|
6
5
|
import {deserialize as deserializeGeneric} from 'flatgeobuf/lib/cjs/generic';
|
|
7
6
|
import {parseProperties as parsePropertiesBinary} from 'flatgeobuf/lib/cjs/generic/feature';
|
|
8
7
|
|
|
8
|
+
import type {FlatGeobufLoaderOptions} from '../flatgeobuf-loader';
|
|
9
|
+
import type {GeoJSONTable, Feature, Table} from '@loaders.gl/schema';
|
|
9
10
|
import {fromGeometry as binaryFromGeometry} from './binary-geometries';
|
|
10
|
-
import {
|
|
11
|
-
import {GeoJSONRowTable, Feature} from '@loaders.gl/schema';
|
|
11
|
+
// import {Feature} from 'flatgeobuf/lib/cjs/feature_generated';
|
|
12
12
|
|
|
13
13
|
// TODO: reproject binary features
|
|
14
14
|
function binaryFromFeature(feature, header) {
|
|
@@ -20,6 +20,7 @@ function binaryFromFeature(feature, header) {
|
|
|
20
20
|
// known in the header?
|
|
21
21
|
const geometryType = header.geometryType || geometry.type();
|
|
22
22
|
const parsedGeometry = binaryFromGeometry(geometry, geometryType);
|
|
23
|
+
// @ts-expect-error this looks wrong
|
|
23
24
|
parsedGeometry.properties = parsePropertiesBinary(feature, header.columns);
|
|
24
25
|
|
|
25
26
|
// TODO: wrap binary data either in points, lines, or polygons key
|
|
@@ -32,39 +33,50 @@ function binaryFromFeature(feature, header) {
|
|
|
32
33
|
* @param arrayBuffer A FlatGeobuf arrayBuffer
|
|
33
34
|
* @return A GeoJSON geometry object
|
|
34
35
|
*/
|
|
35
|
-
export function parseFlatGeobuf(
|
|
36
|
+
export function parseFlatGeobuf(
|
|
37
|
+
arrayBuffer: ArrayBuffer,
|
|
38
|
+
options?: FlatGeobufLoaderOptions
|
|
39
|
+
): Table {
|
|
36
40
|
const shape = options?.gis?.format || options?.flatgeobuf?.shape;
|
|
37
41
|
|
|
38
42
|
switch (shape) {
|
|
39
|
-
case 'geojson
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
case 'geojson':
|
|
44
|
+
case 'geojson-table': {
|
|
45
|
+
const features = parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
46
|
+
const table: GeoJSONTable = {
|
|
47
|
+
shape: 'geojson-table',
|
|
48
|
+
type: 'FeatureCollection',
|
|
49
|
+
features
|
|
43
50
|
};
|
|
44
51
|
return table;
|
|
45
52
|
}
|
|
53
|
+
|
|
46
54
|
case 'columnar-table': // binary + some JS arrays
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
55
|
+
const binary = parseFlatGeobufToBinary(arrayBuffer, options);
|
|
56
|
+
// @ts-expect-error
|
|
57
|
+
return {shape: 'columnar-table', data: binary};
|
|
58
|
+
|
|
50
59
|
case 'binary':
|
|
60
|
+
// @ts-expect-error
|
|
51
61
|
return parseFlatGeobufToBinary(arrayBuffer, options);
|
|
62
|
+
|
|
52
63
|
default:
|
|
53
64
|
throw new Error(shape);
|
|
54
65
|
}
|
|
55
66
|
}
|
|
56
67
|
|
|
57
|
-
function parseFlatGeobufToBinary(arrayBuffer: ArrayBuffer, options: FlatGeobufLoaderOptions) {
|
|
68
|
+
function parseFlatGeobufToBinary(arrayBuffer: ArrayBuffer, options: FlatGeobufLoaderOptions = {}) {
|
|
58
69
|
// TODO: reproject binary features
|
|
59
70
|
// const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};
|
|
60
71
|
|
|
61
72
|
const array = new Uint8Array(arrayBuffer);
|
|
73
|
+
// @ts-expect-error this looks wrong
|
|
62
74
|
return deserializeGeneric(array, binaryFromFeature);
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
function parseFlatGeobufToGeoJSON(
|
|
66
78
|
arrayBuffer: ArrayBuffer,
|
|
67
|
-
options: FlatGeobufLoaderOptions
|
|
79
|
+
options: FlatGeobufLoaderOptions = {}
|
|
68
80
|
): Feature[] {
|
|
69
81
|
if (arrayBuffer.byteLength === 0) {
|
|
70
82
|
return [];
|
|
@@ -75,7 +87,8 @@ function parseFlatGeobufToGeoJSON(
|
|
|
75
87
|
const arr = new Uint8Array(arrayBuffer);
|
|
76
88
|
|
|
77
89
|
let headerMeta;
|
|
78
|
-
|
|
90
|
+
// @ts-expect-error this looks wrong
|
|
91
|
+
const {features} = deserializeGeoJson(arr, undefined, (header) => {
|
|
79
92
|
headerMeta = header;
|
|
80
93
|
});
|
|
81
94
|
|
|
@@ -116,6 +129,7 @@ function parseFlatGeobufInBatchesToBinary(stream, options: FlatGeobufLoaderOptio
|
|
|
116
129
|
// TODO: reproject binary streaming features
|
|
117
130
|
// const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};
|
|
118
131
|
|
|
132
|
+
// @ts-expect-error
|
|
119
133
|
const iterator = deserializeGeneric(stream, binaryFromFeature);
|
|
120
134
|
return iterator;
|
|
121
135
|
}
|
|
@@ -125,12 +139,13 @@ async function* parseFlatGeobufInBatchesToGeoJSON(stream, options: FlatGeobufLoa
|
|
|
125
139
|
const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};
|
|
126
140
|
|
|
127
141
|
let headerMeta;
|
|
128
|
-
const iterator = deserializeGeoJson(stream,
|
|
142
|
+
const iterator = deserializeGeoJson(stream, undefined, (header) => {
|
|
129
143
|
headerMeta = header;
|
|
130
144
|
});
|
|
131
145
|
|
|
132
146
|
let projection;
|
|
133
147
|
let firstRecord = true;
|
|
148
|
+
// @ts-expect-error this looks wrong
|
|
134
149
|
for await (const feature of iterator) {
|
|
135
150
|
if (firstRecord) {
|
|
136
151
|
const crs = headerMeta && headerMeta.crs;
|
package/dist/bundle.js
DELETED
package/dist/es5/lib/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/lib/types.ts"],"sourcesContent":["import type {LoaderOptions} from '@loaders.gl/loader-utils';\n\nexport type FlatGeobufLoaderOptions = LoaderOptions & {\n flatgeobuf?: {\n shape?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary';\n };\n gis?: {\n reproject?: boolean;\n _targetCrs?: string;\n /** @deprecated Use options.flatgeobuf.shape */\n format?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary';\n };\n};\n"],"mappings":""}
|
package/dist/esm/lib/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/lib/types.ts"],"sourcesContent":["import type {LoaderOptions} from '@loaders.gl/loader-utils';\n\nexport type FlatGeobufLoaderOptions = LoaderOptions & {\n flatgeobuf?: {\n shape?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary';\n };\n gis?: {\n reproject?: boolean;\n _targetCrs?: string;\n /** @deprecated Use options.flatgeobuf.shape */\n format?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary';\n };\n};\n"],"mappings":""}
|
|
@@ -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;
|