]> git.street.me.uk Git - andy/viking.git/commitdiff
Add ability to acquire GPS traces stored on OSM
authorGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Sun, 21 Aug 2011 20:32:07 +0000 (22:32 +0200)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Sun, 21 Aug 2011 20:32:07 +0000 (22:32 +0200)
A new menu entry allows to request GPS traces stored on OpenStreetMap.
Currently, only the visible traces are downloaded, ie the traces
contained in the bounding bos of the current viewport.

This feature is really usefull for OSM contributors as it allows to
do some checks before uploading a new trace.

Signed-off-by: Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
help/C/viking.xml
po/POTFILES.in
src/Makefile.am
src/datasource_osm.c [new file with mode: 0644]
src/datasources.h
src/menu.xml.h
src/vikwindow.c

index 8947b8fc0706e41982470229074e3b4eb51d7bf1..4f09f788dcf7d4bbc807136961a2e5d48d892979 100644 (file)
@@ -1212,6 +1212,12 @@ Do not forget to save your configuration (as discussed above).
 </section>
 
 </section>
+<section><title>OpenStreetMap project</title>
+<para>
+<ulink url="http://openstreetmap.org/">OpenStreetMap (OSM)</ulink> is a collaborative project to create a free editable map of the world.
+One of sources of data for this project is GPS tracks.
+&appname; supports this project via the GPS Traces methods, both uploading and downloading such data.
+</para>
 <section><title>Uploading data to OpenStreetMap</title>
 <para>
 It is possible to upload data directly from &appname; to OpenStreetMap.
@@ -1242,8 +1248,29 @@ The description is some descriptive information.
 The tags field is a white separated list of tag.
 </para> 
 </formalpara>
-
 </section>
+<section><title>Downloading traces from OpenStreetMap</title>
+<para>
+It is possible to download GPS traces directly from OpenStreetMap into &appname;.
+This feature can be really useful for checking existing data before uploading new ones.
+</para>
+<formalpara>
+<title>Download all visible tracks</title>
+<para>One solution is to select
+<menuchoice>
+<guimenu>File</guimenu>
+<guisubmenu>Acquire</guisubmenu>
+<guimenuitem>OSM traces...</guimenuitem>
+</menuchoice>.
+Each request can get up to 5,000 points.
+The dialog box allows setting which group of 5,000 points to get. These groups are known as 'Page Numbers' which start at 0.
+Increasing the page number parameter allows one to request the subsequent sets of point groups.
+See <ulink url="http://wiki.openstreetmap.org/wiki/API_v0.6#GPS_Traces"/> for further detail.
+</para>
+</formalpara>
+</section>
+</section>
+
 <section><title>Geocoded Photo</title>
 <para>
 HOWTO GEOCODE YOUR PHOTOS AND SEE THEM IN VIKING 
index 9c62536795bec1568d7a4c4238299653bf77d2a8..1865700f747f32c28ef1c1c0bc697e071bb57291 100644 (file)
@@ -12,6 +12,7 @@ src/googlesearch.c
 src/datasource_gc.c
 src/datasource_google.c
 src/datasource_gps.c
+src/datasource_osm.c
 src/dem.c
 src/download.c
 src/file.c
index d3d40b46db0d32c2765cee81e21e09e75e0d5590..b52f74470ea9dd5bb545160f1aa1df3f4d438fee 100644 (file)
@@ -147,7 +147,8 @@ endif
 if OPENSTREETMAP
 libviking_a_SOURCES += \
        osm.c osm.h \
-       osm-traces.c osm-traces.h
+       osm-traces.c osm-traces.h \
+       datasource_osm.c
 endif
 
 if BLUEMARBLE
