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(),
|
waypoint.getDescription(),
|
||||||
Double.toString(location.getLatitude()),
|
Double.toString(location.getLatitude()),
|
||||||
Double.toString(location.getLongitude()),
|
Double.toString(location.getLongitude()),
|
||||||
Double.toString(location.getAltitude()),
|
getAltitude(location),
|
||||||
Double.toString(location.getBearing()),
|
getBearing(location),
|
||||||
SHORT_FORMAT.format(location.getAccuracy()),
|
getAccuracy(location),
|
||||||
SHORT_FORMAT.format(location.getSpeed()),
|
getSpeed(location),
|
||||||
StringUtils.formatDateTimeIso8601(location.getTime()));
|
StringUtils.formatDateTimeIso8601(location.getTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,16 +196,32 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
|||||||
Integer.toString(pointIndex),
|
Integer.toString(pointIndex),
|
||||||
Double.toString(location.getLatitude()),
|
Double.toString(location.getLatitude()),
|
||||||
Double.toString(location.getLongitude()),
|
Double.toString(location.getLongitude()),
|
||||||
Double.toString(location.getAltitude()),
|
getAltitude(location),
|
||||||
Double.toString(location.getBearing()),
|
getBearing(location),
|
||||||
SHORT_FORMAT.format(location.getAccuracy()),
|
getAccuracy(location),
|
||||||
SHORT_FORMAT.format(location.getSpeed()),
|
getSpeed(location),
|
||||||
StringUtils.formatDateTimeIso8601(location.getTime()),
|
StringUtils.formatDateTimeIso8601(location.getTime()),
|
||||||
power,
|
power,
|
||||||
cadence,
|
cadence,
|
||||||
heartRate);
|
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.
|
* Writes a single line of a CSV file.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -138,7 +138,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
|||||||
public void writeLocation(Location location) {
|
public void writeLocation(Location location) {
|
||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
printWriter.println("<trkpt " + formatLocation(location) + ">");
|
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(
|
printWriter.println(
|
||||||
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
||||||
printWriter.println("</trkpt>");
|
printWriter.println("</trkpt>");
|
||||||
@@ -161,7 +163,9 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
|||||||
Location location = waypoint.getLocation();
|
Location location = waypoint.getLocation();
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
printWriter.println("<wpt " + formatLocation(location) + ">");
|
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(
|
printWriter.println(
|
||||||
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
"<time>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</time>");
|
||||||
printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>");
|
printWriter.println("<name>" + StringUtils.formatCData(waypoint.getName()) + "</name>");
|
||||||
|
|||||||
@@ -229,8 +229,7 @@ public class KmlTrackWriter implements TrackFormatWriter {
|
|||||||
if (printWriter != null) {
|
if (printWriter != null) {
|
||||||
printWriter.println(
|
printWriter.println(
|
||||||
"<when>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</when>");
|
"<when>" + StringUtils.formatDateTimeIso8601(location.getTime()) + "</when>");
|
||||||
printWriter.println("<gx:coord>" + location.getLongitude() + " " + location.getLatitude()
|
printWriter.println("<gx:coord>" + getCoordinates(location, " ") + "</gx:coord>");
|
||||||
+ " " + location.getAltitude() + "</gx:coord>");
|
|
||||||
if (location instanceof MyTracksLocation) {
|
if (location instanceof MyTracksLocation) {
|
||||||
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
|
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
|
||||||
int power = -1;
|
int power = -1;
|
||||||
@@ -302,13 +301,21 @@ public class KmlTrackWriter implements TrackFormatWriter {
|
|||||||
printWriter.println("<styleUrl>#" + styleName + "</styleUrl>");
|
printWriter.println("<styleUrl>#" + styleName + "</styleUrl>");
|
||||||
writeCategory(category);
|
writeCategory(category);
|
||||||
printWriter.println("<Point>");
|
printWriter.println("<Point>");
|
||||||
printWriter.println("<coordinates>" + location.getLongitude() + "," + location.getLatitude()
|
printWriter.println("<coordinates>" + getCoordinates(location, ",") + "</coordinates>");
|
||||||
+ "," + location.getAltitude() + "</coordinates>");
|
|
||||||
printWriter.println("</Point>");
|
printWriter.println("</Point>");
|
||||||
printWriter.println("</Placemark>");
|
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.
|
* Writes the category.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -204,7 +204,9 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
printWriter.println("<LatitudeDegrees>" + location.getLatitude() + "</LatitudeDegrees>");
|
printWriter.println("<LatitudeDegrees>" + location.getLatitude() + "</LatitudeDegrees>");
|
||||||
printWriter.println("<LongitudeDegrees>" + location.getLongitude() + "</LongitudeDegrees>");
|
printWriter.println("<LongitudeDegrees>" + location.getLongitude() + "</LongitudeDegrees>");
|
||||||
printWriter.println("</Position>");
|
printWriter.println("</Position>");
|
||||||
printWriter.println("<AltitudeMeters>" + location.getAltitude() + "</AltitudeMeters>");
|
if (location.hasAltitude()) {
|
||||||
|
printWriter.println("<AltitudeMeters>" + location.getAltitude() + "</AltitudeMeters>");
|
||||||
|
}
|
||||||
|
|
||||||
if (location instanceof MyTracksLocation) {
|
if (location instanceof MyTracksLocation) {
|
||||||
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
|
SensorDataSet sensorDataSet = ((MyTracksLocation) location).getSensorDataSet();
|
||||||
|
|||||||
Reference in New Issue
Block a user