From 13c0553055f4e3c10ba66691a5db9107360a254d Mon Sep 17 00:00:00 2001 From: greg maillet Date: Thu, 28 Oct 2021 12:02:16 +0200 Subject: [PATCH] fix(GeoJson): repeat first point/ GeoJson polygon standard --- src/Parser/GeoJsonParser.js | 10 ++++++- test/data/geojson/holes.geojson.json | 40 +++++++++++++++++++++------ test/data/geojson/simple.geojson.json | 8 +++--- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/Parser/GeoJsonParser.js b/src/Parser/GeoJsonParser.js index 674e52f77d..add38577af 100644 --- a/src/Parser/GeoJsonParser.js +++ b/src/Parser/GeoJsonParser.js @@ -67,7 +67,15 @@ const toFeature = { // Then read contour and holes for (let i = 0; i < coordsIn.length; i++) { - this.populateGeometry(crsIn, coordsIn[i], geometry, feature); + // GeoJson standard: The first and last positions are equivalent, + // and they MUST contain identical values; their representation SHOULD also be identical. + const ring = coordsIn[i]; + if (ring.length > 1) { + if (JSON.stringify(ring[0]) === JSON.stringify(ring[ring.length - 1])) { + ring.pop(); + } + } + this.populateGeometry(crsIn, ring, geometry, feature); } feature.updateExtent(geometry); }, diff --git a/test/data/geojson/holes.geojson.json b/test/data/geojson/holes.geojson.json index 71425cbc2f..cdff084a1e 100644 --- a/test/data/geojson/holes.geojson.json +++ b/test/data/geojson/holes.geojson.json @@ -12,19 +12,25 @@ 0 ], [ - 0, - 1 + 2, + 0 ], [ 2, 1 ], [ - 2, + 0, + 1 + ], + [ + 0, 0 ] ] ] + }, + "properties" : { } }, { @@ -38,19 +44,25 @@ 0.3 ], [ - 0.2, - 0.7 + 1.4, + 0.3 ], [ 1.4, 0.7 ], [ - 1.4, + 0.2, + 0.7 + ], + [ + 0.2, 0.3 ] ] ] + }, + "properties" : { } }, { @@ -64,15 +76,19 @@ 0 ], [ - 0, - 1 + 2, + 0 ], [ 2, 1 ], [ - 2, + 0, + 1 + ], + [ + 0, 0 ] ], @@ -92,9 +108,15 @@ [ 1.4, 0.3 + ], + [ + 0.2, + 0.3 ] ] ] + }, + "properties" : { } } ] diff --git a/test/data/geojson/simple.geojson.json b/test/data/geojson/simple.geojson.json index 004f327bde..52bb1397be 100644 --- a/test/data/geojson/simple.geojson.json +++ b/test/data/geojson/simple.geojson.json @@ -42,16 +42,16 @@ 43.715534726205114 ], [ - 0.9067382756620646, - 43.72744458647463 + 0.36291503347456455, + 43.15710884095329 ], [ 1.1044921819120646, 43.37311218382002 ], [ - 0.36291503347456455, - 43.15710884095329 + 0.9067382756620646, + 43.72744458647463 ], [ 0.30798339284956455,