Extract vertices for polygons or lines
Extracts [x,y] vertices from an sp line or polygon object
extract.vertices(x, as.sp = FALSE, rm.duplicates = FALSE, join = FALSE)
x |
An sp class SpatialPolygonsDataFrame, SpatialPolygons, SpatialLinesDataFrame or SpatialLines object |
as.sp |
(FALSE/TRUE) Output as sp SpatialPointsDataFrame |
rm.duplicates |
(FALSE/TRUE) remove duplicate (x,y) coordinates |
join |
(FALSE/TRUE) Joint attributes from original object |
A SpatialPointsDataFrame or data.frame with id, x, y and merged attributes
This function returns the vertices of a line or polygon object, as opposed to the polygon centroids or line start/stop coordinates available in the @coords slot. This requires accessing the coordinates located in the x@polygons@Polygons or x@lines@Lines slots
Jeffrey S. Evans <jeffrey_evans@tnc.org>
library(sp) library(raster) library(GeNetIt) # For polygons r <- raster(xmn=-11.69, xmx=2988.31, ymn=-749.97, ymx=1650.03, resolution=c(100,100)) r[] <- runif(ncell(r)) names(r) <- "random_process" polys <- as(r, "SpatialPolygonsDataFrame") polys <- polys[sample(1:nrow(polys),10),] extract.vertices(polys, join=TRUE, rm.duplicates=TRUE) v <- extract.vertices(polys, as.sp=TRUE, join=TRUE) head(v@data) plot(polys) points(v, pch=20, cex=2, col="red") # For lines pts <- sampleRandom(r, 10, sp=TRUE) graph <- GeNetIt::knn.graph(pts) extract.vertices(graph) extract.vertices(graph, join=TRUE, rm.duplicates=TRUE) v <- extract.vertices(graph, as.sp=TRUE, join=TRUE) head(v@data) plot(graph) points(v, pch=20, cex=2, col="red")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.