Chapter 6 Geoprocessing
6.1 Lesson Goals
A quick look at a couple typical topological operations (spatial subsetting, spatial joins, dissolve) using sf
6.2 Example one
6.2.1 Spatial Subsetting
Let’s look at the bike paths and parks data in the awra2020spatial
package. A typical spatial question we might ask of our data is ‘what trails go through parks in town?’ A great feature of sf
is it supports spatial indexing:
6.3 Example two
6.3.1 Spatial Join
First we’ll use chained operations to select just a couple columns from both bike_paths and parks, and then we’ll do a spatial join operation in sf
. Note again, when we do a select on just attribute column, the geometry column remains - geometry is sticky in sf
!
library(dplyr)
bike_paths <- bike_paths %>%
dplyr::select(ROUTE_NAME)
parks <- parks %>%
dplyr::select(LOCATION_NAME, ZIPCODE,PARK_TYPE)
parks_bike_paths <- st_join(parks, bike_paths) # st_intersects is the default
glimpse(parks_bike_paths)
## Rows: 606
## Columns: 5
## $ LOCATION_NAME <chr> "Stratford Overlook Greenbelt", "Highland Neighborhoo...
## $ ZIPCODE <chr> "78746", "78752", "78703", "78753", "78724", "78702",...
## $ PARK_TYPE <chr> "Greenbelt", "Neighborhood", "Pocket", "Neighborhood"...
## $ ROUTE_NAME <chr> NA, NA, NA, NA, NA, NA, "TOWN LAKE HIKE & BIKE TRAIL"...
## $ geoms <MULTIPOLYGON [°]> MULTIPOLYGON (((-97.78802 3..., MULTIPOL...
6.4 Example Three
6.4.1 Dissolve
We can perform a spatial dissolve in sf
using dplyr
group_by
and summarize
functions with an sf
object!
Note that we could pull down tidycensus
at tract level, but instead we want to look at running a dissolve to get from block group to tract level