<div dir="ltr"><div>Dear forum members,</div><div><br></div><div>I would like to know how join several points with the aim to track a ship.</div><div><br></div><div>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.</div><div><span><br></span></div><div><br></div><div>Any idea?</div><div><br></div><div>Thanks in advance,</div><div><br></div><div>Marta<br></div><div><br></div><div>#script# it's also attached in a R.file: question loop2.R</div><div>##########################################################</div><div>#<br>#raster# it's attached<br>azoTS1<- raster("C:/Users/Documents/azoTS1.tif")#wgs84</div><div>#<br>#10 points# it's attached<br>boat <- read.table("C:/Users/Documents/10pontos.csv", header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE)#    </div><div>head(boat)</div><div><br>#raster to transitionlayer<br>trCostS4<- transition(1/azoTS1, mean, directions=4)</div><div><br></div><div># points to spatialpointsdataframe<br>x=boat$Long1<br>y=boat$Lat1<br>coords = cbind(x, y)<br>plot(coords)<br>sp = SpatialPoints(coords, proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"), bbox = NULL)<br>sp<br>spdf=SpatialPointsDataFrame(sp,boat)<br>spdf<br>nrow(spdf)<br>plot(sp,axes=TRUE)<br>plot(spdf,add=TRUE, axes=TRUE)</div><div><br></div><div>#shortestpath</div><div><br>## 1) this script only join the first point of the list and the last one, and the points in the middle are not used.<br>CostpathSPdf <- shortestPath(trCostS4, spdf[1,], spdf[10,], output="SpatialLines") <br>plot(CostpathSPdf,add=TRUE,axes=TRUE,col=2)#R_plot1.png (it's attached)</div><div><br>## 2) this script didn't work to me</div><div><br>#first way from website: <a href="http://stackoverflow.com/questions/8127066/loop-or-sapply-function-for-multiple-least-cost-analysis-in-r?answertab=active#tab-top">http://stackoverflow.com/questions/8127066/loop-or-sapply-function-for-multiple-least-cost-analysis-in-r?answertab=active#tab-top</a><br>for(i in 1:nrow(spdf)) {<br>  # Computation<br>  Costpath <- shortestPath(trCostS4, spdf[i,], spdf[10,], output="SpatialLines") <br>  plot(Costpath)<br><br>}</div><div><br></div><div>#Error in validObject(.Object) : <br>#invalid class “SpatialLines” object: bbox should never contain infinite values</div></div>