0

I'm trying to execute some rgrass7 processing from R but I can't even get the first process done. I would like to clean a vector line layer. The goal here is not just to clean the topology, that's collateral, but learning how to execute rgrass7 processes with vector data.

Here is the code that throw error:

library(rgrass7)

# PARAMETERS
lpath <- "./Layers/Lines_light/Lines.shp"
l <- readOGR(lpath)

G <- initGRASS(gisBase = "/usr/lib/grass76",
               home = getwd(),
               gisDbase = getwd(),
               location = 'grassdata',
               mapset = "PERMANENT",
               override = TRUE)
G
use_sf()  

# clean (here, in input, I tried l, "l", "lpath", lpath...
execGRASS("v.clean",
          input = "lpath",
          output = 'l_clean',
          tool = 'break',
          flags = 'c')

The error:

Error in execGRASS("v.clean", input = "lpath", output = "l_clean", tool = "break",  : 
  The command:
v.clean -c input=lpath output=l_clean tool=break
produced an error (1) during execution:
ERROR: El mapa vectorial <lpath> no se ha encontrado

By the way, the tool work just perfect from QGIS in Ubuntu 19.10.

3
  • There you go :-) Apr 19, 2020 at 15:58
  • 1
    I know nothing about using GRASS inside R but in GRASS you would need to import the shapefile for it to become a "map", try v.import first
    – BERA
    Apr 19, 2020 at 16:06
  • 1
    Yes, you are missing the v.import step before doing anything with the map in GRASS GIS.
    – markusN
    Apr 25, 2020 at 21:24

1 Answer 1

0

As @markusN and @BERA comented, I lacked the import part which I did not using v.import if not writeVECT like this:

library(rgrass7)

# PARAMETERS
lpath <- "./Layers/Lines_light/Lines.shp"
l <- readOGR(lpath)

G <- initGRASS(gisBase = "/usr/lib/grass76",
               home = getwd(),
               gisDbase = getwd(),
               location = 'grassdata',
               mapset = "PERMANENT",
               override = TRUE)
G
use_sf()  

# import lines
writeVECT(l, 'l', v.in.ogr_flags = c('o','overwrite','quiet'))

# clean
execGRASS("v.clean",
          input = "l",
          output = 'l_clean',
          tool = 'break',
          flags = 'c')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.