[GRASS-SVN] r67912 - in grass-addons/grass7/vector: . v.in.osm

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 20 10:34:58 PST 2016


Author: turek
Date: 2016-02-20 10:34:58 -0800 (Sat, 20 Feb 2016)
New Revision: 67912

Added:
   grass-addons/grass7/vector/v.in.osm/
   grass-addons/grass7/vector/v.in.osm/Makefile
   grass-addons/grass7/vector/v.in.osm/v.in.osm.html
   grass-addons/grass7/vector/v.in.osm/v.in.osm.py
Modified:
   grass-addons/grass7/vector/Makefile
Log:
v.in.osm: init version

Modified: grass-addons/grass7/vector/Makefile
===================================================================
--- grass-addons/grass7/vector/Makefile	2016-02-20 18:09:04 UTC (rev 67911)
+++ grass-addons/grass7/vector/Makefile	2016-02-20 18:34:58 UTC (rev 67912)
@@ -24,6 +24,7 @@
 	v.in.gps \
 	v.in.natura2000 \
 	v.in.ply \
+	v.in.osm \
 	v.in.redlist \
 	v.in.redwg \
 	v.in.wfs2 \

Added: grass-addons/grass7/vector/v.in.osm/Makefile
===================================================================
--- grass-addons/grass7/vector/v.in.osm/Makefile	                        (rev 0)
+++ grass-addons/grass7/vector/v.in.osm/Makefile	2016-02-20 18:34:58 UTC (rev 67912)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.in.osm
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


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

Added: grass-addons/grass7/vector/v.in.osm/v.in.osm.html
===================================================================
--- grass-addons/grass7/vector/v.in.osm/v.in.osm.html	                        (rev 0)
+++ grass-addons/grass7/vector/v.in.osm/v.in.osm.html	2016-02-20 18:34:58 UTC (rev 67912)
@@ -0,0 +1,26 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.in.osm</em> imports OpenStreetMap data.
+
+<h2>EXAMPLES</h2>
+
+
+<div class="code"><pre>
+v.in.osm input="PG:host=localhost dbname=gis user=ostepok" table=planet_osm_line output=roads type=point,line where="highway is not null" 
+</pre></div>
+
+<h2>REQUIREMENTS</h2>
+PostgreSQL, PostGIS, osm2pgsql
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.in.ogr.html">v.in.ogr</a>
+</em>
+
+<h2>AUTHORS</h2>
+
+Stepan Turek
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass-addons/grass7/vector/v.in.osm/v.in.osm.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/grass7/vector/v.in.osm/v.in.osm.py
===================================================================
--- grass-addons/grass7/vector/v.in.osm/v.in.osm.py	                        (rev 0)
+++ grass-addons/grass7/vector/v.in.osm/v.in.osm.py	2016-02-20 18:34:58 UTC (rev 67912)
@@ -0,0 +1,132 @@
+#!/usr/bin/env python
+"""
+MODULE:    v.in.osm
+
+AUTHOR(S): Stepan Turek <stepan.turek AT seznam.cz>
+
+PURPOSE:   Imports OpenStreetMap data into GRASS GIS.
+
+COPYRIGHT: (C) 2016 Stepan Turek, and by 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.
+"""
+
+#%module
+#% description: Imports OpenStreetMap data into GRASS GIS.
+#% keyword: osm
+#% keyword: vector
+#% keyword: import
+#%end
+
+#%option G_OPT_F_BIN_INPUT
+#% description: Table file to be imported or DB connection string
+#%end
+
+#%option G_OPT_V_OUTPUT
+#% description: Name for output vector map
+#% required: no
+#%end
+
+#%option G_OPT_DB_WHERE
+#%end
+
+#%option G_OPT_V_TYPE
+#% description: Name for output vector map
+#% options: point,line,boundary,centroid
+#% answer: point,line,boundary,centroid
+#% required: no
+#%end
+
+#%option G_OPT_DB_TABLE
+#% required: yes
+#%end
+
+#%flag
+#% key: o
+#% label: Override projection check (use current location's projection)
+#% description: Assume that the dataset has the same projection as the current location
+#%end
+
+import os
+import sys
+import atexit
+from grass.script.utils import try_rmdir
+import grass.script as grass
+from grass.exceptions import CalledModuleError
+
+class OsmImporter:
+
+    def __init__(self):
+
+        self.tmp_vects = []
+        self.tmp_opid = str(os.getpid())
+
+    def cleanup(self):
+
+        for tmp in self.tmp_vects:
+            grass.run_command('g.remove', flags = 'f', type = 'vector',
+                              name = tmp, quiet = True)
+
+    def _getTmpName(self, name):
+
+        return name + '_' + self.tmp_opid
+
+    def getNewTmp(self, name):
+
+        tmp = self._getTmpName(name)
+
+        self.tmp_vects.append(tmp)
+
+        return tmp
+
+    def getTmp(self, name):
+
+        return self._getTmpName(name)
+
+    def main(self, options, flags):
+
+        ogr_flags = []
+        if flags['o']:
+            ogr_flags.append('o')
+
+        try:
+            grass.run_command('v.in.ogr',
+                             quiet=True,
+                             input=options['input'],
+                             output=self.getNewTmp('ogr'),
+                             layer=options['table'],
+                             where=options['where'],
+                             type=options['type'],
+                             flags=ogr_flags
+                            )
+        except CalledModuleError:
+            grass.fatal(_('%s failed') % 'v.in.ogr')
+
+        try:
+            grass.run_command('v.split',
+                             quiet=True,
+                             input=self.getTmp('ogr'),
+                             output=self.getNewTmp('split'),
+                             vertices=2
+                            )
+        except CalledModuleError:
+            grass.fatal(_('%s failed') % 'v.split')
+
+        try:
+            grass.run_command('v.build.polylines',
+                             quiet=True, overwrite=grass.overwrite(),
+                             input=self.getNewTmp('split'),
+                             output=options['output'],
+                             cats='same'
+                             )
+        except CalledModuleError:
+            grass.fatal(_('%s failed') % 'v.build.polylines')
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+
+    osm_imp = OsmImporter()
+    atexit.register(osm_imp.cleanup)
+
+    osm_imp.main(options, flags)


Property changes on: grass-addons/grass7/vector/v.in.osm/v.in.osm.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native



More information about the grass-commit mailing list