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.bonnefi...@gmail.com>

---
 help/C/viking.xml    |   28 +++++++++++-
 src/Makefile.am      |    3 +-
 src/datasource_osm.c |  119 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/datasources.h    |    3 +
 src/menu.xml.h       |    3 +
 src/osm-traces.c     |    1 +
 src/vikwindow.c      |   10 ++++
 7 files changed, 165 insertions(+), 2 deletions(-)

diff --git a/help/C/viking.xml b/help/C/viking.xml
index 8947b8f..7c9dbe6 100644
--- a/help/C/viking.xml
+++ b/help/C/viking.xml
@@ -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 the base data for this project is GPS tracks.
+Quite naturaly, &appname; try to support this project.
+</para>
 <section><title>Uploading data to OpenStreetMap</title>
 <para>
 It is possible to upload data directly from &appname; to OpenStreetMap.
@@ -1242,8 +1248,28 @@ 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 realy 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>.
+The opened dialog box expect a page number.
+The track retrieve process return data with a 5 000 points limit.
+The page number parameter allows to request following points.
+</para>
+</formalpara>
+</section>
+</section>
+
 <section><title>Geocoded Photo</title>
 <para>
 HOWTO GEOCODE YOUR PHOTOS AND SEE THEM IN VIKING 
diff --git a/src/Makefile.am b/src/Makefile.am
index d3d40b4..b52f744 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
index 0000000..9e358b5
--- /dev/null
+++ b/src/datasource_osm.c
@@ -0,0 +1,119 @@
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2011, Guilhem Bonnefille <guilhe.bonnefil...@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 repreesentation */
+  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 );
+}
+
diff --git a/src/datasources.h b/src/datasources.h
index 25bb80b..15e469c 100644
--- a/src/datasources.h
+++ b/src/datasources.h
@@ -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
diff --git a/src/menu.xml.h b/src/menu.xml.h
index 4a45b5c..0e1fee5 100644
--- a/src/menu.xml.h
+++ b/src/menu.xml.h
@@ -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
diff --git a/src/osm-traces.c b/src/osm-traces.c
index f5088ce..ca2b68d 100644
--- a/src/osm-traces.c
+++ b/src/osm-traces.c
@@ -444,3 +444,4 @@ void osm_traces_upload_track_cb ( gpointer pass_along[6] )
 {
   osm_traces_upload_viktrwlayer(VIK_TRW_LAYER(pass_along[0]), pass_along[3]);
 }
+
diff --git a/src/vikwindow.c b/src/vikwindow.c
index 8e8fa89..cbf3fe6 100644
--- a/src/vikwindow.c
+++ b/src/vikwindow.c
@@ -1890,6 +1890,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 )
 {
@@ -2457,6 +2464,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
-- 
tg: (8d582a0..) t/osm/import-traces (depends on: master)

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Viking-devel mailing list
Viking-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viking-devel
Viking home page: http://viking.sf.net/

Reply via email to