[GRASS-SVN] r42094 - in grass-addons/vector: . v.in.osm2

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 3 18:37:58 EDT 2010


Author: hamish
Date: 2010-05-03 18:37:57 -0400 (Mon, 03 May 2010)
New Revision: 42094

Added:
   grass-addons/vector/v.in.osm2/
   grass-addons/vector/v.in.osm2/Makefile
   grass-addons/vector/v.in.osm2/v.in.osm
Log:
v.in.osm: import from OpenStreetMap Xapi API 0.6

Added: grass-addons/vector/v.in.osm2/Makefile
===================================================================
--- grass-addons/vector/v.in.osm2/Makefile	                        (rev 0)
+++ grass-addons/vector/v.in.osm2/Makefile	2010-05-03 22:37:57 UTC (rev 42094)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.in.osm
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass-addons/vector/v.in.osm2/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/vector/v.in.osm2/v.in.osm
===================================================================
--- grass-addons/vector/v.in.osm2/v.in.osm	                        (rev 0)
+++ grass-addons/vector/v.in.osm2/v.in.osm	2010-05-03 22:37:57 UTC (rev 42094)
@@ -0,0 +1,124 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       v.in.osm
+#
+# AUTHOR(S):    Hamish Bowman, Dunedin, New Zealand
+#
+# PURPOSE:      Import vector data direct from OpenStreetMap's database
+#
+# COPYRIGHT:    (c) 2010 Hamish Bowman, and the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#############################################################################
+#
+# -- Experimental --
+#
+#   See  http://wiki.openstreetmap.org/wiki/Xapi
+#
+# REQUIREMENTS:  gpsbabel 1.3.5 or newer
+#                wget
+#                g.region from GRASS 6.5 or newer (needs the -w flag)
+
+#%Module
+#%  description: Import vector data for the current region direct from OpenStreetMap's database
+#%  keywords: vector, import, osm
+#%End
+#%option
+#%  key: output
+#%  type: string
+#%  gisprompt: new,vector,output
+#%  description: Name for output map
+#%  required : yes
+#%end
+#%option
+#%  key: feature
+#%  type: string
+#%  description: Import as nodes or ways (GpsBabel only allows one)
+#%  options: nodes,ways
+#%  answer: ways
+#%end
+#%option
+#%  key: query
+#%  type: string
+#%  label: Xapi query string
+#%  description: For example: "way[highway=track|path]"
+#%  required : no
+#%end
+
+if [ -z "$GISBASE" ] ; then
+   echo "You must be in GRASS GIS to run this program." >&2
+   exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+  exec g.parser "$0" "$@"
+fi
+
+
+#### check if we have wget and gpsbabel
+if [ ! -x "`which wget`" ] ; then
+    g.message -e  "wget required, please install it first"
+    exit 1
+fi
+if [ ! -x "`which gpsbabel`" ] ; then
+    g.message -e  "GpsBabel required, please install it first"
+    exit 1
+fi
+#### check if we have new enough software
+if [ `g.region --interface-description | grep -c '<flag name="w">'` -ne 1 ] ; then
+   g.message -e "Newer version of GRASS is required."
+   exit 1
+fi
+if [ `gpsbabel --help | grep -wc osm` -ne 1 ] ; then
+   g.message -e "Newer version of GpsBabel is required."
+   exit 1
+fi
+
+
+# get bounding box in WGS84
+eval `g.region -bg`
+BBOX="$ll_w,$ll_s,$ll_e,$ll_n"
+
+
+#### setup temporary file
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
+    g.message -e "Unable to create temporary files"
+    exit 1
+fi
+
+BASEURL="http://osmxapi.hypercube.telascience.org/api/0.6"
+
+if [ -z "$GIS_OPT_QUERY" ] ; then
+   wget -O "$TEMPFILE" "$BASEURL/map?bbox=$BBOX"
+else
+   wget -O "$TEMPFILE" "$BASEURL/$GIS_OPT_QUERY[bbox=$BBOX]"
+fi
+
+if [ $? -ne 1 ] ; then
+   g.message -e "Download failed."
+   \rm "$TEMPFILE"
+   exit 1
+fi
+
+if [ "$GIS_OPT_FEATURE" = "ways" ] ; then
+   FEAT="-t"
+else
+   FEAT="-w"
+fi
+
+v.in.gpsbabel $FEAT input="$TEMPFILE" output="$GIS_OPT_OUTPUT" format=osm
+
+if [ $? -ne 1 ] ; then
+   g.message -e "Import failed."
+   \rm "$TEMPFILE"
+   exit 1
+fi
+
+
+\rm "$TEMPFILE"
+g.message "Done."
+


Property changes on: grass-addons/vector/v.in.osm2/v.in.osm
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native



More information about the grass-commit mailing list