Select by Location

A very common operations when dealing with geodata is the process of selecting features based on a spatial relationship to another object (layer). In ArcGIS pro this process is usually performed using the Select by Location tool. This tool offers selecting features based on the following relationships:

Note that many these relationships are specified in an elegant, generic approach known as "Spatial Predicates". Read more about this in chapter \@ref(spatial-predicates)

``{block2, type = "rmdnote"} The operations are based on the following rule:x[y, ,operation]`, where:

For this chapter, we will use the following libraries:

```r
knitr::opts_chunk$set(warning = F, message = F, tidy = T)
library(dplyr)
library(sf)
library(ggplot2)
library(arc2r)

Intersect

Intersect_3d

Within_a_distance

Within_a_distance_3d

Within_a_distance_geodesic

Contains

Completely_contains

Contains_clementini

Within

An example of spatial subsetting could be the following. Let's assume we have a polygon dataset with all the municipalities (Gemeinden) of the Canton of Zurich. Furthermore, we are also using a shapefile in the form of a point dataframe, which represents all the "swimming spots" (Badenplätze) in the same spatial region (Canton of Zurich). So, ultimately, our goal is to find out the "swimming spots" that lie within a specific municipality of the Canton of Zurich.

# Minicipalities (Gemeinde) in Canton Zurich
data("gemeindegrenzen_zh")

# "Swimming" spots in the Canton of Zurich
data("badeplaetze_zh")
richterswil <- filter(gemeindegrenzen_zh, GEMEINDENAME == "Richterswil")

ggplot() + 
  geom_sf(data = gemeindegrenzen_zh) + 
  geom_sf(data = richterswil, fill = "red") +
  geom_sf(data = badeplaetze_zh,color = "blue") + 
  ggtitle("Swimming spots in the Canton of Zurich") + 
  theme_minimal() + 
  coord_sf(datum = 2056)
swimmSpots_richt <- badeplaetze_zh[richterswil, ,op = st_within]
ggplot() + 
  geom_sf(data = gemeindegrenzen_zh) + 
  geom_sf(data = badeplaetze_zh,color = "blue") +
  geom_sf(data = richterswil, fill = "white") + 
  geom_sf(data = swimmSpots_richt, color = "red") + 
  ggtitle("Swimming spots in the Canton of Zurich") + 
  theme_minimal() + 
  coord_sf(datum = 2056)

Completely_within

Within_clementini

Are_identical_to

Boundary_touches

Share_a_line_segment_with

Crossed_by_the_outline_of

Have_their_center_in



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