Skip to content

Commit 425c7e6

Browse files
committed
fix: copy geometry when geometry is of binary format
Signed-off-by: Ihor Dykhta <[email protected]>
1 parent 30ce992 commit 425c7e6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/layers/src/geojson-layer/geojson-utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ export function fieldIsGeoArrow(geoField?: ProtoDatasetField | null): boolean {
5555

5656
export function parseGeoJsonRawFeature(rawFeature: unknown): Feature | null {
5757
const properties = null; // help ensure that properties is present on the returned geojson feature
58+
// Support WKB geometry provided as binary (e.g., from Parquet/GeoParquet)
59+
if (rawFeature instanceof Uint8Array || rawFeature instanceof ArrayBuffer) {
60+
try {
61+
const binaryInput =
62+
rawFeature instanceof ArrayBuffer
63+
? rawFeature
64+
: (rawFeature as Uint8Array).buffer.slice(
65+
(rawFeature as Uint8Array).byteOffset,
66+
(rawFeature as Uint8Array).byteOffset + (rawFeature as Uint8Array).byteLength
67+
);
68+
const binaryGeo = parseSync(binaryInput as ArrayBuffer, WKBLoader);
69+
// @ts-expect-error loaders.gl binary type to GeoJSON geometry
70+
const parsedGeo = binaryToGeometry(binaryGeo);
71+
const normalized = normalize(parsedGeo);
72+
if (!normalized || !Array.isArray(normalized.features)) {
73+
return null;
74+
}
75+
return {properties, ...normalized.features[0]};
76+
} catch (e) {
77+
return null;
78+
}
79+
}
5880
if (typeof rawFeature === 'object') {
5981
// Support GeoJson feature as object
6082
// probably need to normalize it as well

0 commit comments

Comments
 (0)