| snapTo | R Documentation |
Move the points in x onto the edge of the corresponding line or polygon in y.
A point that touches the the target geometry is not changed. A point that is outside the geometry is moved to the nearest location on the edge (the boundary of a polygon, or the line itself).
## S4 method for signature 'SpatVector,SpatVector'
snapTo(x, y, paired=TRUE, ...)
x |
SpatVector of points |
y |
SpatVector of lines or polygons. Either with the same number of geometries as there are points in |
paired |
logical. If |
... |
additional arguments. None implemented |
SpatVector of points
nearest, distance, furdist
crs <- "+proj=utm +zone=1"
p <- vect("POLYGON ((0 0, 8 0, 8 9, 0 9, 0 0))", crs=crs)
# one point inside the polygon (unchanged), one outside (snapped to the edge)
pts <- vect(cbind(c(4, 12), c(4, 4)), crs=crs)
s <- snapTo(pts, p)
crds(s)
# snap to a line
L <- vect("LINESTRING (0 0, 10 0)", crs=crs)
q <- vect(cbind(c(5, 5), c(0, 3)), crs=crs)
crds(snapTo(q, L))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.