~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/python/pythonlib.dox

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*! \page pythonlib GRASS Python Scripting Library
2
 
 
3
 
by GRASS Development Team (http://grass.osgeo.org)
4
 
 
5
 
\section pythonIntro Introduction
6
 
 
7
 
The code in <a
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
10
 
in Python. The <a
11
 
href="http://svn.osgeo.org/grass/grass/trunk/scripts">scripts/</a>
12
 
directory of GRASS 7 contains a series of examples actually provided
13
 
to the end users.
14
 
 
15
 
See code in:
16
 
 
17
 
- python::core
18
 
- python::db
19
 
- python::raster
20
 
- python::vector
21
 
- python::setup
22
 
- python::array
23
 
 
24
 
<b>Table of content</b>
25
 
 
26
 
- \subpage pythonScripting
27
 
- \subpage pythonModules
28
 
 - \subpage pythonCore
29
 
 - \subpage pythonDb
30
 
 - \subpage pythonRaster
31
 
 - \subpage pythonVector
32
 
 - \subpage pythonSetup
33
 
 - \subpage pythonArray
34
 
 
35
 
\section pythonScripting GRASS scripting tasks for Python provided by "grass.script"
36
 
 
37
 
The statement
38
 
 
39
 
\code
40
 
import grass.script as grass
41
 
\endcode
42
 
 
43
 
imports core.py, db.py, raster.py and vector.py modules.
44
 
 
45
 
To import only selected module
46
 
 
47
 
\code
48
 
from grass.script import core as grass
49
 
\endcode
50
 
 
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)
53
 
 
54
 
\code
55
 
#!/usr/bin/env python
56
 
 
57
 
#%module
58
 
#% description: Checks if vector map is 3D
59
 
#% keywords: vector
60
 
#%end
61
 
#%option
62
 
#% key: map
63
 
#% type: string
64
 
#% gisprompt: old,vector,vector
65
 
#% key_desc: name
66
 
#% description: Name of vector map 
67
 
#% required: yes
68
 
#%end
69
 
 
70
 
import sys
71
 
import grass.script as grass
72
 
 
73
 
def main():
74
 
    info = grass.parse_command('v.info',
75
 
                               flags = 't',
76
 
                               map = options['map'])
77
 
    if info['map3d'] == '1':
78
 
        print 'Vector map is 3D'
79
 
    else:
80
 
        print 'Vector map is 2D'
81
 
 
82
 
    return 0
83
 
 
84
 
if __name__ == "__main__":
85
 
    options, flags = grass.parser()
86
 
    sys.exit(main())
87
 
\endcode
88
 
 
89
 
\section pythonModules List of modules
90
 
 
91
 
\subsection pythonCore Core
92
 
 
93
 
<b>GRASS-oriented interface to subprocess module</b>
94
 
 
95
 
 - python::core::exec_command()
96
 
 
97
 
 - python::core::feed_command()
98
 
 
99
 
 - python::core::make_command()
100
 
 
101
 
 - python::core::parse_command()
102
 
 
103
 
 - python::core::pipe_command()
104
 
 
105
 
 - python::core::read_command()
106
 
 
107
 
 - python::core::run_command()
108
 
 
109
 
 - python::core::start_command()
110
 
 
111
 
 - python::core::write_command()
112
 
 
113
 
<b>Interface to g.message</b>
114
 
 
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).
117
 
 
118
 
 - python::core::debug()
119
 
 
120
 
 - python::core::error()
121
 
 
122
 
 - python::core::fatal()
123
 
 
124
 
 - python::core::info()
125
 
 
126
 
 - python::core::message()
127
 
 
128
 
 - python::core::verbose()
129
 
 
130
 
 - python::core::warning()
131
 
 
132
 
<b>Interface to g.parser</b>
133
 
 
134
 
Interface to g.parser, intended to be run from the top-level, e.g.
135
 
 
136
 
\code
137
 
        if __name__ == "__main__":
138
 
            options, flags = grass.parser()
139
 
            main()
140
 
\endcode
141
 
 
142
 
 - python::core::parser()
143
 
 
144
 
