[R-sig-Geo] shortestPath in a loop

marta azores martazores at gmail.com
Tue Jan 24 21:06:46 CET 2017


Hi guys,

I'm still trying to solve my deal. How I can join the survey boat points
using the shortestpath function, to avoid the land. It's important because
I need an output "spatialLines"(boat surveys) to intersect with points(
species points).
I add several files : script and other layers of information.

Thanks in advance,

Marta

2017-01-16 9:45 GMT-01:00 marta azores <martazores at gmail.com>:

> Hi Jerome,
>
> There are several R packages to join points. However, I have two relevant
> issues with them.
>  -The first,  I need to get the "Lines" from these tracks in "spatial
> Lines". For example, in the adehabitatLT package you can get easily the
> trajectories of the animal but with the class " ltraj". I don't know
>    how transform this object class into spatial lines.
> -The second, when I made the tracks I need to avoid the coast, and I don't
> know how do that in adehabitatLT.
>
> Any idea?
>
> Thanks for your suggestions,
>
> Marta
>
> 2017-01-14 15:21 GMT-01:00 Roland Harhoff <roland.harhoff at uni-muenster.de>
> :
>
>> Hi Marta,
>>
>> and did you check the trajectories package ...?
>>
>> https://cran.r-project.org/web/packages/trajectories/index.html
>>
>> Cheers!
>> Roland
>>
>>
>> Jérome Mathieu schrieb am 2017-01-14:
>> > Hi,
>>
>> > Did you have a look at the package adehabitatLT?
>>
>> > https://cran.r-project.org/web/packages/adehabitatLT/vignett
>> es/adehabitatLT.pdf
>>
>> > It deals with trajectories based on points ordered by date.
>>
>> > Jerome
>>
>>
>> > 2017-01-13 11:41 GMT+01:00 marta azores <martazores at gmail.com>:
>>
>> > > Thanks for your quick reply to my question,
>> > >
>> > > This ten points are ordered by time (date + time), and I know ,the
>> points
>> > > are all connected.  I didn't include the column with the time in this
>> > > example, to make it simple.
>> > >
>> > > After read your messages, I was looking the minimum spanning tree for
>> the
>> > > vertices.
>> > > The advantage with the function "shortestPath" is that you have as
>> result a
>> > > spatial line output, which I need it.
>> > > However, the minimum spanning tree give as output an ordiplot.
>> > >
>> > > Is it possible to transform the ordiplot into spatialLines?
>> > >
>> > > Thanks for your answers
>> > >
>> > > Marta
>> > >
>> > >
>> > >
>> > > 2017-01-12 20:03 GMT-01:00 Eric Carr <carr at nimbios.org>:
>> > >
>> > > > Generically independent of R, A graph and the connectivity between
>> points
>> > > > needs defined before a shortest path algorithm can be applied.  If
>> it
>> > > > assumes all points are connected, than the shortest path will be a
>> > > straight
>> > > > line.  What you are looking for is some sort of  minimum spanning
>> tree
>> > > for
>> > > > the vertices.
>> > > > Eric
>> > > >
>> > > > On Thu, Jan 12, 2017 at 11:17 AM, marta azores <
>> martazores at gmail.com>
>> > > > wrote:
>> > > >
>> > > >> Dear forum members,
>> > > >>
>> > > >> I would like to know how join several points with the aim to track
>> a
>> > > ship.
>> > > >>
>> > > >> After reading the documentation of some packages, I decided to use
>> the
>> > > >> function shortestPath, but I only got the line between the first
>> and the
>> > > >> last location of my points list. I need the complete survey,
>> including
>> > > also
>> > > >> the middle points. I try a loop to build the survey of the boats
>> using
>> > > >> their locations, but It didn't work to me.
>> > > >>
>> > > >>
>> > > >> Any idea?
>> > > >>
>> > > >> Thanks in advance,
>> > > >>
>> > > >> Marta
>> > > >>
>> > > >> #script# it's also attached in a R.file: question loop2.R
>> > > >> ##########################################################
>> > > >> #
>> > > >> #raster# it's attached
>> > > >> azoTS1<- raster("C:/Users/Documents/azoTS1.tif")#wgs84
>> > > >> #
>> > > >> #10 points# it's attached
>> > > >> boat <- read.table("C:/Users/Documents/10pontos.csv", header=TRUE,
>> > > >> sep=",", na.strings="NA", dec=".", strip.white=TRUE)#
>> > > >> head(boat)
>> > > >>
>> > > >> #raster to transitionlayer
>> > > >> trCostS4<- transition(1/azoTS1, mean, directions=4)
>> > > >>
>> > > >> # points to spatialpointsdataframe
>> > > >> x=boat$Long1
>> > > >> y=boat$Lat1
>> > > >> coords = cbind(x, y)
>> > > >> plot(coords)
>> > > >> sp = SpatialPoints(coords, proj4string=CRS("+proj=longlat
>> +ellps=WGS84
>> > > >> +datum=WGS84"), bbox = NULL)
>> > > >> sp
>> > > >> spdf=SpatialPointsDataFrame(sp,boat)
>> > > >> spdf
>> > > >> nrow(spdf)
>> > > >> plot(sp,axes=TRUE)
>> > > >> plot(spdf,add=TRUE, axes=TRUE)
>> > > >>
>> > > >> #shortestpath
>> > > >>
>> > > >> ## 1) this script only join the first point of the list and the
>> last
>> > > one,
>> > > >> and the points in the middle are not used.
>> > > >> CostpathSPdf <- shortestPath(trCostS4, spdf[1,], spdf[10,],
>> > > >> output="SpatialLines")
>> > > >> plot(CostpathSPdf,add=TRUE,axes=TRUE,col=2)#R_plot1.png (it's
>> attached)
>> > > >>
>> > > >> ## 2) this script didn't work to me
>> > > >>
>> > > >> #first way from website: http://stackoverflow.com/quest
>> > > >> ions/8127066/loop-or-sapply-function-for-multiple-least-
>> > > >> cost-analysis-in-r?answertab=active#tab-top
>> > > >> for(i in 1:nrow(spdf)) {
>> > > >>   # Computation
>> > > >>   Costpath <- shortestPath(trCostS4, spdf[i,], spdf[10,],
>> > > >> output="SpatialLines")
>> > > >>   plot(Costpath)
>> > > >>
>> > > >> }
>> > > >>
>> > > >> #Error in validObject(.Object) :
>> > > >> #invalid class “SpatialLines” object: bbox should never contain
>> infinite
>> > > >> values
>> > > >>
>> > > >> _______________________________________________
>> > > >> R-sig-Geo mailing list
>> > > >> R-sig-Geo at r-project.org
>> > > >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> > > >>
>> > > >
>> > > >
>> > >
>> > >         [[alternative HTML version deleted]]
>> > >
>> > > _______________________________________________
>> > > R-sig-Geo mailing list
>> > > R-sig-Geo at r-project.org
>> > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> > >
>>
>>
>>
>> > --
>> > Jérôme Mathieu <http://www.jerome-mathieu.com/>
>> > Université Pierre & Marie Curie <http://www.upmc.fr/>
>> > Institute of Ecology and Environmental Science (Paris)
>> > <https://ieesparis.ufr918.upmc.fr/>
>> > Team EERI
>>
>> > 4 place Jussieu
>> > Tour 44-45, 5th floor, door 514
>> > 75005 Paris
>>
>> > tel: 01 44 27 34 22
>>
>> >       [[alternative HTML version deleted]]
>>
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > R-sig-Geo at r-project.org
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170124/fef9941f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: azoTS1.tif
Type: image/tiff
Size: 1841 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170124/fef9941f/attachment.tif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: boat2905.csv
Type: text/csv
Size: 585 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170124/fef9941f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: question4.R
Type: application/octet-stream
Size: 4659 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170124/fef9941f/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sp2pontosDT.csv
Type: text/csv
Size: 107 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170124/fef9941f/attachment-0001.bin>


More information about the R-sig-Geo mailing list