[PATCH] looped way patch for nod branch

Hi, it looks like the looped way check doesn't find all self intersection ways. It just checks if some waypoint is the same like the last way point. It misses loops somewhere in the middle of the way. This results in route calculation hangups on the nuvi. Here comes a patch for the nod branch that fixes the problem. The new function should also work with multiple loops in a way. The check for the two point loops needs a closer look. For now we only check if there are more then 2 points in the way. I have tried a alternate way by checking the distance between the intersection points to be greater the 1 (j-pIdx>1). This will produce some more loop warnings. In one case I was not able to see the reason for the warning so I commented the alternate check out for now. Berni. Index: src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java =================================================================== --- src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java (revision 881) +++ src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java (working copy) @@ -261,36 +261,42 @@ } } - boolean looped = false; - List<Coord> wayPoints = way.getPoints(); - int numPointsInWay = wayPoints.size(); + int numPointsInWay; + int pIdx; + boolean tinyLoop = false; - if(numPointsInWay > 1) { - // check if the last point in the way is the same as - // any other point in the way - if it is, there's a loop - Coord wayEndCoord = wayPoints.get(numPointsInWay - 1); - for(int i = 0; !looped && i < numPointsInWay - 1; ++i) { - if(wayPoints.get(i) == wayEndCoord) - looped = true; + do + { + List<Coord> wayPoints = way.getPoints(); + numPointsInWay = wayPoints.size(); + boolean looped = false; + + // check if the way contains a loop or self intersection + for(pIdx = 0; !looped && pIdx < (numPointsInWay - 1); pIdx++) { + for(int j = pIdx+1; !looped && j < numPointsInWay; j++) { + if(wayPoints.get(pIdx) == wayPoints.get(j)) + { + if(numPointsInWay > 2) // (j-pIdx > 1) will find more ugly stuff + { + Way loopTail = splitWayAt(way, pIdx + 1); + addRoadWithoutLoops(way, gt); + way = loopTail; // the rest + looped = true; + } + else + { + System.err.println("Ignoring looped way with only 2 points located at " + wayPoints.get(0).toDegreeString()); + looped = true; + tinyLoop = true; + } + } + } } - } - - if(looped) { - if(numPointsInWay > 2) { - // create a new way to replace the last segment - Way loopTail = splitWayAt(way, numPointsInWay - 2); - // make roads from the un-looped ways - addRoadWithoutLoops(way, gt); - addRoadWithoutLoops(loopTail, gt); - } - else { - System.err.println("Ignoring looped way with only 2 points located at " + wayPoints.get(0).toDegreeString()); - } - } - else { - // make a road from the way (it wasn't looped) + } while(pIdx < numPointsInWay -1 && !tinyLoop); // until we are at the end of the way + + if(!tinyLoop) addRoadWithoutLoops(way, gt); - } + } void addRoadWithoutLoops(Way way, GType gt) {

Hi Bernhard,
Hi,
it looks like the looped way check doesn't find all self intersection ways. It just checks if some waypoint is the same like the last way point. It misses loops somewhere in the middle of the way. This results in route calculation hangups on the nuvi.
Here comes a patch for the nod branch that fixes the problem. The new function should also work with multiple loops in a way. The check for the two point loops needs a closer look. For now we only check if there are more then 2 points in the way. I have tried a alternate way by checking the distance between the intersection points to be greater the 1 (j-pIdx>1). This will produce some more loop warnings. In one case I was not able to see the reason for the warning so I commented the alternate check out for now.
Berni.
Many thanks for the patch - I did wonder when I wrote the original code whether there would be a problem with intersections. I have reworked the patch to suit my way of thinking and I believe it does a very similar job to the orginal but, to me, it's easier to understand how it works. Also, this new code actually zaps consecutive identical points. Please try the attached patch (on nod branch, not on top of your patch) and see what you think. Cheers, Mark PS - I have received the POI patch for nod and will be trying it out at the first opportunity.

Hi Mark, your code works fine with my test cases. Maybe we should add a URL with the coordinate to the error message to encourage people to fix such consecutive points in osm. Thanks Berni. Mark Burton schrieb:
Hi,
it looks like the looped way check doesn't find all self intersection ways. It just checks if some waypoint is the same like the last way point. It misses loops somewhere in the middle of the way. This results in route calculation hangups on the nuvi.
Here comes a patch for the nod branch that fixes the problem. The new function should also work with multiple loops in a way. The check for the two point loops needs a closer look. For now we only check if there are more then 2 points in the way. I have tried a alternate way by checking the distance between the intersection points to be greater the 1 (j-pIdx>1). This will produce some more loop warnings. In one case I was not able to see the reason for the warning so I commented the alternate check out for now.
Berni.
Many thanks for the patch - I did wonder when I wrote the original code whether there would be a problem with intersections.
I have reworked the patch to suit my way of thinking and I believe it does a very similar job to the orginal but, to me, it's easier to understand how it works. Also, this new code actually zaps consecutive identical points.
Please try the attached patch (on nod branch, not on top of your patch) and see what you think.
Cheers,
Mark
PS - I have received the POI patch for nod and will be trying it out at the first opportunity. ------------------------------------------------------------------------
_______________________________________________ mkgmap-dev mailing list mkgmap-dev@lists.mkgmap.org.uk http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Hi Bernhard,
your code works fine with my test cases. Maybe we should add a URL with the coordinate to the error message to encourage people to fix such consecutive points in osm.
That's a very good idea, then they can just snarf and barf (cut and paste) the URL into their browser/JOSM. Cheers, Mark
participants (2)
-
Bernhard Heibler
-
Mark Burton