12 Spatial Predicates
In Opensource GIS Applications, there is a common standard to describe various relationships between features. They are referred to as “Spatial predicates” and are defined as follows. Take two geometries, a and b:
- Equals:
aandbare equal if- their interiors intersect and
- no part of the interior or boundary of one geometry intersects the exterior of the other
- Disjoint:
aandbare disjoint if they have no point in common (they form a set of disconnected geometries) - Touches:
aandbtouch if- they have at least one point in common but
- their interiors do not intersect
- Contains:
acontainsbif- no points of
blie in the exterior ofaand - at least one point of the interior of
blies in the interior ofa
- no points of
- Covers:
acoversbif at least one point ofblies ina, and no point ofblies in the exterior ofa - Intersects:
aandbintersect if the two geometries have at least one point in common - Within (inside):
ais withinbifalies in the interior of theb - CoveredBy:
ais covered bybifalies inb - Crosses:
acrossesbif they have some but not all interior points in common. - Overlaps:
aoverlapsb- if they have some (but not all) points in common and
- they have the same dimension and
- the intersection of the interiors of the two geometries has the same dimension as the geometries themselves
12.1 Named predicates
12.1.1 Touches
Lets take the example of a chessboard:
library(sf)
library(dplyr)
library(arc2r)
data("chessboard")
chessplot <- ggplot(chessboard) + geom_sf(aes(fill = colour)) + geom_sf_label(aes(label = i)) +
scale_x_continuous(breaks = 1:8 - 0.5, labels = letters[1:8]) + scale_y_continuous(breaks = 1:8 -
0.5, labels = 1:8) + scale_fill_manual(values = c(black = "black", white = "white")) +
theme_void() + theme(legend.position = "none")
chessplot
To find out which field touch field number 36, we can write the following line of code:
st_touches(chessboard[36, ], chessboard)## Sparse geometry binary predicate list of length 1, where the predicate was `touches'
## 1: 27, 28, 29, 35, 37, 43, 44, 45
Visually, these are the following fields:
sel36 <- st_touches(chessboard[36, ], chessboard)[[1]]
chessplot + geom_sf(data = chessboard[36, ], fill = "blue", alpha = 0.4) + geom_sf(data = chessboard[sel36,
], fill = "red", alpha = 0.4)