Index: src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java =================================================================== --- src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java (Revision 1457) +++ src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java (Arbeitskopie) @@ -349,44 +348,39 @@ unfinishedRings.andNot(innerIndexes); // now construct the outer polygon with its holes - for (Way innerRing : innerRings) { - int[] insert = findCpa(outerRing.getPoints(), innerRing - .getPoints()); - if (insert[0] >= 0 && insert[1] >= 0) { - insertPoints(outerRing, innerRing, insert[0], insert[1]); - } - } - - // set the tags of the outer ring - // does the multipolygon itself have any tags? - boolean validTagFound = false; - for (Map.Entry tagEntry : getEntryIteratable()) { + List decomposition = PolygonDecomposer.decompose(outerRing, innerRings); + myWayMap.remove(outerRing.getId()); + for (Way way : decomposition) { + // set the tags of the outer ring + // does the multipolygon itself have any tags? + boolean validTagFound = false; + for (Map.Entry tagEntry : getEntryIteratable()) { if (relationTags.contains(tagEntry.getKey())) { - validTagFound = true; - break; + validTagFound = true; + break; } - } + } - if (validTagFound) { + if (validTagFound) { // the multipolygon contains tags that overwhelm the tags // out the outer ring - outerRing.copyTags(this); - } else { + way.copyTags(this); + } else { // the multipolygon does not contain any relevant tag // use the segments of the outer ring and merge the tags for (Way outerRingSegment : outerRing.getOriginalWays()) { - // TODO uuh, this is bad => the last of the outer ring - // segments win - // => any better idea? - for (Map.Entry outSegmentTag : outerRingSegment - .getEntryIteratable()) { - outerRing.addTag(outSegmentTag.getKey(), - outSegmentTag.getValue()); - } + // TODO uuh, this is bad => the last of the outer ring + // segments win + // => any better idea? + for (Map.Entry outSegmentTag : outerRingSegment + .getEntryIteratable()) { + way.addTag(outSegmentTag.getKey(), + outSegmentTag.getValue()); + } } + } + polygonResults.add(way); } - - polygonResults.add(outerRing); } } @@ -601,11 +595,11 @@ * This is a helper class that stores that gives access to the original segments * of a joined way. */ - private static class JoinedWay extends Way { + private static class JoinedWay extends Way { private final List originalWays; public JoinedWay(Way originalWay) { - super(-originalWay.getId(), new ArrayList(originalWay + super(originalWay.getId(), new ArrayList(originalWay .getPoints())); this.originalWays = new ArrayList(); this.originalWays.add(originalWay); Index: src/uk/me/parabola/mkgmap/reader/osm/Way.java =================================================================== --- src/uk/me/parabola/mkgmap/reader/osm/Way.java (Revision 1457) +++ src/uk/me/parabola/mkgmap/reader/osm/Way.java (Arbeitskopie) @@ -91,7 +91,7 @@ public void reverse() { int numPoints = points.size(); - for(int i = 0; i < numPoints/2; ++i) { + for (int i = 0; i < numPoints/2; ++i) { Coord t = points.get(i); points.set(i, points.get(numPoints - 1 - i)); points.set(numPoints - 1 - i, t); @@ -102,7 +102,21 @@ return !points.isEmpty() && points.get(0).equals(points.get(points.size()-1)); } + /** Check wether a (closed) way is ordered clockwise. + * @return true, if the way is ordered clockwise. + */ + public boolean isClockwise() { + double sum = 0; + int numPoints = points.size(); + for (int i=0; i < numPoints-1; i++) { + Coord p1 = points.get(i); + Coord p2 = points.get(i+1); + sum += p2.getLongitude()*p1.getLatitude() - p1.getLongitude()*p2.getLatitude(); + } + return sum > 0; + } + /** * A simple representation of this way. * @return A string with the name and start point