[R-sig-Geo] v.split.length (GRASS) in R

Manuel Spínola mspinola10 at gmail.com
Wed Nov 23 20:49:38 CET 2016


Thank you very much Jannes.

Does the example works with QGIS 2.18 or should I do some setting in QGIS
before running the code?

Manuel

2016-11-23 8:45 GMT-06:00 "Jannes Münchow" <malNamalJa at gmx.de>:

> To achieve this, you can also use the RQGIS-package in conjunction with
> GRASS given you have installed QGIS along with GRASS (for more information
> have a look at vignette("install_guide", package = "RQGIS"):
>
> # construct a SpatialPointsDataFrame (which will be accepted as input by
> # run_qgis)
> library("sp")
> # from the sp vignette:
> l1 <- cbind(c(1, 2, 3), c(3, 2, 2))
> rownames(l1) <- letters[1:3]
> l1a <- cbind(l1[, 1] + 0.05, l1[, 2] + 0.05)
> rownames(l1a) <- letters[1:3]
> l2 <- cbind(c(1, 2, 3), c(1, 1.5, 1))
> rownames(l2) <- letters[1:3]
> Sl1 <- Line(l1)
> Sl1a <- Line(l1a)
> Sl2 <- Line(l2)
> S1 <- Lines(list(Sl1, Sl1a), ID = "a")
> S2 <- Lines(list(Sl2), ID = "b")
> Sl <- SpatialLines(list(S1, S2))
> # convert it to a SpatialLinesDataFrame
> Sl <- SpatialLinesDataFrame(Sl, data = data.frame(1:2), match.ID = FALSE)
> proj4string(Sl) <- CRS("+proj=longlat +datum=WGS84")
>
> # Now use RQGIS
> library("RQGIS")
> # indicate where QGIS is installed on your computer
> qgis_env <- set_env("C:/OSGeo4W64/")
> args <- get_args_man("grass7:v.split.length", qgis_env = qgis_env,
>                      options = TRUE)
> # have a look at the GRASS online help
> open_help("grass7:v.split.length", qgis_env = qgis_env)
>
> # specify the necessary arguments
> args$input <- Sl
> # here length corresponds to one decimal degree
> args$length <- "1"
> args$output <- file.path(tempdir(), "out.shp")
> # load the output directly into R again
> out <- run_qgis(alg = "grass7:v.split.length", params = args,
>                 load_output = args$output,
>                 qgis_env = qgis_env)
> length(Sl)  # 2 line objects
> length(out)  #  9 line objects
> # Have a look at the output
> plot(out, col = rep(c("blue", "green", "black"), 3))
>
> Cheers,
>
> Jannes
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo




-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.cr <mspinola at una.ac.cr>
mspinola10 at gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río <https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list