Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elipousson/6484cd18c34236467d4563db74e2e4f6 to your computer and use it in GitHub Desktop.
Save elipousson/6484cd18c34236467d4563db74e2e4f6 to your computer and use it in GitHub Desktop.
An R script to update the exif metadata for titles and descriptions for a photographs (in a single folder) of streets and intersections in Baltimore, MD. Related thread: https://twitter.com/elipousson/status/1569722352954490880
# pak::pkg_install("elipousson/mapbaltimore")
# pak::pkg_install("elipousson/sfext")
# pak::pkg_install("elipousson/getdata")
library(dplyr)
library(purrr)
library(sfext)
library(mapbaltimore)
# path = # path to folder with photos
data <-
read_sf_exif(
path = path
)
bbox_exp <-
st_bbox_ext(
x = sf::st_union(data),
# Arbitrary expansion parameter to get features around all photos
diag_ratio = 0.125
)
area_streets <-
getdata::get_location_data(
location = bbox_exp,
data = mapbaltimore::streets
) %>%
mutate(
name = stringr::str_to_title(blocktext) %>%
stringr::str_replace("[:space:]Blk[:space:]", " block ")
)
area_intersections_pts <-
getdata::get_location_data(
location = bbox_exp,
data = mapbaltimore::named_intersections
) %>%
mutate(
name = stringr::str_to_title(name)
)
area_intersections_pavement <-
getdata::get_location_data(
location = area_intersections_pts,
# data must be cached from mapbaltimore package - unsure if cache functions are working
data = "edge_of_pavement",
package = "mapbaltimore"
) %>%
st_filter_ext(area_intersections_pts) %>%
st_buffer_ext(8) %>%
left_join(
sf::st_drop_geometry(area_intersections_pts),
by = "id"
) %>%
mutate(
# manual recoding of missing intersection names
name = case_when(
id == 85485 ~ "6th St & Brooklyn Ave & Audrey Ave",
id == 86251 ~ "6th St",
id == 86224 ~ "6th St",
TRUE ~ name
)
)
intersection_data <-
data %>%
st_filter_ext(
y = area_intersections_pavement
)
street_data <-
data %>%
filter(!(path %in% intersection_data$path))
write_exif_from(
path = street_data,
from = area_streets,
tag = "title",
join = sf::st_nearest_feature
)
write_exif(
path = street_data$path,
keywords = "street"
)
write_exif_from(
path = intersection_data,
from = area_intersections_pavement,
tag = "title",
join = sf::st_nearest_feature
)
write_exif(
intersection_data$path,
keywords = "intersection"
)
districts <- mapbaltimore::council_districts
districts$name <- paste0("Baltimore City Council ", districts$name)
write_exif_from(
path,
from = districts
)
write_exif_from(
path,
from = mapbaltimore::neighborhoods
)
walk2(
data$path,
paste0("View facing ", data$img_cardinal_wind),
~ write_exif(
path = .x,
description = .y,
overwrite = TRUE
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment