Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

fix: pass the feature to table-mode GPU filter accessors (#3710)

Javier Andrés García131f664265ff
diff --git a/src/layers/src/geojson-layer/geojson-layer.ts b/src/layers/src/geojson-layer/geojson-layer.ts
index 2d5c1c764..dd7f31c00 100644
--- a/src/layers/src/geojson-layer/geojson-layer.ts
+++ b/src/layers/src/geojson-layer/geojson-layer.ts
@@ -203,8 +203,10 @@ const geoColumnAccessor =
(dc: DataContainerInterface): arrow.Vector | null =>
dc.getColumn?.(geojson.fieldIdx) as arrow.Vector;
-const getTableModeValueAccessor = feature => {
- // Called from gpu-filter-utils.getFilterValueAccessor()
+const getTableModeValueAccessor = (dc, feature) => {
+ // Called from gpu-filter-utils.getFilterValueAccessor(), which passes
+ // (dataContainer, feature, fieldIndex). The feature carries its own
+ // materialised rows in properties.values, so the data container is not needed.
return field => feature.properties.values.map(v => field.valueAccessor(v));
};
diff --git a/src/layers/src/trip-layer/trip-layer.ts b/src/layers/src/trip-layer/trip-layer.ts
index bbb69807d..1f72b5508 100644
--- a/src/layers/src/trip-layer/trip-layer.ts
+++ b/src/layers/src/trip-layer/trip-layer.ts
@@ -603,7 +603,10 @@ export default class TripLayer extends Layer {
});
}
- _getColumnModeValueAccessor = feature => {
+ // Called from gpu-filter-utils.getFilterValueAccessor(), which passes
+ // (dataContainer, feature, fieldIndex). The trip carries its own materialised
+ // rows in properties.values, so the data container is not needed here.
+ _getColumnModeValueAccessor = (dc, feature) => {
return field => {
if (field.fieldIdx === this.config.columns.timestamp?.fieldIdx) {
return this.dataToTimeStamp[feature.properties.index];
diff --git a/test/browser/layer-tests/geojson-layer-specs.js b/test/browser/layer-tests/geojson-layer-specs.js
index 44069dac1..f574f4afd 100644
--- a/test/browser/layer-tests/geojson-layer-specs.js
+++ b/test/browser/layer-tests/geojson-layer-specs.js
@@ -15,6 +15,8 @@ import {
testFormatLayerDataCases,
testRenderLayerCases,
prepareGeojsonDataset,
+ prepareTripTableDataset,
+ speedFilterDomain0,
geoFilterDomain0,
geojsonFilterDomain0
} from 'test/helpers/layer-utils';
@@ -515,6 +517,58 @@ test('#GeojsonLayer -> formatLayerData', async t => {
t.end();
});
+test('#GeojsonLayer -> formatLayerData -> table column mode with gpu filter', t => {
+ // The GPU filter reads a layer's values through the accessor the layer hands
+ // it, called as getData(dataContainer, feature, fieldIndex). Table column mode
+ // groups rows by id, so the value of each channel is an array, one entry per
+ // point of the grouped feature.
+ const TEST_CASES = [
+ {
+ name: 'Geojson Table.1',
+ layer: {
+ type: 'geojson',
+ id: 'test_geojson_table_layer',
+ config: {
+ dataId,
+ label: 'gps tracks',
+ columnMode: 'table',
+ columns: {
+ id: 'name',
+ lat: 'location-lat',
+ lng: 'location-lng',
+ altitude: 'location-alt'
+ }
+ }
+ },
+ datasets: {
+ [dataId]: prepareTripTableDataset
+ },
+ assert: result => {
+ const {layerData} = result;
+
+ let filterValues;
+ t.doesNotThrow(() => {
+ filterValues = layerData.data.map(layerData.getFilterValue);
+ }, 'getFilterValue should not throw in table column mode');
+
+ // The first feature groups the 8 rows named Thuub that carry a
+ // coordinate; the row with an empty location is dropped.
+ const round = v => Math.round(v * 100) / 100;
+ const groundSpeeds = [0.22, 0.27, 0.32, 0.46, 0.51, 0.3, 0.33, 0.43];
+
+ t.deepEqual(
+ (filterValues?.[0] ?? []).map(point => round(point[0])),
+ groundSpeeds.map(speed => round(speed - speedFilterDomain0)),
+ 'getFilterValue should return one filter value per point of the feature'
+ );
+ }
+ }
+ ];
+
+ testFormatLayerDataCases(t, GeojsonLayer, TEST_CASES);
+ t.end();
+});
+
test('#GeojsonLayer -> renderLayer', t => {
const filteredIndex = [0, 2, 4];
const TEST_CASES = [
diff --git a/test/browser/layer-tests/trip-layer-specs.js b/test/browser/layer-tests/trip-layer-specs.js
index 1a0366821..e9d1adb7d 100644
--- a/test/browser/layer-tests/trip-layer-specs.js
+++ b/test/browser/layer-tests/trip-layer-specs.js
@@ -20,6 +20,8 @@ import {
testFormatLayerDataCases,
testRenderLayerCases,
prepareTripGeoDataset,
+ prepareTripTableDataset,
+ speedFilterDomain0,
valueFilterDomain0,
animationConfig
} from 'test/helpers/layer-utils';
@@ -247,6 +249,59 @@ test('#TripLayer -> formatLayerData', t => {
t.end();
});
+test('#TripLayer -> formatLayerData -> table column mode with gpu filter', t => {
+ // The GPU filter reads a layer's values through the accessor the layer hands
+ // it, called as getData(dataContainer, feature, fieldIndex). Table column mode
+ // groups rows into trips, so the value of each channel is an array, one entry
+ // per vertex of the trip.
+ const TEST_CASES = [
+ {
+ name: 'Trip Table.1',
+ layer: {
+ type: 'trip',
+ id: 'test_trip_table_layer',
+ config: {
+ dataId,
+ label: 'gps trips',
+ columnMode: 'table',
+ columns: {
+ id: 'name',
+ lat: 'location-lat',
+ lng: 'location-lng',
+ timestamp: 'timestamp',
+ altitude: 'location-alt'
+ }
+ }
+ },
+ datasets: {
+ [dataId]: prepareTripTableDataset
+ },
+ assert: result => {
+ const {layerData} = result;
+
+ let filterValues;
+ t.doesNotThrow(() => {
+ filterValues = layerData.data.map(layerData.getFilterValue);
+ }, 'getFilterValue should not throw in table column mode');
+
+ // The first trip groups the 8 rows named Thuub that carry a coordinate
+ // and a timestamp; the row with an empty location is dropped.
+ const round = v => Math.round(v * 100) / 100;
+ const groundSpeeds = [0.22, 0.27, 0.32, 0.46, 0.51, 0.3, 0.33, 0.43];
+
+ t.deepEqual(
+ (filterValues?.[0] ?? []).map(vertex => round(vertex[0])),
+ groundSpeeds.map(speed => round(speed - speedFilterDomain0)),
+ 'getFilterValue should return one filter value per vertex of the trip'
+ );
+ }
+ }
+ ];
+
+ testFormatLayerDataCases(t, TripLayer, TEST_CASES);
+ t.end();
+});
+
test('#TripLayer -> renderLayer', t => {
const filteredIndex = [0, 2, 4];
diff --git a/test/helpers/layer-utils.js b/test/helpers/layer-utils.js
index b78030ac1..3bbf3875d 100644
--- a/test/helpers/layer-utils.js
+++ b/test/helpers/layer-utils.js
@@ -29,6 +29,7 @@ import csvData, {wktCsv} from '../fixtures/test-csv-data';
import testLayerData, {bounds, fieldDomain, iconGeometry} from '../fixtures/test-layer-data';
import {geojsonData} from '../fixtures/geojson';
import tripGeoJson from '../fixtures/trip-geojson';
+import tripCsvData from '../fixtures/test-trip-csv-data';
import {IntlWrapper} from './component-utils';
import {logStep} from '../../scripts/log';
@@ -479,3 +480,18 @@ export const prepareTripGeoDataset = stateWithTripGeojsonFilter.datasets[dataId]
export const prepareTripGeoDatasetFilter = stateWithTripGeojsonFilter.filters[0];
export const valueFilterDomain0 = prepareTripGeoDatasetFilter.domain[0];
export const {animationConfig} = stateWithTripGeojsonFilter;
+
+/*
+ * trip table dataset (id / lat / lng / timestamp columns) with gpu filter
+ */
+export const {rows: tripCsvRows, fields: tripCsvFields} = processCsvData(tripCsvData);
+
+const stateWithTripTableFilter = addFilterToData(
+ {fields: tripCsvFields, rows: tripCsvRows},
+ dataId,
+ [{name: 'ground-speed', value: [0.3, 16]}]
+);
+
+export const prepareTripTableDataset = stateWithTripTableFilter.datasets[dataId];
+export const prepareTripTableDatasetFilter = stateWithTripTableFilter.filters[0];
+export const speedFilterDomain0 = prepareTripTableDatasetFilter.domain[0];