Reorder waypoint and track writing on export.

The GPX schema requires waypoints to come before the track.

Waypoints are not currently used in TCX export, so there are no
changes there.

In KML files, both tracks and waypoints are "Placemark"s, so it
doesn't matter what order they come in there.

This does change the order they appear in CSV files, which could
potentially invalidate some assumptions made in downstream tools.
This commit is contained in:
Jared Casper
2011-02-09 10:42:34 -08:00
parent 7408849eb5
commit f86cadb802
3 changed files with 7 additions and 8 deletions
@@ -143,7 +143,6 @@ public class GpxTrackWriter implements TrackFormatWriter {
@Override
public void writeWaypoint(Waypoint waypoint) {
if (pw != null) {
// TODO: The gpx spec says waypoints should come *before* tracks
Location l = waypoint.getLocation();
if (l != null) {
pw.println("<wpt lat=\""
@@ -255,9 +255,8 @@ public class TrackWriter {
void writeDocument() {
Log.d(MyTracksConstants.TAG, "Started writing track.");
writer.writeHeader();
// TODO: Fix ordering (in GPX waypoints should come first)
writeLocations();
writeWaypoints(track.getId());
writeLocations();
writer.writeFooter();
writer.close();
success = true;
@@ -267,8 +267,13 @@ public class TrackWriterTest extends AndroidTestCase {
wpt.setId(i + 1);
}
// Begin the track
formatWriter.writeHeader();
// Expect reading/writing of the waypoints (except the first)
formatWriter.writeWaypoint(wptEq(wps[1]));
formatWriter.writeWaypoint(wptEq(wps[2]));
// Begin the track
formatWriter.writeBeginTrack(locEq(locs[0]));
// Write locations 1-2
@@ -289,10 +294,6 @@ public class TrackWriterTest extends AndroidTestCase {
// End the track
formatWriter.writeEndTrack(locEq(locs[5]));
// Expect reading/writing of the waypoints (except the first)
formatWriter.writeWaypoint(wptEq(wps[1]));
formatWriter.writeWaypoint(wptEq(wps[2]));
formatWriter.writeFooter();
formatWriter.close();