<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 30, 2015 at 8:14 AM, Panagiotis Mavrogiorgos <span dir="ltr"><<a href="mailto:pmav99@gmail.com" target="_blank">pmav99@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi everyone,<div><br></div><div>Is it possible to perform multiple computations using <font face="monospace, monospace">grass.script.raster.mapcalc()</font>? What I want is to run something like this (example taken from r.mapcalc documentation):</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace, monospace">r.mapcalc <<EOF<br></font><font face="monospace, monospace"> $GIS_OPT_OUTPUT.r = r#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 - .$GIS_OPT_PERCENT) * r#$GIS_OPT_SECOND<br></font><font face="monospace, monospace"> $GIS_OPT_OUTPUT.g = g#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 - .$GIS_OPT_PERCENT) * g#$GIS_OPT_SECOND<br></font><font face="monospace, monospace"> $GIS_OPT_OUTPUT.b = b#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 - .$GIS_OPT_PERCENT) * b#$GIS_OPT_SECOND<br></font><font face="monospace, monospace"> EOF</font></blockquote><div></div></div></blockquote><div><br></div><div>Hi, yes, this should be possible. I think I actually used it some time ago both the multiline and eval expressions. I think this is it:<br><br></div><div># import<br></div><div>from grass.script.raster import mapcalc as rmapcalc<br><br></div><div># prepare strings<br></div><div>mask_expression = []<br>mask_template = '{target} = if({mask}, {source}, null())'<br><br></div><div># create expressions<br></div><div>mask_expression.append(<br> mask_template.format(<br> source=speed, target=speed_masked, mask=buffered_mask))<br>mask_expression.append(<br> mask_template.format(<br> source=direction, target=direction_masked, mask=buffered_mask))<br><br></div><div># concatenate list of strings and execute<br></div><div>rmapcalc('\n'.join(mask_expression))<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>When I give an expression as a multiline string, I get an error like this one: </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace, monospace">Invalid map <i><br></font><font face="monospace, monospace">Parse error<br></font><font face="monospace, monospace">ERROR: parse error<br></font><font face="monospace, monospace">ERROR: An error occurred while running r.mapcalc</font></blockquote></div></blockquote><div><br></div><div>You will need to include the actual code your are using.<br><br></div><div>Best,<br></div><div>Vaclav<br></div><div><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>with kind regards,</div><div>Panos</div></div>
<br>_______________________________________________<br>
grass-user mailing list<br>
<a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/grass-user" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-user</a><br></blockquote></div><br></div></div>