erase.point {spatialEco}R Documentation

Erase points

Description

Removes points intersecting a polygon feature class

Usage

erase.point(y, x, inside = TRUE)

Arguments

y

A sf POINT object

x

A sf POLYGON object

inside

(TRUE/FALSE) Remove points inside polygon, else outside polygon

Details

Used to erase points that intersect polygon(s). The default of inside=TRUE erases points inside the polygons however, if inside=FALSE then the function results in an intersection where points that intersect the polygon are retained.

Value

An sf POINT object

Author(s)

Jeffrey S. Evans <jeffrey_evans<at>tnc.org>

Examples


library(sf)
  
if (require(sp, quietly = TRUE)) {
  data(meuse, package = "sp")
  meuse <- st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")

  s <- st_as_sf(st_sample(st_as_sfc(st_bbox(meuse)), size=1000, 
                 type = "regular"))
    s$id <- 1:nrow(s)
  b <- st_buffer(s[sample(1:nrow(s),5),], dist=300)
    b$id <- 1:nrow(b)
  
# Erase points based on polygons
in.erase <- erase.point(s, b)
out.erase <- erase.point(s, b, inside = FALSE)

 opar <- par(no.readonly=TRUE)
 par(mfrow=c(2,2))
   plot(st_geometry(s), pch=20, main="original data")
     plot(st_geometry(b),add=TRUE)
   plot(st_geometry(in.erase), pch=20, main="erased data")
     plot(st_geometry(b),add=TRUE)
   plot(st_geometry(out.erase), pch=20,  
        main="erased data using inside=FALSE")
     plot(st_geometry(b),add=TRUE)
 par(opar)

} else { 
  cat("Please install sp package to run example", "\n")
}


[Package spatialEco version 2.0-2 Index]