Overlay Toolset {#overlay-toolset}

From the docs [@esri-gptoolref]:

The Overlay toolset contains tools to overlay multiple feature classes to combine, erase, modify, or update spatial features, resulting in a new feature class. New information is created when overlaying one set of features with another. All of the overlay operations involve joining two sets of features into a single set of features to identify spatial relationships between the input features.

knitr::include_graphics("images/network/Analysis_Overlay.png")

For this chapter, you will need the following R Packages:

library(arc2r)
library(sf)
library(dplyr)
library(ggplot2)

Spatial Join {#spatial-join}

@esri-gptoolref describes Spatial Join as follows:

Joins attributes from one feature to another based on the spatial relationship. The target features and the joined attributes from the join features are written to the output feature class.

Say you have two datasets, haltestelle_bahn and kantonsgebiet as shown below.

data("haltestelle_bahn")
data("kantonsgebiet")


head(haltestelle_bahn)
head(kantonsgebiet)


plot(st_geometry(kantonsgebiet))
plot(haltestelle_bahn, add = TRUE, col = "blue", pch = 20)

For each point in haltestelln_bahn, we would like to know the name of the canton in which it is located. In R, the function used to join two datastes is st_join(x,y). If you have to different data types (e.g. Points and Polygons) the first question you have to ask yourself is: what data type should the output be? The datatype of x determines what the output datatype is. So with the above data: Say for each point, we want to know the Name (name) of the "Canton" in which it lies. This means the output is a point dataset. We therefore write:

haltestelle_bahn_join <- st_join(haltestelle_bahn,kantonsgebiet)


haltestelle_bahn_join

The following visualisation shows that each point has inherited the Name of the according Canton.

ggplot() +
  geom_sf(data = kantonsgebiet) +
  geom_sf(data = haltestelle_bahn_join, aes(colour = NAME)) 

By default, the spatial relationship between haltestellen_bahn and kantonsgebiet was that of an "intersection" (this is also de default in ArcGIS). However, we can do spatial joins with other relationships as well: These relationships are commonly known as "spatial predicates".

| ArcGIS Term | R Spatial Predicate | |---------------------------------|-------------------------| | Intersect | st_intersect | | Intersect 3D | $^1$ | | Within a distance | st_is_within_distance | | Within a distance geodesic | $^2$ | | Within a distance 3D | $^1$ | | Contains | st_contains | | Completely contains | st_contains_properly | | Contains clementini | $^2$ | | Within | st_within | | Completely within | $^2$ | | Within clementini | $^2$ | | Are identical to | st_equals | | boundry touches | st_touches | | Share a line segment | $^2$ | | Have their center in | $^2$ | | Closest | st_nearest_feature | | Closest geodesic | $^2$ |

$^1$ All binary predicates only work on 2D Objects (see this issue)

$^2$ We haven't figured out which Spatial Predicate matches this ArcGIS term.



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