Hi,<br><br><div class="gmail_quote">On Wed, Oct 26, 2011 at 9:30 PM, Glynn Clements <span dir="ltr">&lt;<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>&gt;</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>
&gt; I need a little help with r.mapcalc syntax in Python script. I want to<br>
&gt; convert the following formula:<br>
&gt;<br>
&gt; grass.run_command(&#39;r.mapcalculator&#39;, amap = r_stream+&#39;_nothin&#39; , formula =<br>
&gt; &#39;%s*%s&#39; % (r_stream+&#39;_nothin&#39;, r_mask) , outfile = r_stream+&#39;_nothin&#39;,<br>
&gt; overwrite = True)<br>
&gt;<br>
&gt; I want to use r.mapcalc instead of r.mapcalculator. So I write:<br>
&gt;<br>
&gt; grass.mapcalc(&quot;$r_stream_nothin = $r_stream_nothin * $r_mask&quot;,<br>
&gt;                       r_mask = r_mask,<br>
&gt;                       r_stream_nothin = r_stream+&#39;_nothin&#39;)<br>
&gt;<br>
&gt; but I get parse error. What&#39;s the correct way to do this? The aim is to add<br>
&gt; the suffix &#39;_nothin&#39; to the existing variable name r_stream.<br>
<br>
</div>There&#39;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(&quot;&#39;$r_stream_nothin&#39; = &#39;$r_stream_nothin&#39; * &#39;$r_mask&#39;&quot;,<br>
</div>         ...<br></blockquote><div><br></div><div>This doesn&#39;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&#39;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 &quot;map-name&quot; 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 &#39;g.gisenv set=DEBUG=1&#39; 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&#39;t be relied<br>
upon.<br>
<font color="#888888"><br>
--<br>
Glynn Clements &lt;<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>&gt;<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>