GRASS Programmer's Manual
6.4.2(2012)
|
by GRASS Development Team (http://grass.osgeo.org)
The code in lib/python/
provides grass.script in order to support GRASS scripts written in Python. The scripts/
directory of GRASS contains a series of examples actually provided to the end users.
See code in:
Table of content
The statement
import grass.script as grass
imports core.py, db.py, raster.py and vector.py modules.
To import only selected module
from grass.script import core as grass
Sample script (See the GRASS Wiki at http://grass.osgeo.org/wiki/GRASS_and_Python for more examples)
#!/usr/bin/env python #%module #% description: Checks if vector map is 3D #% keywords: vector #%end #%option #% key: map #% type: string #% gisprompt: old,vector,vector #% key_desc: name #% description: Name of vector map #% required: yes #%end import sys import grass.script as grass def main(): info = grass.parse_command('v.info', flags = 't', map = options['map']) if info['map3d'] == '1': print 'Vector map is 3D' else: print 'Vector map is 2D' return 0 if __name__ == "__main__": options, flags = grass.parser() sys.exit(main())
GRASS-oriented interface to subprocess module
Interface to g.message
These all run g.message, differing only in which flag (if any) is used. fatal() is error(), but also calls sys.exit(1).
Interface to g.parser
Interface to g.parser, intended to be run from the top-level, e.g.
if __name__ == "__main__": options, flags = grass.parser() main()
Interface to g.tempfile
Returns the name of a temporary file, created with g.tempfile.
Key-value parsers
Interface to g.gisenv
Interface to g.region
Interface to g.findfile
Interface to g.list
Interface to g.mapsets
Interface to g.version
Color parsing
Check GRASS environment variables
Create new GRASS location
Various utilities, not specific to GRASS
Interface for db.*
modules.
from grass.script import db as grass
Interface for r.*
modules.
from grass.script import raster as grass
Interface for v.*
modules.
from grass.script import vector as grass
from grass.script import setup as gsetup
from grass.script import array as garray
Glynn Clements
Martin Landa <landa.martin gmail.com>