1

I'm trying to use RQGIS interface with QGIS to create a polygon grid. One of the required parameters is TYPE.

Where can i know the type of parameters to this algorithm? and to others?

From

data

Code:

neto  <- readRDS("/path/") #download data from link

# Finding QGIS algoritms 
dir_tmp <- "/my/path/"
my_env <- set_env()
find_algorithms(search_term = "grid")
params <- get_args_man(alg = "qgis:creategrid", qgis_env = my_env)

params$TYPE <- "polygon"
params$EXTENT <- nnetpro
params$HSPACING <- "10" does it accept numeric?
params$VSPACING <- "10" does it accept numeric?
params$CRS <- "EPSG:31983" #does it work with CRS("+init=epsg:31983")?
params$OUTPUT <- file.path(dir_tmp, "g10m.shp")


out <- run_qgis(alg = "qgis:creategrid",
                params = params,
                load_output = params$OUTPUT,
                qgis_env = my_env)

Error in run_qgis(alg = "qgis:creategrid", params = params, load_output = params$OUTPUT,  : 
Error: Wrong parameter value: polygon
1

1 Answer 1

2

Obviously, you want to use another projection, therefore we reproject your data:

library("sp")
neto  <- readRDS("neto.rds")
neto_projected <- spTransform(neto,  CRS("+init=epsg:31983"))

Next, we access the function arguments of "qgis:creategrid".

library("RQGIS")
qgis_env <- set_env(root = "C:/OSGeo4W64/")
params <- get_args_man(alg = "qgis:creategrid", qgis_env = qgis_env)

To access the options for a specific QGIS geoalgorithm, use get_options:

get_options(alg = "qgis:creategrid", qgis_env = qgis_env)

You can also access its online help:

open_help(alg = "qgis:creategrid", qgis_env = qgis_env)

Though I have to admit that the online help in this case is a bit confusing...

Let's specify the arguments accordingly:

params$TYPE <- 1
# extent has to be given in the form of: xmin, xmax, ymin, ymax
params$EXTENT <-  paste(as.vector(raster::extent(neto_projected)), 
                        collapse = ", ")

Obviously, you would like to use a 10 m spacing. That's why we have reprojected your data in the first place. However, be careful if you use another projection, e.g., when using WGS84 10 would correspond to 10 decimal degrees.

params$HSPACING <- 10
params$VSPACING <- 10
params$CRS <- "EPSG:31983" 
params$OUTPUT <- file.path(tempdir(), "g10m.shp")

Now run QGIS. Due to your fine resolution, this takes a little while.

out <- run_qgis(alg = "qgis:creategrid",
                params = params,
                load_output = params$OUTPUT,
                qgis_env = qgis_env)
2
  • I forgot to say that everything was in EPSG:31983, in that case, is it necessary to write the CRS? anyways, the get_options and open_help are the key. Thanks.
    – Sergio
    Commented Mar 9, 2017 at 13:01
  • 1
    Well, your neto-shapefile used the WGS84 projection. Anyways, you need to specify the CRS-argument. Not doing so would result in an QGIS error message saying "Wrong parameter value: None".
    – Jannes
    Commented Mar 9, 2017 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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