spatialEco (version 1.3-2)

extract.vertices: Extract vertices for polygons or lines

Description

Extracts [x,y] vertices from an sp line or polygon object

Usage

extract.vertices(x, as.sp = FALSE, rm.duplicates = FALSE, join = FALSE)

Arguments

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

Value

A SpatialPointsDataFrame or data.frame with id, x, y and merged attributes

Examples

Run this code
# NOT RUN {
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")

# }

Run the code above in your browser using DataLab