[GRASS-SVN] r37353 - grass/trunk/swig/python/examples
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri May 22 05:27:39 EDT 2009
Author: neteler
Date: 2009-05-22 05:27:39 -0400 (Fri, 22 May 2009)
New Revision: 37353
Modified:
grass/trunk/swig/python/examples/m.distance.py
grass/trunk/swig/python/examples/rasteraccess.py
grass/trunk/swig/python/examples/vectoraccess.py
Log:
attempt to update examples (still fail)
Modified: grass/trunk/swig/python/examples/m.distance.py
===================================================================
--- grass/trunk/swig/python/examples/m.distance.py 2009-05-22 09:26:54 UTC (rev 37352)
+++ grass/trunk/swig/python/examples/m.distance.py 2009-05-22 09:27:39 UTC (rev 37353)
@@ -59,7 +59,7 @@
# or:
sys.path.append("/usr/src/grass70/swig/python")
# FIXME: install the g7lib.py bindings in $GISBASE/lib/ ?
- import swig.grass as g7lib
+ 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:26:54 UTC (rev 37352)
+++ grass/trunk/swig/python/examples/rasteraccess.py 2009-05-22 09:27:39 UTC (rev 37353)
@@ -1,10 +1,15 @@
#!/usr/bin/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/ ?
import os, sys
-import swig.grass as grasslib
-import swig.raster as grassrast
+import grass
if not os.environ.has_key("GISBASE"):
print "You must be in GRASS GIS to run this program."
@@ -16,23 +21,23 @@
input = raw_input("Raster Map Name? ")
# initialize
-grasslib.G_gisinit('')
+grass.G_gisinit('')
# find map in search path
-mapset = grasslib.G_find_cell2(input,'')
+mapset = grass.G_find_cell2(input,'')
# determine the inputmap type (CELL/FCELL/DCELL) */
-data_type = grasslib.G_raster_map_type(input, mapset)
+data_type = grass.G_raster_map_type(input, mapset)
-infd = grasslib.G_open_cell_old(input, mapset)
-inrast = grasslib.G_allocate_raster_buf(data_type)
+infd = grass.G_open_cell_old(input, mapset)
+inrast = grass.G_allocate_raster_buf(data_type)
rown=0
while 1:
- myrow = grasslib.G_get_raster_row(infd, inrast, rown, data_type)
+ myrow = grass.G_get_raster_row(infd, inrast, rown, data_type)
print rown,myrow[0:10]
rown = rown+1
if rown==476:break
-grasslib.G_close_cell(inrast)
-grasslib.G_free(cell)
+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:26:54 UTC (rev 37352)
+++ grass/trunk/swig/python/examples/vectoraccess.py 2009-05-22 09:27:39 UTC (rev 37353)
@@ -1,10 +1,15 @@
#!/usr/bin/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/ ?
import os, sys
-import swig.grass as grasslib
-import swig.vector as grassvect
+import grass
if not os.environ.has_key("GISBASE"):
print "You must be in GRASS GIS to run this program."
@@ -16,35 +21,35 @@
input = raw_input("Vector Map Name? ")
# initialize
-grasslib.G_gisinit('')
+grass.G_gisinit('')
# find map in search path
-mapset = grasslib.G_find_vector2(input,'')
+mapset = grass.G_find_vector2(input,'')
# define map structure
-map = grassvect.Map_info()
+map = grass.Map_info()
# define open level (level 2: topology)
-grassvect.Vect_set_open_level (2)
+grass.Vect_set_open_level (2)
# open existing map
-grassvect.Vect_open_old(map, input, mapset)
+grass.Vect_open_old(map, input, mapset)
# query
print 'Vect map: ', input
-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)
+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)
# misleading:
-# print 'Number of lines:', grassvect.Vect_get_num_lines(map)
+# print 'Number of lines:', grass.Vect_get_num_lines(map)
# how to access GV_POINT?
-# print 'Number of points: ', grassvect.Vect_get_num_primitives(map,GV_POINT)
+# print 'Number of points: ', grass.Vect_get_num_primitives(map,GV_POINT)
# confusing:
-#print 'Number of lines: ', Vect_get_num_primitives(map,GV_LINE)
-#print 'Number of areas:', Vect_get_num_primitives(map,GV_AREA)
-print 'Number of areas:', grassvect.Vect_get_num_areas(map)
+#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)
# close map
-grassvect.Vect_close(map)
+grass.Vect_close(map)
## end of the python script
More information about the grass-commit
mailing list