get elevaton single point
This commit is contained in:
parent
fa1a6b3c27
commit
3c5ac660bf
2 changed files with 101 additions and 7 deletions
|
@ -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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||
sb.append("<gpx \n");
|
||||
sb.append(" xmlns=\"http://www.topografix.com/GPX/1/1\" \n");
|
||||
sb.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n");
|
||||
sb.append(" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\" \n");
|
||||
sb.append(" creator=\"BRouter-" + version + "\" version=\"1.1\">\n");
|
||||
}
|
||||
|
||||
static public void formatGpxFooter(BufferedWriter sb) throws IOException {
|
||||
sb.append("</gpx>\n");
|
||||
}
|
||||
|
||||
static public void formatWaypointGpx(BufferedWriter sb, OsmNodeNamed n) throws IOException {
|
||||
sb.append(" <wpt lon=\"").append(formatILon(n.ilon)).append("\" lat=\"")
|
||||
.append(formatILat(n.ilat)).append("\">");
|
||||
if (n.getSElev() != Short.MIN_VALUE) {
|
||||
sb.append("<ele>").append("" + n.getElev()).append("</ele>");
|
||||
}
|
||||
if (n.name != null) {
|
||||
sb.append("<name>").append(StringUtils.escapeXml10(n.name)).append("</name>");
|
||||
}
|
||||
if (n.nodeDescription != null) {
|
||||
sb.append("<desc>").append("hat desc").append("</desc>");
|
||||
}
|
||||
sb.append("</wpt>\n");
|
||||
}
|
||||
|
||||
public void writeKml(String filename) throws Exception {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(filename));
|
||||
|
||||
|
|
|
@ -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<OsmPath> openSet = new SortedHeap<OsmPath>();
|
||||
|
@ -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<OsmNodeNamed> 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<MatchedWaypoint> listOne = new ArrayList<MatchedWaypoint>();
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue