@loaders.gl/flatgeobuf 4.3.0-alpha.2 → 4.3.0-alpha.4
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.dev.js +53 -24
- package/dist/dist.min.js +2 -2
- package/dist/flatgeobuf-loader.d.ts +8 -4
- package/dist/flatgeobuf-loader.d.ts.map +1 -1
- package/dist/flatgeobuf-loader.js +24 -4
- package/dist/flatgeobuf-worker.js +54 -25
- package/dist/floatgeobuf-source.d.ts +51 -0
- package/dist/floatgeobuf-source.d.ts.map +1 -0
- package/dist/floatgeobuf-source.js +72 -0
- package/dist/index.cjs +57 -27
- package/dist/index.cjs.map +2 -2
- package/dist/lib/parse-flatgeobuf.d.ts +11 -3
- package/dist/lib/parse-flatgeobuf.d.ts.map +1 -1
- package/dist/lib/parse-flatgeobuf.js +39 -29
- package/package.json +5 -5
- package/src/flatgeobuf-loader.ts +35 -5
- package/src/floatgeobuf-source.ts +100 -0
- package/src/lib/parse-flatgeobuf.ts +61 -40
package/dist/dist.dev.js
CHANGED
|
@@ -8621,15 +8621,8 @@ var __exports__ = (() => {
|
|
|
8621
8621
|
// src/lib/parse-flatgeobuf.ts
|
|
8622
8622
|
var deserializeGeoJson = deserialize3;
|
|
8623
8623
|
var deserializeGeneric = deserialize4;
|
|
8624
|
-
function binaryFromFeature(feature, header) {
|
|
8625
|
-
const geometry = feature.geometry();
|
|
8626
|
-
const geometryType = header.geometryType || geometry?.type();
|
|
8627
|
-
const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType);
|
|
8628
|
-
parsedGeometry.properties = parseProperties(feature, header.columns);
|
|
8629
|
-
return parsedGeometry;
|
|
8630
|
-
}
|
|
8631
8624
|
function parseFlatGeobuf(arrayBuffer, options) {
|
|
8632
|
-
const shape = options
|
|
8625
|
+
const shape = options.shape;
|
|
8633
8626
|
switch (shape) {
|
|
8634
8627
|
case "geojson-table": {
|
|
8635
8628
|
return parseFlatGeobufToGeoJSONTable(arrayBuffer, options);
|
|
@@ -8647,24 +8640,25 @@ var __exports__ = (() => {
|
|
|
8647
8640
|
const array = new Uint8Array(arrayBuffer);
|
|
8648
8641
|
return deserializeGeneric(array, fgbToBinaryGeometry);
|
|
8649
8642
|
}
|
|
8650
|
-
function parseFlatGeobufToGeoJSONTable(arrayBuffer, options
|
|
8643
|
+
function parseFlatGeobufToGeoJSONTable(arrayBuffer, options) {
|
|
8651
8644
|
if (arrayBuffer.byteLength === 0) {
|
|
8652
8645
|
return { shape: "geojson-table", type: "FeatureCollection", features: [] };
|
|
8653
8646
|
}
|
|
8654
|
-
const { reproject = false,
|
|
8647
|
+
const { reproject = false, crs = "WGS84" } = options;
|
|
8655
8648
|
const arr = new Uint8Array(arrayBuffer);
|
|
8656
8649
|
let fgbHeader;
|
|
8657
8650
|
let schema;
|
|
8658
|
-
|
|
8651
|
+
const rect = options.boundingBox && convertBoundingBox(options.boundingBox);
|
|
8652
|
+
let { features } = deserializeGeoJson(arr, rect, (headerMeta) => {
|
|
8659
8653
|
fgbHeader = headerMeta;
|
|
8660
8654
|
schema = getSchemaFromFGBHeader(fgbHeader);
|
|
8661
8655
|
});
|
|
8662
|
-
const
|
|
8656
|
+
const fromCRS = fgbHeader?.crs?.wkt;
|
|
8663
8657
|
let projection;
|
|
8664
|
-
if (reproject &&
|
|
8658
|
+
if (reproject && fromCRS) {
|
|
8665
8659
|
try {
|
|
8666
|
-
projection = new Proj4Projection({ from:
|
|
8667
|
-
} catch (
|
|
8660
|
+
projection = new Proj4Projection({ from: fromCRS, to: crs });
|
|
8661
|
+
} catch (error) {
|
|
8668
8662
|
}
|
|
8669
8663
|
}
|
|
8670
8664
|
if (projection) {
|
|
@@ -8673,7 +8667,7 @@ var __exports__ = (() => {
|
|
|
8673
8667
|
return { shape: "geojson-table", schema, type: "FeatureCollection", features };
|
|
8674
8668
|
}
|
|
8675
8669
|
function parseFlatGeobufInBatches(stream, options) {
|
|
8676
|
-
const shape = options.
|
|
8670
|
+
const shape = options.shape;
|
|
8677
8671
|
switch (shape) {
|
|
8678
8672
|
case "binary":
|
|
8679
8673
|
return parseFlatGeobufInBatchesToBinary(stream, options);
|
|
@@ -8684,11 +8678,12 @@ var __exports__ = (() => {
|
|
|
8684
8678
|
}
|
|
8685
8679
|
}
|
|
8686
8680
|
function parseFlatGeobufInBatchesToBinary(stream, options) {
|
|
8687
|
-
const
|
|
8681
|
+
const rect = options.boundingBox && convertBoundingBox(options.boundingBox);
|
|
8682
|
+
const iterator = deserializeGeneric(stream, binaryFromFeature, rect);
|
|
8688
8683
|
return iterator;
|
|
8689
8684
|
}
|
|
8690
8685
|
async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
|
|
8691
|
-
const { reproject = false,
|
|
8686
|
+
const { reproject = false, crs = "WGS84" } = options || {};
|
|
8692
8687
|
let fgbHeader;
|
|
8693
8688
|
const iterator = deserializeGeoJson(stream, void 0, (headerMeta) => {
|
|
8694
8689
|
fgbHeader = headerMeta;
|
|
@@ -8697,9 +8692,9 @@ var __exports__ = (() => {
|
|
|
8697
8692
|
let firstRecord = true;
|
|
8698
8693
|
for await (const feature of iterator) {
|
|
8699
8694
|
if (firstRecord) {
|
|
8700
|
-
const
|
|
8701
|
-
if (reproject &&
|
|
8702
|
-
projection = new Proj4Projection({ from:
|
|
8695
|
+
const fromCRS = fgbHeader?.crs?.wkt;
|
|
8696
|
+
if (reproject && fromCRS) {
|
|
8697
|
+
projection = new Proj4Projection({ from: fromCRS, to: crs });
|
|
8703
8698
|
}
|
|
8704
8699
|
firstRecord = false;
|
|
8705
8700
|
}
|
|
@@ -8710,6 +8705,21 @@ var __exports__ = (() => {
|
|
|
8710
8705
|
}
|
|
8711
8706
|
}
|
|
8712
8707
|
}
|
|
8708
|
+
function convertBoundingBox(boundingBox) {
|
|
8709
|
+
return {
|
|
8710
|
+
minX: boundingBox[0][0],
|
|
8711
|
+
minY: boundingBox[0][1],
|
|
8712
|
+
maxX: boundingBox[1][0],
|
|
8713
|
+
maxY: boundingBox[1][1]
|
|
8714
|
+
};
|
|
8715
|
+
}
|
|
8716
|
+
function binaryFromFeature(feature, header) {
|
|
8717
|
+
const geometry = feature.geometry();
|
|
8718
|
+
const geometryType = header.geometryType || geometry?.type();
|
|
8719
|
+
const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType);
|
|
8720
|
+
parsedGeometry.properties = parseProperties(feature, header.columns);
|
|
8721
|
+
return parsedGeometry;
|
|
8722
|
+
}
|
|
8713
8723
|
|
|
8714
8724
|
// src/flatgeobuf-loader.ts
|
|
8715
8725
|
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
@@ -8737,12 +8747,31 @@ var __exports__ = (() => {
|
|
|
8737
8747
|
};
|
|
8738
8748
|
var FlatGeobufLoader = {
|
|
8739
8749
|
...FlatGeobufWorkerLoader,
|
|
8740
|
-
parse: async (arrayBuffer, options) =>
|
|
8741
|
-
parseSync
|
|
8750
|
+
parse: async (arrayBuffer, options = {}) => parseSync(arrayBuffer, options),
|
|
8751
|
+
parseSync,
|
|
8742
8752
|
// @ts-expect-error this is a stream parser not an async iterator parser
|
|
8743
|
-
parseInBatchesFromStream
|
|
8753
|
+
parseInBatchesFromStream,
|
|
8744
8754
|
binary: true
|
|
8745
8755
|
};
|
|
8756
|
+
function parseSync(arrayBuffer, options = {}) {
|
|
8757
|
+
return parseFlatGeobuf(arrayBuffer, getOptions(options));
|
|
8758
|
+
}
|
|
8759
|
+
function parseInBatchesFromStream(stream, options) {
|
|
8760
|
+
return parseFlatGeobufInBatches(stream, getOptions(options));
|
|
8761
|
+
}
|
|
8762
|
+
function getOptions(options) {
|
|
8763
|
+
options = {
|
|
8764
|
+
...options,
|
|
8765
|
+
flatgeobuf: { ...FlatGeobufLoader.options.flatgeobuf, ...options?.flatgeobuf },
|
|
8766
|
+
gis: { ...FlatGeobufLoader.options.gis, ...options?.gis }
|
|
8767
|
+
};
|
|
8768
|
+
return {
|
|
8769
|
+
shape: options?.flatgeobuf?.shape ?? "geojson-table",
|
|
8770
|
+
boundingBox: options?.flatgeobuf?.boundingBox,
|
|
8771
|
+
crs: options?.gis?._targetCrs || "WGS84",
|
|
8772
|
+
reproject: options?.gis?.reproject || false
|
|
8773
|
+
};
|
|
8774
|
+
}
|
|
8746
8775
|
return __toCommonJS(bundle_exports);
|
|
8747
8776
|
})();
|
|
8748
8777
|
/*! Bundled license information:
|