<html style="direction: ltr;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body bidimailui-charset-is-forced="true" style="direction: ltr;"
bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 12/4/18 5:42 PM, Christian Willmes
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:80913593-5451-109d-4549-b11ea4e1cd52@uni-koeln.de">Hello,
<br>
<br>
I am not sure if this is the correct list to ask this specific
question about executing GRASS GIS from R Scripts.
<br>
<br>
My problem is how to determine if a layer exists in the current
GRASS GIS mapset or not.
<br>
<br>
During my script I use r.mapcalc from GRASS GIS to do some
expensive computation. So I want to store and reuse the resulting
layer, wich is produced according to a variable value, in case I
need this layer for the specific variable value again.
<br>
<br>
If I just omit the overwrite tag it does not work, becasue GRASS
GIS stops the execution on this event.
<br>
<br>
Error in execGRASS("r.mapcalc", expression = expr) : The command:
<br>
r.mapcalc expression="rsl40 = GEBCO_2014_2D_4326 >= -40"
<br>
produced an error (1) during execution:
<br>
FEHLER: output map <rsl40> exists. To overwrite, use the
--overwrite flag
<br>
Error in execGRASS("r.mapcalc", expression = expr) : The command:
<br>
r.mapcalc expression="land_NA_1_rsl40 = if( rsl40 , 1 ,null())"
<br>
produced an error (1) during execution:
<br>
FEHLER: output map <land_NA_1_rsl40> exists. To overwrite,
use the
<br>
--overwrite flag
<br>
<br>
So, I tryed to check if a certain layer already exists in the
mapset to test if the computation needs/can be executed or not.
<br>
<br>
Using the following:
<br>
<br>
if(execGRASS("g.findfile", element="cell", file=lyrname,
mapset='"."')){
<br>
return(FALSE)
<br>
}else{
<br>
return(TRUE)
<br>
}
<br>
<br>
Here it stops, if the layer does not exist:
<br>
<br>
Fehler in execGRASS("g.findfile", element = "cell", file =
lyrname, mapset = "\".\"") :
<br>
The command:
<br>
g.findfile element=cell file=rsl40 mapset="."
<br>
produced an error (1) during execution:
<br>
</blockquote>
<p><br>
</p>
<p>I think that the mapset parameter requires the actual mapset
name, *not* the current working directory.</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:80913593-5451-109d-4549-b11ea4e1cd52@uni-koeln.de">
<br>
<br>
Does anyone know a solution to this?
<br>
<br>
Thank you very much!
<br>
<br>
Best,
<br>
Christian
<br>
<br>
<br>
</blockquote>
<pre class="moz-signature" cols="72">--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
</body>
</html>