Skip to content

Commit a3ef296

Browse files
Hans-Joachim ZimmerHans-Joachim Zimmer
Hans-Joachim Zimmer
authored and
Hans-Joachim Zimmer
committed
Changed GPX format: use only one line per TRKPT/WPT.
This creates smaller files and facilitates scripted postprocessing or parsing
1 parent bd813b4 commit a3ef296

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

app/src/main/java/net/osmtracker/gpx/ExportTrackTask.java

+47-47
Original file line numberDiff line numberDiff line change
@@ -342,63 +342,63 @@ private void writeTrackPoints(String trackName, Writer fw, Cursor c, boolean fil
342342
dialogUpdateThreshold++;
343343
}
344344

345-
fw.write("\t" + "<trk>" + "\n");
346-
fw.write("\t\t" + "<name>" + CDATA_START + trackName + CDATA_END + "</name>" + "\n");
345+
fw.write("<trk>" + "\n");
346+
fw.write("<name>" + CDATA_START + trackName + CDATA_END + "</name>" + "\n");
347347
if (fillHDOP) {
348-
fw.write("\t\t" + "<cmt>"
348+
fw.write("<cmt>"
349349
+ CDATA_START
350350
+ context.getResources().getString(R.string.gpx_hdop_approximation_cmt)
351351
+ CDATA_END
352352
+ "</cmt>" + "\n");
353353
}
354-
fw.write("\t\t" + "<trkseg>" + "\n");
354+
fw.write("<trkseg>" + "\n");
355355

356356
int i=0;
357357
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext(),i++) {
358358
StringBuffer out = new StringBuffer();
359-
out.append("\t\t\t" + "<trkpt lat=\""
359+
out.append("<trkpt lat=\""
360360
+ c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LATITUDE)) + "\" "
361-
+ "lon=\"" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE)) + "\">" + "\n");
361+
+ "lon=\"" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE)) + "\">");
362362
if (! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION))) {
363-
out.append("\t\t\t\t" + "<ele>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION)) + "</ele>" + "\n");
363+
out.append("<ele>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION)) + "</ele>");
364364
}
365-
out.append("\t\t\t\t" + "<time>" + pointDateFormatter.format(new Date(c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_TIMESTAMP)))) + "</time>" + "\n");
365+
out.append("<time>" + pointDateFormatter.format(new Date(c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_TIMESTAMP)))) + "</time>");
366366

367367
if(fillHDOP && ! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY))) {
368-
out.append("\t\t\t\t" + "<hdop>" + (c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) / OSMTracker.HDOP_APPROXIMATION_FACTOR) + "</hdop>" + "\n");
368+
out.append("<hdop>" + (c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) / OSMTracker.HDOP_APPROXIMATION_FACTOR) + "</hdop>");
369369
}
370370
if(OSMTracker.Preferences.VAL_OUTPUT_COMPASS_COMMENT.equals(compass) && !c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
371-
out.append("\t\t\t\t" + "<cmt>"+CDATA_START+"compass: " +
371+
out.append("<cmt>"+CDATA_START+"compass: " +
372372
c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))+
373-
"\n\t\t\t\t\tcompAccuracy: " +
373+
" compAccuracy: " +
374374
c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY))+
375-
CDATA_END+"</cmt>"+"\n");
375+
CDATA_END+"</cmt>");
376376
}
377377

378378
String buff = "";
379379
if(! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_SPEED))) {
380-
buff += "\t\t\t\t\t" + "<speed>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_SPEED)) + "</speed>" + "\n";
380+
buff += "<speed>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_SPEED)) + "</speed>";
381381
}
382382
if(OSMTracker.Preferences.VAL_OUTPUT_COMPASS_EXTENSION.equals(compass) && !c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
383-
buff += "\t\t\t\t\t" + "<compass>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) + "</compass>" + "\n";
384-
buff += "\t\t\t\t\t" + "<compass_accuracy>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + "</compass_accuracy>" + "\n";
383+
buff += "<compass>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) + "</compass>";
384+
buff += "<compass_accuracy>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + "</compass_accuracy>";
385385
}
386386
if(! buff.equals("")) {
387-
out.append("\t\t\t\t" + "<extensions>\n");
387+
out.append("<extensions>");
388388
out.append(buff);
389-
out.append("\t\t\t\t" + "</extensions>\n");
389+
out.append("</extensions>");
390390
}
391391

