Attached is a patch the addresses the issue documented in Issue 9765 ( 
http://darktable.org/redmine/issues/9765 ).

The second hunk suppresses spurious error messages; my Garmin device 
generates:

(1) a <metadata> tag that contains a <time> tag; and
(2) a <wpt> tag that contains a <ele> tag.

I have modified the code so that it only tests for <ele> and <time> tags when 
within a <trkpt> tag. Even if the <metadata> and <wpt> tags are not contained 
in the standard for gpx files (if one exists), they must be catered for - this 
is the "real world".

Kevin
diff --git a/src/common/gpx.c b/src/common/gpx.c
index 3d39bf1..b53eb01 100644
--- a/src/common/gpx.c
+++ b/src/common/gpx.c
@@ -161,8 +161,28 @@ gboolean dt_gpx_get_location(struct dt_gpx_t *gpx, GTimeVal *timestamp, gdouble
     if (timestamp->tv_sec >= tp->time.tv_sec &&
         timestamp->tv_sec <= ((_gpx_track_point_t*)item->next->data)->time.tv_sec)
     {
-      *lon = tp->longitude;
-      *lat = tp->latitude;
+      int time_diff = ((_gpx_track_point_t*)item->next->data)->time.tv_sec - tp->time.tv_sec;
+
+      if( !time_diff )
+      {
+        *lat = tp->latitude;
+        *lon = tp->longitude;
+      }
+      else
+      {
+        gdouble time_ratio     = (timestamp->tv_sec - tp->time.tv_sec) / (gdouble) time_diff;
+        gdouble this_latitude  = tp->latitude;
+        gdouble this_longitude = tp->longitude;
+        gdouble next_latitude  = ((_gpx_track_point_t*)item->next->data)->latitude;
+        gdouble next_longitude = ((_gpx_track_point_t*)item->next->data)->longitude;
+
+        // the following assumes that the two points are sufficiently close for the area to be considered a manifold
+        // and that the speed travelled between the two points is constant
+
+        *lat = this_latitude + time_ratio * (next_latitude - this_latitude);
+        *lon = this_longitude + time_ratio * (next_longitude - this_longitude);
+      }
+
       return TRUE;
     }
 
@@ -231,27 +251,17 @@ void _gpx_parser_start_element(GMarkupParseContext *ctx,
 
     gpx->current_parser_element = GPX_PARSER_ELEMENT_TRKPT;
   }
-  else if (strcmp(element_name, "time") == 0)
+  else if (gpx->current_track_point)
   {
-    if (!gpx->current_track_point)
-      goto element_error;
-
-    gpx->current_parser_element = GPX_PARSER_ELEMENT_TIME;
-  }
-  else if (strcmp(element_name, "ele") == 0)
-  {
-    if (!gpx->current_track_point)
-      goto element_error;
-
-    gpx->current_parser_element = GPX_PARSER_ELEMENT_ELE;
+    if (strcmp(element_name, "time") == 0)
+    {
+      gpx->current_parser_element = GPX_PARSER_ELEMENT_TIME;
+    }
+    else if (strcmp(element_name, "ele") == 0)
+    {
+      gpx->current_parser_element = GPX_PARSER_ELEMENT_ELE;
+    }
   }
-
-  return;
-
-element_error:
-  fprintf(stderr, "broken gpx file, element '%s' found outside of trkpt.\n",
-          element_name);
-
 }
 
 void _gpx_parser_end_element (GMarkupParseContext *context, const gchar *element_name,
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
darktable-devel mailing list
darktable-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/darktable-devel

Reply via email to