@loaders.gl/flatgeobuf 4.0.0-alpha.23 → 4.0.0-alpha.25
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 +18 -11
- package/dist/es5/flatgeobuf-loader.js +7 -2
- package/dist/es5/flatgeobuf-loader.js.map +1 -1
- 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 +7 -2
- package/dist/esm/flatgeobuf-loader.js.map +1 -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 +10 -3
- package/dist/flatgeobuf-loader.d.ts.map +1 -1
- package/dist/flatgeobuf-worker.js +19 -12
- package/dist/index.d.ts +1 -1
- 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 +16 -3
- package/src/index.ts +2 -2
- 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 -19
- 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
package/dist/dist.min.js
CHANGED
|
@@ -44,7 +44,12 @@
|
|
|
44
44
|
mimeTypes: ["application/octet-stream"],
|
|
45
45
|
category: "geometry",
|
|
46
46
|
options: {
|
|
47
|
-
flatgeobuf: {
|
|
47
|
+
flatgeobuf: {
|
|
48
|
+
shape: "geojson-table"
|
|
49
|
+
},
|
|
50
|
+
gis: {
|
|
51
|
+
reproject: false
|
|
52
|
+
}
|
|
48
53
|
}
|
|
49
54
|
};
|
|
50
55
|
}
|
|
@@ -9425,35 +9430,37 @@
|
|
|
9425
9430
|
function parseFlatGeobuf(arrayBuffer, options) {
|
|
9426
9431
|
const shape = options?.gis?.format || options?.flatgeobuf?.shape;
|
|
9427
9432
|
switch (shape) {
|
|
9428
|
-
case "geojson
|
|
9433
|
+
case "geojson":
|
|
9434
|
+
case "geojson-table": {
|
|
9435
|
+
const features = parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
9429
9436
|
const table = {
|
|
9430
|
-
shape: "geojson-
|
|
9431
|
-
|
|
9437
|
+
shape: "geojson-table",
|
|
9438
|
+
type: "FeatureCollection",
|
|
9439
|
+
features
|
|
9432
9440
|
};
|
|
9433
9441
|
return table;
|
|
9434
9442
|
}
|
|
9435
9443
|
case "columnar-table":
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
return parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
9444
|
+
const binary = parseFlatGeobufToBinary(arrayBuffer, options);
|
|
9445
|
+
return { shape: "columnar-table", data: binary };
|
|
9439
9446
|
case "binary":
|
|
9440
9447
|
return parseFlatGeobufToBinary(arrayBuffer, options);
|
|
9441
9448
|
default:
|
|
9442
9449
|
throw new Error(shape);
|
|
9443
9450
|
}
|
|
9444
9451
|
}
|
|
9445
|
-
function parseFlatGeobufToBinary(arrayBuffer, options) {
|
|
9452
|
+
function parseFlatGeobufToBinary(arrayBuffer, options = {}) {
|
|
9446
9453
|
const array = new Uint8Array(arrayBuffer);
|
|
9447
9454
|
return (0, import_generic.deserialize)(array, binaryFromFeature);
|
|
9448
9455
|
}
|
|
9449
|
-
function parseFlatGeobufToGeoJSON(arrayBuffer, options) {
|
|
9456
|
+
function parseFlatGeobufToGeoJSON(arrayBuffer, options = {}) {
|
|
9450
9457
|
if (arrayBuffer.byteLength === 0) {
|
|
9451
9458
|
return [];
|
|
9452
9459
|
}
|
|
9453
9460
|
const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
|
|
9454
9461
|
const arr = new Uint8Array(arrayBuffer);
|
|
9455
9462
|
let headerMeta;
|
|
9456
|
-
const { features } = (0, import_geojson.deserialize)(arr,
|
|
9463
|
+
const { features } = (0, import_geojson.deserialize)(arr, void 0, (header) => {
|
|
9457
9464
|
headerMeta = header;
|
|
9458
9465
|
});
|
|
9459
9466
|
const crs = headerMeta && headerMeta.crs;
|
|
@@ -9482,7 +9489,7 @@
|
|
|
9482
9489
|
async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
|
|
9483
9490
|
const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
|
|
9484
9491
|
let headerMeta;
|
|
9485
|
-
const iterator = (0, import_geojson.deserialize)(stream,
|
|
9492
|
+
const iterator = (0, import_geojson.deserialize)(stream, void 0, (header) => {
|
|
9486
9493
|
headerMeta = header;
|
|
9487
9494
|
});
|
|
9488
9495
|
let projection;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.FlatGeobufLoader = void 0;
|
|
7
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
7
|
+
var VERSION = typeof "4.0.0-alpha.25" !== 'undefined' ? "4.0.0-alpha.25" : 'latest';
|
|
8
8
|
var FlatGeobufLoader = {
|
|
9
9
|
id: 'flatgeobuf',
|
|
10
10
|
name: 'FlatGeobuf',
|
|
@@ -15,7 +15,12 @@ var FlatGeobufLoader = {
|
|
|
15
15
|
mimeTypes: ['application/octet-stream'],
|
|
16
16
|
category: 'geometry',
|
|
17
17
|
options: {
|
|
18
|
-
flatgeobuf: {
|
|
18
|
+
flatgeobuf: {
|
|
19
|
+
shape: 'geojson-table'
|
|
20
|
+
},
|
|
21
|
+
gis: {
|
|
22
|
+
reproject: false
|
|
23
|
+
}
|
|
19
24
|
}
|
|
20
25
|
};
|
|
21
26
|
exports.FlatGeobufLoader = FlatGeobufLoader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatgeobuf-loader.js","names":["VERSION","FlatGeobufLoader","id","name","module","version","worker","extensions","mimeTypes","category","options","flatgeobuf","exports"],"sources":["../../src/flatgeobuf-loader.ts"],"sourcesContent":["import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\
|
|
1
|
+
{"version":3,"file":"flatgeobuf-loader.js","names":["VERSION","FlatGeobufLoader","id","name","module","version","worker","extensions","mimeTypes","category","options","flatgeobuf","shape","gis","reproject","exports"],"sources":["../../src/flatgeobuf-loader.ts"],"sourcesContent":["import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type FlatGeobufLoaderOptions = LoaderOptions & {\n flatgeobuf?: {\n shape?: 'geojson-table' | 'columnar-table' | 'geojson-table' | 'geojson' | 'binary';\n };\n gis?: {\n reproject?: boolean;\n _targetCrs?: string;\n /** @deprecated Use options.flatgeobuf.shape */\n format?: never;\n };\n};\n\nexport const FlatGeobufLoader: Loader<any, any, FlatGeobufLoaderOptions> = {\n id: 'flatgeobuf',\n name: 'FlatGeobuf',\n module: 'flatgeobuf',\n version: VERSION,\n worker: true,\n extensions: ['fgb'],\n mimeTypes: ['application/octet-stream'],\n category: 'geometry',\n options: {\n flatgeobuf: {\n shape: 'geojson-table'\n },\n gis: {\n reproject: false\n }\n }\n};\n"],"mappings":";;;;;;AAIA,IAAMA,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAcpE,IAAMC,gBAA2D,GAAG;EACzEC,EAAE,EAAE,YAAY;EAChBC,IAAI,EAAE,YAAY;EAClBC,MAAM,EAAE,YAAY;EACpBC,OAAO,EAAEL,OAAO;EAChBM,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,0BAA0B,CAAC;EACvCC,QAAQ,EAAE,UAAU;EACpBC,OAAO,EAAE;IACPC,UAAU,EAAE;MACVC,KAAK,EAAE;IACT,CAAC;IACDC,GAAG,EAAE;MACHC,SAAS,EAAE;IACb;EACF;AACF,CAAC;AAACC,OAAA,CAAAd,gBAAA,GAAAA,gBAAA"}
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_flatgeobufLoader","require","_parseFlatgeobuf","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","FlatGeobufLoader","FlatGeobufWorkerLoader","parse","_parse","_asyncToGenerator2","_regenerator","mark","_callee","arrayBuffer","options","wrap","_callee$","_context","prev","next","abrupt","parseFlatGeobuf","stop","_x","_x2","parseSync","parseInBatchesFromStream","parseFlatGeobufInBatches","binary","exports"],"sources":["../../src/index.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["_flatgeobufLoader","require","_parseFlatgeobuf","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","FlatGeobufLoader","FlatGeobufWorkerLoader","parse","_parse","_asyncToGenerator2","_regenerator","mark","_callee","arrayBuffer","options","wrap","_callee$","_context","prev","next","abrupt","parseFlatGeobuf","stop","_x","_x2","parseSync","parseInBatchesFromStream","parseFlatGeobufInBatches","binary","exports"],"sources":["../../src/index.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {FlatGeobufLoaderOptions} from './flatgeobuf-loader';\nimport {FlatGeobufLoader as FlatGeobufWorkerLoader} from './flatgeobuf-loader';\nimport {parseFlatGeobuf, parseFlatGeobufInBatches} from './lib/parse-flatgeobuf';\n\nexport {FlatGeobufWorkerLoader};\n\nexport const FlatGeobufLoader: LoaderWithParser<any, any, FlatGeobufLoaderOptions> = {\n ...FlatGeobufWorkerLoader,\n parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),\n parseSync: parseFlatGeobuf,\n // @ts-expect-error this is a stream parser not an async iterator parser\n parseInBatchesFromStream: parseFlatGeobufInBatches,\n binary: true\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAEA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAAiF,SAAAE,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,C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AAM,EAAE;AAAI,EACb;AAACC,OAAA,CAAAxB,gBAAA,GAAAA,gBAAA"}
|
|
@@ -28,32 +28,36 @@ function parseFlatGeobuf(arrayBuffer, options) {
|
|
|
28
28
|
var _options$gis, _options$flatgeobuf;
|
|
29
29
|
var shape = (options === null || options === void 0 ? void 0 : (_options$gis = options.gis) === null || _options$gis === void 0 ? void 0 : _options$gis.format) || (options === null || options === void 0 ? void 0 : (_options$flatgeobuf = options.flatgeobuf) === null || _options$flatgeobuf === void 0 ? void 0 : _options$flatgeobuf.shape);
|
|
30
30
|
switch (shape) {
|
|
31
|
-
case 'geojson
|
|
31
|
+
case 'geojson':
|
|
32
|
+
case 'geojson-table':
|
|
32
33
|
{
|
|
34
|
+
var features = parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
33
35
|
var table = {
|
|
34
|
-
shape: 'geojson-
|
|
35
|
-
|
|
36
|
+
shape: 'geojson-table',
|
|
37
|
+
type: 'FeatureCollection',
|
|
38
|
+
features: features
|
|
36
39
|
};
|
|
37
40
|
return table;
|
|
38
41
|
}
|
|
39
42
|
case 'columnar-table':
|
|
43
|
+
var binary = parseFlatGeobufToBinary(arrayBuffer, options);
|
|
40
44
|
return {
|
|
41
45
|
shape: 'columnar-table',
|
|
42
|
-
data:
|
|
46
|
+
data: binary
|
|
43
47
|
};
|
|
44
|
-
case 'geojson':
|
|
45
|
-
return parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
46
48
|
case 'binary':
|
|
47
49
|
return parseFlatGeobufToBinary(arrayBuffer, options);
|
|
48
50
|
default:
|
|
49
51
|
throw new Error(shape);
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
|
-
function parseFlatGeobufToBinary(arrayBuffer
|
|
54
|
+
function parseFlatGeobufToBinary(arrayBuffer) {
|
|
55
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
53
56
|
var array = new Uint8Array(arrayBuffer);
|
|
54
57
|
return (0, _generic.deserialize)(array, binaryFromFeature);
|
|
55
58
|
}
|
|
56
|
-
function parseFlatGeobufToGeoJSON(arrayBuffer
|
|
59
|
+
function parseFlatGeobufToGeoJSON(arrayBuffer) {
|
|
60
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
57
61
|
if (arrayBuffer.byteLength === 0) {
|
|
58
62
|
return [];
|
|
59
63
|
}
|
|
@@ -64,7 +68,7 @@ function parseFlatGeobufToGeoJSON(arrayBuffer, options) {
|
|
|
64
68
|
_targetCrs = _ref$_targetCrs === void 0 ? 'WGS84' : _ref$_targetCrs;
|
|
65
69
|
var arr = new Uint8Array(arrayBuffer);
|
|
66
70
|
var headerMeta;
|
|
67
|
-
var _deserializeGeoJson = (0, _geojson.deserialize)(arr,
|
|
71
|
+
var _deserializeGeoJson = (0, _geojson.deserialize)(arr, undefined, function (header) {
|
|
68
72
|
headerMeta = header;
|
|
69
73
|
}),
|
|
70
74
|
features = _deserializeGeoJson.features;
|
|
@@ -105,7 +109,7 @@ function _parseFlatGeobufInBatchesToGeoJSON() {
|
|
|
105
109
|
while (1) switch (_context.prev = _context.next) {
|
|
106
110
|
case 0:
|
|
107
111
|
_ref2 = options && options.gis || {}, _ref2$reproject = _ref2.reproject, reproject = _ref2$reproject === void 0 ? false : _ref2$reproject, _ref2$_targetCrs = _ref2._targetCrs, _targetCrs = _ref2$_targetCrs === void 0 ? 'WGS84' : _ref2$_targetCrs;
|
|
108
|
-
iterator = (0, _geojson.deserialize)(stream,
|
|
112
|
+
iterator = (0, _geojson.deserialize)(stream, undefined, function (header) {
|
|
109
113
|
headerMeta = header;
|
|
110
114
|
});
|
|
111
115
|
firstRecord = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-flatgeobuf.js","names":["_proj","require","_gis","_geojson","_generic","_feature","_binaryGeometries","_asyncIterator","iterable","method","async","sync","retry","Symbol","asyncIterator","iterator","call","AsyncFromSyncIterator","TypeError","s","AsyncFromSyncIteratorContinuation","r","Object","Promise","reject","done","resolve","value","then","n","next","prototype","apply","arguments","return","_return","ret","throw","_throw","thr","binaryFromFeature","feature","header","geometry","geometryType","type","parsedGeometry","binaryFromGeometry","properties","parsePropertiesBinary","columns","parseFlatGeobuf","arrayBuffer","options","_options$gis","_options$flatgeobuf","shape","gis","format","flatgeobuf","table","data","parseFlatGeobufToGeoJSON","parseFlatGeobufToBinary","Error","array","Uint8Array","deserializeGeneric","byteLength","_ref","_ref$reproject","reproject","_ref$_targetCrs","_targetCrs","arr","headerMeta","_deserializeGeoJson","deserializeGeoJson","features","crs","projection","Proj4Projection","from","wkt","to","e","transformGeoJsonCoords","coords","project","parseFlatGeobufInBatches","stream","parseFlatGeobufInBatchesToBinary","parseFlatGeobufInBatchesToGeoJSON","_x","_x2","_parseFlatGeobufInBatchesToGeoJSON","_wrapAsyncGenerator2","default","_regenerator","mark","_callee","_ref2","_ref2$reproject","_ref2$_targetCrs","firstRecord","_iteratorAbruptCompletion","_didIteratorError","_iteratorError","_iterator","_step","wrap","_callee$","_context","prev","_awaitAsyncGenerator2","sent","t0","finish","stop"],"sources":["../../../src/lib/parse-flatgeobuf.ts"],"sourcesContent":["// @ts-nocheck\nimport {Proj4Projection} from '@math.gl/proj4';\nimport {transformGeoJsonCoords} from '@loaders.gl/gis';\n\nimport {deserialize as deserializeGeoJson} from 'flatgeobuf/lib/cjs/geojson';\nimport {deserialize as deserializeGeneric} from 'flatgeobuf/lib/cjs/generic';\nimport {parseProperties as parsePropertiesBinary} from 'flatgeobuf/lib/cjs/generic/feature';\n\nimport {fromGeometry as binaryFromGeometry} from './binary-geometries';\nimport {FlatGeobufLoaderOptions} from './types';\nimport {GeoJSONRowTable, Feature} from '@loaders.gl/schema';\n\n// TODO: reproject binary features\nfunction binaryFromFeature(feature, header) {\n const geometry = feature.geometry();\n\n // FlatGeobuf files can only hold a single geometry type per file, otherwise\n // GeometryType is GeometryCollection\n // I believe geometry.type() is null (0) except when the geometry type isn't\n // known in the header?\n const geometryType = header.geometryType || geometry.type();\n const parsedGeometry = binaryFromGeometry(geometry, geometryType);\n parsedGeometry.properties = parsePropertiesBinary(feature, header.columns);\n\n // TODO: wrap binary data either in points, lines, or polygons key\n return parsedGeometry;\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object\n */\nexport function parseFlatGeobuf(arrayBuffer: ArrayBuffer, options?: FlatGeobufLoaderOptions) {\n const shape = options?.gis?.format || options?.flatgeobuf?.shape;\n\n switch (shape) {\n case 'geojson-row-table': {\n const table: GeoJSONRowTable = {\n shape: 'geojson-row-table',\n data: parseFlatGeobufToGeoJSON(arrayBuffer, options)\n };\n return table;\n }\n case 'columnar-table': // binary + some JS arrays\n return {shape: 'columnar-table', data: parseFlatGeobufToBinary(arrayBuffer, options)};\n case 'geojson':\n return parseFlatGeobufToGeoJSON(arrayBuffer, options);\n case 'binary':\n return parseFlatGeobufToBinary(arrayBuffer, options);\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseFlatGeobufToBinary(arrayBuffer: ArrayBuffer, options: FlatGeobufLoaderOptions) {\n // TODO: reproject binary features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const array = new Uint8Array(arrayBuffer);\n return deserializeGeneric(array, binaryFromFeature);\n}\n\nfunction parseFlatGeobufToGeoJSON(\n arrayBuffer: ArrayBuffer,\n options: FlatGeobufLoaderOptions\n): Feature[] {\n if (arrayBuffer.byteLength === 0) {\n return [];\n }\n\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const arr = new Uint8Array(arrayBuffer);\n\n let headerMeta;\n const {features} = deserializeGeoJson(arr, false, (header) => {\n headerMeta = header;\n });\n\n const crs = headerMeta && headerMeta.crs;\n let projection;\n if (reproject && crs) {\n // Constructing the projection may fail for some invalid WKT strings\n try {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n } catch (e) {\n // no op\n }\n }\n\n if (projection) {\n return transformGeoJsonCoords(features, (coords) => projection.project(coords));\n }\n\n return features;\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param {ReadableStream} _ A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object iterator\n */\n// eslint-disable-next-line complexity\nexport function parseFlatGeobufInBatches(stream, options: FlatGeobufLoaderOptions) {\n if (options && options.gis && options.gis.format === 'binary') {\n return parseFlatGeobufInBatchesToBinary(stream, options);\n }\n\n return parseFlatGeobufInBatchesToGeoJSON(stream, options);\n}\n\nfunction parseFlatGeobufInBatchesToBinary(stream, options: FlatGeobufLoaderOptions) {\n // TODO: reproject binary streaming features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const iterator = deserializeGeneric(stream, binaryFromFeature);\n return iterator;\n}\n\n// eslint-disable-next-line complexity\nasync function* parseFlatGeobufInBatchesToGeoJSON(stream, options: FlatGeobufLoaderOptions) {\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n let headerMeta;\n const iterator = deserializeGeoJson(stream, false, (header) => {\n headerMeta = header;\n });\n\n let projection;\n let firstRecord = true;\n for await (const feature of iterator) {\n if (firstRecord) {\n const crs = headerMeta && headerMeta.crs;\n if (reproject && crs) {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n }\n\n firstRecord = false;\n }\n\n if (reproject && projection) {\n // eslint-disable-next-line\n yield transformGeoJsonCoords([feature], (coords) => projection.project(coords));\n } else {\n yield feature;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AACA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAEA,IAAAK,iBAAA,GAAAL,OAAA;AAAuE,SAAAM,eAAAC,QAAA,QAAAC,MAAA,EAAAC,KAAA,EA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A,CAAAlF,IAAA;UAEzB,OAAM,IAAAwD,2BAAsB,EAAC,CAAC7C,OAAO,CAAC,EAAE,UAAC8C,MAAM;YAAA,OAAKP,UAAU,CAACQ,OAAO,CAACD,MAAM,CAAC;UAAA,EAAC;QAAA;UAAAyB,QAAA,CAAAlF,IAAA;UAAA;QAAA;UAAAkF,QAAA,CAAAlF,IAAA;UAE/E,OAAMW,OAAO;QAAA;UAAAgE,yBAAA;UAAAO,QAAA,CAAAlF,IAAA;UAAA;QAAA;UAAAkF,QAAA,CAAAlF,IAAA;UAAA;QAAA;UAAAkF,QAAA,CAAAC,IAAA;UAAAD,QAAA,CAAAI,EAAA,GAAAJ,QAAA;UAAAN,iBAAA;UAAAC,cAAA,GAAAK,QAAA,CAAAI,EAAA;QAAA;UAAAJ,QAAA,CAAAC,IAAA;UAAAD,QAAA,CAAAC,IAAA;UAAA,MAAAR,yBAAA,IAAAG,SAAA,CAAA1E,MAAA;YAAA8E,QAAA,CAAAlF,IAAA;YAAA;UAAA;UAAAkF,QAAA,CAAAlF,IAAA;UAAA,WAAAoF,qBAAA,CAAAjB,OAAA,EAAAW,SAAA,CAAA1E,MAAA;QAAA;UAAA8E,QAAA,CAAAC,IAAA;UAAA,KAAAP,iBAAA;YAAAM,QAAA,CAAAlF,IAAA;YAAA;UAAA;UAAA,MAAA6E,cAAA;QAAA;UAAA,OAAAK,QAAA,CAAAK,MAAA;QAAA;UAAA,OAAAL,QAAA,CAAAK,MAAA;QAAA;QAAA;UAAA,OAAAL,QAAA,CAAAM,IAAA;MAAA;IAAA,GAAAlB,OAAA;EAAA,CAGlB;EAAA,OAAAL,kCAAA,CAAA/D,KAAA,OAAAC,SAAA;AAAA"}
|
|
1
|
+
{"version":3,"file":"parse-flatgeobuf.js","names":["_proj","require","_gis","_geojson","_generic","_feature","_binaryGeometries","_asyncIterator","iterable","method","async","sync","retry","Symbol","asyncIterator","iterator","call","AsyncFromSyncIterator","TypeError","s","AsyncFromSyncIteratorContinuation","r","Object","Promise","reject","done","resolve","value","then","n","next","prototype","apply","arguments","return","_return","ret","throw","_throw","thr","binaryFromFeature","feature","header","geometry","geometryType","type","parsedGeometry","binaryFromGeometry","properties","parsePropertiesBinary","columns","parseFlatGeobuf","arrayBuffer","options","_options$gis","_options$flatgeobuf","shape","gis","format","flatgeobuf","features","parseFlatGeobufToGeoJSON","table","binary","parseFlatGeobufToBinary","data","Error","length","undefined","array","Uint8Array","deserializeGeneric","byteLength","_ref","_ref$reproject","reproject","_ref$_targetCrs","_targetCrs","arr","headerMeta","_deserializeGeoJson","deserializeGeoJson","crs","projection","Proj4Projection","from","wkt","to","e","transformGeoJsonCoords","coords","project","parseFlatGeobufInBatches","stream","parseFlatGeobufInBatchesToBinary","parseFlatGeobufInBatchesToGeoJSON","_x","_x2","_parseFlatGeobufInBatchesToGeoJSON","_wrapAsyncGenerator2","default","_regenerator","mark","_callee","_ref2","_ref2$reproject","_ref2$_targetCrs","firstRecord","_iteratorAbruptCompletion","_didIteratorError","_iteratorError","_iterator","_step","wrap","_callee$","_context","prev","_awaitAsyncGenerator2","sent","t0","finish","stop"],"sources":["../../../src/lib/parse-flatgeobuf.ts"],"sourcesContent":["import {Proj4Projection} from '@math.gl/proj4';\nimport {transformGeoJsonCoords} from '@loaders.gl/gis';\n\nimport {deserialize as deserializeGeoJson} from 'flatgeobuf/lib/cjs/geojson';\nimport {deserialize as deserializeGeneric} from 'flatgeobuf/lib/cjs/generic';\nimport {parseProperties as parsePropertiesBinary} from 'flatgeobuf/lib/cjs/generic/feature';\n\nimport type {FlatGeobufLoaderOptions} from '../flatgeobuf-loader';\nimport type {GeoJSONTable, Feature, Table} from '@loaders.gl/schema';\nimport {fromGeometry as binaryFromGeometry} from './binary-geometries';\n// import {Feature} from 'flatgeobuf/lib/cjs/feature_generated';\n\n// TODO: reproject binary features\nfunction binaryFromFeature(feature, header) {\n const geometry = feature.geometry();\n\n // FlatGeobuf files can only hold a single geometry type per file, otherwise\n // GeometryType is GeometryCollection\n // I believe geometry.type() is null (0) except when the geometry type isn't\n // known in the header?\n const geometryType = header.geometryType || geometry.type();\n const parsedGeometry = binaryFromGeometry(geometry, geometryType);\n // @ts-expect-error this looks wrong\n parsedGeometry.properties = parsePropertiesBinary(feature, header.columns);\n\n // TODO: wrap binary data either in points, lines, or polygons key\n return parsedGeometry;\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object\n */\nexport function parseFlatGeobuf(\n arrayBuffer: ArrayBuffer,\n options?: FlatGeobufLoaderOptions\n): Table {\n const shape = options?.gis?.format || options?.flatgeobuf?.shape;\n\n switch (shape) {\n case 'geojson':\n case 'geojson-table': {\n const features = parseFlatGeobufToGeoJSON(arrayBuffer, options);\n const table: GeoJSONTable = {\n shape: 'geojson-table',\n type: 'FeatureCollection',\n features\n };\n return table;\n }\n\n case 'columnar-table': // binary + some JS arrays\n const binary = parseFlatGeobufToBinary(arrayBuffer, options);\n // @ts-expect-error\n return {shape: 'columnar-table', data: binary};\n\n case 'binary':\n // @ts-expect-error\n return parseFlatGeobufToBinary(arrayBuffer, options);\n\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseFlatGeobufToBinary(arrayBuffer: ArrayBuffer, options: FlatGeobufLoaderOptions = {}) {\n // TODO: reproject binary features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const array = new Uint8Array(arrayBuffer);\n // @ts-expect-error this looks wrong\n return deserializeGeneric(array, binaryFromFeature);\n}\n\nfunction parseFlatGeobufToGeoJSON(\n arrayBuffer: ArrayBuffer,\n options: FlatGeobufLoaderOptions = {}\n): Feature[] {\n if (arrayBuffer.byteLength === 0) {\n return [];\n }\n\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const arr = new Uint8Array(arrayBuffer);\n\n let headerMeta;\n // @ts-expect-error this looks wrong\n const {features} = deserializeGeoJson(arr, undefined, (header) => {\n headerMeta = header;\n });\n\n const crs = headerMeta && headerMeta.crs;\n let projection;\n if (reproject && crs) {\n // Constructing the projection may fail for some invalid WKT strings\n try {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n } catch (e) {\n // no op\n }\n }\n\n if (projection) {\n return transformGeoJsonCoords(features, (coords) => projection.project(coords));\n }\n\n return features;\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param {ReadableStream} _ A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object iterator\n */\n// eslint-disable-next-line complexity\nexport function parseFlatGeobufInBatches(stream, options: FlatGeobufLoaderOptions) {\n if (options && options.gis && options.gis.format === 'binary') {\n return parseFlatGeobufInBatchesToBinary(stream, options);\n }\n\n return parseFlatGeobufInBatchesToGeoJSON(stream, options);\n}\n\nfunction parseFlatGeobufInBatchesToBinary(stream, options: FlatGeobufLoaderOptions) {\n // TODO: reproject binary streaming features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n // @ts-expect-error\n const iterator = deserializeGeneric(stream, binaryFromFeature);\n return iterator;\n}\n\n// eslint-disable-next-line complexity\nasync function* parseFlatGeobufInBatchesToGeoJSON(stream, options: FlatGeobufLoaderOptions) {\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n let headerMeta;\n const iterator = deserializeGeoJson(stream, undefined, (header) => {\n headerMeta = header;\n });\n\n let projection;\n let firstRecord = true;\n // @ts-expect-error this looks wrong\n for await (const feature of iterator) {\n if (firstRecord) {\n const crs = headerMeta && headerMeta.crs;\n if (reproject && crs) {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n }\n\n firstRecord = false;\n }\n\n if (reproject && projection) {\n // eslint-disable-next-line\n yield transformGeoJsonCoords([feature], (coords) => projection.project(coords));\n } else {\n yield feature;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OA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;YAAA;UAAA;UAAA,MAAAgF,cAAA;QAAA;UAAA,OAAAK,QAAA,CAAAK,MAAA;QAAA;UAAA,OAAAL,QAAA,CAAAK,MAAA;QAAA;QAAA;UAAA,OAAAL,QAAA,CAAAM,IAAA;MAAA;IAAA,GAAAlB,OAAA;EAAA,CAGlB;EAAA,OAAAL,kCAAA,CAAAlE,KAAA,OAAAC,SAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
1
|
+
const VERSION = typeof "4.0.0-alpha.25" !== 'undefined' ? "4.0.0-alpha.25" : 'latest';
|
|
2
2
|
export const FlatGeobufLoader = {
|
|
3
3
|
id: 'flatgeobuf',
|
|
4
4
|
name: 'FlatGeobuf',
|
|
@@ -9,7 +9,12 @@ export const FlatGeobufLoader = {
|
|
|
9
9
|
mimeTypes: ['application/octet-stream'],
|
|
10
10
|
category: 'geometry',
|
|
11
11
|
options: {
|
|
12
|
-
flatgeobuf: {
|
|
12
|
+
flatgeobuf: {
|
|
13
|
+
shape: 'geojson-table'
|
|
14
|
+
},
|
|
15
|
+
gis: {
|
|
16
|
+
reproject: false
|
|
17
|
+
}
|
|
13
18
|
}
|
|
14
19
|
};
|
|
15
20
|
//# sourceMappingURL=flatgeobuf-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatgeobuf-loader.js","names":["VERSION","FlatGeobufLoader","id","name","module","version","worker","extensions","mimeTypes","category","options","flatgeobuf"],"sources":["../../src/flatgeobuf-loader.ts"],"sourcesContent":["import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\
|
|
1
|
+
{"version":3,"file":"flatgeobuf-loader.js","names":["VERSION","FlatGeobufLoader","id","name","module","version","worker","extensions","mimeTypes","category","options","flatgeobuf","shape","gis","reproject"],"sources":["../../src/flatgeobuf-loader.ts"],"sourcesContent":["import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type FlatGeobufLoaderOptions = LoaderOptions & {\n flatgeobuf?: {\n shape?: 'geojson-table' | 'columnar-table' | 'geojson-table' | 'geojson' | 'binary';\n };\n gis?: {\n reproject?: boolean;\n _targetCrs?: string;\n /** @deprecated Use options.flatgeobuf.shape */\n format?: never;\n };\n};\n\nexport const FlatGeobufLoader: Loader<any, any, FlatGeobufLoaderOptions> = {\n id: 'flatgeobuf',\n name: 'FlatGeobuf',\n module: 'flatgeobuf',\n version: VERSION,\n worker: true,\n extensions: ['fgb'],\n mimeTypes: ['application/octet-stream'],\n category: 'geometry',\n options: {\n flatgeobuf: {\n shape: 'geojson-table'\n },\n gis: {\n reproject: false\n }\n }\n};\n"],"mappings":"AAIA,MAAMA,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAc3E,OAAO,MAAMC,gBAA2D,GAAG;EACzEC,EAAE,EAAE,YAAY;EAChBC,IAAI,EAAE,YAAY;EAClBC,MAAM,EAAE,YAAY;EACpBC,OAAO,EAAEL,OAAO;EAChBM,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,0BAA0B,CAAC;EACvCC,QAAQ,EAAE,UAAU;EACpBC,OAAO,EAAE;IACPC,UAAU,EAAE;MACVC,KAAK,EAAE;IACT,CAAC;IACDC,GAAG,EAAE;MACHC,SAAS,EAAE;IACb;EACF;AACF,CAAC"}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["FlatGeobufLoader","FlatGeobufWorkerLoader","parseFlatGeobuf","parseFlatGeobufInBatches","parse","arrayBuffer","options","parseSync","parseInBatchesFromStream","binary"],"sources":["../../src/index.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["FlatGeobufLoader","FlatGeobufWorkerLoader","parseFlatGeobuf","parseFlatGeobufInBatches","parse","arrayBuffer","options","parseSync","parseInBatchesFromStream","binary"],"sources":["../../src/index.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {FlatGeobufLoaderOptions} from './flatgeobuf-loader';\nimport {FlatGeobufLoader as FlatGeobufWorkerLoader} from './flatgeobuf-loader';\nimport {parseFlatGeobuf, parseFlatGeobufInBatches} from './lib/parse-flatgeobuf';\n\nexport {FlatGeobufWorkerLoader};\n\nexport const FlatGeobufLoader: LoaderWithParser<any, any, FlatGeobufLoaderOptions> = {\n ...FlatGeobufWorkerLoader,\n parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),\n parseSync: parseFlatGeobuf,\n // @ts-expect-error this is a stream parser not an async iterator parser\n parseInBatchesFromStream: parseFlatGeobufInBatches,\n binary: true\n};\n"],"mappings":"AAEA,SAAQA,gBAAgB,IAAIC,sBAAsB,QAAO,qBAAqB;AAC9E,SAAQC,eAAe,EAAEC,wBAAwB,QAAO,wBAAwB;AAEhF,SAAQF,sBAAsB;AAE9B,OAAO,MAAMD,gBAAqE,GAAG;EACnF,GAAGC,sBAAsB;EACzBG,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEC,OAAO,KAAKJ,eAAe,CAACG,WAAW,EAAEC,OAAO,CAAC;EAC5EC,SAAS,EAAEL,eAAe;EAE1BM,wBAAwB,EAAEL,wBAAwB;EAClDM,MAAM,EAAE;AACV,CAAC"}
|
|
@@ -15,32 +15,36 @@ export function parseFlatGeobuf(arrayBuffer, options) {
|
|
|
15
15
|
var _options$gis, _options$flatgeobuf;
|
|
16
16
|
const shape = (options === null || options === void 0 ? void 0 : (_options$gis = options.gis) === null || _options$gis === void 0 ? void 0 : _options$gis.format) || (options === null || options === void 0 ? void 0 : (_options$flatgeobuf = options.flatgeobuf) === null || _options$flatgeobuf === void 0 ? void 0 : _options$flatgeobuf.shape);
|
|
17
17
|
switch (shape) {
|
|
18
|
-
case 'geojson
|
|
18
|
+
case 'geojson':
|
|
19
|
+
case 'geojson-table':
|
|
19
20
|
{
|
|
21
|
+
const features = parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
20
22
|
const table = {
|
|
21
|
-
shape: 'geojson-
|
|
22
|
-
|
|
23
|
+
shape: 'geojson-table',
|
|
24
|
+
type: 'FeatureCollection',
|
|
25
|
+
features
|
|
23
26
|
};
|
|
24
27
|
return table;
|
|
25
28
|
}
|
|
26
29
|
case 'columnar-table':
|
|
30
|
+
const binary = parseFlatGeobufToBinary(arrayBuffer, options);
|
|
27
31
|
return {
|
|
28
32
|
shape: 'columnar-table',
|
|
29
|
-
data:
|
|
33
|
+
data: binary
|
|
30
34
|
};
|
|
31
|
-
case 'geojson':
|
|
32
|
-
return parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
33
35
|
case 'binary':
|
|
34
36
|
return parseFlatGeobufToBinary(arrayBuffer, options);
|
|
35
37
|
default:
|
|
36
38
|
throw new Error(shape);
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
|
-
function parseFlatGeobufToBinary(arrayBuffer
|
|
41
|
+
function parseFlatGeobufToBinary(arrayBuffer) {
|
|
42
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
40
43
|
const array = new Uint8Array(arrayBuffer);
|
|
41
44
|
return deserializeGeneric(array, binaryFromFeature);
|
|
42
45
|
}
|
|
43
|
-
function parseFlatGeobufToGeoJSON(arrayBuffer
|
|
46
|
+
function parseFlatGeobufToGeoJSON(arrayBuffer) {
|
|
47
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
44
48
|
if (arrayBuffer.byteLength === 0) {
|
|
45
49
|
return [];
|
|
46
50
|
}
|
|
@@ -52,7 +56,7 @@ function parseFlatGeobufToGeoJSON(arrayBuffer, options) {
|
|
|
52
56
|
let headerMeta;
|
|
53
57
|
const {
|
|
54
58
|
features
|
|
55
|
-
} = deserializeGeoJson(arr,
|
|
59
|
+
} = deserializeGeoJson(arr, undefined, header => {
|
|
56
60
|
headerMeta = header;
|
|
57
61
|
});
|
|
58
62
|
const crs = headerMeta && headerMeta.crs;
|
|
@@ -86,7 +90,7 @@ async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
|
|
|
86
90
|
_targetCrs = 'WGS84'
|
|
87
91
|
} = options && options.gis || {};
|
|
88
92
|
let headerMeta;
|
|
89
|
-
const iterator = deserializeGeoJson(stream,
|
|
93
|
+
const iterator = deserializeGeoJson(stream, undefined, header => {
|
|
90
94
|
headerMeta = header;
|
|
91
95
|
});
|
|
92
96
|
let projection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-flatgeobuf.js","names":["Proj4Projection","transformGeoJsonCoords","deserialize","deserializeGeoJson","deserializeGeneric","parseProperties","parsePropertiesBinary","fromGeometry","binaryFromGeometry","binaryFromFeature","feature","header","geometry","geometryType","type","parsedGeometry","properties","columns","parseFlatGeobuf","arrayBuffer","options","_options$gis","_options$flatgeobuf","shape","gis","format","flatgeobuf","
|
|
1
|
+
{"version":3,"file":"parse-flatgeobuf.js","names":["Proj4Projection","transformGeoJsonCoords","deserialize","deserializeGeoJson","deserializeGeneric","parseProperties","parsePropertiesBinary","fromGeometry","binaryFromGeometry","binaryFromFeature","feature","header","geometry","geometryType","type","parsedGeometry","properties","columns","parseFlatGeobuf","arrayBuffer","options","_options$gis","_options$flatgeobuf","shape","gis","format","flatgeobuf","features","parseFlatGeobufToGeoJSON","table","binary","parseFlatGeobufToBinary","data","Error","arguments","length","undefined","array","Uint8Array","byteLength","reproject","_targetCrs","arr","headerMeta","crs","projection","from","wkt","to","e","coords","project","parseFlatGeobufInBatches","stream","parseFlatGeobufInBatchesToBinary","parseFlatGeobufInBatchesToGeoJSON","iterator","firstRecord"],"sources":["../../../src/lib/parse-flatgeobuf.ts"],"sourcesContent":["import {Proj4Projection} from '@math.gl/proj4';\nimport {transformGeoJsonCoords} from '@loaders.gl/gis';\n\nimport {deserialize as deserializeGeoJson} from 'flatgeobuf/lib/cjs/geojson';\nimport {deserialize as deserializeGeneric} from 'flatgeobuf/lib/cjs/generic';\nimport {parseProperties as parsePropertiesBinary} from 'flatgeobuf/lib/cjs/generic/feature';\n\nimport type {FlatGeobufLoaderOptions} from '../flatgeobuf-loader';\nimport type {GeoJSONTable, Feature, Table} from '@loaders.gl/schema';\nimport {fromGeometry as binaryFromGeometry} from './binary-geometries';\n// import {Feature} from 'flatgeobuf/lib/cjs/feature_generated';\n\n// TODO: reproject binary features\nfunction binaryFromFeature(feature, header) {\n const geometry = feature.geometry();\n\n // FlatGeobuf files can only hold a single geometry type per file, otherwise\n // GeometryType is GeometryCollection\n // I believe geometry.type() is null (0) except when the geometry type isn't\n // known in the header?\n const geometryType = header.geometryType || geometry.type();\n const parsedGeometry = binaryFromGeometry(geometry, geometryType);\n // @ts-expect-error this looks wrong\n parsedGeometry.properties = parsePropertiesBinary(feature, header.columns);\n\n // TODO: wrap binary data either in points, lines, or polygons key\n return parsedGeometry;\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object\n */\nexport function parseFlatGeobuf(\n arrayBuffer: ArrayBuffer,\n options?: FlatGeobufLoaderOptions\n): Table {\n const shape = options?.gis?.format || options?.flatgeobuf?.shape;\n\n switch (shape) {\n case 'geojson':\n case 'geojson-table': {\n const features = parseFlatGeobufToGeoJSON(arrayBuffer, options);\n const table: GeoJSONTable = {\n shape: 'geojson-table',\n type: 'FeatureCollection',\n features\n };\n return table;\n }\n\n case 'columnar-table': // binary + some JS arrays\n const binary = parseFlatGeobufToBinary(arrayBuffer, options);\n // @ts-expect-error\n return {shape: 'columnar-table', data: binary};\n\n case 'binary':\n // @ts-expect-error\n return parseFlatGeobufToBinary(arrayBuffer, options);\n\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseFlatGeobufToBinary(arrayBuffer: ArrayBuffer, options: FlatGeobufLoaderOptions = {}) {\n // TODO: reproject binary features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const array = new Uint8Array(arrayBuffer);\n // @ts-expect-error this looks wrong\n return deserializeGeneric(array, binaryFromFeature);\n}\n\nfunction parseFlatGeobufToGeoJSON(\n arrayBuffer: ArrayBuffer,\n options: FlatGeobufLoaderOptions = {}\n): Feature[] {\n if (arrayBuffer.byteLength === 0) {\n return [];\n }\n\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n const arr = new Uint8Array(arrayBuffer);\n\n let headerMeta;\n // @ts-expect-error this looks wrong\n const {features} = deserializeGeoJson(arr, undefined, (header) => {\n headerMeta = header;\n });\n\n const crs = headerMeta && headerMeta.crs;\n let projection;\n if (reproject && crs) {\n // Constructing the projection may fail for some invalid WKT strings\n try {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n } catch (e) {\n // no op\n }\n }\n\n if (projection) {\n return transformGeoJsonCoords(features, (coords) => projection.project(coords));\n }\n\n return features;\n}\n\n/*\n * Parse FlatGeobuf arrayBuffer and return GeoJSON.\n *\n * @param {ReadableStream} _ A FlatGeobuf arrayBuffer\n * @return A GeoJSON geometry object iterator\n */\n// eslint-disable-next-line complexity\nexport function parseFlatGeobufInBatches(stream, options: FlatGeobufLoaderOptions) {\n if (options && options.gis && options.gis.format === 'binary') {\n return parseFlatGeobufInBatchesToBinary(stream, options);\n }\n\n return parseFlatGeobufInBatchesToGeoJSON(stream, options);\n}\n\nfunction parseFlatGeobufInBatchesToBinary(stream, options: FlatGeobufLoaderOptions) {\n // TODO: reproject binary streaming features\n // const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n // @ts-expect-error\n const iterator = deserializeGeneric(stream, binaryFromFeature);\n return iterator;\n}\n\n// eslint-disable-next-line complexity\nasync function* parseFlatGeobufInBatchesToGeoJSON(stream, options: FlatGeobufLoaderOptions) {\n const {reproject = false, _targetCrs = 'WGS84'} = (options && options.gis) || {};\n\n let headerMeta;\n const iterator = deserializeGeoJson(stream, undefined, (header) => {\n headerMeta = header;\n });\n\n let projection;\n let firstRecord = true;\n // @ts-expect-error this looks wrong\n for await (const feature of iterator) {\n if (firstRecord) {\n const crs = headerMeta && headerMeta.crs;\n if (reproject && crs) {\n projection = new Proj4Projection({from: crs.wkt, to: _targetCrs});\n }\n\n firstRecord = false;\n }\n\n if (reproject && projection) {\n // eslint-disable-next-line\n yield transformGeoJsonCoords([feature], (coords) => projection.project(coords));\n } else {\n yield feature;\n }\n }\n}\n"],"mappings":"AAAA,SAAQA,eAAe,QAAO,gBAAgB;AAC9C,SAAQC,sBAAsB,QAAO,iBAAiB;AAEtD,SAAQC,WAAW,IAAIC,kBAAkB,QAAO,4BAA4B;AAC5E,SAAQD,WAAW,IAAIE,kBAAkB,QAAO,4BAA4B;AAC5E,SAAQC,eAAe,IAAIC,qBAAqB,QAAO,oCAAoC;AAI3F,SAAQC,YAAY,IAAIC,kBAAkB,QAAO,qBAAqB;AAItE,SAASC,iBAAiBA,CAACC,OAAO,EAAEC,MAAM,EAAE;EAC1C,MAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAQ,CAAC,CAAC;EAMnC,MAAMC,YAAY,GAAGF,MAAM,CAACE,YAAY,IAAID,QAAQ,CAACE,IAAI,CAAC,CAAC;EAC3D,MAAMC,cAAc,GAAGP,kBAAkB,CAACI,QAAQ,EAAEC,YAAY,CAAC;EAEjEE,cAAc,CAACC,UAAU,GAAGV,qBAAqB,CAACI,OAAO,EAAEC,MAAM,CAACM,OAAO,CAAC;EAG1E,OAAOF,cAAc;AACvB;AAQA,OAAO,SAASG,eAAeA,CAC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eobufLoaderOptions = LoaderOptions & {
|
|
3
|
+
flatgeobuf?: {
|
|
4
|
+
shape?: 'geojson-table' | 'columnar-table' | 'geojson-table' | 'geojson' | 'binary';
|
|
5
|
+
};
|
|
6
|
+
gis?: {
|
|
7
|
+
reproject?: boolean;
|
|
8
|
+
_targetCrs?: string;
|
|
9
|
+
/** @deprecated Use options.flatgeobuf.shape */
|
|
10
|
+
format?: never;
|
|
11
|
+
};
|
|
4
12
|
};
|
|
5
13
|
export declare const FlatGeobufLoader: Loader<any, any, FlatGeobufLoaderOptions>;
|
|
6
|
-
export {};
|
|
7
14
|
//# sourceMappingURL=flatgeobuf-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatgeobuf-loader.d.ts","sourceRoot":"","sources":["../src/flatgeobuf-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAMpE,
|
|
1
|
+
{"version":3,"file":"flatgeobuf-loader.d.ts","sourceRoot":"","sources":["../src/flatgeobuf-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAMpE,MAAM,MAAM,uBAAuB,GAAG,aAAa,GAAG;IACpD,UAAU,CAAC,EAAE;QACX,KAAK,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,eAAe,GAAG,SAAS,GAAG,QAAQ,CAAC;KACrF,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,KAAK,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,uBAAuB,CAiBtE,CAAC"}
|
|
@@ -3446,7 +3446,7 @@
|
|
|
3446
3446
|
}
|
|
3447
3447
|
|
|
3448
3448
|
// src/flatgeobuf-loader.ts
|
|
3449
|
-
var VERSION = true ? "4.0.0-alpha.
|
|
3449
|
+
var VERSION = true ? "4.0.0-alpha.25" : "latest";
|
|
3450
3450
|
var FlatGeobufLoader = {
|
|
3451
3451
|
id: "flatgeobuf",
|
|
3452
3452
|
name: "FlatGeobuf",
|
|
@@ -3457,7 +3457,12 @@
|
|
|
3457
3457
|
mimeTypes: ["application/octet-stream"],
|
|
3458
3458
|
category: "geometry",
|
|
3459
3459
|
options: {
|
|
3460
|
-
flatgeobuf: {
|
|
3460
|
+
flatgeobuf: {
|
|
3461
|
+
shape: "geojson-table"
|
|
3462
|
+
},
|
|
3463
|
+
gis: {
|
|
3464
|
+
reproject: false
|
|
3465
|
+
}
|
|
3461
3466
|
}
|
|
3462
3467
|
};
|
|
3463
3468
|
|
|
@@ -8949,35 +8954,37 @@
|
|
|
8949
8954
|
function parseFlatGeobuf(arrayBuffer, options) {
|
|
8950
8955
|
const shape = options?.gis?.format || options?.flatgeobuf?.shape;
|
|
8951
8956
|
switch (shape) {
|
|
8952
|
-
case "geojson
|
|
8957
|
+
case "geojson":
|
|
8958
|
+
case "geojson-table": {
|
|
8959
|
+
const features = parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
8953
8960
|
const table = {
|
|
8954
|
-
shape: "geojson-
|
|
8955
|
-
|
|
8961
|
+
shape: "geojson-table",
|
|
8962
|
+
type: "FeatureCollection",
|
|
8963
|
+
features
|
|
8956
8964
|
};
|
|
8957
8965
|
return table;
|
|
8958
8966
|
}
|
|
8959
8967
|
case "columnar-table":
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
return parseFlatGeobufToGeoJSON(arrayBuffer, options);
|
|
8968
|
+
const binary = parseFlatGeobufToBinary(arrayBuffer, options);
|
|
8969
|
+
return { shape: "columnar-table", data: binary };
|
|
8963
8970
|
case "binary":
|
|
8964
8971
|
return parseFlatGeobufToBinary(arrayBuffer, options);
|
|
8965
8972
|
default:
|
|
8966
8973
|
throw new Error(shape);
|
|
8967
8974
|
}
|
|
8968
8975
|
}
|
|
8969
|
-
function parseFlatGeobufToBinary(arrayBuffer, options) {
|
|
8976
|
+
function parseFlatGeobufToBinary(arrayBuffer, options = {}) {
|
|
8970
8977
|
const array = new Uint8Array(arrayBuffer);
|
|
8971
8978
|
return (0, import_generic.deserialize)(array, binaryFromFeature);
|
|
8972
8979
|
}
|
|
8973
|
-
function parseFlatGeobufToGeoJSON(arrayBuffer, options) {
|
|
8980
|
+
function parseFlatGeobufToGeoJSON(arrayBuffer, options = {}) {
|
|
8974
8981
|
if (arrayBuffer.byteLength === 0) {
|
|
8975
8982
|
return [];
|
|
8976
8983
|
}
|
|
8977
8984
|
const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
|
|
8978
8985
|
const arr = new Uint8Array(arrayBuffer);
|
|
8979
8986
|
let headerMeta;
|
|
8980
|
-
const { features } = (0, import_geojson.deserialize)(arr,
|
|
8987
|
+
const { features } = (0, import_geojson.deserialize)(arr, void 0, (header) => {
|
|
8981
8988
|
headerMeta = header;
|
|
8982
8989
|
});
|
|
8983
8990
|
const crs = headerMeta && headerMeta.crs;
|
|
@@ -9006,7 +9013,7 @@
|
|
|
9006
9013
|
async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
|
|
9007
9014
|
const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
|
|
9008
9015
|
let headerMeta;
|
|
9009
|
-
const iterator = (0, import_geojson.deserialize)(stream,
|
|
9016
|
+
const iterator = (0, import_geojson.deserialize)(stream, void 0, (header) => {
|
|
9010
9017
|
headerMeta = header;
|
|
9011
9018
|
});
|
|
9012
9019
|
let projection;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +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 { FlatGeobufLoaderOptions } from './lib/types';
|
|
4
4
|
export { FlatGeobufWorkerLoader };
|
|
5
5
|
export declare const FlatGeobufLoader: LoaderWithParser<any, any, FlatGeobufLoaderOptions>;
|
|
6
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-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.25",
|
|
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-alpha.
|
|
36
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
35
|
+
"@loaders.gl/gis": "4.0.0-alpha.25",
|
|
36
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.25",
|
|
37
37
|
"@math.gl/proj4": "^3.3.1",
|
|
38
38
|
"flatgeobuf": "3.6.5"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "40135f391b869388dbbcd615bbe51178d0c370be"
|
|
41
41
|
}
|
package/src/flatgeobuf-loader.ts
CHANGED
|
@@ -4,8 +4,16 @@ import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
|
4
4
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
5
5
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
6
6
|
|
|
7
|
-
type FlatGeobufLoaderOptions = LoaderOptions & {
|
|
8
|
-
flatgeobuf
|
|
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
|
+
};
|
|
9
17
|
};
|
|
10
18
|
|
|
11
19
|
export const FlatGeobufLoader: Loader<any, any, FlatGeobufLoaderOptions> = {
|
|
@@ -18,6 +26,11 @@ export const FlatGeobufLoader: Loader<any, any, FlatGeobufLoaderOptions> = {
|
|
|
18
26
|
mimeTypes: ['application/octet-stream'],
|
|
19
27
|
category: 'geometry',
|
|
20
28
|
options: {
|
|
21
|
-
flatgeobuf: {
|
|
29
|
+
flatgeobuf: {
|
|
30
|
+
shape: 'geojson-table'
|
|
31
|
+
},
|
|
32
|
+
gis: {
|
|
33
|
+
reproject: false
|
|
34
|
+
}
|
|
22
35
|
}
|
|
23
36
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
import {FlatGeobufLoaderOptions} from './lib/types';
|
|
5
5
|
|
|
6
6
|
export {FlatGeobufWorkerLoader};
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ export const FlatGeobufLoader: LoaderWithParser<any, any, FlatGeobufLoaderOption
|
|
|
9
9
|
...FlatGeobufWorkerLoader,
|
|
10
10
|
parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),
|
|
11
11
|
parseSync: parseFlatGeobuf,
|
|
12
|
-
// @ts-expect-error
|
|
12
|
+
// @ts-expect-error this is a stream parser not an async iterator parser
|
|
13
13
|
parseInBatchesFromStream: parseFlatGeobufInBatches,
|
|
14
14
|
binary: true
|
|
15
15
|
};
|
|
@@ -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,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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
|
-
}
|
|
19
|
-
};
|
package/dist/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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
|
-
// @ts-expect-error
|
|
12
|
-
parseInBatchesFromStream: parse_flatgeobuf_1.parseFlatGeobufInBatches,
|
|
13
|
-
binary: true
|
|
14
|
-
};
|
|
@@ -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.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
|
-
};
|