<b>Interface to g.tempfile</b>
145
 
 
146
 
Returns the name of a temporary file, created with g.tempfile.
147
 
 
148
 
 - python::core::tempfile()
149
 
 
150
 
<b>Key-value parsers</b>
151
 
 
152
 
 - python::core::parse_key_val()
153
 
 
154
 
<b>Interface to g.gisenv</b>
155
 
 
156
 
 - python::core::gisenv()
157
 
 
158
 
<b>Interface to g.region</b>
159
 
 
160
 
 - python::core::del_temp_region()
161
 
 
162
 
 - python::core::region()
163
 
 
164
 
 - python::core::region_env()
165
 
 
166
 
 - python::core::use_temp_region()
167
 
 
168
 
<b>Interface to g.findfile</b>
169
 
 
170
 
 - python::core::find_file()
171
 
 
172
 
<b>Interface to g.list</b>
173
 
 
174
 
 - python::core::list_grouped()
175
 
 
176
 
 - python::core::list_pairs()
177
 
 
178
 
 - python::core::list_strings()
179
 
 
180
 
 - python::core::mlist_grouped()
181
 
 
182
 
<b>Interface to g.mapsets</b>
183
 
 
184
 
 - python::core::mapsets()
185
 
 
186
 
<b>Interface to g.version</b>
187
 
 
188
 
 - python::core::version()
189
 
 
190
 
<b>Color parsing</b>
191
 
 
192
 
 - python::core::parse_color()
193
 
 
194
 
<b>Check GRASS environment variables</b>
195
 
 
196
 
 - python::core::overwrite()
197
 
 
198
 
 - python::core::verbosity()
199
 
 
200
 
<b>Create new GRASS location</b>
201
 
 
202
 
 - python::core::create_location()
203
 
 
204
 
<b>Various utilities, not specific to GRASS</b>
205
 
 
206
 
 - python::core::basename()
207
 
 
208
 
 - python::core::find_program()
209
 
 
210
 
 - python::core::try_remove()
211
 
 
212
 
 - python::core::try_rmdir()
213
 
 
214
 
 - python::core::float_or_dms()
215
 
 
216
 
\section pythonDb Database
217
 
 
218
 
Interface for <tt>db.*</tt> modules.
219
 
 
220
 
\code
221
 
from grass.script import db as grass
222
 
\endcode
223
 
 
224
 
 - python::db::db_connection()
225
 
 
226
 
 - python::db::db_describe()
227
 
 
228
 
 - python::db::db_select()
229
 
 
230
 
\section pythonRaster Raster
231
 
 
232
 
Interface for <tt>r.*</tt> modules.
233
 
 
234
 
\code
235
 
from grass.script import raster as grass
236
 
\endcode
237
 
 
238
 
 - python::raster::raster_history()
239
 
 
240
 
 - python::raster::raster_info()
241
 
 
242
 
 - python::raster::mapcalc()
243
 
 
244
 
\section pythonVector Vector
245
 
 
246
 
Interface for <tt>v.*</tt> modules.
247
 
 
248
 
\code
249
 
from grass.script import vector as grass
250
 
\endcode
251
 
 
252
 
 - python::vector::vector_columns()
253
 
 
254
 
 - python::vector::vector_db()
255
 
 
256
 
 - python::vector::vector_db_select()
257
 
 
258
 
 - python::vector::vector_history()
259
 
 
260
 
 - python::vector::vector_info_topo()
261
 
 
262
 
 - python::vector::vector_layer_db()
263
 
 
264
 
\section pythonSetup Setup
265
 
 
266
 
\code
267
 
from grass.script import setup as gsetup
268
 
\endcode
269
 
 
270
 
 - python::setup::init()
271
 
 
272
 
\section pythonArray Array
273
 
 
274
 
\code
275
 
from grass.script import array as garray
276
 
\endcode
277
 
 
278
 
 - python::array::array
279
 
 
280
 
\section pythonAuthors Authors
281
 
 
282
 
 Glynn Clements
283
 
 
284
 
 Martin Landa <landa.martin gmail.com>
285
 
 
286
 
*/