[GRASS-SVN] r38451 -
grass/branches/develbranch_6/swig/python/examples
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 17 18:48:43 EDT 2009
Author: neteler
Date: 2009-07-17 18:48:43 -0400 (Fri, 17 Jul 2009)
New Revision: 38451
Modified:
grass/branches/develbranch_6/swig/python/examples/vectoraccess.py
Log:
show use of GRASS modules
Modified: grass/branches/develbranch_6/swig/python/examples/vectoraccess.py
===================================================================
--- grass/branches/develbranch_6/swig/python/examples/vectoraccess.py 2009-07-17 20:58:13 UTC (rev 38450)
+++ grass/branches/develbranch_6/swig/python/examples/vectoraccess.py 2009-07-17 22:48:43 UTC (rev 38451)
@@ -11,6 +11,7 @@
import os, sys
from grass.lib import grass
from grass.lib import vector as grassvect
+import grass.script as grassscript
if not os.environ.has_key("GISBASE"):
print "You must be in GRASS GIS to run this program."
@@ -61,6 +62,35 @@
#print 'Number of areas:', grassvect.Vect_get_num_primitives(map,GV_AREA)
print 'Number of areas:', grassvect.Vect_get_num_areas(map)
+layer = 1
+tmp = grassscript.tempfile()
+tmpf = file(tmp, 'w')
+
+try:
+ f = grassscript.vector_db(input)[int(layer)]
+except KeyError:
+ grassscript.fatal("There is no table connected to this map. Run v.db.connect or v.db.addtable first.")
+table = f['table']
+database = f['database']
+driver = f['driver']
+
+# call GRASS command
+grassscript.run_command('v.db.select', flags = 'c', map = input,
+ stdout = tmpf)
+tmpf.close()
+
+# check if result is empty
+tmpf = file(tmp)
+if tmpf.read(1) == '':
+ grassscript.fatal("Table <%s> contains no data.", table)
+
+# print table to stdout
+for line in tmpf:
+ print line
+
+tmpf.close()
+os.remove(tmp)
+
# close map
grassvect.Vect_close(map)
## end of the python script
More information about the grass-commit
mailing list