392-
out.append("\t\t\t" + "</trkpt>" + "\n");
392+
out.append("</trkpt>" + "\n");
393393
fw.write(out.toString());
394394

395395
if (i % dialogUpdateThreshold == 0) {
396396
publishProgress((long) dialogUpdateThreshold);
397397
}
398398
}
399399

400-
fw.write("\t\t" + "</trkseg>" + "\n");
401-
fw.write("\t" + "</trk>" + "\n");
400+
fw.write("</trkseg>" + "\n");
401+
fw.write("</trk>" + "\n");
402402
}
403403

404404
/**
@@ -426,81 +426,81 @@ private void writeWayPoints(Writer fw, Cursor c, String accuracyInfo, boolean fi
426426
int i=0;
427427
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext(), i++) {
428428
StringBuffer out = new StringBuffer();
429-
out.append("\t" + "<wpt lat=\""
429+
out.append("<wpt lat=\""
430430
+ c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LATITUDE)) + "\" "
431-
+ "lon=\"" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE)) + "\">" + "\n");
431+
+ "lon=\"" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE)) + "\">");
432432
if (! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION))) {
433-
out.append("\t\t" + "<ele>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION)) + "</ele>" + "\n");
433+
out.append("<ele>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION)) + "</ele>");
434434
}
435-
out.append("\t\t" + "<time>" + pointDateFormatter.format(new Date(c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_TIMESTAMP)))) + "</time>" + "\n");
435+
out.append("<time>" + pointDateFormatter.format(new Date(c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_TIMESTAMP)))) + "</time>");
436436

437437
String name = c.getString(c.getColumnIndex(TrackContentProvider.Schema.COL_NAME));
438438

439439
if (! OSMTracker.Preferences.VAL_OUTPUT_ACCURACY_NONE.equals(accuracyInfo) && ! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY))) {
440440
// Outputs accuracy info for way point
441441
if (OSMTracker.Preferences.VAL_OUTPUT_ACCURACY_WPT_NAME.equals(accuracyInfo)) {
442442
// Output accuracy with name
443-
out.append("\t\t" + "<name>"
443+
out.append("<name>"
444444
+ CDATA_START
445445
+ name
446446
+ " (" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) + meterUnit + ")"
447447
+ CDATA_END
448-
+ "</name>" + "\n");
448+
+ "</name>");
449449
if (OSMTracker.Preferences.VAL_OUTPUT_COMPASS_COMMENT.equals(compass) &&
450450
! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
451-
out.append("\t\t"+ "<cmt>" + CDATA_START + "compass: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
452-
"\n\t\t\tcompass accuracy: " + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + CDATA_END + "</cmt>\n");
451+
out.append("<cmt>" + CDATA_START + "compass: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
452+
" compass accuracy: " + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + CDATA_END + "</cmt>");
453453
}
454454
} else if (OSMTracker.Preferences.VAL_OUTPUT_ACCURACY_WPT_CMT.equals(accuracyInfo)) {
455455
// Output accuracy in separate tag
456-
out.append("\t\t" + "<name>" + CDATA_START + name + CDATA_END + "</name>" + "\n");
456+
out.append("<name>" + CDATA_START + name + CDATA_END + "</name>");
457457
if (OSMTracker.Preferences.VAL_OUTPUT_COMPASS_COMMENT.equals(compass) &&
458458
! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
459-
out.append("\t\t" + "<cmt>" + CDATA_START + accuracy + ": " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) + meterUnit +
460-
"\n\t\t\t compass heading: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
461-
"deg\n\t\t\t compass accuracy: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) +CDATA_END + "</cmt>" + "\n");
459+
out.append("<cmt>" + CDATA_START + accuracy + ": " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) + meterUnit +
460+
" compass heading: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
461+
"deg compass accuracy: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) +CDATA_END + "</cmt>");
462462
} else {
463-
out.append("\t\t" + "<cmt>" + CDATA_START + accuracy + ": " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) + meterUnit + CDATA_END + "</cmt>" + "\n");
463+
out.append("<cmt>" + CDATA_START + accuracy + ": " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) + meterUnit + CDATA_END + "</cmt>");
464464
}
465465
} else {
466466
// Unknown value for accuracy info, shouldn't occur but who knows ?
467467
// See issue #68. Output at least the name just in case.
468-
out.append("\t\t" + "<name>" + CDATA_START + name + CDATA_END + "</name>" + "\n");
468+
out.append("<name>" + CDATA_START + name + CDATA_END + "</name>");
469469
}
470470
} else {
471471
// No accuracy info requested, or available
472-
out.append("\t\t" + "<name>" + CDATA_START + name + CDATA_END + "</name>" + "\n");
472+
out.append("<name>" + CDATA_START + name + CDATA_END + "</name>");
473473
if (OSMTracker.Preferences.VAL_OUTPUT_COMPASS_COMMENT.equals(compass) &&
474474
! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
475-
out.append("\t\t"+ "<cmt>" + CDATA_START + "compass: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
476-
"\n\t\t\tcompass accuracy: " + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + CDATA_END + "</cmt>\n");
475+
out.append("<cmt>" + CDATA_START + "compass: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
476+
" compass accuracy: " + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + CDATA_END + "</cmt>");
477477
}
478478
}
479479

480480
String link = c.getString(c.getColumnIndex(TrackContentProvider.Schema.COL_LINK));
481481
if (link != null) {
482-
out.append("\t\t" + "<link href=\"" + URLEncoder.encode(link) + "\">" + "\n");
483-
out.append("\t\t\t" + "<text>" + link +"</text>\n");
484-
out.append("\t\t" + "</link>" + "\n");
482+
out.append("<link href=\"" + URLEncoder.encode(link) + "\">");
483+
out.append("<text>" + link +"</text>");
484+
out.append("</link>");
485485
}
486486

487487
if (! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_NBSATELLITES))) {
488-
out.append("\t\t" + "<sat>" + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_NBSATELLITES)) + "</sat>" + "\n");
488+
out.append("<sat>" + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_NBSATELLITES)) + "</sat>");
489489
}
490490

491491
if(fillHDOP && ! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY))) {
492-
out.append("\t\t" + "<hdop>" + (c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) / OSMTracker.HDOP_APPROXIMATION_FACTOR) + "</hdop>" + "\n");
492+
out.append("<hdop>" + (c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) / OSMTracker.HDOP_APPROXIMATION_FACTOR) + "</hdop>");
493493
}
494494

495495
if (OSMTracker.Preferences.VAL_OUTPUT_COMPASS_EXTENSION.equals(compass) &&
496496
! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
497-
out.append("\t\t<extensions>\n");
498-
out.append("\t\t\t"+ "<compass>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) + "</compass>\n");
499-
out.append("\t\t\t" + "<compass_accuracy>" + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + "</compass_accuracy>" + "\n");
500-
out.append("\t\t</extensions>\n");
497+
out.append("<extensions>");
498+
out.append("<compass>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) + "</compass>");
499+
out.append("<compass_accuracy>" + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + "</compass_accuracy>");
500+
out.append("</extensions>");
501501
}
502502

503-
out.append("\t" + "</wpt>" + "\n");
503+
out.append("</wpt>" + "\n");
504504

505505
fw.write(out.toString());
506506

0 commit comments

Comments
 (0)