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
Usage:
import grass.script as grass
or just import selected module, e.g.
from grass.script import core as grass
Sample script
#!/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
Color parsing
Check GRASS environment variables
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
Glynn Clements
Martin Landa <landa.martin gmail.com>
1.6.1