recordBatches = {
const stream = await parquet.readParquetStream(url);
const layers = [];
for await (const wasmRecordBatch of streamAsyncIterator(stream)) {
let ipcBatch = wasmRecordBatch.intoIPC();
const table = apacheArrow.tableFromIPC(ipcBatch);
const recordBatch = table.batches[0];
const geometryColumnIdx = 6;
const geometryColumn = recordBatch.getChildAt(geometryColumnIdx);
const geometryOffsets = geometryColumn.data[0].valueOffsets;
const polygonOffsets = geometryColumn.getChildAt(0).data[0].valueOffsets;
const ringOffsets = geometryColumn.getChildAt(0).getChildAt(0)
.data[0].valueOffsets;
const flatCoordinateArray = geometryColumn
.getChildAt(0)
.getChildAt(0)
.getChildAt(0)
.getChildAt(0).data[0].values;
const resolvedPolygonOffsets = new Int32Array(polygonOffsets.length);
for (let i = 0; i < resolvedPolygonOffsets.length; ++i) {
resolvedPolygonOffsets[i] = ringOffsets[polygonOffsets[i]];
}
const data = {
// Number of geometries (here exploding multi polygons)
length: polygonOffsets.length,
// Indices into coordinateArray where each polygon starts
startIndices: resolvedPolygonOffsets,
// Flat coordinates array
attributes: {
getPolygon: { value: flatCoordinateArray, size: 2 }
}
};
const layer = new deck.SolidPolygonLayer({
// This is an Observable hack - changing the id will force the layer to refresh when the cell reevaluates
id: `layer-${Date.now()}`,
data,
// Skip normalization for binary data
_normalize: false,
// Counter-clockwise winding order
_windingOrder: "CCW",
getFillColor: [0, 100, 60, 160],
getLineColor: [0, 0, 0, 255]
});
const pathData = {
length: ringOffsets.length,
startIndices: ringOffsets,
attributes: {
getPath: { value: flatCoordinateArray, size: 2 }
}
};
const pathLayer = new deck.PathLayer({
// This is an Observable hack - changing the id will force the layer to refresh when the cell reevaluates
id: `layer-${Date.now()}`,
pathData,
// _pathType: "open",
getFillColor: [0, 100, 60, 160],
getColor: [200, 0, 0, 150],
getWidth: 300,
widthMinPixels: 1000
});
layers.push(layer);
// bug somewhere
// layers.push(pathLayer);
// Hack: I had to copy into a new layer or else `layers === layers` is true and the map never updates
deckglMap.setProps({ layers: Array.from(layers) });
}
}