Note: A new GRASS GIS stable version has been released: GRASS GIS 7.8. Go directly to the new manual page here
Created on Fri May 25 12:57:10 2012
@author: Pietro Zambelli
Bases: object
This class is design to easily access and modify GRASS computational region.
>>> r = Region()
>>> r.north
40.0
>>> r.south
0.0
>>> r.east
40.0
>>> r.west
0.0
>>> r.cols
20
>>> r.rows
20
>>> r.nsres
2.0
>>> r.ewres
2.0
>>> r.north = 100
>>> r.east = 100
>>> r.adjust(rows=True, cols=True)
>>> r.nsres
5.0
>>> r.ewres
5.0
>>> r.cols
20
>>> r.rows
20
>>> r.read()
>>> r.north = 100
>>> r.east = 100
>>> r.adjust(rows=False, cols=True)
>>> r.nsres
2.0
>>> r.ewres
5.0
>>> r.cols
20
>>> r.rows
50
>>> r.read()
>>> r.north = 100
>>> r.east = 100
>>> r.adjust(rows=True, cols=False)
>>> r.nsres
5.0
>>> r.ewres
2.0
>>> r.cols
50
>>> r.rows
20
>>> r.read()
>>> r.north = 100
>>> r.east = 100
>>> r.adjust(rows=False, cols=False)
>>> r.nsres
2.0
>>> r.ewres
2.0
>>> r.cols
50
>>> r.rows
50
>>> r.read()
>>> r.cols = 1000
>>> r.ewres
0.04
>>> r.rows = 1000
>>> r.nsres
0.04
Adjust rows and cols number according with the nsres and ewres resolutions. If rows or cols parameters are True, the adjust method update nsres and ewres according with the rows and cols numbers.
Adjust region cells to cleanly align with this raster map
Warning: This will change the user GRASS region settings
Parameters: | raster_name (str) – the name of raster |
---|
Set and obtain bottom value
Set and obtain number of columns
Set and obtain number of depths
Set and obtain east coordinate
Set and obtain east-west resolution value
Set the region from the computational region of a raster map layer.
Parameters: |
|
---|
call C function Rast_get_cellhd
Example
>>> reg = Region()
>>> reg.from_rast(test_raster_name)
>>> reg.get_bbox()
Bbox(50.0, 0.0, 60.0, 0.0) >>> reg.read() >>> reg.get_bbox() Bbox(40.0, 0.0, 40.0, 0.0)
Adjust bounding box of region using a vector
Parameters: | vector_name (str) – the name of vector |
---|
Example
>>> reg = Region()
>>> reg.from_vect(test_vector_name)
>>> reg.get_bbox()
Bbox(6.0, 0.0, 14.0, 0.0) >>> reg.read() >>> reg.get_bbox() Bbox(40.0, 0.0, 40.0, 0.0)
Return a Bbox object with the extension of the region.
>>> reg = Region()
>>> reg.get_bbox()
Bbox(40.0, 0.0, 40.0, 0.0)
Get the current working region of this process and store it into this Region object
Previous calls to set_current() affects values returned by this function. Previous calls to read() affects values returned by this function only if the current working region is not initialized.
Example:
>>> r = Region() >>> r.north 40.0>>> r.north = 30 >>> r.north 30.0 >>> r.get_current() >>> r.north 40.0
Return a list of valid keys.
>>> reg = Region()
>>> reg.keys()
[u'proj', u'zone', ..., u'cols', u'cells']
Set and obtain north coordinate
Set and obtain north-south resolution value
Read the region into this region object
Reads the region as stored in the WIND file in the user’s current mapset into region.
3D values are set to defaults if not available in WIND file. An error message is printed and exit() is called if there is a problem reading the region.
<b>Note:</b> GRASS applications that read or write raster maps should not use this routine since its use implies that the active module region will not be used. Programs that read or write raster map data (or vector data) can query the active module region using Rast_window_rows() and Rast_window_cols().
Parameters: | force_read (boolean) – If True the WIND file of the current mapset is re-readed, otherwise the initial region set at process start will be loaded from the internal static variables. |
---|
Get the default region
Reads the default region for the location in this Region object. 3D values are set to defaults if not available in WIND file.
An error message is printed and exit() is called if there is a problem reading the default region.
Set and obtain number of rows
Set region extent from Bbox
Parameters: | bbox (Bbox object) – a Bbox object to set the extent |
---|
>>> from grass.pygrass.vector.basic import Bbox
>>> b = Bbox(230963.640878, 212125.562878, 645837.437393, 628769.374393)
>>> reg = Region()
>>> reg.set_bbox(b)
>>> reg.get_bbox()
Bbox(230963.640878, 212125.562878, 645837.437393, 628769.374393)
>>> reg.get_current()
Set the current working region from this region object
This function adjusts the values before setting the region so you don’t have to call G_adjust_Cell_head().
The GRASS computational region is not affected.
Example:
>>> r = Region()
>>> r.north
40.0 >>> r.south 0.0
>>> r.north = 30
>>> r.south = 20
>>> r.set_current()
>>> r.north
30.0
>>> r.south
20.0
>>> r.get_current()
>>> r.north
30.0
>>> r.south
20.0
>>> r.read(force_read=False)
>>> r.north
40.0
>>> r.south
0.0
>>> r.read(force_read=True)
>>> r.north
40.0
>>> r.south
0.0
Set the computational region (window) for all raster maps in the current process.
The Raster library C function Rast_set_window() is called.
Set and obtain south coordinate
Set and obtain top-bottom 3D value
Set and obtain top value
Set and obtain west coordinate
Writes the region from this region object
This function writes this region to the Region file (WIND) in the users current mapset. This function should be carefully used, since the user will ot notice if his region was changed and would expect that only g.region will do this.
Example
>>> from copy import deepcopy >>> r = Region() >>> rn = deepcopy(r) >>> r.north = 20 >>> r.south = 10>>> r.write() >>> r.read() >>> r.north 20.0 >>> r.south 10.0>>> rn.write() >>> r.read() >>> r.north 40.0 >>> r.south 0.0>>> r.read_default() >>> r.write()
Bases: object
Return Gisdbase object.
>>> from grass.script.core import gisenv
>>> gisdbase = Gisdbase()
>>> gisdbase.name == gisenv()['GISDBASE']
True
Return a list of locations that are available in the gisdbase:
>>> gisdbase = Gisdbase()
>>> gisdbase.locations()
[...]
Set or obtain the name of GISDBASE
Bases: object
Location object
>>> from grass.script.core import gisenv
>>> location = Location()
>>> location
Location(...)
>>> location.gisdbase == gisenv()['GISDBASE']
True
>>> location.name == gisenv()['LOCATION_NAME']
True
Set or obtain the name of GISDBASE
Return a list of the available mapsets.
Parameters: |
|
---|---|
Returns: | a list of mapset’s names |
Return type: | list of strings |
>>> location = Location()
>>> sorted(location.mapsets())
[...]
Set or obtain the name of LOCATION
Bases: object
Mapset
>>> from grass.script.core import gisenv
>>> genv = gisenv()
>>> mapset = Mapset()
>>> mapset
Mapset(...)
>>> mapset.gisdbase == genv['GISDBASE']
True
>>> mapset.location == genv['LOCATION_NAME']
True
>>> mapset.name == genv['MAPSET']
True
Set or obtain the name of GISDBASE
Return a list of grass types like:
- ‘group’,
- ‘label’,
- ‘raster’,
- ‘raster_3d’,
- ‘region’,
- ‘vector’,
Parameters: |
|
---|
>>> mapset = Mapset()
>>> mapset.current()
>>> rast = mapset.glist('raster')
>>> test_raster_name in rast
True
>>> vect = mapset.glist('vector')
>>> test_vector_name in vect
True
Set or obtain the name of LOCATION
Set or obtain the name of MAPSET
Bases: object
VisibleMapset object
Private function to check the correctness of a value.
Parameters: |
|
---|---|
Returns: | True if valid else False |
Return type: | str |
Note: A new GRASS GIS stable version has been released: GRASS GIS 7.8. Go directly to the new manual page here
Help Index | Topics Index | Keywords Index | Full Index
© 2003-2020 GRASS Development Team, GRASS GIS 7.6.2dev Reference Manual