- The same as handling any other kind of data in R
- But: dynamic, complex (e.g. GTFS) reliant on official feeds
- That's why using a language that is powerful and flexible is good
Slides: rpubs.com/RobinLovelace
# u_pct = "https://github.com/npct/pct-data/raw/master/west-yorkshire/l.Rds" # download.file(u_pct, "l.Rds") library(stplanr)
## Loading required package: sp
l = readRDS("l.Rds")
plot(l)
sel_walk = l$foot > 9 l_walk = l[sel_walk,] plot(l) plot(l_walk, add = T, col = "red")
library(dplyr) # for next slide...
## ## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats': ## ## filter, lag
## The following objects are masked from 'package:base': ## ## intersect, setdiff, setequal, union
l_walk1 = l %>% filter(All > 10) # fails
library(sf)
## Linking to GEOS 3.5.1, GDAL 2.1.3, proj.4 4.9.2, lwgeom 2.3.2 r15302
l_sf = st_as_sf(l) plot(l_sf[6])
l_walk2 = l_sf %>% filter(foot > 9) plot(l_sf[6]) plot(l_walk2, add = T)
l_sf$distsf = as.numeric(st_length(l_sf)) summary(l_sf$distsf)
## Min. 1st Qu. Median Mean 3rd Qu. Max. ## 589.7 5204.3 8343.3 8910.0 12238.3 20034.3
l_drive_short = l_sf %>% filter(distsf < 1000 & car_driver > foot) l_drive_short2 = l_sf %>% filter(distsf < 1000) %>% filter(car_driver > foot) l_short = l_sf %>% filter(distsf < 1000) plot(l_drive_short[6])
devtools::install_github("osmdatar/osmdata")
library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
q = opq(bbox = "Leeds") %>% add_feature(key = "railway", value = "station") stations = osmdata_sf(q = q) plot(l_sf[6]) plot(stations$osm_points, add = T)