Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/layers/src/geojson-layer/geojson-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ export function fieldIsGeoArrow(geoField?: ProtoDatasetField | null): boolean {

export function parseGeoJsonRawFeature(rawFeature: unknown): Feature | null {
const properties = null; // help ensure that properties is present on the returned geojson feature
// Support WKB geometry provided as binary (e.g., from Parquet/GeoParquet)
if (rawFeature instanceof Uint8Array || rawFeature instanceof ArrayBuffer) {
try {
const binaryInput =
rawFeature instanceof ArrayBuffer
? rawFeature
: (rawFeature as Uint8Array).buffer.slice(
(rawFeature as Uint8Array).byteOffset,
(rawFeature as Uint8Array).byteOffset + (rawFeature as Uint8Array).byteLength
);
const binaryGeo = parseSync(binaryInput as ArrayBuffer, WKBLoader);
// @ts-expect-error loaders.gl binary type to GeoJSON geometry
const parsedGeo = binaryToGeometry(binaryGeo);
const normalized = normalize(parsedGeo);
if (!normalized || !Array.isArray(normalized.features) || !normalized.features.length) {
return null;
}
return {properties, ...normalized.features[0]};
} catch (e) {
return null;
}
}
if (typeof rawFeature === 'object') {
// Support GeoJson feature as object
// probably need to normalize it as well
Expand Down