Spatial Predicates {#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:

Named predicates

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)

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)


arc2r/book documentation built on March 5, 2021, 2:10 p.m.