if (msg->easy_handle == _autoroute_data.curl_easy) {
/* This is the autoroute download. */
/* Now, parse the autoroute and update the display. */
- if (_autoroute_data.enabled && gpx_parse(&_route, _autoroute_data.rdl_data.bytes, _autoroute_data.rdl_data.bytes_read, 0)) {
+ if (_autoroute_data.enabled && path_gpx_parse(_route, _autoroute_data.rdl_data.bytes, _autoroute_data.rdl_data.bytes_read, 0)) {
/* Find the nearest route point, if we're connected. */
- path_find_nearest_point(_route);
+ path_find_nearest_point(_route, _gps->data.lat, _gps->data.lon);
}
route_cancel_autoroute(_route, TRUE); /* We're done. Clean up. */
} else {
name text default null, \
t int not null);"
+#define PATH_SQL_SELECT_TRACKS "select id,name,slat,slon,elat,elon,len,sdate,edate from tracks order by sdate"
+#define PATH_SQL_INSERT_TRACK "insert into tracks (id,name,sloc,sdate) values (?,?,?,?);
+#define PATH_SQL_INSERT_TRACK_POINT "insert into trackpoints (tid,dt,lat,lon,alt,hdop,vdop,pdop,sat,fix) values (?,?,?,?,?,?,?,?,?,?)"
+#define PATH_SQL_SELECT_TRACK_POINTS "select tid,dt,lat,lon,alt,hdop,vdop,pdop,sat,fix from trackpoints where tid=? order by dt"
+
enum {
NEW_POINT, /* A new point was appended to track track */
NEW_BREAK, /* A break was appended to the track */
path->wtail->point=path->tail;
path->wtail->desc=desc;
-path_find_nearest_point(path);
-
g_signal_emit(G_OBJECT(path), signals[NEW_WAYPOINT], 0, NULL);
return TRUE;
guint64 near_dist_squared;
g_return_val_if_fail(path, FALSE);
+g_return_val_if_fail(point, FALSE);
/* If we have waypoints (_next_way != NULL), then determine the "next
* waypoint", which is defined as the waypoint after the nearest point,
* UNLESS we've passed that waypoint, in which case the waypoint after
* that waypoint becomes the "next" waypoint. */
if (path->next_way) {
- /* First, set near_dist_squared with the new distance from
- * near_point. */
+ /* First, set near_dist_squared with the new distance from near_point. */
near = path->near_point;
near_dist_squared = DISTANCE_SQUARED(*point, *near);
* Reset the near_point data by searching the entire path for the nearest point and waypoint.
*/
void
-path_find_nearest_point(Path *path)
+path_find_nearest_point(Path *path, gdouble lat, gdouble lon)
{
+Point p;
+
g_return_if_fail(path);
/* Initialize near_point to first non-zero point. */
path->next_wpt=NULL;
path->next_wpt_dist_squared=-1;
+latlon2unit(lat, lon, p.unitx, p.unity);
+path_update_nears(path, &p, FALSE);
}
/**
/******************************************************************************/
+/**
+ *
+ *
+ */
+gdouble
+path_calculate_distance_from(Path *path, Point *point)
+{
+Point *curr;
+gdouble lat1, lon1, lat2, lon2;
+gdouble sum=0.0;
+
+for (curr = path->tail; curr > point; --curr) {
+ if (curr->unity) {
+ unit2latlon(curr->unitx, curr->unity, &lat2, &lon2);
+ sum += calculate_distance(lat1, lon1, lat2, lon2);
+ lat1 = lat2;
+ lon1 = lon2;
+ }
+}
+return sum;
+}
+
+/**
+ * path_get_distance_to:
+ * @path
+ * @point
+ * @lat
+ * @lon
+ *
+ * Calculate distancance from lat,lon to point in given path.
+ *
+ * Returns: The distance, or 0.0 if path or point is invalid.
+ */
gdouble
path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon)
{