Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit d6d13bb

Browse files
committed
strip out rings with 3 or less coordinates during conversion
1 parent dc8ac90 commit d6d13bb

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

spec/arcgisSpec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ describe("ArcGIS Tools", function(){
108108
});
109109
});
110110

111+
it("should strip invalid rings when converting a GeoJSON Polygon to and ArcGIS Polygon", function() {
112+
var input = {
113+
"type": "Polygon",
114+
"coordinates": [
115+
[ [100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0] ],
116+
[ [100.2,0.2],[100.8,0.2],[100.2,0.2] ]
117+
]
118+
};
119+
120+
var output = Terraformer.ArcGIS.convert(input);
121+
122+
expect(output).toEqual({
123+
"rings": [
124+
[ [100, 0], [100, 1], [101, 1], [101, 0], [100, 0] ]
125+
],
126+
"spatialReference":{
127+
"wkid":4326
128+
}
129+
});
130+
});
131+
111132
it("should close ring when converting a GeoJSON Polygon w/ a hole to an ArcGIS Polygon", function() {
112133
var input = {
113134
"type": "Polygon",
@@ -626,6 +647,25 @@ describe("ArcGIS Tools", function(){
626647
expect(output.type).toEqual("MultiPolygon");
627648
});
628649

650+
it("should strip invalid rings when converting ArcGIS Polygons to GeoJSON", function() {
651+
var input = {
652+
"rings":[
653+
[[-122.63,45.52],[-122.57,45.53],[-122.52,45.50],[-122.49,45.48],[-122.64,45.49],[-122.63,45.52],[-122.63,45.52]],
654+
[[-83,35],[-74,35],[-83,35]] // closed but too small
655+
],
656+
"spatialReference": {
657+
"wkid":4326
658+
}
659+
};
660+
661+
var output = Terraformer.ArcGIS.parse(input);
662+
663+
expect(output.coordinates).toEqual([
664+
[ [-122.63,45.52],[-122.57,45.53],[-122.52,45.5],[-122.49,45.48],[-122.64,45.49],[-122.63,45.52],[-122.63,45.52] ]
665+
]);
666+
expect(output.type).toEqual("Polygon");
667+
});
668+
629669
it("should properly close rings when converting an ArcGIS Polygon in a Terraformer GeoJSON MultiPolygon", function() {
630670
var input = {
631671
"rings":[

terraformer-arcgis-parser.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,22 @@
101101
var output = [];
102102
var polygon = poly.slice(0);
103103
var outerRing = closeRing(polygon.shift().slice(0));
104+
if(outerRing.length >= 4){
105+
if(!ringIsClockwise(outerRing)){
106+
outerRing.reverse();
107+
}
104108

105-
if(!ringIsClockwise(outerRing)){
106-
outerRing.reverse();
107-
}
108-
109-
output.push(outerRing);
109+
output.push(outerRing);
110110

111-
for (var i = 0; i < polygon.length; i++) {
112-
var hole = closeRing(polygon[i].slice(0));
113-
if(ringIsClockwise(hole)){
114-
hole.reverse();
111+
for (var i = 0; i < polygon.length; i++) {
112+
var hole = closeRing(polygon[i].slice(0));
113+
if(hole.length >= 4){
114+
if(ringIsClockwise(hole)){
115+
hole.reverse();
116+
}
117+
output.push(hole);
118+
}
115119
}
116-
output.push(hole);
117120
}
118121

119122
return output;
@@ -171,7 +174,9 @@
171174
// for each ring
172175
for (var r = 0; r < rings.length; r++) {
173176
var ring = closeRing(rings[r].slice(0));
174-
177+
if(ring.length < 4){
178+
continue;
179+
}
175180
// is this ring an outer ring? is it clockwise?
176181
if(ringIsClockwise(ring)){
177182
var polygon = [ ring ];

0 commit comments

Comments
 (0)