[GRASS-SVN] r68412 - grass-addons/grass7/vector/v.in.osm
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon May 9 06:47:19 PDT 2016
Author: neteler
Date: 2016-05-09 06:47:18 -0700 (Mon, 09 May 2016)
New Revision: 68412
Modified:
grass-addons/grass7/vector/v.in.osm/v.in.osm.html
grass-addons/grass7/vector/v.in.osm/v.in.osm.py
Log:
v.in.osm addon: added list layers (-l) support and minor tweaks for OSM .pbf import
Modified: grass-addons/grass7/vector/v.in.osm/v.in.osm.html
===================================================================
--- grass-addons/grass7/vector/v.in.osm/v.in.osm.html 2016-05-09 03:43:12 UTC (rev 68411)
+++ grass-addons/grass7/vector/v.in.osm/v.in.osm.html 2016-05-09 13:47:18 UTC (rev 68412)
@@ -4,13 +4,23 @@
<h2>EXAMPLES</h2>
+Import from PostgreSQL DB:
<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"
+v.in.osm input="PG:host=localhost dbname=gis user=ostepok" table=planet_osm_line \
+ type=point,line output=roads where="highway is not null"
</pre></div>
+<p>
+Import from OSM PBF file:
+
+<div class="code"><pre>
+v.in.osm input=saarland-latest.osm.pbf table=lines type=point,line output=roads \
+ where="highway is not null"
+</pre></div>
+
<h2>REQUIREMENTS</h2>
-PostgreSQL, PostGIS, osm2pgsql
+PostgreSQL, PostGIS, <a href="http://wiki.openstreetmap.org/wiki/Osm2pgsql">osm2pgsql</a>
<h2>SEE ALSO</h2>
Modified: grass-addons/grass7/vector/v.in.osm/v.in.osm.py
===================================================================
--- grass-addons/grass7/vector/v.in.osm/v.in.osm.py 2016-05-09 03:43:12 UTC (rev 68411)
+++ grass-addons/grass7/vector/v.in.osm/v.in.osm.py 2016-05-09 13:47:18 UTC (rev 68412)
@@ -7,6 +7,7 @@
PURPOSE: Imports OpenStreetMap data into GRASS GIS.
COPYRIGHT: (C) 2016 Stepan Turek, and by the GRASS Development Team
+ - list layers (-l) support and minor tweaks for OSM .pbf import by Markus Neteler
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@@ -39,7 +40,6 @@
#%end
#%option G_OPT_DB_TABLE
-#% required: yes
#%end
#%flag
@@ -48,6 +48,11 @@
#% description: Assume that the dataset has the same projection as the current location
#%end
+#%flag
+#% key: l
+#% label: List available OGR layers in data source and exit
+#%end
+
import os
import sys
import atexit
@@ -86,11 +91,29 @@
def main(self, options, flags):
- ogr_flags = []
- if flags['o']:
- ogr_flags.append('o')
+ # just get the layer names
+ if flags['l']:
+ try:
+ grass.run_command('v.in.ogr',
+ quiet=True,
+ input=options['input'],
+ flags='l'
+ )
+ sys.exit()
+ except CalledModuleError:
+ grass.fatal(_('%s failed') % 'v.in.ogr')
+ else:
+ if not options['table']:
+ grass.fatal(_('Required parameter <%s> not set') % 'table')
+ if not options['output']:
+ grass.fatal(_('Required parameter <%s> not set') % 'output')
+ # process
try:
+ # http://gdal.org/drv_osm.html
+ os.environ['OGR_INTERLEAVED_READING'] = 'YES'
+
+ grass.debug('Step 1/3: v.in.ogr...', 2)
grass.run_command('v.in.ogr',
quiet=True,
input=options['input'],
@@ -98,12 +121,13 @@
layer=options['table'],
where=options['where'],
type=options['type'],
- flags=ogr_flags
+ flags=flags['o']
)
except CalledModuleError:
grass.fatal(_('%s failed') % 'v.in.ogr')
try:
+ grass.debug('Step 2/3: v.split...', 2)
grass.run_command('v.split',
quiet=True,
input=self.getTmp('ogr'),
@@ -114,8 +138,9 @@
grass.fatal(_('%s failed') % 'v.split')
try:
+ grass.debug('Step 3/3: v.build.polylines...', 2)
grass.run_command('v.build.polylines',
- quiet=True, overwrite=grass.overwrite(),
+ quiet=True,
input=self.getNewTmp('split'),
output=options['output'],
cats='same'
More information about the grass-commit
mailing list