]> git.street.me.uk Git - andy/viking.git/commitdiff
Add time property to Waypoints since it's in the GPX1.0 standard.
authorRob Norris <rw_norris@hotmail.com>
Tue, 30 Apr 2013 19:47:17 +0000 (20:47 +0100)
committerRob Norris <rw_norris@hotmail.com>
Tue, 30 Apr 2013 22:06:33 +0000 (23:06 +0100)
Waypoints with timestamps are written by my Garmin Etrex 20,
so I want to be able to use them!

src/gpx.c
src/gpx.h
src/vikwaypoint.c
src/vikwaypoint.h

index f766753880ec9c0edf1072ec3d70164865db86fa..97c723f06f3de595d0138e1371c359ece9991eb9 100644 (file)
--- a/src/gpx.c
+++ b/src/gpx.c
@@ -54,7 +54,8 @@ typedef enum {
         tt_wpt_desc,
         tt_wpt_name,
         tt_wpt_ele,
-       tt_wpt_sym,
+        tt_wpt_sym,
+        tt_wpt_time,
         tt_wpt_link,            /* New in GPX 1.1 */
 
         tt_trk,
@@ -108,6 +109,7 @@ tag_mapping tag_path_map[] = {
         { tt_waypoint_name, "/loc/waypoint/name" },
 
         { tt_wpt_ele, "/gpx/wpt/ele" },
+        { tt_wpt_time, "/gpx/wpt/time" },
         { tt_wpt_name, "/gpx/wpt/name" },
         { tt_wpt_cmt, "/gpx/wpt/cmt" },
         { tt_wpt_desc, "/gpx/wpt/desc" },
@@ -249,6 +251,7 @@ static void gpx_start(VikTrwLayer *vtl, const char *el, const char **attr)
      case tt_wpt_desc:
      case tt_wpt_name:
      case tt_wpt_ele:
+     case tt_wpt_time:
      case tt_wpt_link:
      case tt_trk_cmt:
      case tt_trk_desc:
@@ -282,6 +285,7 @@ static void gpx_start(VikTrwLayer *vtl, const char *el, const char **attr)
 static void gpx_end(VikTrwLayer *vtl, const char *el)
 {
   static GTimeVal tp_time;
+  static GTimeVal wp_time;
 
   g_string_truncate ( xpath, xpath->len - strlen(el) - 1 );
 
@@ -366,6 +370,14 @@ static void gpx_end(VikTrwLayer *vtl, const char *el)
        g_string_erase ( c_cdata, 0, -1 );
        break;
 
+     case tt_wpt_time:
+       if ( g_time_val_from_iso8601(c_cdata->str, &wp_time) ) {
+         c_wp->timestamp = wp_time.tv_sec;
+         c_wp->has_timestamp = TRUE;
+       }
+       g_string_erase ( c_cdata, 0, -1 );
+       break;
+
      case tt_trk_trkseg_trkpt_time:
        if ( g_time_val_from_iso8601(c_cdata->str, &tp_time) ) {
          c_tp->timestamp = tp_time.tv_sec;
@@ -434,6 +446,7 @@ static void gpx_cdata(void *dta, const XML_Char *s, int len)
     case tt_trk_cmt:
     case tt_trk_desc:
     case tt_trk_trkseg_trkpt_time:
+    case tt_wpt_time:
     case tt_trk_trkseg_trkpt_course:
     case tt_trk_trkseg_trkpt_speed:
     case tt_trk_trkseg_trkpt_fix:
@@ -689,6 +702,18 @@ static void gpx_write_waypoint ( VikWaypoint *wp, GpxWritingContext *context )
     fprintf ( f, "  <ele>%s</ele>\n", tmp );
     g_free ( tmp );
   }
+
+  if ( wp->has_timestamp ) {
+    GTimeVal timestamp;
+    timestamp.tv_sec = wp->timestamp;
+    timestamp.tv_usec = 0;
+
+    gchar *time_iso8601 = g_time_val_to_iso8601 ( &timestamp );
+    if ( time_iso8601 != NULL )
+      fprintf ( f, "  <time>%s</time>\n", time_iso8601 );
+    g_free ( time_iso8601 );
+  }
+
   if ( wp->comment )
   {
     tmp = entitize(wp->comment);
index d8f7d4e2e1104dcb615410a4a467e77f53d7ea8e..7b1c925e080c74dbeca7a7c401b699187561a83f 100644 (file)
--- a/src/gpx.h
+++ b/src/gpx.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
  * Options adapting GPX writing.
  */
 typedef struct {
+       // NB force options only apply to trackpoints
        gboolean force_ele; /// Force ele field
        gboolean force_time; /// Force time field
        gboolean hidden; /// Write invisible tracks/waypoints (default is yes)
index 48cd2f2f4e70cba8658d5676f48df5c02c3dd6eb..0a42c12aa936abbf440b193be81a52dfdecc01b7 100644 (file)
@@ -127,6 +127,8 @@ VikWaypoint *vik_waypoint_copy(const VikWaypoint *wp)
   new_wp->coord = wp->coord;
   new_wp->visible = wp->visible;
   new_wp->altitude = wp->altitude;
+  new_wp->has_timestamp = wp->has_timestamp;
+  new_wp->timestamp = wp->timestamp;
   vik_waypoint_set_name(new_wp,wp->name);
   vik_waypoint_set_comment(new_wp,wp->comment);
   vik_waypoint_set_description(new_wp,wp->description);
index 8f8a53afcf8b965ecd43182384c8788f29f153b1..5fd8da999c7a655efdf3f7d7e426eb327f94ed0f 100644 (file)
@@ -36,6 +36,8 @@ typedef struct _VikWaypoint VikWaypoint;
 struct _VikWaypoint {
   VikCoord coord;
   gboolean visible;
+  gboolean has_timestamp;
+  time_t timestamp;
   gdouble altitude;
   gchar *name;
   gchar *comment;