Hello,
my GPS device outputs waypoints like this:
<wpt lat="49.751007641" lon="6.685312260">
<ele>274.580200</ele>
<name>001</name>
<cmt>18-AUG-08 11:33:03</cmt>
<desc>18-AUG-08 13:33:03</desc>
<sym>Flag, Blue</sym>
</wpt>
As there is no <time> given, JOSM will try to estimate its timestamp
from the position, which works only for ~ 50% of my waypoints.
I wrote the attached small patch, so JOSM tries to read the time from
the comment in <cmt>, when there is no <time>.
If it is, only <time> is considered.
I used the date-format for <cmt> as I found it in my GPX, a Garmin
GPSMAP 60Csx, GPX downloaded with "gpsbabel -t -w -i garmin -f
/dev/ttyUSB0 -o gpx -F track.gpx".
Can it be merged into the official version?
Regards
Roland
Index: /home/roland/josm/trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
===================================================================
--- /home/roland/josm/trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
(revision 808)
+++ /home/roland/josm/trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
(working copy)
@@ -35,12 +35,17 @@
* Convert the time stamp of the waypoint into seconds from the epoch
*/
public void setTime () {
- if (! attr.containsKey("time")) {
- time = 0.0;
- return;
- }
+ Date d = null;
+
+ //try to parse the <time>-value, try <cmt> as fallback if no
<time> is there
+ if (attr.containsKey("time")) {
SimpleDateFormat f = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone
- Date d = f.parse(attr.get("time").toString(), new
ParsePosition(0));
+ d = f.parse(attr.get("time").toString(), new ParsePosition(0));
+ } else if (attr.containsKey("cmt")) { /*fallback: try to parse
the comment*/
+ SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy
HH:mm:ss"); // has no timezone
+ d = f.parse(attr.get("cmt").toString(), new
ParsePosition(0));
+ }
+
if (d == null /* failed to parse */) {
time = 0.0;
} else {
Index: /home/roland/josm/trunk/src/org/openstreetmap/josm/io/GpxReader.java
===================================================================
--- /home/roland/josm/trunk/src/org/openstreetmap/josm/io/GpxReader.java
(revision 808)
+++ /home/roland/josm/trunk/src/org/openstreetmap/josm/io/GpxReader.java
(working copy)
@@ -226,9 +226,9 @@
if (qName.equals("ele") || qName.equals("desc")
|| qName.equals("magvar") ||
qName.equals("geoidheight")
|| qName.equals("name") ||
qName.equals("sym")
- || qName.equals("cmt") ||
qName.equals("type")) {
+ || qName.equals("type")) {
currentWayPoint.attr.put(qName,
accumulator.toString());
- } else if (qName.equals("time")) {
+ } else if (qName.equals("time") ||
qName.equals("cmt")) {
currentWayPoint.attr.put(qName,
accumulator.toString());
currentWayPoint.setTime();
} else if (qName.equals("rtept")) {
_______________________________________________
josm-dev mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/josm-dev