[GRASS-dev] Access current region in pygrass

Nikos Alexandris nik at nikosalexandris.net
Thu Sep 1 18:19:08 PDT 2016


Blumentrath, Stefan:

>Hi devs,
>
>I am trying to access the Bbox of my current region in pygrass (GRASS 7.0.4), following examples here:
>https://grass.osgeo.org/grass70/manuals/libpython/pygrass.gis.html#module-pygrass.gis.region.
>
>Unfortunately, "north" returns always 1, for some reason I do not understand...
>
>This is what I do:
>
>>>> from grass.pygrass.gis.region import Region
>>>> Region()
>projection: 3 (Latitude-Longitude)
>zone:       0
>datum:      wgs84
>ellipsoid:  wgs84
>north:      75N
>south:      60N
>west:       15E
>east:       6W
>nsres:      1
>ewres:      1
>rows:       15
>cols:       339
>cells:      5085
>
>>>> r = Region()
>>>> r
>projection: 3 (Latitude-Longitude)
>zone:       0
>datum:      wgs84
>ellipsoid:  wgs84
>north:      75N
>south:      60N
>west:       15E
>east:       6W
>nsres:      1
>ewres:      1
>rows:       15
>cols:       339
>cells:      5085

Here,

g.region -p
projection: 3 (Latitude-Longitude)
zone:       0
datum:      wgs84
ellipsoid:  wgs84
north:      75N
south:      60N
west:       15E
east:       6W
nsres:      1
ewres:      1
rows:       15
cols:       339
cells:      5085

or, with the new flag `f` to easily share a one-liner:

g.region -fg

projection=3
zone=0
n=75 s=60 w=15 e=354 nsres=1 ewres=1 rows=15 cols=339 cells=5085

>So, the region definition in my Python object "r" looks OK, but then
>>>> r.north
>1.0

Here I get 75.0.

>Where I would expect to get 75.0 and
>>>> r.get_bbox
><bound method Region.get_bbox of Region(north=1, south=0, east=1, west=0, nsres=1, ewres=1)>

and here,

<bound method Region.get_bbox of Region(north=75, south=60, east=354, west=15, nsres=1, ewres=1, rows=15, cols=339, cells=5085, zone=0, proj=3)>

Can't replicate.

So, maybe the question is: why are (your) `rows`, `cols`, `cells`, `zone` and `proj` missing?

By the way, you do really mean an "horizontally" elongated box and not

`g.region res=1 n=75 s=60 e=15 w=6`, right?

Nikos


More information about the grass-dev mailing list