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

2016-11-24 Thread Roger Bivand
Before giving advice, please do ask for clarification. There is no 
v.split.length in GRASS at all, there is only v.split. Without a fully 
specified GRASS command, such as:


v.split -n input=??, output=??, length=10.0, units="meters"

which means add vertices each 10m, but do not split the vector line, we 
could think that the OP wants to divide a line into contiguous shorter 
segments. What does the OP actually want to do? Once we know that (which 
we do not), we can offer advice, including running the command in GRASS - 
which should be done anyway to ensure that the output of R-only approaches 
matches the desired output object.


Roger


On Wed, 23 Nov 2016, Manuel Spínola wrote:


Dear list members,

Is it possible to run v.split.length from GRASS in R? Or is there anyway to
split a SpatialLinesDataFrame to shorter segments by length in R?

Best,

Manuel

--
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: roger.biv...@nhh.no
http://orcid.org/-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0J&hl=en
http://depsy.org/person/434412___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: [R-sig-Geo] rgrass7 : Error in parseGRASS

2016-11-24 Thread Chris Reudenbach

Michael,

Using a fresh OSGEO4W64 standard quick desktop installation (i.e. 
installation of the default desktop GIS software packages with the 
installer and using C:\OSGeo4W64 as path)  I suggest the below solution.


You have to set all necessary eniromental and system variables manually. 
I am not quit sure if I got them but actually it seems to work for your 
question. As a conclusion I think your Python and all of the rest is 
installed correct.



cheers Chris


### librarys, data etc 
-

library(rgrass7)
library(sp)

# setup a temp workingdir
working.dir<- "~/tmp/"

# get meuse data

data(meuse)
data(meuse.grid)

# georeference the meuse grid data
coordinates(meuse.grid) <- ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) <- TRUE

# get a first cellsize/pixel resolution for GRASS
resolution <- meuse.grid@grid@cellsize[1]

# georeference the meuse data
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")

# get projection, proj4 string and extent for GRASS
projection<-(strsplit(meuse@proj4string@projargs,split = " "))
proj4<- paste(projection[[1]][2:length(unlist(projection))], collapse = ' ')
xmax<-meuse@bbox[3]
xmin<-meuse@bbox[1]
ymax<-meuse@bbox[4]
ymin<-meuse@bbox[2]

# create and set working directory
if (!file.exists(file.path(working.dir,"run"))){
  dir.create(file.path(working.dir,"run"),recursive = TRUE)
}
setwd(file.path( working.dir,"run"))


### SETUP OSGEO4W enviroment settings manually 
-

# setup the OSGEO4W environ manually
# assuming a osgeow4w default "deskop fastinstall
# using the default installation directory "C:\OSGeo4W64"

# set OSGE4W base directory
osgeo4w.root<-"C:\\OSGEO4~1"
Sys.setenv(OSGEO4W_ROOT=osgeo4w.root)
# define GISBASE
grass.gis.base<-paste0(osgeo4w.root,"\\apps\\grass\\grass-7.0.5")
Sys.setenv(GISBASE=grass.gis.base)

