[GRASS-dev] help

Markus Neteler neteler at osgeo.org
Tue Apr 22 16:46:33 PDT 2014


On Wed, Apr 23, 2014 at 12:56 AM, Glynn Clements <glynn at gclements.plus.com>
wrote:
>
> Markus Neteler wrote:
>
>> .. indeed a nice feature! But would it be nice to have not only:
>
>> ... this part of the script but for the truly lazy also the respective
>> grass.run_command() call included?
>
> If you're generating a "front end" for a module, exec_command() may be
> more appropriate.
>
>> Something like
>>
>> coords = options['coordinates']
>> grass.run_command('r.profile',
>>                input = input_map,
>>                output = output_file,
>>                profile = coords)
>
> Choosing variable names has a minor complication, in that there are a
> couple of option names which are Python keywords (e.g. "from").
>
> If you just want to get rid of the dictionary syntax, the options
> could be stored in an object which supports both attribute-style and
> key-style access, so you could use either options.coordinates or
> options['coordinates'].

In the past hours I realized that most of it is probably already
offered by pyGRASS:

# Example 1
from grass.pygrass.modules import Module
slope_aspect = Module("r.slope.aspect")
slope_aspect(elevation='elevation', slope='slp',  aspect='asp',
format='degrees', overwrite=True)

------
# Example 2
from grass.pygrass.modules.shortcuts import general as g
from grass.pygrass.modules.shortcuts import raster as r

g.message("Filter elevation map by a threshold...")
# set computational region
input = 'elevation'
g.region(rast=input)

# hardcoded:
# r.mapcalc('elev_100m = if(elevation > 100, elevation, null())', overwrite
= True)
# with variables

output = 'elev_100m'
thresh = 100.0
r.mapcalc("%s = if(%s > %d, %s, null())" % (output, input, thresh, input),
overwrite = True)
r.colors(map=output, color="elevation")


Easier than that... Added to
http://grasswiki.osgeo.org/wiki/GRASS_and_Python#pygrass_Library

Markus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140423/895f3ed9/attachment.html>


More information about the grass-dev mailing list