diff --git a/brouter-core/src/main/java/btools/router/OsmTrack.java b/brouter-core/src/main/java/btools/router/OsmTrack.java
index c8fbed6..f9418e7 100644
--- a/brouter-core/src/main/java/btools/router/OsmTrack.java
+++ b/brouter-core/src/main/java/btools/router/OsmTrack.java
@@ -839,6 +839,49 @@ public final class OsmTrack {
return sb.toString();
}
+ static public String formatAsGpxWaypoint(OsmNodeNamed n) {
+ try {
+ StringWriter sw = new StringWriter(8192);
+ BufferedWriter bw = new BufferedWriter(sw);
+ formatGpxHeader(bw);
+ formatWaypointGpx(bw, n);
+ formatGpxFooter(bw);
+ bw.close();
+ sw.close();
+ return sw.toString();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static public void formatGpxHeader(BufferedWriter sb) throws IOException {
+ sb.append("\n");
+ sb.append("\n");
+ }
+
+ static public void formatGpxFooter(BufferedWriter sb) throws IOException {
+ sb.append("\n");
+ }
+
+ static public void formatWaypointGpx(BufferedWriter sb, OsmNodeNamed n) throws IOException {
+ sb.append(" ");
+ if (n.getSElev() != Short.MIN_VALUE) {
+ sb.append("").append("" + n.getElev()).append("");
+ }
+ if (n.name != null) {
+ sb.append("").append(StringUtils.escapeXml10(n.name)).append("");
+ }
+ if (n.nodeDescription != null) {
+ sb.append("").append("hat desc").append("");
+ }
+ sb.append("\n");
+ }
+
public void writeKml(String filename) throws Exception {
BufferedWriter bw = new BufferedWriter(new FileWriter(filename));
diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java
index 6717c95..8156f2c 100644
--- a/brouter-core/src/main/java/btools/router/RoutingEngine.java
+++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java
@@ -28,7 +28,7 @@ public class RoutingEngine extends Thread {
public final static int BROUTER_ENGINEMODE_ROUTING = 0;
public final static int BROUTER_ENGINEMODE_SEED = 1;
- public final static int BROUTER_ENGINEMODE_OTHER = 2;
+ public final static int BROUTER_ENGINEMODE_GETELEV = 2;
private NodesCache nodesCache;
private SortedHeap openSet = new SortedHeap();
@@ -50,6 +50,7 @@ public class RoutingEngine extends Thread {
private OsmTrack foundRawTrack = null;
private int alternativeIndex = 0;
+ protected String outputMessage = null;
protected String errorMessage = null;
private volatile boolean terminated;
@@ -81,7 +82,7 @@ public class RoutingEngine extends Thread {
public RoutingEngine(String outfileBase, String logfileBase, File segmentDir,
List waypoints, RoutingContext rc) {
this(0, outfileBase, logfileBase, segmentDir,
- waypoints, rc);
+ waypoints, rc);
}
public RoutingEngine(int engineMode, String outfileBase, String logfileBase, File segmentDir,
@@ -94,7 +95,6 @@ public class RoutingEngine extends Thread {
this.routingContext = rc;
this.engineMode = engineMode;
-
File baseFolder = new File(routingContext.localFunction).getParentFile();
baseFolder = baseFolder == null ? null : baseFolder.getParentFile();
if (baseFolder != null) {
@@ -120,6 +120,7 @@ public class RoutingEngine extends Thread {
if (hasInfo()) {
logInfo("parsed profile " + rc.localFunction + " cached=" + cachedProfile);
}
+
}
private boolean hasInfo() {
@@ -153,11 +154,19 @@ public class RoutingEngine extends Thread {
}
public void doRun(long maxRunningTime) {
+
switch (engineMode) {
- case BROUTER_ENGINEMODE_ROUTING: doRouting(maxRunningTime); break;
- case BROUTER_ENGINEMODE_SEED: /* do nothing, handled the old way */ break;
- case BROUTER_ENGINEMODE_OTHER: /* call others */ break;
- default: doRouting(maxRunningTime); break;
+ case BROUTER_ENGINEMODE_ROUTING:
+ doRouting(maxRunningTime);
+ break;
+ case BROUTER_ENGINEMODE_SEED: /* do nothing, handled the old way */
+ break;
+ case BROUTER_ENGINEMODE_GETELEV:
+ doGetElev();
+ break;
+ default:
+ doRouting(maxRunningTime);
+ break;
}
}
@@ -262,6 +271,44 @@ public class RoutingEngine extends Thread {
}
}
+ public void doGetElev() {
+ try {
+ startTime = System.currentTimeMillis();
+
+ routingContext.turnInstructionMode = 9;
+ MatchedWaypoint wpt1 = new MatchedWaypoint();
+ wpt1.waypoint = waypoints.get(0);
+ wpt1.name = "wpt_info";
+ List listOne = new ArrayList();
+ listOne.add(wpt1);
+ matchWaypointsToNodes(listOne);
+
+ resetCache(true);
+ nodesCache.nodesMap.cleanupMode = 0;
+
+ int dist_cn1 = listOne.get(0).crosspoint.calcDistance(listOne.get(0).node1);
+ int dist_cn2 = listOne.get(0).crosspoint.calcDistance(listOne.get(0).node2);
+
+ OsmNode startNode;
+ if (dist_cn1 < dist_cn2) {
+ startNode = nodesCache.getStartNode(listOne.get(0).node1.getIdFromPos());
+ } else {
+ startNode = nodesCache.getStartNode(listOne.get(0).node2.getIdFromPos());
+ }
+
+ OsmNodeNamed n = new OsmNodeNamed(listOne.get(0).crosspoint);
+ n.selev = startNode != null ? startNode.getSElev() : Short.MIN_VALUE;
+
+ outputMessage = OsmTrack.formatAsGpxWaypoint(n);
+
+ long endTime = System.currentTimeMillis();
+ logInfo("execution time = " + (endTime - startTime) / 1000. + " seconds");
+ } catch (Exception e) {
+ e.getStackTrace();
+ logException(e);
+ }
+ }
+
private void postElevationCheck(OsmTrack track) {
OsmPathElement lastPt = null;
OsmPathElement startPt = null;
@@ -1568,6 +1615,10 @@ public class RoutingEngine extends Thread {
return foundTrack;
}
+ public String getFoundInfo() {
+ return outputMessage;
+ }
+
public int getAlternativeIndex() {
return alternativeIndex;
}