Hi Felix,
Please try the attached patch and see if it fixes the problem.
The patch fools with the way splitting code a bit so please check it doesn't
screw anything else.
That's it for tonight!
Cheers,
Mark
diff --git a/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java b/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
index b4480c2..425e0dd 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
@@ -862,21 +862,18 @@ public class StyledConverter implements OsmConverter {
if(clippedWays != null) {
for(Way cw : clippedWays) {
- while(cw.getPoints().size() > MAX_POINTS_IN_WAY) {
- Way tail = splitWayAt(cw, MAX_POINTS_IN_WAY - 1);
- addRoadAfterSplittingLoops(cw, gt);
- cw = tail;
- }
+ // make sure the way has nodes at each end
+ cw.getPoints().get(0).incHighwayCount();
+ cw.getPoints().get(cw.getPoints().size() - 1).incHighwayCount();
addRoadAfterSplittingLoops(cw, gt);
}
}
else {
// no bounding box or way was not clipped
- while(way.getPoints().size() > MAX_POINTS_IN_WAY) {
- Way tail = splitWayAt(way, MAX_POINTS_IN_WAY - 1);
- addRoadAfterSplittingLoops(way, gt);
- way = tail;
- }
+
+ // make sure the way has nodes at each end
+ way.getPoints().get(0).incHighwayCount();
+ way.getPoints().get(way.getPoints().size() - 1).incHighwayCount();
addRoadAfterSplittingLoops(way, gt);
}
}
@@ -955,7 +952,9 @@ public class StyledConverter implements OsmConverter {
}
// safeToSplitWay() returns true if it safe (no short arcs will be
- // created) to split a way at a given position
+ // created) to split a way at a given position - assumes that the
+ // floor and ceiling points will become nodes even if they are not
+ // yet
//
// points - the way's points
// pos - the position we are testing
@@ -964,13 +963,24 @@ public class StyledConverter implements OsmConverter {
boolean safeToSplitWay(List<Coord> points, int pos, int floor, int ceiling) {
Coord candidate = points.get(pos);
+ // avoid running off the ends of the list
+ if(floor < 0)
+ floor = 0;
+ if(ceiling >= points.size())
+ ceiling = points.size() - 1;
// test points after pos
for(int i = pos + 1; i <= ceiling; ++i) {
Coord p = points.get(i);
- if(p.getHighwayCount() > 1) {
+ if(i == ceiling || p.getHighwayCount() > 1) {
// point is going to be a node
- if(candidate.equals(p))
+ if(candidate.equals(p)) {
+ // coordinates are equal, that's too close
return false;
+ }
+ // no need to test further
+ break;
+ }
+ else if(!candidate.equals(p)) {
// no need to test further
break;
}
@@ -978,10 +988,16 @@ public class StyledConverter implements OsmConverter {
// test points before pos
for(int i = pos - 1; i >= floor; --i) {
Coord p = points.get(i);
- if(p.getHighwayCount() > 1) {
+ if(i == floor || p.getHighwayCount() > 1) {
// point is going to be a node
- if(candidate.equals(p))
+ if(candidate.equals(p)) {
+ // coordinates are equal, that's too close
return false;
+ }
+ // no need to test further
+ break;
+ }
+ else if(!candidate.equals(p)) {
// no need to test further
break;
}
@@ -1007,14 +1023,10 @@ public class StyledConverter implements OsmConverter {
Way trailingWay = null;
String debugWayName = getDebugName(way);
- // make sure the way has nodes at each end
- points.get(0).incHighwayCount();
- points.get(points.size() - 1).incHighwayCount();
-
// collect the Way's nodes and also split the way if any
// inter-node arc length becomes excessive
double arcLength = 0;
- int numPointsInArc = 0;
+ int numPointsInArc = 1;
// track the dimensions of the way's bbox so that we can
// detect if it would be split by the LineSizeSplitterFilter
class WayBBox {
@@ -1108,11 +1120,41 @@ public class StyledConverter implements OsmConverter {
// this will have truncated the current Way's
// points so the loop will now terminate
}
+ else if(i >= (MAX_POINTS_IN_WAY / 2) &&
+ points.size() > MAX_POINTS_IN_WAY &&
+ p.getHighwayCount() > 1) {
+ // this point is already a node so it's a good place
+ // to split the way
+ log.info("Splitting way " + debugWayName + " at " + points.get(i).toOSMURL() + " (using an existing node) to limit number of points in this way to " + i + ", way has " + (points.size() - i) + " more points");
+ assert trailingWay == null : "trailingWay not null #5";
+ trailingWay = splitWayAt(way, i);
+ // this will have truncated the current Way's
+ // points so the loop will now terminate
+ }
+ else if(i >= (MAX_POINTS_IN_WAY-1)) {
+ // we have to split the way here or earlier
+ // search backwards for a safe place to split the way
+ int splitI = i;
+ while(splitI > 0 &&
+ !safeToSplitWay(points, splitI, i - numPointsInArc, points.size() - 1))
+ --splitI;
+ if(splitI > 0) {
+ log.info("Splitting way " + debugWayName + " at " + points.get(splitI).toOSMURL() + " (making a new node) to limit number of points in this way to " + splitI + ", way has " + (points.size() - splitI) + " more points");
+ assert trailingWay == null : "trailingWay not null #6";
+ trailingWay = splitWayAt(way, splitI);
+ // this will have truncated the current Way's
+ // points so the loop will now terminate
+ }
+ else {
+ log.error("Way " + debugWayName + " at " + points.get(i).toOSMURL() + " has too many points (" + points.size() + ") but I can't find a safe place to split the way - something's badly wrong here!");
+ return;
+ }
+ }
else {
if(p.getHighwayCount() > 1) {
// point is a node so zero arc length
arcLength = 0;
- numPointsInArc = 0;
+ numPointsInArc = 1;
}
arcLength += d;
@@ -1134,7 +1176,7 @@ public class StyledConverter implements OsmConverter {
// this isn't the last point in the way so split
// it here to avoid exceeding the max nodes in way
// limit
- assert trailingWay == null : "trailingWay not null #5";
+ assert trailingWay == null : "trailingWay not null #7";
trailingWay = splitWayAt(way, i);
// this will have truncated the current Way's
// points so the loop will now terminate
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev