Street Maps
Create street map art with R and road network files
Data
STATCAN road network files
Germany rail roads
My shape files
Prepare Data
# Load libraries
library(tidyverse)
library(sf)
myCaption <- "www.dblogr.com/ or derekmichaelwright.github.io/dblogr/"
# STATCAN file
roads <- st_read("lrnf000r16a_e.shp")
# Filter cities
roads_saskatoon <- roads[roads$CSDNAME_L == "Saskatoon",]
roads_regina <- roads[roads$CSDNAME_L == "Regina",]
# Save
st_write(roads_saskatoon, "roads_saskatoon.shp")
st_write(roads_regina, "roads_regina.shp")
#
s_roads <- st_read("railways.shp")
Maps
Saskatoon
# Read file
s_roads <- st_read("roads_saskatoon.shp", quiet = T)
# Crop
s_roads2 <- st_intersection(s_roads, st_buffer(st_centroid(st_union(s_roads)), 8500))
# Plot
mp <- ggplot(s_roads2) +
geom_sf(color = "black") +
coord_sf(crs = st_crs(4326)) +
theme_void() +
theme(panel.grid.major = element_line("transparent")) +
labs(caption = myCaption)
ggsave("roads_saskatoon.png", mp, bg = "transparent", width = 6, height = 6)
# Crop
s_roads2 <- st_intersection(s_roads, st_buffer(st_centroid(st_union(s_roads)), 4000))
# Plot
mp <- ggplot(s_roads2) +
geom_sf(color = "black") +
coord_sf(crs = st_crs(4326)) +
theme_void() +
theme(panel.grid.major = element_line("transparent")) +
labs(caption = myCaption)
ggsave("roads_saskatoon_zoom.png", mp, bg = "transparent", width = 6, height = 6)
Regina
# Read file
r_roads <- st_read("roads_regina.shp", quiet = T)
# Crop
r_roads2 <- st_intersection(r_roads, st_buffer(st_centroid(st_union(r_roads)), 5000))
# Plot
mp <- ggplot(r_roads2) +
geom_sf(color = "black") +
coord_sf(crs = st_crs(4326)) +
theme_void() +
theme(panel.grid.major = element_line("transparent")) +
labs(caption = myCaption)
ggsave(filename = "roads_regina.png", mp, bg = "transparent", width = 6, height = 6)
Germany Railroads
# Read file
rail_roads <- st_read("railways.shp", quiet = T)
# Plot
mp <- ggplot(rail_roads) +
geom_sf(color = "black") +
coord_sf(crs = st_crs(4326)) +
theme_void() +
theme(panel.grid.major = element_line("transparent")) +
labs(caption = myCaption)
ggsave("railroads_germany.png", mp, bg = "transparent", width = 6, height = 6)
rcityviews
https://koenderks.github.io/rcityviews/
## name country lat long
## 1 Amstelveen The Netherlands 52.32 4.86
## 2 Amsterdam The Netherlands 52.37 4.89
## 3 Amstetten Austria 48.13 14.86
## 4 New Amsterdam Guyana 6.25 -57.53
## 5 Nieuw Amsterdam Suriname 5.91 -55.07
city <- new_city(name = "Lagos", country = "Portugal", lat = 37.10, long = -8.68)
#
p <- cityview(name = "Amsterdam", zoom = 1) # or cityview(name = city)
# see ?cityview for more input parameters of this function
ggplot2::ggsave(filename = "Amsterdam.png", plot = p, height = 500, width = 500, units = "mm", dpi = 100)
xx <- list_cities()
xx <- list_cities(match = "Saskatoon")
#
p <- cityview(name = "Saskatoon", zoom = 0.5) # or cityview(name = city)
city <- new_city(name = "Lagos", country = "Portugal", lat = 37.10, long = -8.68)
# see ?cityview for more input parameters of this function
ggplot2::ggsave(filename = "Saskatoon.png", plot = p, height = 500, width = 500, units = "mm", dpi = 100)