From 8f9a06e195384ed02b8d2aa7782f3904998ca0ca Mon Sep 17 00:00:00 2001 From: Jonathan Beezley Date: Fri, 26 Aug 2016 13:33:19 -0400 Subject: [PATCH] Ignore features with empty geometries --- src/jsonReader.js | 7 +++++++ tests/cases/geojsonReader.js | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/jsonReader.js b/src/jsonReader.js index ed93c5029b..c7aa3dad3e 100644 --- a/src/jsonReader.js +++ b/src/jsonReader.js @@ -133,6 +133,13 @@ var jsonReader = function (arg) { features.forEach(function (feature) { Array.prototype.push.apply(normalized, m_this._feature(feature)); }); + + // remove features with empty geometries + normalized = normalized.filter(function (feature) { + return feature.geometry && + feature.geometry.coordinates && + feature.geometry.coordinates.length; + }); return normalized; }; diff --git a/tests/cases/geojsonReader.js b/tests/cases/geojsonReader.js index ca00171eef..dd4829da77 100644 --- a/tests/cases/geojsonReader.js +++ b/tests/cases/geojsonReader.js @@ -213,6 +213,31 @@ describe('geojsonReader', function () { coordinates: [1, 1] } }]); + + it('empty geometry', function () { + expect(reader._featureArray({ + type: 'FeatureCollection', + features: [{ + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [] + } + }, { + type: 'Feature', + geometry: { + type: 'LineString', + coordinates: [] + } + }, { + type: 'Feature', + geometry: { + type: 'Polygon', + coordinates: [] + } + }] + })).toEqual([]); + }); }); describe('Errors', function () {