[GRASS-dev] Python Scripts- mapcalc

António Rocha antonio.rocha at deimos.com.pt
Fri Feb 12 06:30:17 EST 2010


Hey

Regarding a previous message, from Glynn, about how to use mapcalc in a 
Python Script in GRASS6.4. I have the following script (module hearer is 
also there):
import os
import sys
import grass.script as grass

def main():
    output = options['output']
    raster1 = options['raster1']
    raster2 = options['raster2']          
    grass.mapcalc("${out} = ${rast1} + ${rast2}", out = output, rast1 = 
raster1, rast2 = raster2)
    return 0

if __name__ == "__main__":
    options, flags = grass

When I enter:
python.teste raster1=aspect at PERMANENT raster2=aspect at PERMANENT 
output=Zteste8  

GRASS freezes, I mean. It's still processing without stopping or exiting 
or even any error. Any idea of what might be wrong?
Thanks

Best Regards
Antonio
> António Rocha wrote:
>
>   
>> By the way, I'm having some difficulties in using mapcalc in a python 
>> scripts.
>> I'm doing this
>> grass.mapcalc(options['output']=options['raster1']+options['raster2'])
>>     
>
> This isn't valid Python syntax.
>
> grass.mapcalc() accepts a template string followed by keyword
> arguments for the substitutions, e.g.:
>
> 	grass.mapcalc("${out} = ${rast1} + ${rast2}",
> 	              out = options['output'],
> 	              rast1 = options['raster1'],
> 	              rast2 = options['raster2'])
>
> Although, I normally copy all of the options[] into separate variables
> at the beginning of main(), i.e.:
>
> 	def main():
> 	    output = options['output']
> 	    raster1 = options['raster1']
> 	    raster2 = options['raster2']
>
> 	...
>
> 	    grass.mapcalc("${out} = ${rast1} + ${rast2}",
> 	                  out = output,
> 	                  rast1 = raster1,
> 	                  rast2 = raster2)
>
>   



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4860 (20100212) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




More information about the grass-dev mailing list