1
/*! \page pythonlib GRASS Python Scripting Library
3
by GRASS Development Team (http://grass.osgeo.org)
5
\section pythonIntro Introduction
8
href="http://svn.osgeo.org/grass/grass/branches/develbranch_6/lib/python/">lib/python/</a>
9
provides <b>grass.script</b> in order to support GRASS scripts written
11
href="http://svn.osgeo.org/grass/grass/trunk/scripts">scripts/</a>
12
directory of GRASS 7 contains a series of examples actually provided
24
<b>Table of content</b>
26
- \subpage pythonScripting
27
- \subpage pythonModules
30
- \subpage pythonRaster
31
- \subpage pythonVector
32
- \subpage pythonSetup
33
- \subpage pythonArray
35
\section pythonScripting GRASS scripting tasks for Python provided by "grass.script"
40
import grass.script as grass
43
imports core.py, db.py, raster.py and vector.py modules.
45
To import only selected module
48
from grass.script import core as grass
51
Sample script (See the GRASS Wiki at
52
<a href="http://grass.osgeo.org/wiki/GRASS_and_Python">http://grass.osgeo.org/wiki/GRASS_and_Python</a> for more examples)
58
#% description: Checks if vector map is 3D
64
#% gisprompt: old,vector,vector
66
#% description: Name of vector map
71
import grass.script as grass
74
info = grass.parse_command('v.info',
77
if info['map3d'] == '1':
78
print 'Vector map is 3D'
80
print 'Vector map is 2D'
84
if __name__ == "__main__":
85
options, flags = grass.parser()
89
\section pythonModules List of modules
91
\subsection pythonCore Core
93
<b>GRASS-oriented interface to subprocess module</b>
95
- python::core::exec_command()
97
- python::core::feed_command()
99
- python::core::make_command()
101
- python::core::parse_command()
103
- python::core::pipe_command()
105
- python::core::read_command()
107
- python::core::run_command()
109
- python::core::start_command()
111
- python::core::write_command()
113
<b>Interface to g.message</b>
115
These all run g.message, differing only in which flag (if any) is
116
used. fatal() is error(), but also calls sys.exit(1).
118
- python::core::debug()
120
- python::core::error()
122
- python::core::fatal()
124
- python::core::info()
126
- python::core::message()
128
- python::core::verbose()
130
- python::core::warning()
132
<b>Interface to g.parser</b>
134
Interface to g.parser, intended to be run from the top-level, e.g.
137
if __name__ == "__main__":
138
options, flags = grass.parser()
142
- python::core::parser()
144
<b>Interface to g.tempfile</b>
146
Returns the name of a temporary file, created with g.tempfile.
148
- python::core::tempfile()
150
<b>Key-value parsers</b>
152
- python::core::parse_key_val()
154
<b>Interface to g.gisenv</b>
156
- python::core::gisenv()
158
<b>Interface to g.region</b>
160
- python::core::del_temp_region()
162
- python::core::region()
164
- python::core::region_env()
166
- python::core::use_temp_region()
168
<b>Interface to g.findfile</b>
170
- python::core::find_file()
172
<b>Interface to g.list</b>
174
- python::core::list_grouped()
176
- python::core::list_pairs()
178
- python::core::list_strings()
180
- python::core::mlist_grouped()
182
<b>Interface to g.mapsets</b>
184
- python::core::mapsets()
186
<b>Interface to g.version</b>
188
- python::core::version()
192
- python::core::parse_color()
194
<b>Check GRASS environment variables</b>
196
- python::core::overwrite()
198
- python::core::verbosity()
200
<b>Create new GRASS location</b>
202
- python::core::create_location()
204
<b>Various utilities, not specific to GRASS</b>
206
- python::core::basename()
208
- python::core::find_program()
210
- python::core::try_remove()
212
- python::core::try_rmdir()
214
- python::core::float_or_dms()
216
\section pythonDb Database
218
Interface for <tt>db.*</tt> modules.
221
from grass.script import db as grass
224
- python::db::db_connection()
226
- python::db::db_describe()
228
- python::db::db_select()
230
\section pythonRaster Raster
232
Interface for <tt>r.*</tt> modules.
235
from grass.script import raster as grass
238
- python::raster::raster_history()
240
- python::raster::raster_info()
242
- python::raster::mapcalc()
244
\section pythonVector Vector
246
Interface for <tt>v.*</tt> modules.
249
from grass.script import vector as grass
252
- python::vector::vector_columns()
254
- python::vector::vector_db()
256
- python::vector::vector_db_select()
258
- python::vector::vector_history()
260
- python::vector::vector_info_topo()
262
- python::vector::vector_layer_db()
264
\section pythonSetup Setup
267
from grass.script import setup as gsetup
270
- python::setup::init()
272
\section pythonArray Array
275
from grass.script import array as garray
278
- python::array::array
280
\section pythonAuthors Authors
284
Martin Landa <landa.martin gmail.com>