diff --git a/src/datasource_osm.c b/src/datasource_osm.c
new file mode 100644 (file)
index 0000000..36f0e97
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2011, Guilhem Bonnefille <guilhe.bonnefillee@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <string.h>
+
+#include <glib/gprintf.h>
+#include <glib/gi18n.h>
+
+#include "viking.h"
+#include "babel.h"
+#include "gpx.h"
+#include "acquire.h"
+
+/**
+ * See http://wiki.openstreetmap.org/wiki/API_v0.6#GPS_Traces
+ */
+#define DOWNLOAD_URL_FMT "api.openstreetmap.org/api/0.6/trackpoints?bbox=%s,%s,%s,%s&page=%d"
+
+typedef struct {
+  GtkWidget *page_number;
+  VikViewport *vvp;
+} datasource_osm_widgets_t;
+
+static gdouble last_page_number = 0;
+
+static gpointer datasource_osm_init( );
+static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
+static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, gchar **cmd, gchar **input_file_type ); 
+static void datasource_osm_cleanup ( gpointer data );
+
+VikDataSourceInterface vik_datasource_osm_interface = {
+  N_("OSM traces"),
+  N_("OSM traces"),
+  VIK_DATASOURCE_URL,
+  VIK_DATASOURCE_ADDTOLAYER,
+  VIK_DATASOURCE_INPUTTYPE_NONE,
+  TRUE,
+  TRUE,
+  (VikDataSourceInitFunc)              datasource_osm_init,
+  (VikDataSourceCheckExistenceFunc)    NULL,
+  (VikDataSourceAddSetupWidgetsFunc)   datasource_osm_add_setup_widgets,
+  (VikDataSourceGetCmdStringFunc)      datasource_osm_get_cmd_string,
+  (VikDataSourceProgressFunc)          NULL,
+  (VikDataSourceAddProgressWidgetsFunc)        NULL,
+  (VikDataSourceCleanupFunc)           datasource_osm_cleanup,
+  (VikDataSourceOffFunc)                NULL,
+};
+
+static gpointer datasource_osm_init ( )
+{
+  datasource_osm_widgets_t *widgets = g_malloc(sizeof(*widgets));
+  return widgets;
+}
+
+static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
+{
+  datasource_osm_widgets_t *widgets = (datasource_osm_widgets_t *)user_data;
+  GtkWidget *page_number_label;
+  page_number_label = gtk_label_new (_("Page number:"));
+  widgets->page_number = gtk_spin_button_new_with_range(0, 100, 1);
+  gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->page_number), last_page_number);
+  gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), page_number_label, FALSE, FALSE, 5 );
+  gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->page_number, FALSE, FALSE, 5 );
+  gtk_widget_show_all(dialog);
+  /* Keep reference to viewport */
+  widgets->vvp = vvp;
+}
+
+static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, gchar **cmd, gchar **input_file_type )
+{
+  int page = 0;
+  gdouble min_lat, max_lat, min_lon, max_lon;
+  gchar sminlon[G_ASCII_DTOSTR_BUF_SIZE];
+  gchar smaxlon[G_ASCII_DTOSTR_BUF_SIZE];
+  gchar sminlat[G_ASCII_DTOSTR_BUF_SIZE];
+  gchar smaxlat[G_ASCII_DTOSTR_BUF_SIZE];
+
+  /* TODO get Viewport bounding box vik_viewport_get_min_max_lat_lon */
+  vik_viewport_get_min_max_lat_lon ( widgets->vvp, &min_lat, &max_lat, &min_lon, &max_lon );
+
+  /* Convert as LANG=C double representation */
+  g_ascii_dtostr (sminlon, G_ASCII_DTOSTR_BUF_SIZE, min_lon);
+  g_ascii_dtostr (smaxlon, G_ASCII_DTOSTR_BUF_SIZE, max_lon);
+  g_ascii_dtostr (sminlat, G_ASCII_DTOSTR_BUF_SIZE, min_lat);
+  g_ascii_dtostr (smaxlat, G_ASCII_DTOSTR_BUF_SIZE, max_lat);
+
+  /* Retrieve the specified page number */
+  last_page_number = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->page_number));
+  page = last_page_number;
+
+  *cmd = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page );
+  *input_file_type = g_strdup("gpx");
+}
+
+static void datasource_osm_cleanup ( gpointer data )
+{
+  g_free ( data );
+}
+
index 25bb80b0381063804879202d9fbcbf882a5a8001..15e469c5b54a607c5205e89f4236d0dafca594dc 100644 (file)
@@ -25,6 +25,9 @@
 
 extern VikDataSourceInterface vik_datasource_gps_interface;
 extern VikDataSourceInterface vik_datasource_google_interface;
+#ifdef VIK_CONFIG_OPENSTREETMAP
+extern VikDataSourceInterface vik_datasource_osm_interface;
+#endif
 #ifdef VIK_CONFIG_GEOCACHES
 extern VikDataSourceInterface vik_datasource_gc_interface;
 #endif
index 4a45b5c75d43cb304129e07e095d12aec1584eb9..0e1fee56e41ba639c6045e3490d7a14f6d8201bb 100644 (file)
@@ -15,6 +15,9 @@ static const char *menu_xml =
        "      <menu action='Acquire'>"
        "        <menuitem action='AcquireGPS'/>"
        "        <menuitem action='AcquireGoogle'/>"
+#ifdef VIK_CONFIG_OPENSTREETMAP
+       "        <menuitem action='AcquireOSM'/>"
+#endif
 #ifdef VIK_CONFIG_GEOCACHES
        "        <menuitem action='AcquireGC'/>"
 #endif
index 5bff50e74804133b04efb031c1f595b74e8233b9..b76b519794addec21b2c41c9a9ec8a7b4d76f27a 100644 (file)
@@ -1898,6 +1898,13 @@ static void acquire_from_google ( GtkAction *a, VikWindow *vw )
   a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface );
 }
 
+#ifdef VIK_CONFIG_OPENSTREETMAP
+static void acquire_from_osm ( GtkAction *a, VikWindow *vw )
+{
+  a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_osm_interface );
+}
+#endif
+
 #ifdef VIK_CONFIG_GEOCACHES
 static void acquire_from_gc ( GtkAction *a, VikWindow *vw )
 {
@@ -2465,6 +2472,9 @@ static GtkActionEntry entries[] = {
   { "Acquire", NULL, N_("A_cquire"), 0, 0, 0 },
   { "AcquireGPS",   NULL,                N_("From _GPS..."),                     NULL,         N_("Transfer data from a GPS device"),              (GCallback)acquire_from_gps      },
   { "AcquireGoogle",   NULL,             N_("Google _Directions..."),     NULL,         N_("Get driving directions from Google"),           (GCallback)acquire_from_google   },
+#ifdef VIK_CONFIG_OPENSTREETMAP
+  { "AcquireOSM",   NULL,                 N_("_OSM Traces..."),          NULL,         N_("Get traces from OpenStreetMap"),            (GCallback)acquire_from_osm       },
+#endif
 #ifdef VIK_CONFIG_GEOCACHES
   { "AcquireGC",   NULL,                 N_("Geo_caches..."),            NULL,         N_("Get Geocaches from geocaching.com"),            (GCallback)acquire_from_gc       },
 #endif