Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore geojson features with empty coordinates #609

Merged
merged 2 commits into from
Aug 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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