diff --git a/DataExtractionOSM/src-tests/net/osmand/data/MultipolygonTest.java b/DataExtractionOSM/src-tests/net/osmand/data/MultipolygonTest.java index 7e57693303..ac94ae6cc2 100644 --- a/DataExtractionOSM/src-tests/net/osmand/data/MultipolygonTest.java +++ b/DataExtractionOSM/src-tests/net/osmand/data/MultipolygonTest.java @@ -168,6 +168,13 @@ public class MultipolygonTest { assertFalse(testee.hasOpenedPolygons()); } - + @Test + public void test_firstEmptyWayThanOpenedWay() + { + testee.addOuterWay(new Way(111)); + testee.addOuterWay(poly1_1_of_2); + assertEquals(1, testee.countOuterPolygons()); + assertTrue(testee.hasOpenedPolygons()); + } } diff --git a/DataExtractionOSM/src/net/osmand/data/Multipolygon.java b/DataExtractionOSM/src/net/osmand/data/Multipolygon.java index 47bd17601c..48bd769697 100644 --- a/DataExtractionOSM/src/net/osmand/data/Multipolygon.java +++ b/DataExtractionOSM/src/net/osmand/data/Multipolygon.java @@ -32,18 +32,20 @@ public class Multipolygon { protected IdentityHashMap> outerInnerMapping; private void addNewPolygonPart(List polygons, List closedPolygons, Way newPoly) { - if (isClosed(newPoly)) { - closedPolygons.add(newPoly); //if closed, put directly to closed polygons - } else if (polygons.isEmpty()) { - polygons.add(newPoly); //if open, and first, put to polygons.. - } else { - // now we try to merge the ways to form bigger polygons - Stack wayStack = new Stack(); - wayStack.push(newPoly); - addAndMergePolygon(polygons, closedPolygons, wayStack); - } - //reset the mapping - outerInnerMapping = null; + if (!newPoly.getNodes().isEmpty()) { + if (isClosed(newPoly)) { + closedPolygons.add(newPoly); //if closed, put directly to closed polygons + } else if (polygons.isEmpty()) { + polygons.add(newPoly); //if open, and first, put to polygons.. + } else { + // now we try to merge the ways to form bigger polygons + Stack wayStack = new Stack(); + wayStack.push(newPoly); + addAndMergePolygon(polygons, closedPolygons, wayStack); + } + //reset the mapping + outerInnerMapping = null; + } //else do nothing } private boolean isClosed(Way newPoly) {