Hi,<br><br><div class="gmail_quote">On Wed, Oct 26, 2011 at 9:30 PM, Glynn Clements <span dir="ltr"><<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
Margherita Di Leo wrote:<br>
<br>
> I need a little help with r.mapcalc syntax in Python script. I want to<br>
> convert the following formula:<br>
><br>
> grass.run_command('r.mapcalculator', amap = r_stream+'_nothin' , formula =<br>
> '%s*%s' % (r_stream+'_nothin', r_mask) , outfile = r_stream+'_nothin',<br>
> overwrite = True)<br>
><br>
> I want to use r.mapcalc instead of r.mapcalculator. So I write:<br>
><br>
> grass.mapcalc("$r_stream_nothin = $r_stream_nothin * $r_mask",<br>
> r_mask = r_mask,<br>
> r_stream_nothin = r_stream+'_nothin')<br>
><br>
> but I get parse error. What's the correct way to do this? The aim is to add<br>
> the suffix '_nothin' to the existing variable name r_stream.<br>
<br>
</div>There's nothing obviously wrong with the above code, although you<br>
should probably quote the map names, i.e.:<br>
<div class="im"><br>
grass.mapcalc("'$r_stream_nothin' = '$r_stream_nothin' * '$r_mask'",<br>
</div> ...<br></blockquote><div><br></div><div>This doesn't work, I keep getting Parse error. I can find a workaround for my script, but I was just curious whether I did it wrong or grass doesn't allow this kind of parsing. Glynn, thanks for precious hints.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Map names which contain symbols need to be quoted, otherwise e.g. a<br>
map named "map-name" will be parsed as a subtraction.<br>
<br>
Check the values of r_stream and r_mask with e.g.:<br>
<br>
print repr(r_stream), repr(r_mask)<br>
<br>
Running 'g.gisenv set=DEBUG=1' prior to the script will enable some<br>
debugging information, including the exact r.mapcalc command.<br>
<br>
Also, using the same map as both input and output is unwise. It<br>
appears to work, at least for simple cases, but shouldn't be relied<br>
upon.<br>
<font color="#888888"><br>
--<br>
Glynn Clements <<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>><br></font></blockquote><div><br></div><div>regards,</div><div>madi </div></div><br><br clear="all"><div><br></div>-- <br><span style="color:rgb(102, 102, 102)">Eng. Margherita Di Leo</span><br style="color:rgb(102, 102, 102)">
<span style="color:rgb(102, 102, 102)">Ph.D. Candidate</span><br style="color:rgb(102, 102, 102)"><span style="color:rgb(102, 102, 102)">Methods and Technologies for Environmental Monitoring</span><br style="color:rgb(102, 102, 102)">
<span style="color:rgb(102, 102, 102)">Department of Environmental Engineering and Physics (DIFA)</span><br style="color:rgb(102, 102, 102)"><br style="color:rgb(102, 102, 102)"><span style="color:rgb(102, 102, 102)">University of Basilicata </span><br style="color:rgb(102, 102, 102)">
<span style="color:rgb(102, 102, 102)">Campus Macchia Romana</span><br style="color:rgb(102, 102, 102)"><span style="color:rgb(102, 102, 102)">85100 - Potenza </span><br style="color:rgb(102, 102, 102)"><span style="color:rgb(102, 102, 102)">Italy</span><br style="color:rgb(102, 102, 102)">
<br style="color:rgb(102, 102, 102)"><span style="color:rgb(102, 102, 102)">Office: +39-0971205360</span><br style="color:rgb(102, 102, 102)"><span style="color:rgb(102, 102, 102)"></span><br><br><br>