~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to swig/python/examples/rasteraccess.py

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
"""
4
 
Run within GRASS session
5
 
Run this before starting python to append module search path:
6
 
 
7
 
@code
8
 
export PYTHONPATH=/usr/src/grass64/swig/python
9
 
@endcode
10
 
 
11
 
Check with "import sys; sys.path"
12
 
or:
13
 
 
14
 
@code
15
 
sys.path.append("/usr/src/grass64/swig/python")
16
 
@endcode
17
 
 
18
 
\todo install the grass bindings in $GISBASE/lib/ ?
19
 
"""
20
 
 
21
 
import os, sys
22
 
from grass.lib import grass
23
 
 
24
 
if not os.environ.has_key("GISBASE"):
25
 
    print "You must be in GRASS GIS to run this program."
26
 
    sys.exit(1)
27
 
 
28
 
if len(sys.argv)==2:
29
 
  input = sys.argv[1]
30
 
else:
31
 
  input = raw_input("Raster Map Name? ")
32
 
 
33
 
# initialize
34
 
grass.G_gisinit('')
35
 
 
36
 
# find map in search path
37
 
mapset = grass.G_find_cell2(input, '')
38
 
 
39
 
# determine the inputmap type (CELL/FCELL/DCELL) */
40
 
data_type = grass.G_raster_map_type(input, mapset)
41
 
 
42
 
infd = grass.G_open_cell_old(input, mapset)
43
 
inrast = grass.G_allocate_raster_buf(data_type)
44
 
 
45
 
rown = 0
46
 
while True:
47
 
    myrow = grass.G_get_raster_row(infd, inrast, rown, data_type)
48
 
    print rown, myrow[0:10]
49
 
    rown += 1
50
 
    if rown == 476:
51
 
        break
52
 
 
53
 
grass.G_close_cell(inrast)
54
 
grass.G_free(cell)