Merge pull request #170 from Phyks/exportWaypoints
Export waypoints in formatted tracks
This commit is contained in:
commit
e4c11e6dbf
3 changed files with 172 additions and 67 deletions
|
@ -60,6 +60,9 @@ public final class OsmTrack
|
|||
|
||||
public String name = "unset";
|
||||
|
||||
protected List<MatchedWaypoint> matchedWaypoints;
|
||||
public boolean exportWaypoints = false;
|
||||
|
||||
public void addNode( OsmPathElement node )
|
||||
{
|
||||
nodes.add( 0, node );
|
||||
|
@ -530,6 +533,28 @@ public final class OsmTrack
|
|||
.append( "</wpt>\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( exportWaypoints )
|
||||
{
|
||||
for( int i=0; i<=matchedWaypoints.size() - 1; i++ )
|
||||
{
|
||||
sb.append( " <wpt lon=\"" ).append( formatILon( matchedWaypoints.get(i).waypoint.ilon ) ).append( "\" lat=\"" )
|
||||
.append( formatILat( matchedWaypoints.get(i).waypoint.ilat ) ).append( "\">\n" )
|
||||
.append( " <name>" ).append( matchedWaypoints.get(i).name ).append( "</name>\n" );
|
||||
if(i == 0)
|
||||
{
|
||||
sb.append( " <type>from</type>\n" );
|
||||
}
|
||||
else if (i == matchedWaypoints.size() - 1)
|
||||
{
|
||||
sb.append( " <type>to</type>\n" );
|
||||
}
|
||||
else {
|
||||
sb.append( " <type>via</type>\n" );
|
||||
}
|
||||
sb.append( " </wpt>\n" );
|
||||
}
|
||||
}
|
||||
sb.append( " <trk>\n" );
|
||||
sb.append( " <name>" ).append( name ).append( "</name>\n" );
|
||||
if ( turnInstructionMode == 1 ) // trkpt/sym style
|
||||
|
@ -601,7 +626,7 @@ public final class OsmTrack
|
|||
sb.append( " <description><![CDATA[If the <tessellate> tag has a value of 1, the line will contour to the underlying terrain]]></description>\n" );
|
||||
sb.append( " <LineString>\n" );
|
||||
sb.append( " <tessellate>1</tessellate>\n" );
|
||||
sb.append( " <coordinates> " );
|
||||
sb.append( " <coordinates>" );
|
||||
|
||||
for ( OsmPathElement n : nodes )
|
||||
{
|
||||
|
@ -612,6 +637,41 @@ public final class OsmTrack
|
|||
sb.append( " </LineString>\n" );
|
||||
sb.append( " </Placemark>\n" );
|
||||
sb.append( " </Folder>\n" );
|
||||
if ( exportWaypoints )
|
||||
{
|
||||
sb.append( " <Folder>\n" );
|
||||
sb.append( " <name>start</name>\n" );
|
||||
sb.append( " <Placemark>\n" );
|
||||
sb.append( " <name> " + matchedWaypoints.get(0).name + "</name>\n" );
|
||||
sb.append( " <Point>\n" );
|
||||
sb.append( " <coordinates>" + formatILon(matchedWaypoints.get(0).waypoint.ilon) + "," + formatILat(matchedWaypoints.get(0).waypoint.ilat) + "</coordinates>\n" );
|
||||
sb.append( " </Point>\n" );
|
||||
sb.append( " </Placemark>\n" );
|
||||
sb.append( " </Folder>\n" );
|
||||
if (matchedWaypoints.size() > 2) {
|
||||
sb.append( " <Folder>\n" );
|
||||
sb.append( " <name>via</name>\n" );
|
||||
for( int i=1; i<=matchedWaypoints.size() - 2; i++ )
|
||||
{
|
||||
sb.append( " <Placemark>\n" );
|
||||
sb.append( " <name> " + matchedWaypoints.get(i).name + "</name>\n" );
|
||||
sb.append( " <Point>\n" );
|
||||
sb.append( " <coordinates>" + formatILon(matchedWaypoints.get(i).waypoint.ilon) + "," + formatILat(matchedWaypoints.get(i).waypoint.ilat) + "</coordinates>\n" );
|
||||
sb.append( " </Point>\n" );
|
||||
sb.append( " </Placemark>\n" );
|
||||
}
|
||||
sb.append( " </Folder>\n" );
|
||||
}
|
||||
sb.append( " <Folder>\n" );
|
||||
sb.append( " <name>end</name>\n" );
|
||||
sb.append( " <Placemark>\n" );
|
||||
sb.append( " <name> " + matchedWaypoints.get(matchedWaypoints.size() - 1).name + "</name>\n" );
|
||||
sb.append( " <Point>\n" );
|
||||
sb.append( " <coordinates>" + formatILon(matchedWaypoints.get(matchedWaypoints.size() - 1).waypoint.ilon) + "," + formatILat(matchedWaypoints.get(matchedWaypoints.size() - 1).waypoint.ilat) + "</coordinates>\n" );
|
||||
sb.append( " </Point>\n" );
|
||||
sb.append( " </Placemark>\n" );
|
||||
sb.append( " </Folder>\n" );
|
||||
}
|
||||
sb.append( " </Document>\n" );
|
||||
sb.append( "</kml>\n" );
|
||||
|
||||
|
@ -713,7 +773,46 @@ public final class OsmTrack
|
|||
|
||||
sb.append( " ]\n" );
|
||||
sb.append( " }\n" );
|
||||
sb.append( " }\n" );
|
||||
if ( exportWaypoints )
|
||||
{
|
||||
sb.append( " },\n" );
|
||||
for( int i=0; i<=matchedWaypoints.size() - 1; i++ )
|
||||
{
|
||||
sb.append( " {\n" );
|
||||
sb.append( " \"type\": \"Feature\",\n" );
|
||||
sb.append( " \"properties\": {\n" );
|
||||
sb.append( " \"name\": \"" + matchedWaypoints.get(i).name + "\",\n" );
|
||||
if(i == 0)
|
||||
{
|
||||
sb.append( " \"type\": \"from\"\n" );
|
||||
}
|
||||
else if (i == matchedWaypoints.size() - 1)
|
||||
{
|
||||
sb.append( " \"type\": \"to\"\n" );
|
||||
}
|
||||
else
|
||||
sb.append( " \"type\": \"via\"\n" );
|
||||
{
|
||||
}
|
||||
sb.append( " },\n" );
|
||||
sb.append( " \"geometry\": {\n" );
|
||||
sb.append( " \"type\": \"Point\",\n" );
|
||||
sb.append( " \"coordinates\": [\n" );
|
||||
sb.append( " " + formatILon(matchedWaypoints.get(i).waypoint.ilon) + ",\n" );
|
||||
sb.append( " " + formatILat(matchedWaypoints.get(i).waypoint.ilat) + "\n" );
|
||||
sb.append( " ]\n" );
|
||||
sb.append( " }\n" );
|
||||
if (i < matchedWaypoints.size() - 1) {
|
||||
sb.append( " },\n" );
|
||||
}
|
||||
else {
|
||||
sb.append( " }\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
sb.append( " }\n" );
|
||||
}
|
||||
sb.append( " ]\n" );
|
||||
sb.append( "}\n" );
|
||||
|
||||
|
|
|
@ -446,6 +446,7 @@ public class RoutingEngine extends Thread
|
|||
totaltrack.appendTrack( seg );
|
||||
lastTracks[i] = seg;
|
||||
}
|
||||
totaltrack.matchedWaypoints = matchedWaypoints;
|
||||
return totaltrack;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||
* alternativeidx = [0|1|2|3] (optional, default 0)
|
||||
* format = [kml|gpx|geojson] (optional, default gpx)
|
||||
* trackname = name used for filename and format specific trackname (optional, default brouter)
|
||||
* exportWaypoints = 1 to export them (optional, default is no export)
|
||||
*
|
||||
* Example URLs:
|
||||
* {@code http://localhost:17777/brouter?lonlats=8.799297,49.565883|8.811764,49.563606&nogos=&profile=trekking&alternativeidx=0&format=gpx}
|
||||
|
@ -118,6 +119,10 @@ public class ServerHandler extends RequestHandler {
|
|||
if (trackName != null) {
|
||||
track.name = trackName;
|
||||
}
|
||||
String exportWaypointsStr = params.get( "exportWaypoints" );
|
||||
if (exportWaypointsStr != null && Integer.parseInt(exportWaypointsStr) != 0) {
|
||||
track.exportWaypoints = true;
|
||||
}
|
||||
|
||||
if (format == null || "gpx".equals(format))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue