Merge pull request #776 from afischerdev/merge_via
Added export for corrected Via Points
This commit is contained in:
commit
89be5f58dd
@ -197,25 +197,28 @@ public class FormatGpx extends Formatter {
|
|||||||
|
|
||||||
for (int i = 0; i <= t.pois.size() - 1; i++) {
|
for (int i = 0; i <= t.pois.size() - 1; i++) {
|
||||||
OsmNodeNamed poi = t.pois.get(i);
|
OsmNodeNamed poi = t.pois.get(i);
|
||||||
formatWaypointGpx(sb, poi);
|
formatWaypointGpx(sb, poi, "poi");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.exportWaypoints) {
|
if (t.exportWaypoints) {
|
||||||
for (int i = 0; i <= t.matchedWaypoints.size() - 1; i++) {
|
for (int i = 0; i <= t.matchedWaypoints.size() - 1; i++) {
|
||||||
MatchedWaypoint wt = t.matchedWaypoints.get(i);
|
MatchedWaypoint wt = t.matchedWaypoints.get(i);
|
||||||
sb.append(" <wpt lon=\"").append(formatILon(wt.waypoint.ilon)).append("\" lat=\"")
|
|
||||||
.append(formatILat(wt.waypoint.ilat)).append("\">\n")
|
|
||||||
.append(" <name>").append(StringUtils.escapeXml10(wt.name)).append("</name>\n");
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
sb.append(" <type>from</type>\n");
|
formatWaypointGpx(sb, wt, "from");
|
||||||
} else if (i == t.matchedWaypoints.size() - 1) {
|
} else if (i == t.matchedWaypoints.size() - 1) {
|
||||||
sb.append(" <type>to</type>\n");
|
formatWaypointGpx(sb, wt, "to");
|
||||||
} else {
|
} else {
|
||||||
sb.append(" <type>via</type>\n");
|
formatWaypointGpx(sb, wt, "via");
|
||||||
}
|
}
|
||||||
sb.append(" </wpt>\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (t.exportCorrectedWaypoints && t.correctedWaypoints != null) {
|
||||||
|
for (int i = 0; i <= t.correctedWaypoints.size() - 1; i++) {
|
||||||
|
OsmNodeNamed n = t.correctedWaypoints.get(i);
|
||||||
|
formatWaypointGpx(sb, n, "via_corr");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sb.append(" <trk>\n");
|
sb.append(" <trk>\n");
|
||||||
if (turnInstructionMode == 9
|
if (turnInstructionMode == 9
|
||||||
|| turnInstructionMode == 2
|
|| turnInstructionMode == 2
|
||||||
@ -454,7 +457,7 @@ public class FormatGpx extends Formatter {
|
|||||||
StringWriter sw = new StringWriter(8192);
|
StringWriter sw = new StringWriter(8192);
|
||||||
BufferedWriter bw = new BufferedWriter(sw);
|
BufferedWriter bw = new BufferedWriter(sw);
|
||||||
formatGpxHeader(bw);
|
formatGpxHeader(bw);
|
||||||
formatWaypointGpx(bw, n);
|
formatWaypointGpx(bw, n, null);
|
||||||
formatGpxFooter(bw);
|
formatGpxFooter(bw);
|
||||||
bw.close();
|
bw.close();
|
||||||
sw.close();
|
sw.close();
|
||||||
@ -477,7 +480,7 @@ public class FormatGpx extends Formatter {
|
|||||||
sb.append("</gpx>\n");
|
sb.append("</gpx>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void formatWaypointGpx(BufferedWriter sb, OsmNodeNamed n) throws IOException {
|
public void formatWaypointGpx(BufferedWriter sb, OsmNodeNamed n, String type) throws IOException {
|
||||||
sb.append(" <wpt lon=\"").append(formatILon(n.ilon)).append("\" lat=\"")
|
sb.append(" <wpt lon=\"").append(formatILon(n.ilon)).append("\" lat=\"")
|
||||||
.append(formatILat(n.ilat)).append("\">");
|
.append(formatILat(n.ilat)).append("\">");
|
||||||
if (n.getSElev() != Short.MIN_VALUE) {
|
if (n.getSElev() != Short.MIN_VALUE) {
|
||||||
@ -489,6 +492,24 @@ public class FormatGpx extends Formatter {
|
|||||||
if (n.nodeDescription != null && rc != null) {
|
if (n.nodeDescription != null && rc != null) {
|
||||||
sb.append("<desc>").append(rc.expctxWay.getKeyValueDescription(false, n.nodeDescription)).append("</desc>");
|
sb.append("<desc>").append(rc.expctxWay.getKeyValueDescription(false, n.nodeDescription)).append("</desc>");
|
||||||
}
|
}
|
||||||
|
if (type != null) {
|
||||||
|
sb.append("<type>").append(type).append("</type>");
|
||||||
|
}
|
||||||
|
sb.append("</wpt>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void formatWaypointGpx(BufferedWriter sb, MatchedWaypoint wp, String type) throws IOException {
|
||||||
|
sb.append(" <wpt lon=\"").append(formatILon(wp.waypoint.ilon)).append("\" lat=\"")
|
||||||
|
.append(formatILat(wp.waypoint.ilat)).append("\">");
|
||||||
|
if (wp.waypoint.getSElev() != Short.MIN_VALUE) {
|
||||||
|
sb.append("<ele>").append("" + wp.waypoint.getElev()).append("</ele>");
|
||||||
|
}
|
||||||
|
if (wp.name != null) {
|
||||||
|
sb.append("<name>").append(StringUtils.escapeXml10(wp.name)).append("</name>");
|
||||||
|
}
|
||||||
|
if (type != null) {
|
||||||
|
sb.append("<type>").append(type).append("</type>");
|
||||||
|
}
|
||||||
sb.append("</wpt>\n");
|
sb.append("</wpt>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -126,7 +126,7 @@ public class FormatJson extends Formatter {
|
|||||||
|
|
||||||
sb.append(" ]\n");
|
sb.append(" ]\n");
|
||||||
sb.append(" }\n");
|
sb.append(" }\n");
|
||||||
if (t.exportWaypoints || !t.pois.isEmpty()) {
|
if (t.exportWaypoints || t.exportCorrectedWaypoints || !t.pois.isEmpty()) {
|
||||||
sb.append(" },\n");
|
sb.append(" },\n");
|
||||||
for (int i = 0; i <= t.pois.size() - 1; i++) {
|
for (int i = 0; i <= t.pois.size() - 1; i++) {
|
||||||
OsmNodeNamed poi = t.pois.get(i);
|
OsmNodeNamed poi = t.pois.get(i);
|
||||||
@ -137,6 +137,7 @@ public class FormatJson extends Formatter {
|
|||||||
sb.append(" \n");
|
sb.append(" \n");
|
||||||
}
|
}
|
||||||
if (t.exportWaypoints) {
|
if (t.exportWaypoints) {
|
||||||
|
if (!t.pois.isEmpty()) sb.append(" ,\n");
|
||||||
for (int i = 0; i <= t.matchedWaypoints.size() - 1; i++) {
|
for (int i = 0; i <= t.matchedWaypoints.size() - 1; i++) {
|
||||||
String type;
|
String type;
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@ -155,6 +156,19 @@ public class FormatJson extends Formatter {
|
|||||||
sb.append(" \n");
|
sb.append(" \n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (t.exportCorrectedWaypoints) {
|
||||||
|
if (t.exportWaypoints) sb.append(" ,\n");
|
||||||
|
for (int i = 0; i <= t.correctedWaypoints.size() - 1; i++) {
|
||||||
|
String type = "via_corr";
|
||||||
|
|
||||||
|
OsmNodeNamed wp = t.correctedWaypoints.get(i);
|
||||||
|
addFeature(sb, type, wp.name, wp.ilat, wp.ilon, wp.getSElev());
|
||||||
|
if (i < t.correctedWaypoints.size() - 1) {
|
||||||
|
sb.append(",");
|
||||||
|
}
|
||||||
|
sb.append(" \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sb.append(" }\n");
|
sb.append(" }\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public class FormatKml extends Formatter {
|
|||||||
sb.append(" </LineString>\n");
|
sb.append(" </LineString>\n");
|
||||||
sb.append(" </Placemark>\n");
|
sb.append(" </Placemark>\n");
|
||||||
sb.append(" </Folder>\n");
|
sb.append(" </Folder>\n");
|
||||||
if (t.exportWaypoints || !t.pois.isEmpty()) {
|
if (t.exportWaypoints || t.exportCorrectedWaypoints || !t.pois.isEmpty()) {
|
||||||
if (!t.pois.isEmpty()) {
|
if (!t.pois.isEmpty()) {
|
||||||
sb.append(" <Folder>\n");
|
sb.append(" <Folder>\n");
|
||||||
sb.append(" <name>poi</name>\n");
|
sb.append(" <name>poi</name>\n");
|
||||||
@ -62,6 +62,10 @@ public class FormatKml extends Formatter {
|
|||||||
}
|
}
|
||||||
createFolder(sb, "end", t.matchedWaypoints.subList(size - 1, size));
|
createFolder(sb, "end", t.matchedWaypoints.subList(size - 1, size));
|
||||||
}
|
}
|
||||||
|
if (t.exportCorrectedWaypoints) {
|
||||||
|
int size = t.correctedWaypoints.size();
|
||||||
|
createViaFolder(sb, "via_cor", t.correctedWaypoints.subList(0, size));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sb.append(" </Document>\n");
|
sb.append(" </Document>\n");
|
||||||
sb.append("</kml>\n");
|
sb.append("</kml>\n");
|
||||||
@ -79,6 +83,16 @@ public class FormatKml extends Formatter {
|
|||||||
sb.append(" </Folder>\n");
|
sb.append(" </Folder>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createViaFolder(StringBuilder sb, String type, List<OsmNodeNamed> waypoints) {
|
||||||
|
sb.append(" <Folder>\n");
|
||||||
|
sb.append(" <name>" + type + "</name>\n");
|
||||||
|
for (int i = 0; i < waypoints.size(); i++) {
|
||||||
|
OsmNodeNamed wp = waypoints.get(i);
|
||||||
|
createPlaceMark(sb, wp.name, wp.ilat, wp.ilon);
|
||||||
|
}
|
||||||
|
sb.append(" </Folder>\n");
|
||||||
|
}
|
||||||
|
|
||||||
private void createPlaceMark(StringBuilder sb, String name, int ilat, int ilon) {
|
private void createPlaceMark(StringBuilder sb, String name, int ilat, int ilon) {
|
||||||
sb.append(" <Placemark>\n");
|
sb.append(" <Placemark>\n");
|
||||||
sb.append(" <name>" + StringUtils.escapeXml10(name) + "</name>\n");
|
sb.append(" <name>" + StringUtils.escapeXml10(name) + "</name>\n");
|
||||||
|
|||||||
@ -61,7 +61,9 @@ public final class OsmTrack {
|
|||||||
public String name = "unset";
|
public String name = "unset";
|
||||||
|
|
||||||
protected List<MatchedWaypoint> matchedWaypoints;
|
protected List<MatchedWaypoint> matchedWaypoints;
|
||||||
|
protected List<OsmNodeNamed> correctedWaypoints;
|
||||||
public boolean exportWaypoints = false;
|
public boolean exportWaypoints = false;
|
||||||
|
public boolean exportCorrectedWaypoints = false;
|
||||||
|
|
||||||
public void addNode(OsmPathElement node) {
|
public void addNode(OsmPathElement node) {
|
||||||
nodes.add(0, node);
|
nodes.add(0, node);
|
||||||
|
|||||||
@ -224,6 +224,7 @@ public final class RoutingContext {
|
|||||||
|
|
||||||
public String outputFormat = "gpx";
|
public String outputFormat = "gpx";
|
||||||
public boolean exportWaypoints = false;
|
public boolean exportWaypoints = false;
|
||||||
|
public boolean exportCorrectedWaypoints = false;
|
||||||
|
|
||||||
public OsmPrePath firstPrePath;
|
public OsmPrePath firstPrePath;
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ public class RoutingEngine extends Thread {
|
|||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
|
|
||||||
protected List<OsmNodeNamed> waypoints = null;
|
protected List<OsmNodeNamed> waypoints = null;
|
||||||
|
protected List<OsmNodeNamed> correctedWaypoints = null;
|
||||||
List<OsmNodeNamed> extraWaypoints = null;
|
List<OsmNodeNamed> extraWaypoints = null;
|
||||||
protected List<MatchedWaypoint> matchedWaypoints;
|
protected List<MatchedWaypoint> matchedWaypoints;
|
||||||
private int linksProcessed = 0;
|
private int linksProcessed = 0;
|
||||||
@ -262,6 +263,7 @@ public class RoutingEngine extends Thread {
|
|||||||
}
|
}
|
||||||
oldTrack = null;
|
oldTrack = null;
|
||||||
track.exportWaypoints = routingContext.exportWaypoints;
|
track.exportWaypoints = routingContext.exportWaypoints;
|
||||||
|
track.exportCorrectedWaypoints = routingContext.exportCorrectedWaypoints;
|
||||||
filename = outfileBase + i + "." + routingContext.outputFormat;
|
filename = outfileBase + i + "." + routingContext.outputFormat;
|
||||||
switch (routingContext.outputFormat) {
|
switch (routingContext.outputFormat) {
|
||||||
case "gpx":
|
case "gpx":
|
||||||
@ -975,6 +977,10 @@ public class RoutingEngine extends Thread {
|
|||||||
hasDirectRouting = true;
|
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;
|
routingContext.hasDirectRouting = hasDirectRouting;
|
||||||
|
|
||||||
@ -1030,6 +1036,7 @@ public class RoutingEngine extends Thread {
|
|||||||
|
|
||||||
matchedWaypoints.get(matchedWaypoints.size() - 1).indexInTrack = totaltrack.nodes.size() - 1;
|
matchedWaypoints.get(matchedWaypoints.size() - 1).indexInTrack = totaltrack.nodes.size() - 1;
|
||||||
totaltrack.matchedWaypoints = matchedWaypoints;
|
totaltrack.matchedWaypoints = matchedWaypoints;
|
||||||
|
totaltrack.correctedWaypoints = correctedWaypoints;
|
||||||
totaltrack.processVoiceHints(routingContext);
|
totaltrack.processVoiceHints(routingContext);
|
||||||
totaltrack.prepareSpeedProfile(routingContext);
|
totaltrack.prepareSpeedProfile(routingContext);
|
||||||
|
|
||||||
@ -1188,6 +1195,13 @@ public class RoutingEngine extends Thread {
|
|||||||
|
|
||||||
setNewVoiceHint(t, last, lastJunctions, newJunction, newTarget);
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -227,6 +227,8 @@ public class RoutingParamCollector {
|
|||||||
}
|
}
|
||||||
} else if (key.equals("exportWaypoints")) {
|
} else if (key.equals("exportWaypoints")) {
|
||||||
rctx.exportWaypoints = (Integer.parseInt(value) == 1);
|
rctx.exportWaypoints = (Integer.parseInt(value) == 1);
|
||||||
|
} else if (key.equals("exportCorrectedWaypoints")) {
|
||||||
|
rctx.exportCorrectedWaypoints = (Integer.parseInt(value) == 1);
|
||||||
} else if (key.equals("format")) {
|
} else if (key.equals("format")) {
|
||||||
rctx.outputFormat = ((String) value).toLowerCase();
|
rctx.outputFormat = ((String) value).toLowerCase();
|
||||||
} else if (key.equals("trackFormat")) {
|
} else if (key.equals("trackFormat")) {
|
||||||
|
|||||||
@ -161,6 +161,7 @@ public class BRouterWorker {
|
|||||||
track = cr.getFoundTrack();
|
track = cr.getFoundTrack();
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
track.exportWaypoints = rc.exportWaypoints;
|
track.exportWaypoints = rc.exportWaypoints;
|
||||||
|
track.exportCorrectedWaypoints = rc.exportCorrectedWaypoints;
|
||||||
if (pathToFileResult == null) {
|
if (pathToFileResult == null) {
|
||||||
switch (writeFromat) {
|
switch (writeFromat) {
|
||||||
case OUTPUT_FORMAT_KML:
|
case OUTPUT_FORMAT_KML:
|
||||||
|
|||||||
@ -78,6 +78,10 @@ public class ServerHandler extends RequestHandler {
|
|||||||
if (exportWaypointsStr != null && Integer.parseInt(exportWaypointsStr) != 0) {
|
if (exportWaypointsStr != null && Integer.parseInt(exportWaypointsStr) != 0) {
|
||||||
track.exportWaypoints = true;
|
track.exportWaypoints = true;
|
||||||
}
|
}
|
||||||
|
exportWaypointsStr = params.get("exportCorrectedWaypoints");
|
||||||
|
if (exportWaypointsStr != null && Integer.parseInt(exportWaypointsStr) != 0) {
|
||||||
|
track.exportCorrectedWaypoints = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (format == null || "gpx".equals(format)) {
|
if (format == null || "gpx".equals(format)) {
|
||||||
result = new FormatGpx(rc).format(track);
|
result = new FormatGpx(rc).format(track);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user