Extract Toolset {#extract-toolset}

From the docs [@esri-gptoolref]:

GIS datasets often contain more data than you need. The Extract tools let you select features and attributes in a feature class or table based on a query (SQL expression) or spatial and attribute extraction. The output features and attributes are stored in a feature class or table.

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

library(arc2r)
library(sf)
library(tmap)

Clip {#clip}

Quite often in spatial analysis, we come across cases where we do not want to use all the available data there is. In other words, we want to focus on a specific area of interest, which dictates the need for clipping the existing dataset based on it's relationship to some other existing spatial feature. In R this operation can be easily performed using the st_intersection function in sf.

Let's assume in the example below that we want to clip the available dataset of all the train stations in Switzerland by focusing our analysis on the cantons Zurich, St. Gallen, Thurgau and Aargau. In the following chunk we prerpare and visualize this situation.

# Point dataset depicting the train stations locations across Switzerland
data("haltestelle_bahn")

# Dataset depicting Switzerland on canton level
data("kantonsgebiet")

kanton_filter <- filter(kantonsgebiet, NAME %in% c("Zürich","St. Gallen","Thurgau","Aargau"))

plot(st_geometry(haltestelle_bahn))
plot(st_geometry(kanton_filter), col = "grey", add = TRUE,alpha = 1)

To clip the dataset haltestellen_bahn to the extent of _kanton_filter, we can simply use the st_intersection function as shown below:

haltestelle_bahn_clipped <- st_intersection(kanton_filter, haltestelle_bahn)

We can now visualize the result from our operation:

plot(st_geometry(haltestelle_bahn_clipped))
plot(st_geometry(kanton_filter), add = TRUE,alpha = 1)

So, ultimately, as we can see above, the st_intersection function creates a result where the point dataset is precisely "clipped" based on the area of interest. The operation above produces the same outcome as the one depicted in the figure below \@ref(fig:clip).

knitr::include_graphics("images/clipOperation.png")

Select {#select}

This chapter is covered in \@ref(select-by-attribute).

Split {#split}

The split tool is used in ArcGIS to split a dataset into multiple outputs.

When clipping the haltestellen dataset in \@ref(clip) with a polygon containing multiple features (kanton_filter). Each point in haltestelle_bahn_clipped now has the attributes originating from kanton_filter, which we can use to split the dataset into different parts. The function split() (from base-R) helps us with this. It returns a list of sf objects, that we can each save in it's own dataset if need be.

haltestellen_split <- split(haltestelle_bahn_clipped,haltestelle_bahn_clipped$name)

str(haltestellen_split[1:2])

Split by Attributes {#split-by-attributes}

See \@ref(split).



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