From 2682981da9655bbda48a12f5f7643d167130e6de Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sat, 5 Apr 2025 18:08:46 +0200 Subject: [PATCH] added export for corrected via points --- .../src/main/java/btools/router/OsmTrack.java | 2 ++ .../main/java/btools/router/RoutingContext.java | 1 + .../src/main/java/btools/router/RoutingEngine.java | 14 ++++++++++++++ .../java/btools/router/RoutingParamCollector.java | 2 ++ .../main/java/btools/routingapp/BRouterWorker.java | 1 + .../java/btools/server/request/ServerHandler.java | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/brouter-core/src/main/java/btools/router/OsmTrack.java b/brouter-core/src/main/java/btools/router/OsmTrack.java index ccc232a..b56a7df 100644 --- a/brouter-core/src/main/java/btools/router/OsmTrack.java +++ b/brouter-core/src/main/java/btools/router/OsmTrack.java @@ -61,7 +61,9 @@ public final class OsmTrack { public String name = "unset"; protected List matchedWaypoints; + protected List correctedWaypoints; public boolean exportWaypoints = false; + public boolean exportCorrectedWaypoints = false; public void addNode(OsmPathElement node) { nodes.add(0, node); diff --git a/brouter-core/src/main/java/btools/router/RoutingContext.java b/brouter-core/src/main/java/btools/router/RoutingContext.java index f5b2bf3..03b6b4a 100644 --- a/brouter-core/src/main/java/btools/router/RoutingContext.java +++ b/brouter-core/src/main/java/btools/router/RoutingContext.java @@ -221,6 +221,7 @@ public final class RoutingContext { public String outputFormat = "gpx"; public boolean exportWaypoints = false; + public boolean exportCorrectedWaypoints = false; public OsmPrePath firstPrePath; diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index 698bc7b..351aa61 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -41,6 +41,7 @@ public class RoutingEngine extends Thread { private boolean finished = false; protected List waypoints = null; + protected List correctedWaypoints = null; List extraWaypoints = null; protected List matchedWaypoints; private int linksProcessed = 0; @@ -262,6 +263,7 @@ public class RoutingEngine extends Thread { } oldTrack = null; track.exportWaypoints = routingContext.exportWaypoints; + track.exportCorrectedWaypoints = routingContext.exportCorrectedWaypoints; filename = outfileBase + i + "." + routingContext.outputFormat; switch (routingContext.outputFormat) { case "gpx": @@ -975,6 +977,10 @@ public class RoutingEngine extends Thread { hasDirectRouting = true; } } + for (MatchedWaypoint mwp : matchedWaypoints) { + //System.out.println(FormatGpx.getWaypoint(mwp.waypoint.ilon, mwp.waypoint.ilat, mwp.name, null)); + //System.out.println(FormatGpx.getWaypoint(mwp.crosspoint.ilon, mwp.crosspoint.ilat, mwp.name+"_cp", null)); + } routingContext.hasDirectRouting = hasDirectRouting; @@ -1030,6 +1036,7 @@ public class RoutingEngine extends Thread { matchedWaypoints.get(matchedWaypoints.size() - 1).indexInTrack = totaltrack.nodes.size() - 1; totaltrack.matchedWaypoints = matchedWaypoints; + totaltrack.correctedWaypoints = correctedWaypoints; totaltrack.processVoiceHints(routingContext); totaltrack.prepareSpeedProfile(routingContext); @@ -1183,6 +1190,13 @@ public class RoutingEngine extends Thread { setNewVoiceHint(t, last, lastJunctions, newJunction, newTarget); + if (correctedWaypoints == null) correctedWaypoints = new ArrayList<>(); + OsmNodeNamed n = new OsmNodeNamed(); + n.ilon = newJunction.getILon(); + n.ilat = newJunction.getILat(); + n.name = startWp.name + "_corr"; + correctedWaypoints.add(n); + return true; } return false; diff --git a/brouter-core/src/main/java/btools/router/RoutingParamCollector.java b/brouter-core/src/main/java/btools/router/RoutingParamCollector.java index f239315..1bcc6ee 100644 --- a/brouter-core/src/main/java/btools/router/RoutingParamCollector.java +++ b/brouter-core/src/main/java/btools/router/RoutingParamCollector.java @@ -227,6 +227,8 @@ public class RoutingParamCollector { } } else if (key.equals("exportWaypoints")) { rctx.exportWaypoints = (Integer.parseInt(value) == 1); + } else if (key.equals("exportCorrectedWaypoints")) { + rctx.exportCorrectedWaypoints = (Integer.parseInt(value) == 1); } else if (key.equals("format")) { rctx.outputFormat = ((String) value).toLowerCase(); } else if (key.equals("trackFormat")) { diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java index 33ee802..437d136 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java @@ -161,6 +161,7 @@ public class BRouterWorker { track = cr.getFoundTrack(); if (track != null) { track.exportWaypoints = rc.exportWaypoints; + track.exportCorrectedWaypoints = rc.exportCorrectedWaypoints; if (pathToFileResult == null) { switch (writeFromat) { case OUTPUT_FORMAT_KML: diff --git a/brouter-server/src/main/java/btools/server/request/ServerHandler.java b/brouter-server/src/main/java/btools/server/request/ServerHandler.java index 37ba145..fcb536c 100644 --- a/brouter-server/src/main/java/btools/server/request/ServerHandler.java +++ b/brouter-server/src/main/java/btools/server/request/ServerHandler.java @@ -78,6 +78,10 @@ public class ServerHandler extends RequestHandler { if (exportWaypointsStr != null && Integer.parseInt(exportWaypointsStr) != 0) { track.exportWaypoints = true; } + exportWaypointsStr = params.get("exportCorrectedWaypoints"); + if (exportWaypointsStr != null && Integer.parseInt(exportWaypointsStr) != 0) { + track.exportCorrectedWaypoints = true; + } if (format == null || "gpx".equals(format)) { result = new FormatGpx(rc).format(track);