[GRASS-user] Help; Running Grass from R - SQLite database setup

Mehrdad Varedi varedi at gmail.com
Wed Aug 28 11:12:39 PDT 2019


Hi Micha,
Your answer makes perfect sense. Thank you. I was expecting to get the
database when only I had imported raster files!
Anyway, when I tried to import a vector file with the following command, I
got an error:






*execGRASS("v.import", parameters=list(                input =
 basename(inputWM),                output = "WM"                ),
flags=c("overwrite"))*

Here is the error:




*In system(cmd0, intern = TRUE) :  running command 'v.import.bat
--interface-description' had status 1Error in parseGRASS(cmd, legacyExec =
legacyExec) : v.import not parsed*


I traced the code and found that the parseGRASS adds the .bat extension for
the v.import and the lagacyExec has a TRUE value (default for Windows OS)

FYI, I couldn't run GRASS from Rstudio unless ran the RStudio from the
"OSGeo4W" environment. It helps RStudio to find the functions in GRASS. (I
learned it from a previous post). So it works and importing the raster
files had no problem (I imported a virtual raster .vrt with "r.in.gdal"
command). Also, I processed the raster file with no problem. The problem
only shows up when I try to import the vector files with r.import command.

Any idea what is happening here?

Thanks for your help,

Mehrdad


ᐧ

On Wed, Aug 28, 2019 at 6:24 AM Micha Silver <tsvibar at gmail.com> wrote:

>
> On 28/08/2019 9:56, Mehrdad Varedi wrote:
>
> Hi Everyone,
> I used the code from Micha and managed to run grass in R and create a new
> dataset from R. I can't see the SQLite database in the created folders like
> the ones I usually get when creating new datasets from GRASS.
>
> How can I have the new SQlite database?
>
>
> If you import some vector you'll have the sqlite.db setup for you:
>
> (Following the example from before)
>
>
> > input_vect = "Israel_border.gpkg"
> > grass_vect = "isr_border"
> > execGRASS("v.import", input=input_vect, output=grass_vect, flags="o")
> Over-riding projection check
> Check if OGR layer <Israel_border> contains polygons...
>  100%
> Creating attribute table for layer <Israel_border>...
> Default driver / database set to:
> driver: sqlite
> database: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
> Importing 1 features (OGR layer <Israel_border>)...
>  100%
>
>
> Then in a separate terminal:
>
> micha at TP480:~$ ll /tmp/tmp_location/tmp_mapset/sqlite/
> total 20
> drwxr-xr-x 2 micha micha  4096 Aug 28 13:19 ./
> drwxr-xr-x 6 micha micha  4096 Aug 28 13:19 ../
> -rw-r--r-- 1 micha micha 12288 Aug 28 13:19 sqlite.db
>
>
> Thanks for your help.
>
>
> On Sun, Apr 28, 2019 at 10:55 AM Micha Silver <tsvibar at gmail.com> wrote:
>
>> Maybe this will help:
>>
>> (You must have GRASS installed, of course)
>>
>>
>> # Parameters for the GRASS installation and temporary GRASS mapset
>>
>> GISBase = "/usr/lib/grass76"
>> # Set these as you like
>>
>> GISDbase = "/tmp"
>> Location = "tmp_location"
>> Mapset = "tmp_mapset"
>> georef = "EPSG:2039"
>>
>> mapset_path = file.path(GISDbase, Location, Mapset)
>>
>> # Now run the 'grass' command within R and
>>
>> # use the -c and -e flags to create the temp mapset, then exit
>>
>> setup_grass_cmd = paste("grass", "-c", georef, "-e", mapset_path)
>>
>> system(setup_grass_cmd)
>>
>>
>> # Load the R grass interface and initialize GRASS within R,
>>
>> # using the temporary mapset from above
>>
>> library(rgrass7)
>> initGRASS(home=tempdir(),
>>           gisBase = GISBase,
>>           gisDbase = GISDbase,
>>           location = Location,
>>           mapset = Mapset,
>>           remove_GISRC = TRUE)
>>
>>
>> # Try some GRASS commands
>>
>> input_tif = "isrlat12.tif"
>>
>> grass_rast = "isrlat12"
>> execGRASS("r.in.gdal",  flags = c("o","overwrite"),
>>           input = input_tif,
>>           output = grass_rast)
>> execGRASS("g.region", flags="p", raster = grass_rast)
>>
>> I did not add a command to remove the temporary mapset.  Something like:
>>
>> unlink(file.path(GISDbase, Location), recusive = TRUE) might be necessary
>>
>> Micha Silver
>>
>> Ben Gurion Univ.
>> Sde Boker, Remote Sensing Lab
>> cell: +972-523-665918
>>
>>
>
> --
> Mehrdad Varedi
>>
> --
> Micha Silver
> Ben Gurion Univ.
> Sde Boker, Remote Sensing Lab
> cell: +972-523-665918
>
>

-- 
Mehrdad Varedi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20190828/f2c0e117/attachment-0001.html>


More information about the grass-user mailing list