forked from upstream-mirrors/OpenTracks
Export altitude only when it is defined
This commit is contained in:
@@ -123,10 +123,10 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
||||
waypoint.getDescription(),
|
||||
Double.toString(location.getLatitude()),
|
||||
Double.toString(location.getLongitude()),
|
||||
Double.toString(location.getAltitude()),
|
||||
Double.toString(location.getBearing()),
|
||||
SHORT_FORMAT.format(location.getAccuracy()),
|
||||
SHORT_FORMAT.format(location.getSpeed()),
|
||||
getAltitude(location),
|
||||
getBearing(location),
|
||||
getAccuracy(location),
|
||||
getSpeed(location),
|
||||
StringUtils.formatDateTimeIso8601(location.getTime()));
|
||||
}
|
||||
|
||||
@@ -196,16 +196,32 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
||||
Integer.toString(pointIndex),
|
||||
Double.toString(location.getLatitude()),
|
||||
Double.toString(location.getLongitude()),
|
||||
Double.toString(location.getAltitude()),
|
||||
Double.toString(location.getBearing()),
|
||||
SHORT_FORMAT.format(location.getAccuracy()),
|
||||
SHORT_FORMAT.format(location.getSpeed()),
|
||||
getAltitude(location),
|
||||
getBearing(location),
|
||||
getAccuracy(location),
|
||||
getSpeed(location),
|
||||
StringUtils.formatDateTimeIso8601(location.getTime()),
|
||||
power,
|
||||
cadence,
|
||||
heartRate);
|
||||
}
|
||||
|
||||
|
||||
private String getAltitude(Location location) {
|
||||
return location.hasAltitude() ? Double.toString(location.getAltitude()) : null;
|
||||
}
|
||||
|
||||
private String getBearing(Location location) {
|
||||
return location.hasBearing() ? Double.toString(location.getBearing()) : null;
|
||||
}
|
||||
|
||||
private String getAccuracy(Location location) {
|
||||
return location.hasAccuracy() ? SHORT_FORMAT.format(location.getAccuracy()) : null;
|
||||
}
|
||||
|
||||
private String getSpeed(Location location) {
|
||||
return location.hasSpeed() ? SHORT_FORMAT.format(location.getSpeed()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a single line of a CSV file.
|
||||
*
|
||||
|
||||
@@ -138,7 +138,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
||||
public void writeLocation(Location location) {
|
||||
if (printWriter != null) {
|
||||
printWriter.println("<trkpt " + formatLocation(location) + ">");
|
||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
||||
if (location.hasAltitude()) {
|
||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
||||
}
|
||||
printWriter.println(
|
||||
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
||||
printWriter.println("</trkpt>");
|
||||
@@ -161,7 +163,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
||||
Location location = waypoint.getLocation();
|
||||
if (location != null) {
|
||||
printWriter.println("<wpt " + formatLocation(location) + ">");
|
||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
||||
if (location.hasAltitude()) {
|
||||
printWriter.println("<ele>" + ELEVATION_FORMAT.format(location.getAltitude()) + "</ele>");
|
||||
}
|
||||
printWriter.println(
|
||||
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
||||
printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>");
|
||||
|
||||
@@ -229,8 +229,7 @@ public class KmlTrackWriter implements TrackFormatWriter {
|
||||
if (printWriter != null) {
|
||||
printWriter.println(
|
||||
"<when>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</when>");
|
||||
printWriter.println("<gx:coord>" + location.getLongitude() + " " + location.getLatitude()
|
||||
+ " " + location.getAltitude() + "</gx:coord>");
|
||||
printWriter.println("<gx:coord>" + getCoordinates(location, " ") + "</gx:coord>");
|
||||
if (location instanceof MyTracksLocation) {
|
||||
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
|
||||
int power = -1;
|
||||
@@ -302,12 +301,20 @@ public class KmlTrackWriter implements TrackFormatWriter {
|
||||
printWriter.println("<styleUrl>#" + styleName + "</styleUrl>");
|
||||
writeCategory(category);
|
||||
printWriter.println("<Point>");
|
||||
printWriter.println("<coordinates>" + location.getLongitude() + "," + location.getLatitude()
|
||||
+ "," + location.getAltitude() + "</coordinates>");
|
||||
printWriter.println("<coordinates>" + getCoordinates(location, ",") + "</coordinates>");
|
||||
printWriter.println("</Point>");
|
||||
printWriter.println("</Placemark>");
|
||||
}
|
||||
}
|
||||
|
||||
private String getCoordinates(Location location, String separator) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(location.getLongitude() + separator + location.getLatitude());
|
||||
if (location.hasAltitude()) {
|
||||
buffer.append(separator + location.getAltitude());
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the category.
|
||||
|
||||
@@ -204,7 +204,9 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
||||
printWriter.println("<LatitudeDegrees>" + location.getLatitude() + "</LatitudeDegrees>");
|
||||
printWriter.println("<LongitudeDegrees>" + location.getLongitude() + "</LongitudeDegrees>");
|
||||
printWriter.println("</Position>");
|
||||
printWriter.println("<AltitudeMeters>" + location.getAltitude() + "</AltitudeMeters>");
|
||||
if (location.hasAltitude()) {
|
||||
printWriter.println("<AltitudeMeters>" + location.getAltitude() + "</AltitudeMeters>");
|
||||
}
|
||||
|
||||
if (location instanceof MyTracksLocation) {
|
||||
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
|
||||
|
||||
Reference in New Issue
Block a user