Index: src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java =================================================================== --- src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java (revision 1593) +++ src/uk/me/parabola/mkgmap/reader/osm/MultiPolygonRelation.java (working copy) @@ -325,6 +325,22 @@ } Coord p1 = way.getPoints().get(0); Coord p2 = way.getPoints().get(way.getPoints().size() - 1); + + // check if both endpoints are outside the bounding box + // and if they are on the same side of the bounding box + if ((p1.getLatitude() <= bbox.getMinLat() && p2.getLatitude() <= bbox.getMinLat()) + || (p1.getLatitude() >= bbox.getMaxLat() && p2.getLatitude() >= bbox.getMaxLat()) + || (p1.getLongitude() <= bbox.getMinLong() && p2.getLongitude() <= bbox.getMinLong()) + || (p1.getLongitude() >= bbox.getMaxLong() && p2.getLongitude() >= bbox.getMaxLong())) { + // they are on the same side outside of the bbox + // so just close them without worrying about if + // they intersect itself because the intersection also + // is outside the bbox + way.closeWayArtificially(); + log.info("Endpoints of way",way,"are both outside the bbox. Closing it directly."); + continue; + } + Line2D closingLine = new Line2D.Float(p1.getLongitude(), p1 .getLatitude(), p2.getLongitude(), p2.getLatitude());