From 10dcc2c34b68f68e4ed655e755c18204007bdf99 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Thu, 6 Feb 2020 10:12:31 -0800 Subject: [PATCH] fix: Return array when given single feature with null geometry. (#27) Fixes #26. --- index.js | 2 +- tap-snapshots/test-flatten.js-TAP.test.js | 238 ++++++++++++++++++++++ 2 files changed, 239 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 09aaeb8..8834356 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ export default function flatten(gj) { }, []); return gj; case "Feature": - if (!gj.geometry) return gj; + if (!gj.geometry) return [gj]; return flatten(gj.geometry).map(function(geom) { var data = { type: "Feature", diff --git a/tap-snapshots/test-flatten.js-TAP.test.js b/tap-snapshots/test-flatten.js-TAP.test.js index 5b3ff4e..664c053 100644 --- a/tap-snapshots/test-flatten.js-TAP.test.js +++ b/tap-snapshots/test-flatten.js-TAP.test.js @@ -5,6 +5,81 @@ * Make sure to inspect the output below. Do not ignore changes! */ 'use strict' +exports[`test/flatten.js TAP flatten multigeometry-single.input.geojson > multigeometry-single.input.geojson 1`] = ` +Array [ + Object { + "geometry": Object { + "coordinates": Array [ + -122.4425587930444, + 37.80666418607323, + 0, + ], + "type": "Point", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, + Object { + "geometry": Object { + "coordinates": Array [ + -122.4428379594768, + 37.80663578323093, + 0, + ], + "type": "Point", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, + Object { + "geometry": Object { + "coordinates": Array [ + Array [ + -122.4425587930444, + 37.80666418607323, + 0, + ], + Array [ + -122.4428379594768, + 37.80663578323093, + 0, + ], + ], + "type": "LineString", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, + Object { + "geometry": Object { + "coordinates": Array [ + Array [ + -122.4425509770566, + 37.80662588061205, + 0, + ], + Array [ + -122.4428340530617, + 37.8065999493009, + 0, + ], + ], + "type": "LineString", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, +] +` + exports[`test/flatten.js TAP flatten multigeometry.input.geojson > multigeometry.input.geojson 1`] = ` Object { "features": Array [ @@ -83,6 +158,49 @@ Object { } ` +exports[`test/flatten.js TAP flatten multilinestring-single.input.geojson > multilinestring-single.input.geojson 1`] = ` +Array [ + Object { + "geometry": Object { + "coordinates": Array [ + Array [ + 0, + 0, + ], + Array [ + 1, + 1, + ], + ], + "type": "LineString", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, + Object { + "geometry": Object { + "coordinates": Array [ + Array [ + 2, + 2, + ], + Array [ + 3, + 3, + ], + ], + "type": "LineString", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, +] +` + exports[`test/flatten.js TAP flatten multilinestring.input.geojson > multilinestring.input.geojson 1`] = ` Object { "features": Array [ @@ -129,6 +247,37 @@ Object { } ` +exports[`test/flatten.js TAP flatten multipoint-single.input.geojson > multipoint-single.input.geojson 1`] = ` +Array [ + Object { + "geometry": Object { + "coordinates": Array [ + 0, + 0, + ], + "type": "Point", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, + Object { + "geometry": Object { + "coordinates": Array [ + 1, + 1, + ], + "type": "Point", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, +] +` + exports[`test/flatten.js TAP flatten multipoint.input.geojson > multipoint.input.geojson 1`] = ` Object { "features": Array [ @@ -163,6 +312,65 @@ Object { } ` +exports[`test/flatten.js TAP flatten multipolygon-single.input.geojson > multipolygon-single.input.geojson 1`] = ` +Array [ + Object { + "geometry": Object { + "coordinates": Array [ + Array [ + 0, + 0, + ], + Array [ + 1, + 1, + ], + Array [ + 4, + 2, + ], + Array [ + 0, + 0, + ], + ], + "type": "Polygon", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, + Object { + "geometry": Object { + "coordinates": Array [ + Array [ + 0, + 0, + ], + Array [ + 5, + 5, + ], + Array [ + 4, + 2, + ], + Array [ + 0, + 0, + ], + ], + "type": "Polygon", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, +] +` + exports[`test/flatten.js TAP flatten multipolygon.input.geojson > multipolygon.input.geojson 1`] = ` Object { "features": Array [ @@ -225,6 +433,18 @@ Object { } ` +exports[`test/flatten.js TAP flatten nullgeometry-single.input.geojson > nullgeometry-single.input.geojson 1`] = ` +Array [ + Object { + "geometry": null, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, +] +` + exports[`test/flatten.js TAP flatten nullgeometry.input.geojson > nullgeometry.input.geojson 1`] = ` Object { "features": Array [ @@ -240,6 +460,24 @@ Object { } ` +exports[`test/flatten.js TAP flatten point-single.input.geojson > point-single.input.geojson 1`] = ` +Array [ + Object { + "geometry": Object { + "geometries": Array [ + 0, + 0, + ], + "type": "Point", + }, + "properties": Object { + "name": "SF Marina Harbor Master", + }, + "type": "Feature", + }, +] +` + exports[`test/flatten.js TAP flatten point.input.geojson > point.input.geojson 1`] = ` Object { "features": Array [