Skip to content

Commit

Permalink
fix(GeoJson): repeat first point/ GeoJson polygon standard
Browse files Browse the repository at this point in the history
  • Loading branch information
ign-packo committed Oct 28, 2021
1 parent 4f0a286 commit 13c0553
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
10 changes: 9 additions & 1 deletion src/Parser/GeoJsonParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
40 changes: 31 additions & 9 deletions test/data/geojson/holes.geojson.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
0
],
[
0,
1
2,
0
],
[
2,
1
],
[
2,
0,
1
],
[
0,
0
]
]
]
},
"properties" : {
}
},
{
Expand All @@ -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" : {
}
},
{
Expand All @@ -64,15 +76,19 @@
0
],
[
0,
1
2,
0
],
[
2,
1
],
[
2,
0,
1
],
[
0,
0
]
],
Expand All @@ -92,9 +108,15 @@
[
1.4,
0.3
],
[
0.2,
0.3
]
]
]
},
"properties" : {
}
}
]
Expand Down
8 changes: 4 additions & 4 deletions test/data/geojson/simple.geojson.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 13c0553

Please sign in to comment.