diff --git a/scripts/02_reporting/0180-photos-extract-metadata.R b/scripts/02_reporting/0180-photos-extract-metadata.R index ddc34e0..3a18ba8 100644 --- a/scripts/02_reporting/0180-photos-extract-metadata.R +++ b/scripts/02_reporting/0180-photos-extract-metadata.R @@ -5,21 +5,21 @@ # define your project repo name b/c this is not repo_name <- 'fish_passage_skeena_2023_reporting' -photo_metadata_prep <- exifr::read_exif('data/photos',recursive=T) %>% - janitor::clean_names() %>% - select(file_name, source_file, create_date, gps_latitude, gps_longitude) %>% +photo_metadata_prep <- exifr::read_exif('data/photos',recursive=T) |> + janitor::clean_names() |> + select(file_name, source_file, create_date, gps_latitude, gps_longitude) |> mutate(url = paste0('https://github.com/NewGraphEnvironment/', repo_name, '/raw/main/', - source_file)) %>% + source_file)) |> # filter photos used in hab con site memos, but do not include photos used for pscis phase 2 submission portal as we don't want to clutter map # portal photos have been labelled '_k_nm' to distinguish them, they are still committed to repo - filter( - file_name %like% '_k_'& !file_name %like% '_nm_' - ) %>% + dplyr::filter( + stringr::str_detect(file_name, "_k_") & !stringr::str_detect(file_name, "_nm_") + ) |> mutate(create_date = lubridate::as_datetime(create_date, tz="America/Vancouver")) -# MW photos aren't georeferenced so link them to tracks +# some of what I think are MW photos aren't georeferenced so link them to tracks # read in tracks -track_points_prep = read_sf('data/habitat_confirmation_tracks.gpx', layer = "track_points") +track_points_prep = read_sf('data/gps/skeena_2023_field_mw.gpx', layer = "track_points") track_points <- track_points_prep %>% st_coordinates() %>% @@ -27,8 +27,10 @@ track_points <- track_points_prep %>% setNames(c("gps_longitude","gps_latitude")) %>% rowid_to_column() + +# 'TimePhoto' seems to be naming convention for photos taken by MW mw_photos <- photo_metadata_prep %>% - filter(source_file %like% 'TimePhoto') %>% + dplyr::filter(stringr::str_detect(source_file, 'TimePhoto')) %>% select(file_name, source_file, create_date) %>% mutate(create_date = lubridate::as_datetime(create_date, tz="America/Vancouver")) @@ -52,6 +54,8 @@ indx_closest_point <- sapply(mw_photos$create_date, as_tibble() # closest point corresponds to row id in track points so join dataframes +# this step should only replace the coordinates when they are not already present. +# thinking left_join with a case_when joined_tracks <- left_join(indx_closest_point, track_points, by = c('value' = 'rowid')) %>% mutate(gps_latitude = as.character(gps_latitude)) %>% mutate(gps_longitude = as.character(gps_longitude)) @@ -62,18 +66,18 @@ photo_metadata_processed <- bind_cols(mw_photos, joined_tracks) %>% mutate(url = paste0('https://github.com/NewGraphEnvironment/', repo_name, '/raw/main/', source_file)) -photo_metadata <- filter(photo_metadata_prep, !source_file %like% 'TimePhoto') %>% - bind_rows(photo_metadata_processed) %>% - select(-create_date) - +photo_metadata <- photo_metadata_prep |> + dplyr::filter(!str_detect(source_file, 'TimePhoto')) |> + bind_rows(photo_metadata_processed) |> + select(-create_date) -conn <- rws_connect("data/bcfishpass.sqlite") -rws_list_tables(conn) -rws_drop_table("photo_metadata", conn = conn) ##now drop the table so you can replace it -rws_write(photo_metadata, exists = F, delete = TRUE, +conn <- readwritesqlite::rws_connect("data/bcfishpass.sqlite") +readwritesqlite::rws_list_tables(conn) +readwritesqlite::rws_drop_table("photo_metadata", conn = conn) ##now drop the table so you can replace it +readwritesqlite::rws_write(photo_metadata, exists = F, delete = TRUE, conn = conn, x_name = "photo_metadata") -rws_list_tables(conn) -rws_disconnect(conn) +readwritesqlite::rws_list_tables(conn) +readwritesqlite::rws_disconnect(conn)