Skip to content

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

[Bug] fix empty geometry causing trip layer detection to fail (#826)

Shan He010f4bc07617
diff --git a/src/layers/geojson-layer/geojson-utils.js b/src/layers/geojson-layer/geojson-utils.js
index d5eb6e24a..4c44b6992 100644
--- a/src/layers/geojson-layer/geojson-utils.js
+++ b/src/layers/geojson-layer/geojson-utils.js
@@ -87,8 +87,9 @@ export function getGeojsonDataMaps(allData, getFeature) {
};
dataToFeature[index] = feature;
+ } else {
+ dataToFeature[index] = null;
}
-
}
return dataToFeature;
diff --git a/src/layers/trip-layer/trip-utils.js b/src/layers/trip-layer/trip-utils.js
index 86fd08791..b9debc0b0 100644
--- a/src/layers/trip-layer/trip-utils.js
+++ b/src/layers/trip-layer/trip-utils.js
@@ -81,8 +81,7 @@ export function isTripGeoJsonField(allData = [], field) {
const sampleRawFeatures =
allData.length > maxCount ? getSampleData(allData, maxCount, getValue) : allData.map(getValue);
- const features = sampleRawFeatures.map(parseGeoJsonRawFeature);
-
+ const features = sampleRawFeatures.map(parseGeoJsonRawFeature).filter(f => f);
const featureTypes = getGeojsonFeatureTypes(features);
// condition 1: contain line string
diff --git a/test/fixtures/test-csv-data.js b/test/fixtures/test-csv-data.js
index c99fd2444..22a01108e 100644
--- a/test/fixtures/test-csv-data.js
+++ b/test/fixtures/test-csv-data.js
@@ -451,11 +451,14 @@ export const parsedDataWithNulls = [
];
export const wktCsv = `a_zip,simplified_shape_v2,simplified_shape,m_rate,c_zip_type,c_number
-7014,"{""type"":""Polygon"",""coordinates"":[[[-74.158491,40.835947],[-74.157914,40.83902],[-74.148473,40.834522]]]}","POLYGON ((-74.158491 40.835947, -74.158491 40.835947))",7.5,C_Medium_High,29.07437458
-7016,"{""type"":""Polygon"",""coordinates"":[[[-74.31687,40.656696],[-74.319449,40.658154],[-74.31687,40.656696]]]}","POLYGON ((-74.31687 40.656696, -74.312298 40.654042, -74.31687 40.656696))",6.5,C_Medium_High,27.60106201
-7023,"{""type"":""Polygon"",""coordinates"":[[[-74.387589,40.632238],[-74.387589,40.632238]]]}","POLYGON ((-74.387589 40.632238, -74.382333 40.632417, -74.384457 40.630453, -74.387589 40.632238))",7.6,C_Medium_High,23.85239437
-7029,"{""type"":""Polygon"",""coordinates"":[[[-74.165995,40.747969],[-74.165987,40.745199],[-74.165995,40.747969]]]}","POLYGON ((-74.165995 40.747969, -74.163788 40.739201, -74.165987 40.745199, -74.165995 40.747969))",11.8,C_Medium_High,39.13775443
-7416,"{""type"":""MultiPolygon"",""coordinates"":[[[[-74.566993,41.087294],[-74.564908,41.089339],[-74.552353,41.091647],[-74.566993,41.087294]]],[[[-74.593264,41.088526],[-74.593264,41.088526]]]]}","MULTIPOLYGON (((-74.566993 41.087294, -74.564908 41.089339, -74.56559 41.090507, -74.557344 41.105958, -74.585763 41.083491, -74.593264 41.088526)))",10,A_Low_Rural,13.81679389`;
+7015,,,7,C_Medium_High,22.22
+7014,"{""type"":""Polygon"",""coordinates"":[[[-74.158491,40.835947],[-74.157914,40.83902],[-74.148473,40.834522]]]}","POLYGON ((-74.158491 40.835947, -74.157914 40.83902, -74.148473 40.834522))",7.5,C_Medium_High,29.07437458
+7016,"{""type"":""Polygon"",""coordinates"":[[[-74.31687,40.656696],[-74.319449,40.658154],[-74.31687,40.656696]]]}","POLYGON ((-74.31687 40.656696, -74.319449 40.658154, -74.31687 40.656696))",6.5,C_Medium_High,27.60106201
+7023,"{""type"":""Polygon"",""coordinates"":[[[-74.387589,40.632238],[-74.387589,40.632238]]]}","POLYGON ((-74.387589 40.632238, -74.387589 40.632238))",7.6,C_Medium_High,23.85239437
+7029,"{""type"":""Polygon"",""coordinates"":[[[-74.165995,40.747969],[-74.165987,40.745199],[-74.165995,40.747969]]]}","POLYGON ((-74.165995 40.747969, -74.165987 40.745199, -74.165995 40.747969))",11.8,C_Medium_High,39.13775443
+7416,"{""type"":""MultiPolygon"",""coordinates"":[[[[-74.566993,41.087294],[-74.564908,41.089339],[-74.552353,41.091647],[-74.566993,41.087294]]],[[[-74.593264,41.088526],[-74.593264,41.088526]]]]}","MULTIPOLYGON (((-74.566993 41.087294, -74.564908 41.089339, -74.552353 41.091647, -74.566993 41.087294)),((-74.593264 41.088526, -74.593264 41.088526)))",10,A_Low_Rural,13.81679389
+7023,"{""type"":""LineString"",""coordinates"":[[-74.387589,40.632238],[-74.387589,40.632238]]}","LINESTRING (-74.387589 40.632238, -74.387589 40.632238)",7.6,C_Medium_High,23.85239437
+`;
export const testFields = [
{
@@ -883,11 +886,12 @@ export const testAllData = [
export default data;
export const updatedLayerV2 = {
- dataToFeature: {
- 0: {
+ dataToFeature: [
+ null,
+ {
type: 'Feature',
properties: {
- index: 0
+ index: 1
},
geometry: {
type: 'Polygon',
@@ -900,10 +904,10 @@ export const updatedLayerV2 = {
]
}
},
- 1: {
+ {
type: 'Feature',
properties: {
- index: 1
+ index: 2
},
geometry: {
type: 'Polygon',
@@ -916,20 +920,20 @@ export const updatedLayerV2 = {
]
}
},
- 2: {
+ {
type: 'Feature',
properties: {
- index: 2
+ index: 3
},
geometry: {
type: 'Polygon',
coordinates: [[[-74.387589, 40.632238], [-74.387589, 40.632238]]]
}
},
- 3: {
+ {
type: 'Feature',
properties: {
- index: 3
+ index: 4
},
geometry: {
type: 'Polygon',
@@ -942,10 +946,10 @@ export const updatedLayerV2 = {
]
}
},
- 4: {
+ {
type: 'Feature',
properties: {
- index: 4
+ index: 5
},
geometry: {
type: 'MultiPolygon',
@@ -961,102 +965,21 @@ export const updatedLayerV2 = {
[[[-74.593264, 41.088526], [-74.593264, 41.088526]]]
]
}
- }
- },
- meta: {
- featureTypes: {polygon: true},
- bounds: [-74.593264, 40.632238, -74.148473, 41.091647],
- fixedRadius: false
- }
-};
-
-export const updatedLayerSimplifiedShape = {
- dataToFeature: {
- 0: {
- type: 'Feature',
- properties: {
- index: 0
- },
- geometry: {
- type: 'Polygon',
- coordinates: [[[-74.158491, 40.835947], [-74.158491, 40.835947]]]
- }
},
- 1: {
+ {
type: 'Feature',
properties: {
- index: 1
+ index: 6
},
geometry: {
- type: 'Polygon',
- coordinates: [
- [
- [-74.31687, 40.656696],
- [-74.312298, 40.654042],
- [-74.31687, 40.656696]
- ]
- ]
- }
- },
- 2: {
- type: 'Feature',
- properties: {
- index: 2
- },
- geometry: {
- type: 'Polygon',
- coordinates: [
- [
- [-74.387589, 40.632238],
- [-74.382333, 40.632417],
- [-74.384457, 40.630453],
- [-74.387589, 40.632238]
- ]
- ]
- }
- },
- 3: {
- type: 'Feature',
- properties: {
- index: 3
- },
- geometry: {
- type: 'Polygon',
- coordinates: [
- [
- [-74.165995, 40.747969],
- [-74.163788, 40.739201],
- [-74.165987, 40.745199],
- [-74.165995, 40.747969]
- ]
- ]
- }
- },
- 4: {
- type: 'Feature',
- properties: {
- index: 4
- },
- geometry: {
- type: 'MultiPolygon',
- coordinates: [
- [
- [
- [-74.566993, 41.087294],
- [-74.564908, 41.089339],
- [-74.56559, 41.090507],
- [-74.557344, 41.105958],
- [-74.585763, 41.083491],
- [-74.593264, 41.088526]
- ]
- ]
- ]
+ type: 'LineString',
+ coordinates: [[-74.387589, 40.632238], [-74.387589, 40.632238]]
}
}
- },
+ ],
meta: {
- featureTypes: {polygon: true},
- bounds: [-74.593264, 40.630453, -74.158491, 41.105958],
+ featureTypes: {polygon: true, line: true},
+ bounds: [-74.593264, 40.632238, -74.148473, 41.091647],
fixedRadius: false
}
};
diff --git a/test/node/layer-tests/geojson-layer-specs.js b/test/node/layer-tests/geojson-layer-specs.js
index ba50b4303..9cc84c3ce 100644
--- a/test/node/layer-tests/geojson-layer-specs.js
+++ b/test/node/layer-tests/geojson-layer-specs.js
@@ -22,24 +22,31 @@ import test from 'tape';
import GeojsonLayer from 'layers/geojson-layer/geojson-layer';
import {processCsvData} from 'processors/data-processor';
-import {wktCsv, updatedLayerSimplifiedShape, updatedLayerV2}
-from 'test/fixtures/test-csv-data';
-import {testCreateCases, testFormatLayerDataCases} from 'test/helpers/layer-utils';
+import {wktCsv, updatedLayerV2} from 'test/fixtures/test-csv-data';
+import {
+ testCreateCases,
+ testFormatLayerDataCases
+} from 'test/helpers/layer-utils';
test('#GeojsonLayer -> constructor', t => {
const TEST_CASES = {
- CREATE: [{
- props: {
- dataId: 'smoothie',
- isVisible: true,
- label: 'test geojson layer'
- },
- test: layer => {
- t.ok(layer.config.dataId === 'smoothie', 'geojsonLayer dataId should be correct');
- t.ok(layer.type === 'geojson', 'type should be geojson');
- t.ok(layer.isAggregated === false, 'geojsonLayer is not aggregated');
+ CREATE: [
+ {
+ props: {
+ dataId: 'smoothie',
+ isVisible: true,
+ label: 'test geojson layer'
+ },
+ test: layer => {
+ t.ok(
+ layer.config.dataId === 'smoothie',
+ 'geojsonLayer dataId should be correct'
+ );
+ t.ok(layer.type === 'geojson', 'type should be geojson');
+ t.ok(layer.isAggregated === false, 'geojsonLayer is not aggregated');
+ }
}
- }]
+ ]
};
testCreateCases(t, GeojsonLayer, TEST_CASES.CREATE);
@@ -49,93 +56,156 @@ test('#GeojsonLayer -> constructor', t => {
test('#GeojsonLayer -> formatLayerData', t => {
const {rows} = processCsvData(wktCsv);
- const filteredIndex = [0, 2, 4];
- const data = [rows[0], rows[2], rows[4]];
+ const filteredIndex = [0, 1, 2, 4];
+ const data = [rows[0], rows[1], rows[2], rows[4]];
- const TEST_CASES = [{
- props: {
- dataId: '0dj3h',
- label: 'some geometry file',
- columns: {
- geojson: {
- value: 'simplified_shape_v2',
- fieldIdx: 1
+ const TEST_CASES = [
+ {
+ props: {
+ dataId: '0dj3h',
+ label: 'some geometry file',
+ columns: {
+ geojson: {
+ value: 'simplified_shape_v2',
+ fieldIdx: 1
+ }
}
- }
- },
- data: [data, rows, filteredIndex, undefined],
- test: result => {
- const {layerData, layer} = result;
- const expectedLayerData = {
- data: [
- updatedLayerV2.dataToFeature[0],
- updatedLayerV2.dataToFeature[2],
- updatedLayerV2.dataToFeature[4]
- ],
- getFeature: () => {},
- getFillColor: () => {},
- getLineColor: () => {},
- getLineWidth: () => {},
- getElevation: () => {},
- getRadius: () => {}
- };
- const expectedLayerMeta = updatedLayerV2.meta;
- const expectedDataToFeature = updatedLayerV2.dataToFeature;
+ },
+ data: [data, rows, filteredIndex, undefined],
+ test: result => {
+ const {layerData, layer} = result;
+ const expectedLayerData = {
+ data: [
+ updatedLayerV2.dataToFeature[1],
+ updatedLayerV2.dataToFeature[2],
+ updatedLayerV2.dataToFeature[4]
+ ],
+ getFeature: () => {},
+ getFillColor: () => {},
+ getLineColor: () => {},
+ getLineWidth: () => {},
+ getElevation: () => {},
+ getRadius: () => {}
+ };
+ const expectedLayerMeta = updatedLayerV2.meta;
+ const expectedDataToFeature = updatedLayerV2.dataToFeature;
- t.deepEqual(layerData.data, expectedLayerData.data, 'should format correct geojson layerData');
- t.ok(typeof layerData.getFeature === 'function', 'should have getFeature');
- t.ok(typeof layerData.getFillColor === 'function', 'should have getFillColor');
- t.ok(typeof layerData.getLineColor === 'function', 'should have getLineColor');
- t.ok(typeof layerData.getLineWidth === 'function', 'should have getSize');
- t.ok(typeof layerData.getElevation === 'function', 'should have getRadius');
- t.ok(typeof layerData.getRadius === 'function', 'should have getRadius');
+ t.deepEqual(
+ layerData.data,
+ expectedLayerData.data,
+ 'should format correct geojson layerData'
+ );
+ t.ok(
+ typeof layerData.getFeature === 'function',
+ 'should have getFeature'
+ );
+ t.ok(
+ typeof layerData.getFillColor === 'function',
+ 'should have getFillColor'
+ );
+ t.ok(
+ typeof layerData.getLineColor === 'function',
+ 'should have getLineColor'
+ );
+ t.ok(
+ typeof layerData.getLineWidth === 'function',
+ 'should have getSize'
+ );
+ t.ok(
+ typeof layerData.getElevation === 'function',
+ 'should have getRadius'
+ );
+ t.ok(
+ typeof layerData.getRadius === 'function',
+ 'should have getRadius'
+ );
- t.deepEqual(layer.meta, expectedLayerMeta, 'should format correct geojson layerData');
- t.deepEqual(layer.dataToFeature, expectedDataToFeature, 'should format correct geojson layerData');
- }
- }, {
- props: {
- dataId: '0dj3h',
- label: 'some geometry file',
- columns: {
- geojson: {
- value: 'simplified_shape',
- fieldIdx: 2
- }
+ t.deepEqual(
+ layer.meta,
+ expectedLayerMeta,
+ 'should format correct geojson layer meta'
+ );
+ t.deepEqual(
+ layer.dataToFeature,
+ expectedDataToFeature,
+ 'should format correct geojson dataToFeature'
+ );
}
},
- data: [data, rows, filteredIndex, undefined],
- test: result => {
- const {layerData, layer} = result;
+ {
+ props: {
+ dataId: '0dj3h',
+ label: 'some geometry file',
+ columns: {
+ geojson: {
+ value: 'simplified_shape',
+ fieldIdx: 2
+ }
+ }
+ },
+ data: [data, rows, filteredIndex, undefined],
+ test: result => {
+ const {layerData, layer} = result;
- const expectedLayerData = {
- data: [
- updatedLayerSimplifiedShape.dataToFeature[0],
- updatedLayerSimplifiedShape.dataToFeature[2],
- updatedLayerSimplifiedShape.dataToFeature[4]
- ],
- getFeature: () => {},
- getFillColor: () => {},
- getLineColor: () => {},
- getLineWidth: () => {},
- getElevation: () => {},
- getRadius: () => {}
- };
- const expectedLayerMeta = updatedLayerSimplifiedShape.meta;
- const expectedDataToFeature = updatedLayerSimplifiedShape.dataToFeature;
+ const expectedLayerData = {
+ data: [
+ updatedLayerV2.dataToFeature[1],
+ updatedLayerV2.dataToFeature[2],
+ updatedLayerV2.dataToFeature[4]
+ ],
+ getFeature: () => {},
+ getFillColor: () => {},
+ getLineColor: () => {},
+ getLineWidth: () => {},
+ getElevation: () => {},
+ getRadius: () => {}
+ };
+ const expectedLayerMeta = updatedLayerV2.meta;
+ const expectedDataToFeature = updatedLayerV2.dataToFeature;
- t.deepEqual(layerData.data, expectedLayerData.data, 'should format correct geojson layerData');
- t.ok(typeof layerData.getFeature === 'function', 'should have getFeature');
- t.ok(typeof layerData.getFillColor === 'function', 'should have getFillColor');
- t.ok(typeof layerData.getLineColor === 'function', 'should have getLineColor');
- t.ok(typeof layerData.getLineWidth === 'function', 'should have getSize');
- t.ok(typeof layerData.getElevation === 'function', 'should have getRadius');
- t.ok(typeof layerData.getRadius === 'function', 'should have getRadius');
+ t.deepEqual(
+ layerData.data,
+ expectedLayerData.data,
+ 'should format correct geojson layerData'
+ );
+ t.ok(
+ typeof layerData.getFeature === 'function',
+ 'should have getFeature'
+ );
+ t.ok(
+ typeof layerData.getFillColor === 'function',
+ 'should have getFillColor'
+ );
+ t.ok(
+ typeof layerData.getLineColor === 'function',
+ 'should have getLineColor'
+ );
+ t.ok(
+ typeof layerData.getLineWidth === 'function',
+ 'should have getSize'
+ );
+ t.ok(
+ typeof layerData.getElevation === 'function',
+ 'should have getRadius'
+ );
+ t.ok(
+ typeof layerData.getRadius === 'function',
+ 'should have getRadius'
+ );
- t.deepEqual(layer.meta, expectedLayerMeta, 'should format correct geojson layerData');
- t.deepEqual(layer.dataToFeature, expectedDataToFeature, 'should format correct geojson layerData');
+ t.deepEqual(
+ layer.meta,
+ expectedLayerMeta,
+ 'should format correct geojson layer meta'
+ );
+ t.deepEqual(
+ layer.dataToFeature,
+ expectedDataToFeature,
+ 'should format correct geojson dataToFeature'
+ );
+ }
}
- }];
+ ];
testFormatLayerDataCases(t, GeojsonLayer, TEST_CASES);
t.end();