Skip to content
Prev 20301 / 29559 Next

Calculate distance along a path

On Wed, 29 Jan 2014, Javier Garcia-Pintado wrote:

            
maptools::snapPointsToLines by Germ?n Carrillo - please use SVN 
revision 279 from R-Forge until the next maptools release.

library(sp)
library(rgeos)
l1 <- readWKT("LINESTRING(0 0, 1 1)")
set.seed(1)
pts <- SpatialPoints(cbind(runif(5), runif(5)))
plot(l1, axes=TRUE)
points(pts)
text(coordinates(pts), labels=row.names(pts), pos=4)
library(maptools)
res <- snapPointsToLines(pts, l1)
points(res, pch=16, col="red")
text(coordinates(res), labels=row.names(res), pos=4, col="red")

Roger