extract.vertices

0th

Percentile

Extract vertices for polygons or lines

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

Note

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

Aliases
  • extract.vertices
Examples
# 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")

# }
Documentation reproduced from package spatialEco, version 1.3-2, License: GPL-3

Community examples

Looks like there are no examples yet.