<div dir="ltr">On Wed, Apr 23, 2014 at 12:56 AM, Glynn Clements <<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>> wrote:<br>><br>> Markus Neteler wrote:<br>><br>>> .. indeed a nice feature! But would it be nice to have not only:<br>
><br>>> ... this part of the script but for the truly lazy also the respective<br>>> grass.run_command() call included?<br>><br>> If you're generating a "front end" for a module, exec_command() may be<br>
> more appropriate.<br>><br>>> Something like<br>>><br>>> coords = options['coordinates']<br>>> grass.run_command('r.profile',<br>>> input = input_map,<br>
>> output = output_file,<br>>> profile = coords)<br>><br>> Choosing variable names has a minor complication, in that there are a<br>> couple of option names which are Python keywords (e.g. "from").<br>
><br>> If you just want to get rid of the dictionary syntax, the options<br>> could be stored in an object which supports both attribute-style and<br>> key-style access, so you could use either options.coordinates or<br>
> options['coordinates'].<br><br>In the past hours I realized that most of it is probably already<div>offered by pyGRASS:<br><br># Example 1<br>from grass.pygrass.modules import Module<br>slope_aspect = Module("r.slope.aspect")<br>
slope_aspect(elevation='elevation', slope='slp', aspect='asp', format='degrees', overwrite=True)<br><br>------<br># Example 2<br>from grass.pygrass.modules.shortcuts import general as g<br>
from grass.pygrass.modules.shortcuts import raster as r<br><br>g.message("Filter elevation map by a threshold...")<br># set computational region<br>input = 'elevation'<br>g.region(rast=input)<br><br># hardcoded:<br>
# r.mapcalc('elev_100m = if(elevation > 100, elevation, null())', overwrite = True)<br># with variables<br><br>output = 'elev_100m'<br>thresh = 100.0<br>r.mapcalc("%s = if(%s > %d, %s, null())" % (output, input, thresh, input), overwrite = True)<br>
r.colors(map=output, color="elevation")<br><br><br>Easier than that... Added to<br><a href="http://grasswiki.osgeo.org/wiki/GRASS_and_Python#pygrass_Library">http://grasswiki.osgeo.org/wiki/GRASS_and_Python#pygrass_Library</a><br>
<br>Markus</div></div>