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:
[, ,]
within the brackets denotes the column number we want to retrieve from the spatial subsetting. In our example this argument was empty, which means we wanted to retrieve all rows for every attribute column. [op = ]
specifies the spatial operation we want to perform. In the example above, the goal was to find out how many subset features of the target object swimmSpots lie withing the source spatial object richterswil. For that reason we chose the function st_within()
.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)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.