Skip to content

Commit

Permalink
Merge pull request #609 from OpenGeoscience/geojson-empty-geometries
Browse files Browse the repository at this point in the history
Ignore geojson features with empty coordinates
  • Loading branch information
jbeezley authored Aug 26, 2016
2 parents 60335a1 + 12006b9 commit 0a6efce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/jsonReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
25 changes: 25 additions & 0 deletions tests/cases/geojsonReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 0a6efce

Please sign in to comment.