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
:
a
and b
are equal ifa
and b
are disjoint if they have no point in common (they form a set of disconnected geometries)a
and b
touch ifa
contains b
ifb
lie in the exterior of a
andb
lies in the interior of a
a
covers b
if at least one point of b
lies in a
, and no point of b
lies in the exterior of a
a
and b
intersect if the two geometries have at least one point in commona
is within b
if a
lies in the interior of the b
a
is covered by b
if a
lies in b
a
crosses b
if they have some but not all interior points in common.a
overlaps b
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.