<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;"
text="#000000" bgcolor="#FFFFFF">
<br>
<div class="moz-cite-prefix">On 27/04/2019 22:05, Mehrdad Varedi
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CA+F3BSDfwRkA74p40+MAg1wQ++-7iVpnKtDU55VMAVfBJZ2zcA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr"><br clear="all">
<div>Hi Everyone,
<div>I have detail explanations of connecting to an existing
dataset in GRASS from R in this address: <a
href="https://grasswiki.osgeo.org/wiki/R_statistics/rgrass7"
target="_blank" moz-do-not-send="true">https://grasswiki.osgeo.org/wiki/R_statistics/rgrass7</a></div>
<div><br>
</div>
<div>What I hope I could do is to create a GRASS dataset in R
on the fly and without the need to install GRASS or create a
dataset on it. Is there any way to do this?</div>
<div><br>
</div>
</div>
</div>
</blockquote>
<p>Maybe this will help:</p>
<p>(You must have GRASS installed, of course)</p>
<p><br>
</p>
<p><font size="+1"><tt># Parameters for the GRASS installation and
temporary GRASS mapset</tt></font></p>
<p><font size="+1"><tt>GISBase = "/usr/lib/grass76"</tt></font><br>
<font size="+1"><tt><font size="+1"><tt><span style="font-size:
14px"># Set these as you like</span></tt></font></tt></font></p>
<p><font size="+1"><tt>GISDbase = "/tmp"</tt><tt><br>
</tt><tt>Location = "tmp_location"</tt><tt><br>
</tt><tt>Mapset = "tmp_mapset"</tt><tt><br>
</tt><tt>georef = "EPSG:2039"</tt><tt><br>
</tt><tt><br>
</tt><tt>mapset_path = file.path(GISDbase, Location, Mapset)</tt></font></p>
<p><tt><font size="+1"># Now run the 'grass' command within R and </font></tt><br>
<font size="+1"><tt></tt><tt></tt></font></p>
<p><font size="+1"><tt># use the -c and -e flags to create the temp
mapset, then exit<br>
</tt></font></p>
<p><font size="+1"><tt>setup_grass_cmd = paste("grass", "-c",
georef, "-e", mapset_path)</tt></font></p>
<p><font size="+1"><tt>system(setup_grass_cmd)</tt></font></p>
<p><span style="font-size: 14px"><font face="monospace"><font
size="+1"><br>
</font></font></span></p>
<p><span style="font-size: 14px"><font face="monospace"><font
size="+1"># Load the R grass interface and initialize GRASS
within R, </font></font></span></p>
<p><span style="font-size: 14px"><font face="monospace"><font
size="+1"># using the temporary mapset from above</font></font></span><br>
</p>
<p><font size="+1"><tt>library(rgrass7)</tt><tt><br>
</tt><tt>initGRASS(home=tempdir(), </tt><tt><br>
</tt><tt> gisBase = GISBase,</tt><tt><br>
</tt><tt> gisDbase = GISDbase,</tt><tt><br>
</tt><tt> location = Location,</tt><tt><br>
</tt><tt> mapset = Mapset,</tt><tt><br>
</tt><tt> remove_GISRC = TRUE)</tt><tt><br>
</tt><tt></tt></font></p>
<p><font size="+1"><tt><br>
</tt></font></p>
<p><font size="+1"><tt># Try some GRASS commands</tt></font></p>
<p><font size="+1"><tt>input_tif = "isrlat12.tif" <br>
</tt></font></p>
<p><font size="+1"><tt>grass_rast = "isrlat12"</tt><tt><br>
</tt><tt>execGRASS("r.in.gdal", flags = c("o","overwrite"),</tt><tt><br>
</tt><tt> input = input_tif,</tt><tt><br>
</tt><tt> output = grass_rast)</tt><tt><br>
</tt><tt>execGRASS("g.region", flags="p", raster = grass_rast)</tt><tt><br>
</tt></font><br>
</p>
<p>I did not add a command to remove the temporary mapset.
Something like:</p>
<p> <tt>unlink(file.path(GISDbase, Location), recusive = TRUE)</tt>
might be necessary</p>
<p><br>
</p>
<p>One other note: you probably will get better suggestions on the
R-sig-geo list...</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:CA+F3BSDfwRkA74p40+MAg1wQ++-7iVpnKtDU55VMAVfBJZ2zcA@mail.gmail.com">
<div dir="ltr">
<div>
<div>i.e. I have a vector /raster file and use that to
identify the region and details required to set up a dataset
and use GRASS functions just by including rgrass library.</div>
<div><br>
</div>
<div>Thanks for your help and attention,</div>
<div><br>
</div>
<div>Mehrdad</div>
</div>
-- <br>
<div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">Mehrdad Varedi</div>
</div>
<div hspace="streak-pt-mark" style="max-height:1px"><img alt=""
style="width:0px;max-height:0px;overflow:hidden"
src="https://mailfoogae.appspot.com/t?sender=admFyZWRpQGdtYWlsLmNvbQ%3D%3D&type=zerocontent&guid=dbe7ab29-5a21-45c9-97bb-082f4f48224a"
moz-do-not-send="true"><font size="1" color="#ffffff">ᐧ</font></div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
grass-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/grass-user">https://lists.osgeo.org/mailman/listinfo/grass-user</a></pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
</body>
</html>