2

I'm tring to read a raster map from my grassData.

I'm using this code

import os
import grass.script.setup as gsetup
from grass.pygrass import raster

gisbase = os.environ['GISBASE']  
gisdbase = os.path.abspath("/home/myuser/grassData") 
location = 'mylocation'           
mapset = 'mymapset' 
gsetup.init(gisbase, gisdbase, location, mapset)

elev=raster.RasterRow('elevation')
elev.open()
for row in elev:
    print row

But I get all values with nan, where is the error?

If I do elev.info() I get this result

elevation@
rows: 4502
cols: 5554
north: 45.0743663458 south: 45.0500262069 nsres:5.40651685671e-06
east:  7.67457811722 west: 7.6445503225 ewres:5.40651687473e-06
range: 233.050003052, 310.049987793
proj: 3

Tnx

Lorenzo

4

The raster

enter image description here

If your raster is not in a the current region, all the values are nan

Therefore by security

from grass.pygrass.gis.region import Region
current = Region()
current.align('aspect')

Then

elev=raster.RasterRow('aspect') # one of my raster layers
elev.open()
elev.is_open()
True
elev.get_row(1)
Buffer([ nan,  nan,  nan, ...,  nan,  nan,  nan], dtype=float32)
elev.get_row(56)
Buffer([ nan,  296.56192017,  281.30841064, ...,  354.0930481 ,
    351.86880493, nan], dtype=float32)
# or
for row in elev[:3]:
   row[:4]
Buffer([ nan,  nan,  nan,  nan], dtype=float32)
Buffer([ nan,  nan,  nan,  nan], dtype=float32)
Buffer([nan,  45.00392151,  71.5674057 ,  59.03970337], dtype=float32)
# and
for row in elev:
    print row
 [ nan  nan  nan ...,  nan  nan  nan]
 [ nan  nan  nan ...,  nan  nan  nan]
 [ nan  45.00392151  71.5674057  ...,  63.43808365  45.00392151 nan]
 [ nan  63.43808365  90. ...,  59.03970337  59.03970337 nan]
 ....
 elev.cats[56]
 ('304 degrees ccw from east', 303.5, 304.5)
 from grass.pygrass.vector.geometry import Point
 elev.get_value(Point(237952.69,122535.2))
 160.63855

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.