diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java index 495227ec6b..ebd94155a6 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java @@ -101,7 +101,7 @@ private void removeLoops() { List removedEdges = new ArrayList<>(); for (var node : output) { for (var edge : List.copyOf(node.getEdges())) { - if (removedEdges.contains(edge)) { + if (removedEdges.contains(edge) || removedEdges.contains(edge.reversed)) { continue; } if (edge.from == edge.to && edge.length <= loopMinLength) { @@ -113,8 +113,9 @@ private void removeLoops() { try { var allPaths = findAllPaths(edge.from, edge.to, loopMinLength); if (allPaths.size() > 1) { + var firstEdgeShortestPath = allPaths.get(0).getFirst(); for (var path : allPaths.subList(1, allPaths.size())) { - if (path.size() > 0) { + if (path.size() > 0 && !firstEdgeShortestPath.equals(path.get(0))) { removedEdges.add(path.get(0)); path.get(0).remove(); } diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/util/LoopLineMergerTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/util/LoopLineMergerTest.java index fb91ae0bca..1dc37e0cfc 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/util/LoopLineMergerTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/util/LoopLineMergerTest.java @@ -259,7 +259,7 @@ void testMergeCarriagewaysWithTwoSplits() { @Test void testRealWorldHarkingen() { var merger = new LoopLineMerger() - .setMinLength(0) + .setMinLength(4 * 0.0625) .setLoopMinLength(8 * 0.0625); merger.add(newLineString(99.185791015625,109.83056640625, 99.202392578125,109.8193359375, 99.21337890625,109.810302734375, 99.222412109375,109.8017578125, 99.229736328125,109.793701171875, 99.241943359375,109.779541015625));