1 """!@package grass.script.raster
3 @brief GRASS Python scripting module (raster functions)
5 Raster related functions to be used in Python scripts.
10 from grass.script import raster as grass
12 grass.raster_history(map)
16 (C) 2008-2009 by the GRASS Development Team
17 This program is free software under the GNU General Public
18 License (>=v2). Read the file COPYING that comes with GRASS
21 @author Glynn Clements
22 @author Martin Landa <landa.martin gmail.com>
32 gettext.install(
'grasslibs', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode=
True)
37 """!Set the command history for a raster map to the command used to
38 invoke the script (interface to `r.support').
42 @return True on success
43 @return False on failure
45 current_mapset =
gisenv()[
'MAPSET']
46 if find_file(name = map)[
'mapset'] == current_mapset:
47 run_command(
'r.support', map = map, history = os.environ[
'CMDLINE'])
50 warning(_(
"Unable to write history for <%(map)s>. "
51 "Raster map <%(map)s> not found in current mapset." % {
'map' : map,
'map' : map}))
57 """!Return information about a raster map (interface to
61 >>> grass.raster_info('elevation')
62 {'north': 228500.0, 'timestamp': '"none"', 'min': 55.578792572021499,
63 'datatype': 'FCELL', 'max': 156.32986450195301, 'ewres': 10.0,
64 'vertical_datum': '', 'west': 630000.0, 'units': '',
65 'title': 'South-West Wake county: Elevation NED 10m (elev_ned10m)',
66 'east': 645000.0, 'nsres': 10.0, 'south': 215000.0}
71 @return parsed raster info
80 s =
read_command(
'r.info', flags =
'rgstmpud', map = map)
82 for k
in [
'min',
'max']:
83 kv[k] = float_or_null(kv[k])
84 for k
in [
'north',
'south',
'east',
'west']:
86 for k
in [
'nsres',
'ewres']:
92 def mapcalc(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
93 """!Interface to r.mapcalc.
98 t = string.Template(exp)
99 e = t.substitute(**kwargs)
101 env = os.environ.copy()
103 env[
'GRASS_VERBOSE'] =
'0'
105 env[
'GRASS_VERBOSE'] =
'3'
107 env[
'GRASS_OVERWRITE'] =
'1'
110 fatal(_(
"An error occurred while running r.mapcalc"))
113 def mapcalc_start(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
114 """!Interface to r.mapcalc, doesn't wait for it to finish, returns Popen object.
117 >>> expr1 = '"%s" = "%s" * 10' % (output, input)
118 >>> expr2 = '...' # etc.
119 >>> # launch the jobs:
120 >>> p1 = grass.mapcalc_start(expr1)
121 >>> p2 = grass.mapcalc_start(expr2) # etc.
123 >>> # wait for them to finish:
128 @param exp expression
133 t = string.Template(exp)
134 e = t.substitute(**kwargs)
136 env = os.environ.copy()
138 env[
'GRASS_VERBOSE'] =
'0'
140 env[
'GRASS_VERBOSE'] =
'3'
142 env[
'GRASS_OVERWRITE'] =
'1'
def float_or_dms
Convert DMS to float.
def feed_command
Passes all arguments to start_command(), but also adds "stdin = PIPE".
def raster_history
Set the command history for a raster map to the command used to invoke the script (interface to `r...
def fatal
Display an error message using g.message -e, then abort.
def parse_key_val
Parse a string into a dictionary, where entries are separated by newlines and the key and value are s...
def mapcalc_start
Interface to r.mapcalc, doesn't wait for it to finish, returns Popen object.
def write_command
Passes all arguments to feed_command, with the string specified by the 'stdin' argument fed to the pr...
def mapcalc
Interface to r.mapcalc.
def warning
Display a warning message using g.message -w
def run_command
Passes all arguments to start_command(), then waits for the process to complete, returning its exit c...
def read_command
Passes all arguments to pipe_command, then waits for the process to complete, returning its stdout (i...
def gisenv
Returns the output from running g.gisenv (with no arguments), as a dictionary.
def raster_info
Return information about a raster map (interface to `r.info').