5.1 Select by Attribute

One of the popular approaches in ArcGIS pro for selecting features in a layer is by using an attribute query. The action is performed using the Select By Attributes tool.

Select By Attributes tool allows us to provide an SQL query expression to select features that match the selection criteria.

R on the other hand offers quite easy and straightforward options to perform similar operations. Let’s examine one of them.

As a first step, we might want to import a shapefile. To do so, we can use sf package to work with vector data in R. Important to know is that the rgdal package automatically loads when sf is loaded.

In the code snippet below, we read the shapefile, which represents the parking spots for bicycles within the canton of Zurich. The dataset is publicly available for download in the following link: (https://opendata.swiss/en/dataset/veloparkierungsanlagen).

library(sf)
library(ggplot2)
data("veloparkierungsanlagen_zh")

After importing the dataset, let’s say we want to filter it by selecting only the parking spots that lie within a specific municipality (Gemeinde) in the canton of Zurich. More specifically, we will select only the parking spots within the municipality of Winterthur. For the aforementioned operation, R offers the function filter(), which lies within the dplyr package. This functions works as follows: filter(dataset, condition)

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:terra':
## 
##     collapse, desc, intersect, near, select, union
## The following objects are masked from 'package:raster':
## 
##     intersect, select, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
parkBikes_winti <- filter(veloparkierungsanlagen_zh,GEMEINDE == "Winterthur")

The operation above produces the same outcome as the one depicted in the figure below 5.2.

Select by Attributes in ArcGIS pro

Figure 5.2: Select by Attributes in ArcGIS pro