spatialEco (version 1.3-2)

spatial.select: Spatial Select

Description

Performs a spatial select (feature subset) between a polygon(s) and other feature class

Performs a spatial select of features based on an overlay of a polygon (x), which can represent multiple features, and a polygon, point or line feature classes (y). User can specify a partial or complete intersection, using within argument, or within a distance, using distance argument, predicated on the query polygon. This function is similar to ArcGIS/Pro spatial select. Please note that for point to point neighbor selections use the knn function.

Usage

spatial.select(
  x,
  y = NULL,
  distance = NULL,
  predicate = c("intersect", "contains", "covers", "touches", "proximity",
    "contingency"),
  neighbors = c("queen", "rook")
)

Arguments

x

An sp or sf polygon(s) object that defines the spatial query

y

A sp or sf feature class that will be subset by the query of x

distance

A proximity distance of features to select (within distance)

predicate

Spatial predicate for intersection

neighbors

If predicate = "contingency" type of neighbors options are c("queen", "rook")

Value

An sp object representing a subset of y based on the spatial query of x or, if predicate = contingency a sparse matrix representing neighbor indexes

See Also

gIntersects for details on intersect predicate

gContains for details on contain predicate

gCovers for details on covers predicate

gTouches for details on touches predicate

gWithinDistance for details on proximity predicate

https://en.wikipedia.org/wiki/DE-9IM for details on DE-9IM topology model

Examples

Run this code
# NOT RUN {
library(raster)
library(sp)   

data(meuse)
  coordinates(meuse) <- ~x+y

spolys <- hexagons(meuse, res=100)
p <- raster(extent(spolys), res=800)
  p[] <- runif(ncell(p)) * 10
    p <- rasterToPolygons(p, fun=function(x){x > 6})
	
#### On polygons	 
sub.int <- spatial.select(p, spolys, predicate = "intersect")
sub.contains <- spatial.select(p, spolys, predicate = "contains")
sub.cov <- spatial.select(p, spolys, predicate = "covers")
sub.touches <- spatial.select(p, spolys, predicate = "touches")
sub.prox <- spatial.select(p, spolys, distance=100, predicate = "proximity")

opar <- par(no.readonly=TRUE)
par(mfrow=c(2,3))
  plot(spolys, main="all data")
    plot(p, add=TRUE)  
  plot(sub.int, main="intersects")
    plot(p, add=TRUE) 
  plot(sub.contains, main="contains")
    plot(p, add=TRUE) 
  plot(sub.cov, main="covers")
    plot(p, add=TRUE) 	 
  plot(sub.touches, main="touches")
    plot(p, add=TRUE) 	
  plot(sub.prox, main="Proximity 100m distance")
    plot(p, add=TRUE) 
par(opar)

#### On points 
#### note; touches is not relevant for points and intersect/contains/covers 
####       yield the same results  
sub.int <- spatial.select(p, meuse, predicate = "intersect")
sub.contains <- spatial.select(p, meuse, predicate = "contains")
sub.prox <- spatial.select(p, meuse, distance=200, predicate = "proximity")

opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2))
  plot(meuse, main="all data", pch=20)
    plot(p, add=TRUE)  
  plot(sub.int, main="intersects", pch=20)
    plot(p, add=TRUE) 
  plot(sub.contains, main="contains", pch=20)
    plot(p, add=TRUE) 
  plot(sub.prox, main="Proximity 200m distance", pch=20)
    plot(p, add=TRUE)
par(opar)

#### For rook or queen polygon contingency 	
spolys <- as(sf::st_make_grid(sf::st_sfc(sf::st_point(c(0,0)), 
             sf::st_point(c(3,3))), n = c(3,3)), "Spatial")

spatial.select(spolys, predicate = "contingency")
spatial.select(spolys, predicate = "contingency", neighbors = "rook") 

# }

Run the code above in your browser using DataLab