I just started using RQGIS. I ran the example code using qgis:polygoncentroids shown on https://github.com/jannes-m/RQGIS with no problem.
I tried then to create a vector grid using qgis:vectorgrid but I get an error, which seems to indicate that the command expects a raster format output, when the output in QGIS for this plugin is a shapefile.
If I run
run_qgis without the
load_output argument I don't get an error, but no file is created on the disk either (I am on Ubuntu 16.04).
My code is as follows:
library(RQGIS) library(rgdal) library(rgeos) library(raster) ##PARAMETERS #working directory work.dir <- "/media/olivier/olivier_ext/gedata_current/jde_coffee/data/ES" #Location and name of the grid to output out <- c("Grids","ES_grid_test") #Resolution of the grid in km res <- 2 #Location and name of shapefile with the extent and outline of the grid shp.ext <- c("Boundaries","Espirito_Santo_geo") #Projection to use project <- CRS("+init=epsg:32723") #Set working directory setwd(work.dir) #Import boundary and extent bound <- readOGR(dsn=shp.ext, layer=shp.ext, stringsAsFactors=F) bound <- spTransform(bound, project) #Set a QGIS environment env <- set_env() #retrieve the function arguments args <- get_args_man(alg = "qgis:vectorgrid", options = TRUE, qgis_env = env) #Fill arguments args$EXTENT <- as.vector(extent(bound)) args$STEP_X <- res*1000 #In meters if UTM args$STEP_Y <- res*1000 args$TYPE <- 0 args$OUTPUT <- paste0(work.dir,"/",out,"/",out,".shp") grid.shp <- run_qgis(alg = "qgis:vectorgrid", params = args, load_output = args$OUTPUT, qgis_env = env)
I get the following error:
Error in .local(.Object, ...) :
`/media/olivier/olivier_ext/gedata_current/jde_coffee/data/ES/Grids/ES_grid_test.shp' does not exist in the file system, and is not recognised as a supported dataset name.
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file. (file does not exist)
It makes me believe that
run_qgis expects a raster format... But in QGIS it's definitely a shapefile output.