spatialEco (version 1.3-2)

erase.point: Erase points

Description

Removes points intersecting a polygon feature class

Usage

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

Arguments

y

A SpatialPoints or SpatialPointsDataFrame

x

A SpatialPolygons or SpatialPolygonsDataFrame

inside

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

Value

A SpatialPoints or SpatialPointsDataFrame

Examples

Run this code
# NOT RUN {
library(sp)
library(raster)
library(rgeos)
  data(meuse)
  coordinates(meuse) = ~x+y

# Create systematic sample and polygons
s <- spsample(x=as(extent(meuse), "SpatialPolygons"), n=1000,
              type="regular")
b <- rgeos::gBuffer(s[sample(1:length(s),5),],
                    byid = FALSE, width = 300)

# Erase points based on polygons
s.erase <- erase.point(s, b)
 
 opar <- par(no.readonly=TRUE)
 par(mfrow=c(2,2))
   plot(s, pch=20, main="original data")
   plot(b, main="erased data")
     points(s.erase, pch=20)
   plot(b, main="erased data using inside=FALSE")
     points(erase.point(s, b, inside=FALSE), pch=20)
 par(opar)

# }

Run the code above in your browser using DataCamp Workspace