GRASS GIS logo

Note: A new GRASS GIS stable version has been released: GRASS GIS 7.4. Go directly to the new manual page here

pygrass.gis package

Submodules

pygrass.gis.region module

Created on Fri May 25 12:57:10 2012

@author: Pietro Zambelli

class pygrass.gis.region.Region(default=False)[source]

Bases: object

This class is design to easily access and modify GRASS computational region.

>>> default = Region(default=True)
>>> current_original = Region()
>>> current = Region()
>>> current.align('elevation')
>>> default == current
True
>>> current.cols
1500
>>> current.ewres
10.0
>>> current.cols = 3000
>>> current.ewres
5.0
>>> current.ewres = 20.0
>>> current.cols
750
>>> current.set_current()
>>> default == current
False
>>> current.get_default()
>>> default = Region(default=True)
>>> default == current
True
>>> current_original.set_current()
adjust(rows=False, cols=False)[source]

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.

align(raster_name)[source]

Adjust region cells to cleanly align with this raster map

Parameters:raster_name (str) – the name of raster
bottom

Set and obtain bottom value

cells[source]

Return the number of cells

cols

Set and obtain number of columns

east

Set and obtain east coordinate

ewres

Set and obtain east-west resolution value

get_bbox()[source]

Return a Bbox object with the extension of the region.

>>> reg = Region()
>>> reg.get_bbox()
Bbox(228500.0, 215000.0, 645000.0, 630000.0)
get_current()[source]

Set the current GRASS region to the Region object

get_default()[source]

Set the default GRASS region to the Region object

items()[source]

Return a list of tuple with key and value.

>>> reg = Region()
>>> reg.items()                              
[(u'proj', 99), ..., (u'cells', 2025000)]
keys()[source]

Return a list of valid keys.

>>> reg = Region()
>>> reg.keys()                               
[u'proj', u'zone', ..., u'cols', u'cells']
north

Set and obtain north coordinate

nsres

Set and obtain north-south resolution value

proj[source]

Return a code for projection

>>> reg = Region()
>>> reg.proj
99
rows

Set and obtain number of rows

set_bbox(bbox)[source]

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_current()[source]

Set the Region object to the current GRASS region

set_default()[source]

Set the Region object to the default GRASS region. It works only in PERMANENT mapset

south

Set and obtain south coordinate

tbres

Set and obtain top-bottom 3D value

top

Set and obtain top value

vect(vector_name)[source]

Adjust bounding box of region using a vector

Parameters:vector_name (str) – the name of vector
>>> reg = Region()
>>> reg.vect('census')
>>> reg.get_bbox()
Bbox(230963.640878, 212125.562878, 645837.437393, 628769.374393)
>>> reg.get_default()
west

Set and obtain west coordinate

zone[source]

Return the zone of projection

>>> reg = Region()
>>> reg.zone
0
zoom(raster_name)[source]

Shrink region until it meets non-NULL data from this raster map

Parameters:raster_name (str) – the name of raster

Module contents

class pygrass.gis.Gisdbase(gisdbase=u'')[source]

Bases: object

Return Gisdbase object.

>>> from grass.script.core import gisenv
>>> gisdbase = Gisdbase()
>>> gisdbase.name == gisenv()['GISDBASE']
True
locations()[source]

Return a list of locations that are available in the gisdbase:

>>> gisdbase = Gisdbase()
>>> gisdbase.locations()                     
[...]
name

Set or obtain the name of GISDBASE

new_location()[source]
class pygrass.gis.Location(location=u'', gisdbase=u'')[source]

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
gisdbase

Set or obtain the name of GISDBASE

mapsets(pattern=None, permissions=True)[source]

Return a list of the available mapsets.

Parameters:
  • pattern (str) – the pattern to filter the result
  • permissions (bool) – check the permission of mapset
Returns:

a list of mapset’s names

Return type:

list of strings

>>> location = Location()
>>> sorted(location.mapsets())
['PERMANENT', 'user1']
name

Set or obtain the name of LOCATION

path()[source]

Return the complete path of the location

class pygrass.gis.Mapset(mapset=u'', location=u'', gisdbase=u'')[source]

Bases: object

Mapset

>>> mapset = Mapset()
>>> mapset
Mapset('user1')
>>> mapset.gisdbase                               
'/home/...'
>>> mapset.location
'nc_basic_spm_grass7'
>>> mapset.name
'user1'
current()[source]

Set the mapset as current

delete()[source]

Delete the mapset

gisdbase

Set or obtain the name of GISDBASE

glist(type, pattern=None)[source]

Return a list of grass types like:

  • ‘group’,
  • ‘label’,
  • ‘raster’,
  • ‘raster_3d’,
  • ‘region’,
  • ‘vector’,
Parameters:
  • type (str) – the type of element to query
  • pattern (str) – the pattern to filter the result
>>> mapset = Mapset('PERMANENT')
>>> rast = mapset.glist('rast')
>>> rast.sort()
>>> rast                                      
['basins', 'elevation', ...]
>>> sorted(mapset.glist('rast', pattern='el*'))
['elevation', 'elevation_shade']
is_current()[source]

Check if the MAPSET is the working MAPSET

location

Set or obtain the name of LOCATION

name

Set or obtain the name of MAPSET

path()[source]

Return the complete path of the mapset

class pygrass.gis.VisibleMapset(mapset, location=u'', gisdbase=u'')[source]

Bases: object

VisibleMapset object:

>>> mapset = VisibleMapset('user1')
>>> mapset
['user1', 'PERMANENT']
add(mapset)[source]

Add a mapset to the search path

Parameters:mapset (str) – a mapset’s name
extend(mapsets)[source]

Add more mapsets to the search path

Parameters:mapsets (list) – a list of mapset’s names
read()[source]

Return the mapsets in the search path

remove(mapset)[source]

Remove mapset to the search path

Parameters:mapset (str) – a mapset’s name
reset()[source]

Reset to the original search path

pygrass.gis.make_mapset(mapset, location=None, gisdbase=None)[source]

Create a new mapset

Parameters:
  • mapset – Name of the mapset
  • location (str) – Name of the location
  • gisdbase (str) – Name of the gisdbase
pygrass.gis.set_current_mapset(mapset, location=None, gisdbase=None)[source]

Set the current mapset as working area

Parameters:
  • mapset – Name of the mapset
  • location (str) – Name of the location
  • gisdbase (str) – Name of the gisdbase

Table Of Contents

Previous topic

pygrass package

Next topic

pygrass.messages package


Note: A new GRASS GIS stable version has been released: GRASS GIS 7.4. Go directly to the new manual page here

Help Index | Topics Index | Keywords Index | Full Index

© 2003-2018 GRASS Development Team, GRASS GIS 7.0.7svn Reference Manual