Skip to content

Commit 9d60501

Browse files
authored
Support separated (struct) coordinates for all applicable layers (#139)
* Support separated (struct) coordinates for solid polygon layer * Typo in struct geom check * Prettify utils.ts * Update additional layers to support struct coordinate arrow table * Prettify arc layer imports * Add comment about double transformation in solid polygon layer
1 parent 598a62c commit 9d60501

10 files changed

+203
-29
lines changed

src/layers/arc-layer.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import { ArcLayer } from "@deck.gl/layers";
1515
import type { ArcLayerProps } from "@deck.gl/layers";
1616
import * as arrow from "apache-arrow";
1717
import * as ga from "@geoarrow/geoarrow-js";
18-
import { assignAccessor, extractAccessorsFromProps } from "../utils/utils";
18+
import {
19+
assignAccessor,
20+
convertStructToFixedSizeList,
21+
extractAccessorsFromProps,
22+
isGeomSeparate,
23+
} from "../utils/utils";
1924
import { child } from "@geoarrow/geoarrow-js";
2025
import {
2126
GeoArrowExtraPickingProps,
@@ -157,9 +162,15 @@ export class GeoArrowArcLayer<
157162
recordBatchIdx < table.batches.length;
158163
recordBatchIdx++
159164
) {
160-
const sourceData = sourcePosition.data[recordBatchIdx];
165+
let sourceData = sourcePosition.data[recordBatchIdx];
166+
if (isGeomSeparate(sourceData)) {
167+
sourceData = convertStructToFixedSizeList(sourceData);
168+
}
161169
const sourceValues = child.getPointChild(sourceData).values;
162-
const targetData = targetPosition.data[recordBatchIdx];
170+
let targetData = targetPosition.data[recordBatchIdx];
171+
if (isGeomSeparate(targetData)) {
172+
targetData = convertStructToFixedSizeList(targetData);
173+
}
163174
const targetValues = child.getPointChild(targetData).values;
164175

165176
const props: ArcLayerProps = {

src/layers/column-layer.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import type { ColumnLayerProps } from "@deck.gl/layers";
1616
import * as arrow from "apache-arrow";
1717
import {
1818
assignAccessor,
19+
convertStructToFixedSizeList,
1920
extractAccessorsFromProps,
2021
getGeometryVector,
22+
isGeomSeparate,
2123
} from "../utils/utils";
2224
import * as ga from "@geoarrow/geoarrow-js";
2325
import { ColorAccessor, FloatAccessor, GeoArrowPickingInfo } from "../types";
@@ -161,7 +163,10 @@ export class GeoArrowColumnLayer<
161163
recordBatchIdx < table.batches.length;
162164
recordBatchIdx++
163165
) {
164-
const geometryData = geometryColumn.data[recordBatchIdx];
166+
let geometryData = geometryColumn.data[recordBatchIdx];
167+
if (isGeomSeparate(geometryData)) {
168+
geometryData = convertStructToFixedSizeList(geometryData);
169+
}
165170
const flatCoordsData = ga.child.getPointChild(geometryData);
166171
const flatCoordinateArray = flatCoordsData.values;
167172

src/layers/heatmap-layer.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import * as arrow from "apache-arrow";
1616
import * as ga from "@geoarrow/geoarrow-js";
1717
import {
1818
assignAccessor,
19+
convertStructToFixedSizeList,
1920
extractAccessorsFromProps,
2021
getGeometryVector,
22+
isGeomSeparate,
2123
} from "../utils/utils";
2224
import { FloatAccessor } from "../types";
2325
import { EXTENSION_NAME } from "../constants";
@@ -128,7 +130,10 @@ export class GeoArrowHeatmapLayer<
128130
recordBatchIdx < table.batches.length;
129131
recordBatchIdx++
130132
) {
131-
const geometryData = geometryColumn.data[recordBatchIdx];
133+
let geometryData = geometryColumn.data[recordBatchIdx];
134+
if (isGeomSeparate(geometryData)) {
135+
geometryData = convertStructToFixedSizeList(geometryData);
136+
}
132137
const flatCoordsData = ga.child.getPointChild(geometryData);
133138
const flatCoordinateArray = flatCoordsData.values;
134139

src/layers/path-layer.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import {
1919
assignAccessor,
2020
extractAccessorsFromProps,
2121
getGeometryVector,
22+
getInterleavedLineString,
2223
getMultiLineStringResolvedOffsets,
2324
invertOffsets,
25+
isGeomSeparate,
2426
} from "../utils/utils";
2527
import {
2628
GeoArrowExtraPickingProps,
@@ -172,7 +174,10 @@ export class GeoArrowPathLayer<
172174
recordBatchIdx < table.batches.length;
173175
recordBatchIdx++
174176
) {
175-
const lineStringData = geometryColumn.data[recordBatchIdx];
177+
let lineStringData = geometryColumn.data[recordBatchIdx];
178+
if (isGeomSeparate(lineStringData)) {
179+
lineStringData = getInterleavedLineString(lineStringData);
180+
}
176181
const geomOffsets = lineStringData.valueOffsets;
177182
const pointData = ga.child.getLineStringChild(lineStringData);
178183
const nDim = pointData.type.listSize;
@@ -243,8 +248,11 @@ export class GeoArrowPathLayer<
243248
recordBatchIdx++
244249
) {
245250
const multiLineStringData = geometryColumn.data[recordBatchIdx];
246-
const lineStringData =
251+
let lineStringData =
247252
ga.child.getMultiLineStringChild(multiLineStringData);
253+
if (isGeomSeparate(lineStringData)) {
254+
lineStringData = getInterleavedLineString(lineStringData);
255+
}
248256
const pointData = ga.child.getLineStringChild(lineStringData);
249257
const coordData = ga.child.getPointChild(pointData);
250258

src/layers/point-cloud-layer.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import * as arrow from "apache-arrow";
1919
import * as ga from "@geoarrow/geoarrow-js";
2020
import {
2121
assignAccessor,
22+
convertStructToFixedSizeList,
2223
extractAccessorsFromProps,
2324
getGeometryVector,
25+
isGeomSeparate,
2426
} from "../utils/utils";
2527
import {
2628
GeoArrowExtraPickingProps,
@@ -156,7 +158,10 @@ export class GeoArrowPointCloudLayer<
156158
recordBatchIdx < table.batches.length;
157159
recordBatchIdx++
158160
) {
159-
const geometryData = geometryColumn.data[recordBatchIdx];
161+
let geometryData = geometryColumn.data[recordBatchIdx];
162+
if (isGeomSeparate(geometryData)) {
163+
geometryData = convertStructToFixedSizeList(geometryData);
164+
}
160165
const flatCoordsData = ga.child.getPointChild(geometryData);
161166
const flatCoordinateArray = flatCoordsData.values;
162167

src/layers/scatterplot-layer.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import * as arrow from "apache-arrow";
1717
import * as ga from "@geoarrow/geoarrow-js";
1818
import {
1919
assignAccessor,
20+
convertStructToFixedSizeList,
2021
extractAccessorsFromProps,
2122
getGeometryVector,
2223
invertOffsets,
24+
isGeomSeparate,
2325
} from "../utils/utils";
2426
import {
2527
GeoArrowExtraPickingProps,
@@ -169,7 +171,10 @@ export class GeoArrowScatterplotLayer<
169171
recordBatchIdx < table.batches.length;
170172
recordBatchIdx++
171173
) {
172-
const geometryData = geometryColumn.data[recordBatchIdx];
174+
let geometryData = geometryColumn.data[recordBatchIdx];
175+
if (isGeomSeparate(geometryData)) {
176+
geometryData = convertStructToFixedSizeList(geometryData);
177+
}
173178
const flatCoordsData = ga.child.getPointChild(geometryData);
174179
const flatCoordinateArray = flatCoordsData.values;
175180

@@ -238,7 +243,10 @@ export class GeoArrowScatterplotLayer<
238243
recordBatchIdx++
239244
) {
240245
const multiPointData = geometryColumn.data[recordBatchIdx];
241-
const pointData = ga.child.getMultiPointChild(multiPointData);
246+
let pointData = ga.child.getMultiPointChild(multiPointData);
247+
if (isGeomSeparate(pointData)) {
248+
pointData = convertStructToFixedSizeList(pointData);
249+
}
242250
const geomOffsets = multiPointData.valueOffsets;
243251
const flatCoordsData = ga.child.getPointChild(pointData);
244252
const flatCoordinateArray = flatCoordsData.values;

src/layers/solid-polygon-layer.ts

+34-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import {
2121
assignAccessor,
2222
extractAccessorsFromProps,
2323
getGeometryVector,
24+
getInterleavedPolygon,
2425
getMultiPolygonResolvedOffsets,
2526
getPolygonResolvedOffsets,
2627
invertOffsets,
28+
isGeomSeparate,
2729
} from "../utils/utils";
2830
import {
2931
GeoArrowExtraPickingProps,
@@ -249,7 +251,12 @@ export class GeoArrowSolidPolygonLayer<
249251
recordBatchIdx < geometryColumn.data.length;
250252
recordBatchIdx++
251253
) {
252-
const polygonData = geometryColumn.data[recordBatchIdx];
254+
let polygonData = geometryColumn.data[recordBatchIdx];
255+
// TODO: Note here that [when applicable] we do this conversion twice -
256+
// one for triangulation (earcut) here and the other for rendering later.
257+
if (isGeomSeparate(polygonData)) {
258+
polygonData = getInterleavedPolygon(polygonData);
259+
}
253260
const [preparedPolygonData, arrayBuffers] = ga.worker.preparePostMessage(
254261
polygonData,
255262
true,
@@ -278,7 +285,12 @@ export class GeoArrowSolidPolygonLayer<
278285
recordBatchIdx < geometryColumn.data.length;
279286
recordBatchIdx++
280287
) {
281-
const polygonData = geometryColumn.data[recordBatchIdx];
288+
let polygonData = geometryColumn.data[recordBatchIdx];
289+
// TODO: Note here that [when applicable] we do this conversion twice -
290+
// one for triangulation (earcut) here and the other for rendering later.
291+
if (isGeomSeparate(polygonData)) {
292+
polygonData = getInterleavedPolygon(polygonData);
293+
}
282294
result[recordBatchIdx] = ga.algorithm.earcut(polygonData);
283295
}
284296

@@ -303,7 +315,12 @@ export class GeoArrowSolidPolygonLayer<
303315
recordBatchIdx++
304316
) {
305317
const multiPolygonData = geometryColumn.data[recordBatchIdx];
306-
const polygonData = ga.child.getMultiPolygonChild(multiPolygonData);
318+
let polygonData = ga.child.getMultiPolygonChild(multiPolygonData);
319+
// TODO: Note here that [when applicable] we do this conversion twice -
320+
// one for triangulation (earcut) here and the other for rendering later.
321+
if (isGeomSeparate(polygonData)) {
322+
polygonData = getInterleavedPolygon(polygonData);
323+
}
307324
const [preparedPolygonData, arrayBuffers] = ga.worker.preparePostMessage(
308325
polygonData,
309326
true,
@@ -333,7 +350,12 @@ export class GeoArrowSolidPolygonLayer<
333350
recordBatchIdx++
334351
) {
335352
const multiPolygonData = geometryColumn.data[recordBatchIdx];
336-
const polygonData = ga.child.getMultiPolygonChild(multiPolygonData);
353+
let polygonData = ga.child.getMultiPolygonChild(multiPolygonData);
354+
// TODO: Note here that [when applicable] we do this conversion twice -
355+
// one for triangulation (earcut) here and the other for rendering later.
356+
if (isGeomSeparate(polygonData)) {
357+
polygonData = getInterleavedPolygon(polygonData);
358+
}
337359
result[recordBatchIdx] = ga.algorithm.earcut(polygonData);
338360
}
339361

@@ -417,7 +439,10 @@ export class GeoArrowSolidPolygonLayer<
417439
recordBatchIdx < table.batches.length;
418440
recordBatchIdx++
419441
) {
420-
const polygonData = geometryColumn.data[recordBatchIdx];
442+
let polygonData = geometryColumn.data[recordBatchIdx];
443+
if (isGeomSeparate(polygonData)) {
444+
polygonData = getInterleavedPolygon(polygonData);
445+
}
421446
const ringData = ga.child.getPolygonChild(polygonData);
422447
const pointData = ga.child.getLineStringChild(ringData);
423448
const coordData = ga.child.getPointChild(pointData);
@@ -499,7 +524,10 @@ export class GeoArrowSolidPolygonLayer<
499524
recordBatchIdx++
500525
) {
501526
const multiPolygonData = geometryColumn.data[recordBatchIdx];
502-
const polygonData = ga.child.getMultiPolygonChild(multiPolygonData);
527+
let polygonData = ga.child.getMultiPolygonChild(multiPolygonData);
528+
if (isGeomSeparate(polygonData)) {
529+
polygonData = getInterleavedPolygon(polygonData);
530+
}
503531
const ringData = ga.child.getPolygonChild(polygonData);
504532
const pointData = ga.child.getLineStringChild(ringData);
505533
const coordData = ga.child.getPointChild(pointData);

src/layers/text-layer.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import * as arrow from "apache-arrow";
1717
import * as ga from "@geoarrow/geoarrow-js";
1818
import {
1919
assignAccessor,
20+
convertStructToFixedSizeList,
2021
expandArrayToCoords,
2122
extractAccessorsFromProps,
2223
getGeometryVector,
24+
isGeomSeparate,
2325
} from "../utils/utils";
2426
import {
2527
GeoArrowExtraPickingProps,
@@ -207,7 +209,10 @@ export class GeoArrowTextLayer<
207209
recordBatchIdx < table.batches.length;
208210
recordBatchIdx++
209211
) {
210-
const geometryData = geometryColumn.data[recordBatchIdx];
212+
let geometryData = geometryColumn.data[recordBatchIdx];
213+
if (isGeomSeparate(geometryData)) {
214+
geometryData = convertStructToFixedSizeList(geometryData);
215+
}
211216
const flatCoordsData = ga.child.getPointChild(geometryData);
212217
const flatCoordinateArray = flatCoordsData.values;
213218
const textData = this.props.getText.data[recordBatchIdx];

src/layers/trips-layer.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
assignAccessor,
1818
extractAccessorsFromProps,
1919
getGeometryVector,
20+
getInterleavedLineString,
21+
isGeomSeparate,
2022
} from "../utils/utils";
2123
import { TimestampAccessor, ColorAccessor, FloatAccessor } from "../types";
2224
import {
@@ -146,7 +148,10 @@ export class GeoArrowTripsLayer<
146148
recordBatchIdx < table.batches.length;
147149
recordBatchIdx++
148150
) {
149-
const lineStringData = geometryColumn.data[recordBatchIdx];
151+
let lineStringData = geometryColumn.data[recordBatchIdx];
152+
if (isGeomSeparate(lineStringData)) {
153+
lineStringData = getInterleavedLineString(lineStringData);
154+
}
150155
const geomOffsets = lineStringData.valueOffsets;
151156
const pointData = ga.child.getLineStringChild(lineStringData);
152157
const nDim = pointData.type.listSize;

0 commit comments

Comments
 (0)