[GRASS-SVN] r37355 - grass/trunk/swig/python/examples

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 22 05:46:30 EDT 2009


Author: martinl
Date: 2009-05-22 05:46:15 -0400 (Fri, 22 May 2009)
New Revision: 37355

Modified:
   grass/trunk/swig/python/examples/m.distance.py
   grass/trunk/swig/python/examples/rasteraccess.py
   grass/trunk/swig/python/examples/vectoraccess.py
Log:
quick fix, r37353


Modified: grass/trunk/swig/python/examples/m.distance.py
===================================================================
--- grass/trunk/swig/python/examples/m.distance.py	2009-05-22 09:30:10 UTC (rev 37354)
+++ grass/trunk/swig/python/examples/m.distance.py	2009-05-22 09:46:15 UTC (rev 37355)
@@ -59,7 +59,7 @@
     # or:
     sys.path.append("/usr/src/grass70/swig/python")
     # FIXME: install the g7lib.py bindings in $GISBASE/lib/ ?
-    import grass as g7lib
+    from grass.lib import grass as g7lib
  
     # for passing pointers
     import Numeric

Modified: grass/trunk/swig/python/examples/rasteraccess.py
===================================================================
--- grass/trunk/swig/python/examples/rasteraccess.py	2009-05-22 09:30:10 UTC (rev 37354)
+++ grass/trunk/swig/python/examples/rasteraccess.py	2009-05-22 09:46:15 UTC (rev 37355)
@@ -1,15 +1,25 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 
-# run within GRASS Spearfish session
-# run this before starting python to append module search path:
-#   export PYTHONPATH=/usr/src/grass70/swig/python
-#   check with "import sys; sys.path"
-# or:
-#   sys.path.append("/usr/src/grass70/swig/python")
-# FIXME: install the grass bindings in $GISBASE/lib/ ?
+"""
+Run within GRASS session
+Run this before starting python to append module search path:
 
+ at code
+export PYTHONPATH=/usr/src/grass70/swig/python
+ at endcode
+
+Check with "import sys; sys.path"
+or:
+
+ at code
+sys.path.append("/usr/src/grass70/swig/python")
+ at endcode
+
+\todo install the grass bindings in $GISBASE/lib/ ?
+"""
+
 import os, sys
-import grass
+from grass.lib import grass
 
 if not os.environ.has_key("GISBASE"):
     print "You must be in GRASS GIS to run this program."
@@ -24,7 +34,7 @@
 grass.G_gisinit('')
 
 # find map in search path
-mapset = grass.G_find_cell2(input,'')
+mapset = grass.G_find_cell2(input, '')
 
 # determine the inputmap type (CELL/FCELL/DCELL) */
 data_type = grass.G_raster_map_type(input, mapset)
@@ -32,12 +42,13 @@
 infd = grass.G_open_cell_old(input, mapset)
 inrast = grass.G_allocate_raster_buf(data_type)
 
-rown=0
-while 1:
+rown = 0
+while True:
     myrow = grass.G_get_raster_row(infd, inrast, rown, data_type)
-    print rown,myrow[0:10]
-    rown = rown+1
-    if rown==476:break
+    print rown, myrow[0:10]
+    rown += 1
+    if rown == 476:
+        break
 
 grass.G_close_cell(inrast)
 grass.G_free(cell)

Modified: grass/trunk/swig/python/examples/vectoraccess.py
===================================================================
--- grass/trunk/swig/python/examples/vectoraccess.py	2009-05-22 09:30:10 UTC (rev 37354)
+++ grass/trunk/swig/python/examples/vectoraccess.py	2009-05-22 09:46:15 UTC (rev 37355)
@@ -9,7 +9,8 @@
 # FIXME: install the grass bindings in $GISBASE/lib/ ?
 
 import os, sys
-import grass
+from grass.lib import grass
+from grass.lib import vector as grassvect
 
 if not os.environ.has_key("GISBASE"):
     print "You must be in GRASS GIS to run this program."
@@ -27,29 +28,29 @@
 mapset = grass.G_find_vector2(input,'')
 
 # define map structure
-map = grass.Map_info()
+map = grassvect.Map_info()
 
 # define open level (level 2: topology)
-grass.Vect_set_open_level (2)
+grassvect.Vect_set_open_level (2)
 
 # open existing map
-grass.Vect_open_old(map, input, mapset)
+grassvect.Vect_open_old(map, input, mapset)
 
 # query
 print 'Vect map: ', input
-print 'Vect is 3D: ', grass.Vect_is_3d (map)
-print 'Vect DB links: ', grass.Vect_get_num_dblinks(map)
-print 'Map Scale:  1:', grass.Vect_get_scale(map)
+print 'Vect is 3D: ', grassvect.Vect_is_3d (map)
+print 'Vect DB links: ', grassvect.Vect_get_num_dblinks(map)
+print 'Map Scale:  1:', grassvect.Vect_get_scale(map)
 # misleading:
-# print 'Number of lines:', grass.Vect_get_num_lines(map)
+# print 'Number of lines:', grassvect.Vect_get_num_lines(map)
 # how to access GV_POINT?
-# print 'Number of points: ', grass.Vect_get_num_primitives(map,GV_POINT)
+# print 'Number of points: ', grassvect.Vect_get_num_primitives(map,GV_POINT)
 # confusing:
-#print 'Number of lines: ', grass.Vect_get_num_primitives(map,GV_LINE)
-#print 'Number of areas:', grass.Vect_get_num_primitives(map,GV_AREA)
-print 'Number of areas:', grass.Vect_get_num_areas(map)
+#print 'Number of lines: ', grassvect.Vect_get_num_primitives(map,GV_LINE)
+#print 'Number of areas:', grassvect.Vect_get_num_primitives(map,GV_AREA)
+print 'Number of areas:', grassvect.Vect_get_num_areas(map)
 
 # close map
-grass.Vect_close(map)
+grassvect.Vect_close(map)
 ## end of the python script
 



More information about the grass-commit mailing list