Sys.setenv(GRASS_PYTHON=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\bin\\python.exe"))
Sys.setenv(PYTHONHOME=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\Python27"))
Sys.setenv(PYTHONPATH=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\grass\\grass-7.0.5\\etc\\python"))
Sys.setenv(GRASS_PROJSHARE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
Sys.setenv(PROJ_LIB=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
Sys.setenv(GDAL_DATA=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\gdal"))
Sys.setenv(GEOTIFF_CSV=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\epsg_csv"))
Sys.setenv(FONTCONFIG_FILE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\etc\\fonts.conf"))

# call all OSGEO4W settings
system("C:/OSGeo4W64/bin/o-help.bat")


# create PATH variable
Sys.setenv(PATH=paste0(grass.gis.base,";",
"C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\numpy\\core",";",
"C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\bin",";",
"C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\lib",";",
"C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc",";",
"C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc\\python",";",
"C:\\OSGeo4W64\\apps\\Python27\\Scripts",";",
   "C:\\OSGeo4W64\\bin",";",
   "c:\\OSGeo4W64\\apps",";",
   "C:\\OSGEO4~1\\apps\\saga",";",
   paste0(Sys.getenv("WINDIR"),"/WBem"),";",
   Sys.getenv("PATH")))


 start with GRASS setup 


rgrass7::initGRASS(gisBase=grass.gis.base,
   home=tempdir(),
   mapset='PERMANENT',
   override=TRUE
)

# assign GRASS projection according to data set
rgrass7::execGRASS('g.proj',
   flags=c('c','quiet'),
   proj4=proj4
)

# assign GRASS extent and resolution
rgrass7::execGRASS('g.region',
   flags=c('quiet'),
   n=as.character(ymax),
   s=as.character(ymin),
   e=as.character(xmax),
   w=as.character(xmin),
   res=as.character(resolution)
)


#   now do GRASS STUFF 
-


rgrass7::writeVECT(meuse,"meuse")
rgrass7::execGRASS("v.db.addcolumn", map = "meuse", columns = "area_m2 
double

   precision")
#  do other command line stuff 
-


## call gdal
system("gdal_merge")

# call saga cli
system("saga_cmd")


Am 23.11.2016 um 07:38 schrieb Michael DELORME:

Thanks for your insight.
I'll use a stand-alone GRASS install.

Cordially

Le 22/11/2016 15:13, Roger Bivand a écrit :

On Tue, 22 Nov 2016, Michael DELORME wrote:


Thanks for investigating.

I'll try a standalone version of GRASS if needed.

Here is the traceback


traceback()

4: stop(paste(cmd, "not parsed"))
3: parseGRASS(cmd, legacyExec = legacyExec)
2: doGRASS(cmd, flags = flags, ..., parameters = parameters, echoCmd =
echoCmd, legacyExec = legacyExec)
1: execGRASS("v.db.addcolumn", map = "meuse", columns = "area_m2 double
precision")

My

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

2016-11-24 Thread Roger Bivand
Never hi-jack existing threads. If you want to ask a question, start a new 
thread with a new subject line; do not reply to an existing post chaning 
the subject line either.


Before asking questions, read the instructions and posting guide:

https://www.r-project.org/mail.html#instructions
https://www.r-project.org/posting-guide.html

Open questions like yours need to go to the correct list - this is not a 
spatial question.


Roger Bivand
List admin.

On Thu, 24 Nov 2016, julian magezi via R-sig-Geo wrote:


Hello members,
Which package in R does nonparametric statistical testing?
Thanks
 Julian Ijumulana, MSc (Geoinformatics)Land surveyor, GIS/RS Specialist & 
Assistant Lecturer, Department of Transportation and Geotechnical 
Engineering,College of Engineering and Technology,University of Dar es Salaam,Box 
35131,Dar es SalaamTANZANIA
Mob: +255 767675416



   On Wednesday, 23 November 2016, 20:49, Manuel Spínola  
wrote:


Thank you very much Florian.

Do you know any R function/package to do the same without relying on GRASS?

Manuel

2016-11-23 7:28 GMT-06:00 Florian Betz :


Assuming you are using GRASS 7, you can use the rgrass7 package. First
thing to do is to initialize the R-GRASS connection, then you can run the
module using execGRASS.

library(rgrass7)
#Arguments depending on your system
initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.0.5",home=tempdir(),
          gisDbase="Path to the folder with your location, location="Your
GRASS location",mapset="Your GRASS mapset",override=TRUE)
#See the help of v.split.lenght for the necessary function arguments
execGRASS("v.split.length", argument1=, argument2=, ...)

Regards,

Flo


Am 23.11.2016 um 14:15 schrieb Manuel Spínola:


Dear list members,

Is it possible to run v.split.length from GRASS in R? Or is there anyway
to
split a SpatialLinesDataFrame to shorter segments by length in R?

Best,

Manuel







--
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río 
Institutional website: ICOMVIS 

    [[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: roger.biv...@nhh.no
http://orcid.org/-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0J&hl=en
http://depsy.org/person/434412___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: [R-sig-Geo] rgrass7 : Error in parseGRASS

2016-11-24 Thread Michael DELORME
That's great Chris, it works fine as is !
Thank you, I don't have to keep another GRASS install aside then.

I'm sure it will be helpful to other people also.
Thanks again

Le 24/11/2016 09:17, Chris Reudenbach a écrit :
> Michael,
>
> Using a fresh OSGEO4W64 standard quick desktop installation (i.e.
> installation of the default desktop GIS software packages with the
> installer and using C:\OSGeo4W64 as path)  I suggest the below solution.
>
> You have to set all necessary eniromental and system variables
> manually. I am not quit sure if I got them but actually it seems to
> work for your question. As a conclusion I think your Python and all of
> the rest is installed correct.
>
>
> cheers Chris
>
>
> ### librarys, data etc
> -
> library(rgrass7)
> library(sp)
>
> # setup a temp workingdir
> working.dir<- "~/tmp/"
>
> # get meuse data
>
> data(meuse)
> data(meuse.grid)
>
> # georeference the meuse grid data
> coordinates(meuse.grid) <- ~x+y
> proj4string(meuse.grid) <- CRS("+init=epsg:28992")
> gridded(meuse.grid) <- TRUE
>
> # get a first cellsize/pixel resolution for GRASS
> resolution <- meuse.grid@grid@cellsize[1]
>
> # georeference the meuse data
> coordinates(meuse) <- ~x+y
> proj4string(meuse) <- CRS("+init=epsg:28992")
>
> # get projection, proj4 string and extent for GRASS
> projection<-(strsplit(meuse@proj4string@projargs,split = " "))
> proj4<- paste(projection[[1]][2:length(unlist(projection))], collapse
> = ' ')
> xmax<-meuse@bbox[3]
> xmin<-meuse@bbox[1]
> ymax<-meuse@bbox[4]
> ymin<-meuse@bbox[2]
>
> # create and set working directory
> if (!file.exists(file.path(working.dir,"run"))){
>   dir.create(file.path(working.dir,"run"),recursive = TRUE)
> }
> setwd(file.path( working.dir,"run"))
>
>
> ### SETUP OSGEO4W enviroment settings manually
> -
> # setup the OSGEO4W environ manually
> # assuming a osgeow4w default "deskop fastinstall
> # using the default installation directory "C:\OSGeo4W64"
>
> # set OSGE4W base directory
> osgeo4w.root<-"C:\\OSGEO4~1"
> Sys.setenv(OSGEO4W_ROOT=osgeo4w.root)
> # define GISBASE
> grass.gis.base<-paste0(osgeo4w.root,"\\apps\\grass\\grass-7.0.5")
> Sys.setenv(GISBASE=grass.gis.base)
>
> Sys.setenv(GRASS_PYTHON=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\bin\\python.exe"))
>
> Sys.setenv(PYTHONHOME=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\Python27"))
>
> Sys.setenv(PYTHONPATH=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\grass\\grass-7.0.5\\etc\\python"))
>
> Sys.setenv(GRASS_PROJSHARE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
>
> Sys.setenv(PROJ_LIB=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
> Sys.setenv(GDAL_DATA=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\gdal"))
> Sys.setenv(GEOTIFF_CSV=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\epsg_csv"))
>
> Sys.setenv(FONTCONFIG_FILE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\etc\\fonts.conf"))
>
>
> # call all OSGEO4W settings
> system("C:/OSGeo4W64/bin/o-help.bat")
>
>
> # create PATH variable
> Sys.setenv(PATH=paste0(grass.gis.base,";",
> "C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\numpy\\core",";",
> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\bin",";",
> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\lib",";",
> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc",";",
> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc\\python",";",
> "C:\\OSGeo4W64\\apps\\Python27\\Scripts",";",
>"C:\\OSGeo4W64\\bin",";",
>"c:\\OSGeo4W64\\apps",";",
>"C:\\OSGEO4~1\\apps\\saga",";",
>paste0(Sys.getenv("WINDIR"),"/WBem"),";",
>Sys.getenv("PATH")))
>
>
>  start with GRASS setup
> 
> rgrass7::initGRASS(gisBase=grass.gis.base,
>home=tempdir(),
>mapset='PERMANENT',
>override=TRUE
> )
>
> # assign GRASS projection according to data set
> rgrass7::execGRASS('g.proj',
>flags=c('c','quiet'),
>proj4=proj4
> )
>
> # assign GRASS extent and resolution
> rgrass7::execGRASS('g.region',
>flags=c('quiet'),
>n=as.character(ymax),
>s=as.character(ymin),
>e=as.character(xmax),
>w=as.character(xmin),
>res=as.character(resolution)
> )
>
>
> #   now do GRASS STUFF
> -
>
> rgrass7::writeVECT(meuse,"meuse")
> rgrass7::execGRASS("v.db.addcolumn", map = "meuse", columns = "area_m2
> double
>precision")
> #  do other command line stuff
> -
>
> ## call gdal
> system("gdal_merge")
>
> # call saga cli
> system("saga_cmd")
>
>
> Am 23.11.2016 um 07:38 schrieb Michael DELORME:
>> Thanks for your insight.
>> I'll use a stand-alone GRASS install.
>>
>> Cordially
>>
>> 

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

2016-11-24 Thread Jannes Münchow

Hi Manuel,

 

overall we recommend to use RQGIS with the long-term release of QGIS (2.14). Nevertheless, RQGIS works also with QGIS 2.18. However, there is a bug in the QGIS Python code. Therefore, one needs to manually change the Python code. Here you find how you can do that:

 

https://github.com/jannes-m/RQGIS#qgis-216-modifications.

 

Regarding this issue, we have already notified the QGIS developers, and they told us that they fixed the issue. Hence, with the release of the next QGIS patch release, the manual adjustment of the Python code should no longer be necessary.

 

Best regards,

 

Jannes

 


 

 

Gesendet: Mittwoch, 23. November 2016 um 20:49 Uhr
Von: "Manuel Spínola" 
An: "Jannes Münchow" 
Cc: "r-sig-geo@r-project.org" 
Betreff: Re: [R-sig-Geo] v.split.length (GRASS) in R


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" :

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 = "" 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@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
mspin...@una.cr
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río
Institutional website: ICOMVIS








___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: [R-sig-Geo] rgrass7 : Error in parseGRASS

2016-11-24 Thread Roger Bivand

On Thu, 24 Nov 2016, Michael DELORME wrote:


That's great Chris, it works fine as is !
Thank you, I don't have to keep another GRASS install aside then.


Thanks for confirming this. I'll try to set up a test rig to allow 
initGRASS to set up the environment variables when using GRASS in OSGeo4W 
for a later release.


Roger



I'm sure it will be helpful to other people also.
Thanks again

Le 24/11/2016 09:17, Chris Reudenbach a écrit :

Michael,

Using a fresh OSGEO4W64 standard quick desktop installation (i.e.
installation of the default desktop GIS software packages with the
installer and using C:\OSGeo4W64 as path)  I suggest the below solution.

You have to set all necessary eniromental and system variables
manually. I am not quit sure if I got them but actually it seems to
work for your question. As a conclusion I think your Python and all of
the rest is installed correct.


cheers Chris


### librarys, data etc
-
library(rgrass7)
library(sp)

# setup a temp workingdir
working.dir<- "~/tmp/"

# get meuse data

data(meuse)
data(meuse.grid)

# georeference the meuse grid data
coordinates(meuse.grid) <- ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) <- TRUE

# get a first cellsize/pixel resolution for GRASS
resolution <- meuse.grid@grid@cellsize[1]

# georeference the meuse data
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")

# get projection, proj4 string and extent for GRASS
projection<-(strsplit(meuse@proj4string@projargs,split = " "))
proj4<- paste(projection[[1]][2:length(unlist(projection))], collapse
= ' ')
xmax<-meuse@bbox[3]
xmin<-meuse@bbox[1]
ymax<-meuse@bbox[4]
ymin<-meuse@bbox[2]

# create and set working directory
if (!file.exists(file.path(working.dir,"run"))){
  dir.create(file.path(working.dir,"run"),recursive = TRUE)
}
setwd(file.path( working.dir,"run"))


### SETUP OSGEO4W enviroment settings manually
-
# setup the OSGEO4W environ manually
# assuming a osgeow4w default "deskop fastinstall
# using the default installation directory "C:\OSGeo4W64"

# set OSGE4W base directory
osgeo4w.root<-"C:\\OSGEO4~1"
Sys.setenv(OSGEO4W_ROOT=osgeo4w.root)
# define GISBASE
grass.gis.base<-paste0(osgeo4w.root,"\\apps\\grass\\grass-7.0.5")
Sys.setenv(GISBASE=grass.gis.base)

Sys.setenv(GRASS_PYTHON=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\bin\\python.exe"))

Sys.setenv(PYTHONHOME=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\Python27"))

Sys.setenv(PYTHONPATH=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\grass\\grass-7.0.5\\etc\\python"))

Sys.setenv(GRASS_PROJSHARE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))

Sys.setenv(PROJ_LIB=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
Sys.setenv(GDAL_DATA=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\gdal"))
Sys.setenv(GEOTIFF_CSV=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\epsg_csv"))

Sys.setenv(FONTCONFIG_FILE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\etc\\fonts.conf"))


# call all OSGEO4W settings
system("C:/OSGeo4W64/bin/o-help.bat")


# create PATH variable
Sys.setenv(PATH=paste0(grass.gis.base,";",
"C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\numpy\\core",";",
"C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\bin",";",
"C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\lib",";",
"C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc",";",
"C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc\\python",";",
"C:\\OSGeo4W64\\apps\\Python27\\Scripts",";",
   "C:\\OSGeo4W64\\bin",";",
   "c:\\OSGeo4W64\\apps",";",
   "C:\\OSGEO4~1\\apps\\saga",";",
   paste0(Sys.getenv("WINDIR"),"/WBem"),";",
   Sys.getenv("PATH")))


 start with GRASS setup

rgrass7::initGRASS(gisBase=grass.gis.base,
   home=tempdir(),
   mapset='PERMANENT',
   override=TRUE
)

# assign GRASS projection according to data set
rgrass7::execGRASS('g.proj',
   flags=c('c','quiet'),
   proj4=proj4
)

# assign GRASS extent and resolution
rgrass7::execGRASS('g.region',
   flags=c('quiet'),
   n=as.character(ymax),
   s=as.character(ymin),
   e=as.character(xmax),
   w=as.character(xmin),
   res=as.character(resolution)
)


#   now do GRASS STUFF
-

rgrass7::writeVECT(meuse,"meuse")
rgrass7::execGRASS("v.db.addcolumn", map = "meuse", columns = "area_m2
double
   precision")
#  do other command line stuff
-

## call gdal
system("gdal_merge")

# call saga cli
system("saga_cmd")


Am 23.11.2016 um 07:38 schrieb Michael DELORME:

Thanks for your insight.
I'll use a stand-alone GRASS install.

Cordially

Le 22/11/2016 15:13, Roger Bivand a écrit :


Re: [R-sig-Geo] rgrass7 : Error in parseGRASS

2016-11-24 Thread Michael DELORME
Let me use this opportunity to thank you for all the tools,
documentation and support you provide. This makes R a very useful tool
for us.

Cordially

Le 24/11/2016 10:48, Roger Bivand a écrit :
> On Thu, 24 Nov 2016, Michael DELORME wrote:
>
>> That's great Chris, it works fine as is !
>> Thank you, I don't have to keep another GRASS install aside then.
>
> Thanks for confirming this. I'll try to set up a test rig to allow
> initGRASS to set up the environment variables when using GRASS in
> OSGeo4W for a later release.
>
> Roger
>
>>
>> I'm sure it will be helpful to other people also.
>> Thanks again
>>
>> Le 24/11/2016 09:17, Chris Reudenbach a écrit :
>>> Michael,
>>>
>>> Using a fresh OSGEO4W64 standard quick desktop installation (i.e.
>>> installation of the default desktop GIS software packages with the
>>> installer and using C:\OSGeo4W64 as path)  I suggest the below
>>> solution.
>>>
>>> You have to set all necessary eniromental and system variables
>>> manually. I am not quit sure if I got them but actually it seems to
>>> work for your question. As a conclusion I think your Python and all of
>>> the rest is installed correct.
>>>
>>>
>>> cheers Chris
>>>
>>>
>>> ### librarys, data etc
>>> -
>>> library(rgrass7)
>>> library(sp)
>>>
>>> # setup a temp workingdir
>>> working.dir<- "~/tmp/"
>>>
>>> # get meuse data
>>>
>>> data(meuse)
>>> data(meuse.grid)
>>>
>>> # georeference the meuse grid data
>>> coordinates(meuse.grid) <- ~x+y
>>> proj4string(meuse.grid) <- CRS("+init=epsg:28992")
>>> gridded(meuse.grid) <- TRUE
>>>
>>> # get a first cellsize/pixel resolution for GRASS
>>> resolution <- meuse.grid@grid@cellsize[1]
>>>
>>> # georeference the meuse data
>>> coordinates(meuse) <- ~x+y
>>> proj4string(meuse) <- CRS("+init=epsg:28992")
>>>
>>> # get projection, proj4 string and extent for GRASS
>>> projection<-(strsplit(meuse@proj4string@projargs,split = " "))
>>> proj4<- paste(projection[[1]][2:length(unlist(projection))], collapse
>>> = ' ')
>>> xmax<-meuse@bbox[3]
>>> xmin<-meuse@bbox[1]
>>> ymax<-meuse@bbox[4]
>>> ymin<-meuse@bbox[2]
>>>
>>> # create and set working directory
>>> if (!file.exists(file.path(working.dir,"run"))){
>>>   dir.create(file.path(working.dir,"run"),recursive = TRUE)
>>> }
>>> setwd(file.path( working.dir,"run"))
>>>
>>>
>>> ### SETUP OSGEO4W enviroment settings manually
>>> -
>>> # setup the OSGEO4W environ manually
>>> # assuming a osgeow4w default "deskop fastinstall
>>> # using the default installation directory "C:\OSGeo4W64"
>>>
>>> # set OSGE4W base directory
>>> osgeo4w.root<-"C:\\OSGEO4~1"
>>> Sys.setenv(OSGEO4W_ROOT=osgeo4w.root)
>>> # define GISBASE
>>> grass.gis.base<-paste0(osgeo4w.root,"\\apps\\grass\\grass-7.0.5")
>>> Sys.setenv(GISBASE=grass.gis.base)
>>>
>>> Sys.setenv(GRASS_PYTHON=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\bin\\python.exe"))
>>>
>>>
>>> Sys.setenv(PYTHONHOME=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\Python27"))
>>>
>>>
>>> Sys.setenv(PYTHONPATH=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\grass\\grass-7.0.5\\etc\\python"))
>>>
>>>
>>> Sys.setenv(GRASS_PROJSHARE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
>>>
>>>
>>> Sys.setenv(PROJ_LIB=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
>>> Sys.setenv(GDAL_DATA=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\gdal"))
>>>
>>> Sys.setenv(GEOTIFF_CSV=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\epsg_csv"))
>>>
>>>
>>> Sys.setenv(FONTCONFIG_FILE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\etc\\fonts.conf"))
>>>
>>>
>>>
>>> # call all OSGEO4W settings
>>> system("C:/OSGeo4W64/bin/o-help.bat")
>>>
>>>
>>> # create PATH variable
>>> Sys.setenv(PATH=paste0(grass.gis.base,";",
>>> "C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\numpy\\core",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\bin",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\lib",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc\\python",";",
>>> "C:\\OSGeo4W64\\apps\\Python27\\Scripts",";",
>>>"C:\\OSGeo4W64\\bin",";",
>>>"c:\\OSGeo4W64\\apps",";",
>>>"C:\\OSGEO4~1\\apps\\saga",";",
>>>paste0(Sys.getenv("WINDIR"),"/WBem"),";",
>>>Sys.getenv("PATH")))
>>>
>>>
>>>  start with GRASS setup
>>> 
>>> rgrass7::initGRASS(gisBase=grass.gis.base,
>>>home=tempdir(),
>>>mapset='PERMANENT',
>>>override=TRUE
>>> )
>>>
>>> # assign GRASS projection according to data set
>>> rgrass7::execGRASS('g.proj',
>>>flags=c('c','quiet'),
>>>proj4=proj4
>>> )
>>>
>>> # assign GRASS extent and resolution
>>> rgrass7::execGRASS('g.region',
>>>flags=c('quiet'),
>>>n=as.character(ymax),
>>>   

Re: [R-sig-Geo] rgrass7 : Error in parseGRASS

2016-11-24 Thread Chris Reudenbach
@Michael fine!

@Roger

this is  pretty dirty "hack" I did not cross check if I got all 
variables dealing with GRASS. I would like to do it more systematically. 
Nevertheless as far as I understand the osgeo4w concept, we have only 
two changing names. 1) the installation root directory   2) the GRASS 
version name, that is used as a part of the internal  path structure.  I 
would like to check this and if so it might be easy to integrate this in 
initGRASS.

cheers Chris

Am 24.11.2016 um 10:48 schrieb Roger Bivand:
> On Thu, 24 Nov 2016, Michael DELORME wrote:
>
>> That's great Chris, it works fine as is !
>> Thank you, I don't have to keep another GRASS install aside then.
>
> Thanks for confirming this. I'll try to set up a test rig to allow 
> initGRASS to set up the environment variables when using GRASS in 
> OSGeo4W for a later release.
>
> Roger
>
>>
>> I'm sure it will be helpful to other people also.
>> Thanks again
>>
>> Le 24/11/2016 09:17, Chris Reudenbach a �crit :
>>> Michael,
>>>
>>> Using a fresh OSGEO4W64 standard quick desktop installation (i.e.
>>> installation of the default desktop GIS software packages with the
>>> installer and using C:\OSGeo4W64 as path)  I suggest the below 
>>> solution.
>>>
>>> You have to set all necessary eniromental and system variables
>>> manually. I am not quit sure if I got them but actually it seems to
>>> work for your question. As a conclusion I think your Python and all of
>>> the rest is installed correct.
>>>
>>>
>>> cheers Chris
>>>
>>>
>>> ### librarys, data etc
>>> -
>>> library(rgrass7)
>>> library(sp)
>>>
>>> # setup a temp workingdir
>>> working.dir<- "~/tmp/"
>>>
>>> # get meuse data
>>>
>>> data(meuse)
>>> data(meuse.grid)
>>>
>>> # georeference the meuse grid data
>>> coordinates(meuse.grid) <- ~x+y
>>> proj4string(meuse.grid) <- CRS("+init=epsg:28992")
>>> gridded(meuse.grid) <- TRUE
>>>
>>> # get a first cellsize/pixel resolution for GRASS
>>> resolution <- meuse.grid@grid@cellsize[1]
>>>
>>> # georeference the meuse data
>>> coordinates(meuse) <- ~x+y
>>> proj4string(meuse) <- CRS("+init=epsg:28992")
>>>
>>> # get projection, proj4 string and extent for GRASS
>>> projection<-(strsplit(meuse@proj4string@projargs,split = " "))
>>> proj4<- paste(projection[[1]][2:length(unlist(projection))], collapse
>>> = ' ')
>>> xmax<-meuse@bbox[3]
>>> xmin<-meuse@bbox[1]
>>> ymax<-meuse@bbox[4]
>>> ymin<-meuse@bbox[2]
>>>
>>> # create and set working directory
>>> if (!file.exists(file.path(working.dir,"run"))){
>>>   dir.create(file.path(working.dir,"run"),recursive = TRUE)
>>> }
>>> setwd(file.path( working.dir,"run"))
>>>
>>>
>>> ### SETUP OSGEO4W enviroment settings manually
>>> -
>>> # setup the OSGEO4W environ manually
>>> # assuming a osgeow4w default "deskop fastinstall
>>> # using the default installation directory "C:\OSGeo4W64"
>>>
>>> # set OSGE4W base directory
>>> osgeo4w.root<-"C:\\OSGEO4~1"
>>> Sys.setenv(OSGEO4W_ROOT=osgeo4w.root)
>>> # define GISBASE
>>> grass.gis.base<-paste0(osgeo4w.root,"\\apps\\grass\\grass-7.0.5")
>>> Sys.setenv(GISBASE=grass.gis.base)
>>>
>>> Sys.setenv(GRASS_PYTHON=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\bin\\python.exe"))
>>>  
>>>
>>>
>>> Sys.setenv(PYTHONHOME=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\Python27"))
>>>  
>>>
>>>
>>> Sys.setenv(PYTHONPATH=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\apps\\grass\\grass-7.0.5\\etc\\python"))
>>>  
>>>
>>>
>>> Sys.setenv(GRASS_PROJSHARE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
>>>  
>>>
>>>
>>> Sys.setenv(PROJ_LIB=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\proj"))
>>> Sys.setenv(GDAL_DATA=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\gdal")) 
>>>
>>> Sys.setenv(GEOTIFF_CSV=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\share\\epsg_csv"))
>>>  
>>>
>>>
>>> Sys.setenv(FONTCONFIG_FILE=paste0(Sys.getenv("OSGEO4W_ROOT"),"\\etc\\fonts.conf"))
>>>  
>>>
>>>
>>>
>>> # call all OSGEO4W settings
>>> system("C:/OSGeo4W64/bin/o-help.bat")
>>>
>>>
>>> # create PATH variable
>>> Sys.setenv(PATH=paste0(grass.gis.base,";",
>>> "C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\numpy\\core",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\bin",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\lib",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc",";",
>>> "C:\\OSGeo4W64\\apps\\grass\\grass-7.0.5\\etc\\python",";",
>>> "C:\\OSGeo4W64\\apps\\Python27\\Scripts",";",
>>>"C:\\OSGeo4W64\\bin",";",
>>>"c:\\OSGeo4W64\\apps",";",
>>>"C:\\OSGEO4~1\\apps\\saga",";",
>>> paste0(Sys.getenv("WINDIR"),"/WBem"),";",
>>>Sys.getenv("PATH")))
>>>
>>>
>>>  start with GRASS setup
>>> 
>>> rgrass7::initGRASS(gisBase=grass.gis.base,
>>>home=tempdir(),
>>>mapset='PERMANENT',
>>>override=TRUE
>>> )
>>>
>>> # ass

[R-sig-Geo] package sp, extract values points-lines

2016-11-24 Thread marta azores
Hi everyone,

I need to join two datasets, one with survey boats and other with
sightings. There are different boats in the same area.
First I've created the tracks with the gps information, and give to each
track an ID number(column) .
Second, I would like to join by time and space the sightings with the track
of the boats.
I'm trying the"over" function of the package sp.

The first test was try to join only by space, but the function say there
aren't overlap. I don't know why, because the points of the sightings are
over the line.

Any idea?
Thanks in advance
Marta

#boat data
boat <- read.table("path/.csv", header=TRUE, sep=",", na.strings="NA",
dec=".", strip.white=TRUE)#
boatdf<-as.data.frame(boat)
#sighting data
sght <- read.table("path/.csv.csv", header=TRUE, sep=",", na.strings="NA",
dec=".", strip.white=TRUE)#

#Spatial points
#sightings
Sxy = cbind(sght$LONG,sght$LAT)
Spts = SpatialPoints(Sxy)
sghtdf<-as.data.frame(sght)
#boats
xy = cbind(boat$Long1,boat$Lat1)
pts = SpatialPoints(xy)

# dataframe
ptsdf = SpatialPointsDataFrame(pts, boatdf)#data frame barcos
Sptsdf = SpatialPointsDataFrame(Spts, sghtdf)#data frame species

#Line
line<-as(ptsdf, "SpatialLines")

#
#extract values
over(Sptsdf, line)# NA?

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2016-11-24 Thread Manuel Spínola
Thank you very much Roger.

Sorry about that, I took the name from the Processing toolbox in QGIS and I
assumed (wrongly)  that was the name in GRASS.

I want to split a vector line (route) in equal contiguous segments of 500 m.

Manuel

2016-11-24 2:09 GMT-06:00 Roger Bivand :

> Before giving advice, please do ask for clarification. There is no
> v.split.length in GRASS at all, there is only v.split. Without a fully
> specified GRASS command, such as:
>
> v.split -n input=??, output=??, length=10.0, units="meters"
>
> which means add vertices each 10m, but do not split the vector line, we
> could think that the OP wants to divide a line into contiguous shorter
> segments. What does the OP actually want to do? Once we know that (which we
> do not), we can offer advice, including running the command in GRASS -
> which should be done anyway to ensure that the output of R-only approaches
> matches the desired output object.
>
> Roger
>
>
> On Wed, 23 Nov 2016, Manuel Spínola wrote:
>
> Dear list members,
>>
>> Is it possible to run v.split.length from GRASS in R? Or is there anyway
>> to
>> split a SpatialLinesDataFrame to shorter segments by length in R?
>>
>> Best,
>>
>> Manuel
>>
>> --
>> *Manuel Spínola, Ph.D.*
>> Instituto Internacional en Conservación y Manejo de Vida Silvestre
>> Universidad Nacional
>> Apartado 1350-3000
>> Heredia
>> COSTA RICA
>> mspin...@una.cr 
>> mspinol...@gmail.com
>> Teléfono: (506) 8706 - 4662
>> Personal website: Lobito de río > /lobitoderio/>
>> Institutional website: ICOMVIS 
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: roger.biv...@nhh.no
> http://orcid.org/-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0J&hl=en
> http://depsy.org/person/434412




-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: [R-sig-Geo] package sp, extract values points-lines

2016-11-24 Thread rolandh
Hi Marta,

by ?sp::over you will see that SpatialLines are not supported.

Moreover it says:
"over methods that involve SpatialLines objects, or pairs of SpatialPolygons 
require package rgeos, and use gIntersects."

So, try gIntersects ...

Cheers,
Roland

marta azores schrieb am 2016-11-24:
> Hi everyone,

> I need to join two datasets, one with survey boats and other with
> sightings. There are different boats in the same area.
> First I've created the tracks with the gps information, and give to each
> track an ID number(column) .
> Second, I would like to join by time and space the sightings with the track
> of the boats.
> I'm trying the"over" function of the package sp.

> The first test was try to join only by space, but the function say there
> aren't overlap. I don't know why, because the points of the sightings are
> over the line.

> Any idea?
> Thanks in advance
> Marta

> #boat data
> boat <- read.table("path/.csv", header=TRUE, sep=",", na.strings="NA",
> dec=".", strip.white=TRUE)#
> boatdf<-as.data.frame(boat)
> #sighting data
> sght <- read.table("path/.csv.csv", header=TRUE, sep=",", na.strings="NA",
> dec=".", strip.white=TRUE)#

> #Spatial points
> #sightings
> Sxy = cbind(sght$LONG,sght$LAT)
> Spts = SpatialPoints(Sxy)
> sghtdf<-as.data.frame(sght)
> #boats
> xy = cbind(boat$Long1,boat$Lat1)
> pts = SpatialPoints(xy)

> # dataframe
> ptsdf = SpatialPointsDataFrame(pts, boatdf)#data frame barcos
> Sptsdf = SpatialPointsDataFrame(Spts, sghtdf)#data frame species

> #Line
> line<-as(ptsdf, "SpatialLines")

> #
> #extract values
> over(Sptsdf, line)# NA?

>   [[alternative HTML version deleted]]

> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2016-11-24 Thread Roger Bivand

On Thu, 24 Nov 2016, Manuel Spínola wrote:


Thank you very much Roger.

Sorry about that, I took the name from the Processing toolbox in QGIS and I
assumed (wrongly)  that was the name in GRASS.

I want to split a vector line (route) in equal contiguous segments of 500 m.


So for a Line object of 5km, you'd want 10 separate contiguous Line 
objects each of 500m in a Lines object? This would be the inverse 
operation to rgeos::gLineMerge(). sp::spsample can give n regular points 
on lines, but they are not a given distance apart (fixed distance, but n 
is given, n total points on the object. The code in spsample methods could 
give guidance. There are many edge cases, unfortunately, especially for 
typical input objects, which may not be clean. GRASS may be the best way 
of doing this, because it has a topological vector model, and will clean 
the lines on input.


Roger



Manuel

2016-11-24 2:09 GMT-06:00 Roger Bivand :


Before giving advice, please do ask for clarification. There is no
v.split.length in GRASS at all, there is only v.split. Without a fully
specified GRASS command, such as:

v.split -n input=??, output=??, length=10.0, units="meters"

which means add vertices each 10m, but do not split the vector line, we
could think that the OP wants to divide a line into contiguous shorter
segments. What does the OP actually want to do? Once we know that (which we
do not), we can offer advice, including running the command in GRASS -
which should be done anyway to ensure that the output of R-only approaches
matches the desired output object.

Roger


On Wed, 23 Nov 2016, Manuel Spínola wrote:

Dear list members,


Is it possible to run v.split.length from GRASS in R? Or is there anyway
to
split a SpatialLinesDataFrame to shorter segments by length in R?

Best,

Manuel

--
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: roger.biv...@nhh.no
http://orcid.org/-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0J&hl=en
http://depsy.org/person/434412








--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: roger.biv...@nhh.no
http://orcid.org/-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0J&hl=en
http://depsy.org/person/434412___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: [R-sig-Geo] package sp, extract values points-lines

2016-11-24 Thread Roger Bivand

On Thu, 24 Nov 2016, rola...@uni-muenster.de wrote:


Hi Marta,

by ?sp::over you will see that SpatialLines are not supported.

Moreover it says:
"over methods that involve SpatialLines objects, or pairs of SpatialPolygons require 
package rgeos, and use gIntersects."

So, try gIntersects ...


Right, and note that the precision model will bite painfully (the points 
may appear to be on the lines, but given the precision model may not 
actually intersect in the default representation (think one thousandth of 
a millimetre). You may need to buffer either points or lines to get the 
intersections you expect.


Roger



Cheers,
Roland

marta azores schrieb am 2016-11-24:

Hi everyone,



I need to join two datasets, one with survey boats and other with
sightings. There are different boats in the same area.
First I've created the tracks with the gps information, and give to each
track an ID number(column) .
Second, I would like to join by time and space the sightings with the track
of the boats.
I'm trying the"over" function of the package sp.



The first test was try to join only by space, but the function say there
aren't overlap. I don't know why, because the points of the sightings are
over the line.



Any idea?
Thanks in advance
Marta



#boat data
boat <- read.table("path/.csv", header=TRUE, sep=",", na.strings="NA",
dec=".", strip.white=TRUE)#
boatdf<-as.data.frame(boat)
#sighting data
sght <- read.table("path/.csv.csv", header=TRUE, sep=",", na.strings="NA",
dec=".", strip.white=TRUE)#



#Spatial points
#sightings
Sxy = cbind(sght$LONG,sght$LAT)
Spts = SpatialPoints(Sxy)
sghtdf<-as.data.frame(sght)
#boats
xy = cbind(boat$Long1,boat$Lat1)
pts = SpatialPoints(xy)



# dataframe
ptsdf = SpatialPointsDataFrame(pts, boatdf)#data frame barcos
Sptsdf = SpatialPointsDataFrame(Spts, sghtdf)#data frame species



#Line
line<-as(ptsdf, "SpatialLines")



#
#extract values
over(Sptsdf, line)# NA?



[[alternative HTML version deleted]]



___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: roger.biv...@nhh.no
http://orcid.org/-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0J&hl=en
http://depsy.org/person/434412

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2016-11-24 Thread Manuel Spínola
Thank you Jannes,

I installed the QGIS LTR, but I got the following error:

qgis_env <- set_env("C:/Program Files/QGIS 2.14")

ruta <- readOGR(dsn = ".", layer = "Ruta32_CRTM05_FINAL")

args <- get_args_man("grass7:v.split.length", qgis_env = qgis_env, options
= TRUE)

args$input <- ruta

args$length <- 500

args$output <- "ruta_s.shp"

out <- run_qgis(alg = "grass7:v.split.length", params = args, load_output =
args$output, qgis_env = qgis_env)

Error in .local(.Object, ...) :

 Show Traceback
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",
: Cannot create a RasterLayer object from this file. (file does not exist)












2016-11-24 3:43 GMT-06:00 "Jannes Münchow" :

> Hi Manuel,
>
> overall we recommend to use RQGIS with the long-term release of QGIS
> (2.14). Nevertheless, RQGIS works also with QGIS 2.18. However, there is a
> bug in the QGIS Python code. Therefore, one needs to manually change the
> Python code. Here you find how you can do that:
>
> https://github.com/jannes-m/RQGIS#qgis-216-modifications.
>
> Regarding this issue, we have already notified the QGIS developers, and
> they told us that they fixed the issue. Hence, with the release of the next
> QGIS patch release, the manual adjustment of the Python code should no
> longer be necessary.
>
> Best regards,
>
> Jannes
>
>
>
>
> *Gesendet:* Mittwoch, 23. November 2016 um 20:49 Uhr
> *Von:* "Manuel Spínola" 
> *An:* "Jannes Münchow" 
> *Cc:* "r-sig-geo@r-project.org" 
> *Betreff:* Re: [R-sig-Geo] v.split.length (GRASS) in R
> 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" :
>>
>> 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@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
> mspin...@una.cr 
> mspinol...@gmail.com
> Teléfono: (506) 8706 - 4662
> Personal website: Lobito de río
> 
> Institutional website: ICOMVIS 
>



-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

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

2016-11-24 Thread Manuel Spínola
Thank you very much Roger.



2016-11-24 8:09 GMT-06:00 Roger Bivand :

> On Thu, 24 Nov 2016, Manuel Spínola wrote:
>
> Thank you very much Roger.
>>
>> Sorry about that, I took the name from the Processing toolbox in QGIS and
>> I
>> assumed (wrongly)  that was the name in GRASS.
>>
>> I want to split a vector line (route) in equal contiguous segments of 500
>> m.
>>
>
> So for a Line object of 5km, you'd want 10 separate contiguous Line
> objects each of 500m in a Lines object? This would be the inverse operation
> to rgeos::gLineMerge(). sp::spsample can give n regular points on lines,
> but they are not a given distance apart (fixed distance, but n is given, n
> total points on the object. The code in spsample methods could give
> guidance. There are many edge cases, unfortunately, especially for typical
> input objects, which may not be clean. GRASS may be the best way of doing
> this, because it has a topological vector model, and will clean the lines
> on input.
>
> Roger
>
>
>
>> Manuel
>>
>> 2016-11-24 2:09 GMT-06:00 Roger Bivand :
>>
>> Before giving advice, please do ask for clarification. There is no
>>> v.split.length in GRASS at all, there is only v.split. Without a fully
>>> specified GRASS command, such as:
>>>
>>> v.split -n input=??, output=??, length=10.0, units="meters"
>>>
>>> which means add vertices each 10m, but do not split the vector line, we
>>> could think that the OP wants to divide a line into contiguous shorter
>>> segments. What does the OP actually want to do? Once we know that (which
>>> we
>>> do not), we can offer advice, including running the command in GRASS -
>>> which should be done anyway to ensure that the output of R-only
>>> approaches
>>> matches the desired output object.
>>>
>>> Roger
>>>
>>>
>>> On Wed, 23 Nov 2016, Manuel Spínola wrote:
>>>
>>> Dear list members,
>>>

 Is it possible to run v.split.length from GRASS in R? Or is there anyway
 to
 split a SpatialLinesDataFrame to shorter segments by length in R?

 Best,

 Manuel

 --
 *Manuel Spínola, Ph.D.*
 Instituto Internacional en Conservación y Manejo de Vida Silvestre
 Universidad Nacional
 Apartado 1350-3000
 Heredia
 COSTA RICA
 mspin...@una.cr 
 mspinol...@gmail.com
 Teléfono: (506) 8706 - 4662
 Personal website: Lobito de río 
 Institutional website: ICOMVIS 

 [[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


>>> --
>>> Roger Bivand
>>> Department of Economics, Norwegian School of Economics,
>>> Helleveien 30, N-5045 Bergen, Norway.
>>> voice: +47 55 95 93 55; fax +47 55 95 91 00
>>> e-mail: roger.biv...@nhh.no
>>> http://orcid.org/-0003-2392-6140
>>> https://scholar.google.no/citations?user=AWeghB0J&hl=en
>>> http://depsy.org/person/434412
>>>
>>
>>
>>
>>
>>
>>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: roger.biv...@nhh.no
> http://orcid.org/-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0J&hl=en
> http://depsy.org/person/434412
>



-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: [R-sig-Geo] package sp, extract values points-lines

2016-11-24 Thread marta azores
Hi Roger,

Thanks for the tip. I tried with only one track the function gIntersects
and gbuffer . It works.
I created my spatiallines from a data frame , and now I was looking for how
create the spatiallines by categories (1 variable of the data.frame).
I have only one spatial line with all the coordinates, and I would like to
have 1000 different lines separates by the IdkeyL. It's that possible??


My spatial data frame:
coordinates IdkeyL  Date
1 (-24.54572, 37.30128)  2815L 42229
2 (-24.59933, 37.32453)  2815L 42229
3 (-24.68027, 37.36087)  2815L 42229


I checked the sp and rgeos manual, and I look into the forums, but in every
example they only use a few lines, which are defined one by one.
l1 <- cbind(c(1, 2, 3), c(3, 2, 2)) l2 <- cbind(c(1, 2, 3), c(1, 1.5, 1))
Sl1 <- Line(l1) Sl2 <- Line(l2) S1 <- Lines(list(Sl1), ID = "a") S2 <- Lines
(list(Sl2), ID = "b") Sl <- SpatialLines(list(S1, S2))

Thanks in advance
Marta


2016-11-24 13:12 GMT-01:00 Roger Bivand :

> On Thu, 24 Nov 2016, rola...@uni-muenster.de wrote:
>
> Hi Marta,
>>
>> by ?sp::over you will see that SpatialLines are not supported.
>>
>> Moreover it says:
>> "over methods that involve SpatialLines objects, or pairs of
>> SpatialPolygons require package rgeos, and use gIntersects."
>>
>> So, try gIntersects ...
>>
>
> Right, and note that the precision model will bite painfully (the points
> may appear to be on the lines, but given the precision model may not
> actually intersect in the default representation (think one thousandth of a
> millimetre). You may need to buffer either points or lines to get the
> intersections you expect.
>
> Roger
>
>
>
>> Cheers,
>> Roland
>>
>> marta azores schrieb am 2016-11-24:
>>
>>> Hi everyone,
>>>
>>
>> I need to join two datasets, one with survey boats and other with
>>> sightings. There are different boats in the same area.
>>> First I've created the tracks with the gps information, and give to each
>>> track an ID number(column) .
>>> Second, I would like to join by time and space the sightings with the
>>> track
>>> of the boats.
>>> I'm trying the"over" function of the package sp.
>>>
>>
>> The first test was try to join only by space, but the function say there
>>> aren't overlap. I don't know why, because the points of the sightings are
>>> over the line.
>>>
>>
>> Any idea?
>>> Thanks in advance
>>> Marta
>>>
>>
>> #boat data
>>> boat <- read.table("path/.csv", header=TRUE, sep=",", na.strings="NA",
>>> dec=".", strip.white=TRUE)#
>>> boatdf<-as.data.frame(boat)
>>> #sighting data
>>> sght <- read.table("path/.csv.csv", header=TRUE, sep=",",
>>> na.strings="NA",
>>> dec=".", strip.white=TRUE)#
>>>
>>
>> #Spatial points
>>> #sightings
>>> Sxy = cbind(sght$LONG,sght$LAT)
>>> Spts = SpatialPoints(Sxy)
>>> sghtdf<-as.data.frame(sght)
>>> #boats
>>> xy = cbind(boat$Long1,boat$Lat1)
>>> pts = SpatialPoints(xy)
>>>
>>
>> # dataframe
>>> ptsdf = SpatialPointsDataFrame(pts, boatdf)#data frame barcos
>>> Sptsdf = SpatialPointsDataFrame(Spts, sghtdf)#data frame species
>>>
>>
>> #Line
>>> line<-as(ptsdf, "SpatialLines")
>>>
>>
>> #
>>> #extract values
>>> over(Sptsdf, line)# NA?
>>>
>>
>> [[alternative HTML version deleted]]
>>>
>>
>> ___
>>> R-sig-Geo mailing list
>>> R-sig-Geo@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> ___
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: roger.biv...@nhh.no
> http://orcid.org/-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0J&hl=en
> http://depsy.org/person/434412
>

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Error with loading rJava for spcosa [SEC=UNCLASSIFIED]

2016-11-24 Thread Li Jin
Hi All,

I have been using library(spcosa) in R version 3.2.3 (2015-12-10) and all 
worked well, until today.

The error was as below when I called:
>  library(spcosa)
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: fun(libname, pkgname)
  error: JAVA_HOME cannot be determined from the Registry
Error: package 'rJava' could not be loaded

Although rJava was installed, I reinstalled it, successfully as:
>   install.packages("rJava")
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.2/rJava_0.9-8.zip'
Content type 'application/zip' length 765340 bytes (747 KB)
downloaded 747 KB

package 'rJava' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\u09672\AppData\Local\Temp\1\Rtmp2PslO0\downloaded_packages

But when I called:
> library(rJava)
Error in get(Info[i, 1], envir = env) :
  lazy-load database 'C:/LegacyApps/R-3.2.3/library/rJava/R/rJava.rdb' is 
corrupt
In addition: Warning messages:
1: package 'rJava' was built under R version 3.2.5
2: In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1
Error: package or namespace load failed for 'rJava'

When I called:
>  library(spcosa)
Loading required package: rJava
Error in get(Info[i, 1], envir = env) :
  lazy-load database 'C:/LegacyApps/R-3.2.3/library/rJava/R/rJava.rdb' is 
corrupt
In addition: Warning messages:
1: package 'rJava' was built under R version 3.2.5
2: In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1
Error: package 'rJava' could not be loaded

Looks like something is wrong with loading "rJava". The only thing has been 
changed is that my PC was refreshed recently.

Any suggestions to how to fix this loading problem? Thanks!


> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] raster_2.5-8 sp_1.2-3

loaded via a namespace (and not attached):
[1] tools_3.2.3 Rcpp_0.12.7 grid_3.2.3  lattice_0.20-34
>

Please note this error persists for:  R version 3.3.1 (2016-06-21)

Kind regards,
Jin

Jin Li, PhD | Spatial Modeller / Computational Statistician
National Earth and Marine Observations | Environmental Geoscience Division
t:  +61 2 6249 9899

Geoscience Australia Disclaimer: This e-mail (and files transmitted with it) is 
intended only for the person or entity to which it is addressed. If you are not 
the intended recipient, then you have received this e-mail by mistake and any 
use, dissemination, forwarding, printing or copying of this e-mail and its file 
attachments is prohibited. The security of emails transmitted cannot be 
guaranteed; by forwarding or replying to this email, you acknowledge and accept 
these risks.
-


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2016-11-24 Thread Jannes Münchow

Hi Manuel,

 

yes, this is the old error message. I guess QGIS/GRASS did not produce any output. Since you specified the load_output argument, the function tries to load it into R. First it tries to read a shapefile, if this not works, it tries to read a raster file. That's also the reason why the error message talks of a raster problem. Using the RQGIS developer version from github the function would tell you now that QGIS did not produce any output.

 

Without the shapefile I can't tell you what went wrong. You can send it to me or you could also try to first use QGIS interactively to see if while using the GUI an output will be produced. Please note also that is does not make much sense to load the line shapefile into R when it is already saved on disk. Because now you read in the shapefile and run_qgis saves it again to the temporary folder. So it would be more efficient to indicate the file path to the shapefile in the input-argument

 

Kind regards,

 

Jannes

 
 

 

Gesendet: Donnerstag, 24. November 2016 um 16:00 Uhr
Von: "Manuel Spínola" 
An: "Jannes Münchow" 
Cc: "r-sig-geo@r-project.org" 
Betreff: Re: Re: [R-sig-Geo] v.split.length (GRASS) in R


Thank you Jannes,
 

I installed the QGIS LTR, but I got the following error:

 

qgis_env <- set_env("C:/Program Files/QGIS 2.14")

 

ruta <- readOGR(dsn = ".", layer = "Ruta32_CRTM05_FINAL")

 

args <- get_args_man("grass7:v.split.length", qgis_env = qgis_env, options = TRUE)

 

args$input <- ruta

 

args$length <- 500

 

args$output <- "ruta_s.shp"

 


out <- run_qgis(alg = "grass7:v.split.length", params = args, load_output = args$output, qgis_env = qgis_env)

 



Error in .local(.Object, ...) : 

 

 Show Traceback

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file. (file does not exist)


 

 

 

 

 

 

 

 

 

 

 


 
2016-11-24 3:43 GMT-06:00 "Jannes Münchow" :





Hi Manuel,

 

overall we recommend to use RQGIS with the long-term release of QGIS (2.14). Nevertheless, RQGIS works also with QGIS 2.18. However, there is a bug in the QGIS Python code. Therefore, one needs to manually change the Python code. Here you find how you can do that:

 

https://github.com/jannes-m/RQGIS#qgis-216-modifications.

 

Regarding this issue, we have already notified the QGIS developers, and they told us that they fixed the issue. Hence, with the release of the next QGIS patch release, the manual adjustment of the Python code should no longer be necessary.

 

Best regards,

 

Jannes

 


 

 

Gesendet: Mittwoch, 23. November 2016 um 20:49 Uhr
Von: "Manuel Spínola" 
An: "Jannes Münchow" 
Cc: "r-sig-geo@r-project.org" 
Betreff: Re: [R-sig-Geo] v.split.length (GRASS) in R




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" :

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 = "" 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@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 Naciona