Appendix - UAV Imagery
Since 2023, orthoimagery and elevation model rasters have been generated and stored as Cloud Optimized Geotiffs on a cloud service provider (AWS) with select imagery linked to in the collaborative GIS project. Additionally - a tile service has been set up to facilitate viewing and downloading of individual images, provided in Table 5.11.
# only needs to be run at the beginning or if we want to update
# Grab the imagery from the stac
# bc bounding box
bcbbox <- as.numeric(
sf::st_bbox(bcmaps::bc_bound()) |> sf::st_transform(crs = 4326)
)
# use rstac to query the collection
q <- rstac::stac("https://images.a11s.one/") |>
rstac::stac_search(
collections = "imagery-uav-bc-prod",
bbox = bcbbox
) |>
rstac::post_request()
# get deets of the items
r <- q |>
rstac::items_fetch()# build the table to display the info
tab_uav <- tibble::tibble(url_download = purrr::map_chr(r$features, ~ purrr::pluck(.x, "assets", "image", "href"))) |>
dplyr::mutate(stub = stringr::str_replace_all(url_download, "https://imagery-uav-bc.s3.amazonaws.com/", "")) |>
tidyr::separate(
col = stub,
into = c("region", "watershed_group", "year", "item", "rest"),
sep = "/",
extra = "drop"
) |>
dplyr::mutate(
link_view =
dplyr::case_when(
!tools::file_path_sans_ext(basename(url_download)) %in% c("dsm", "dtm") ~
ngr::ngr_str_link_url(
url_base = "https://viewer.a11s.one/?cog=",
url_resource = url_download,
url_resource_path = FALSE,
# anchor_text= "URL View"
anchor_text= tools::file_path_sans_ext(basename(url_download))),
T ~ "-"),
link_download = ngr::ngr_str_link_url(url_base = url_download, anchor_text = url_download)
)|>
dplyr::select(region, watershed_group, year, item, link_view, link_download)
# grab the imagery for this project area.
#
# Driven from the param, not a literal. A hardcoded region here shadows
# params$project_region and, because this chunk is `eval = F`, the table it
# writes to sqlite outlives the repo it was written in - a spawned report
# inherits the ancestor's rows and republishes them. That is how this report
# came to publish Peace imagery (#19).
#
# `region` is the first segment of the S3 key and is a basin name, which is not
# always what params$project_region holds - the Peace report's project_region is
# "peace" while its imagery is filed under "mackenzie". It matches here, checked
# against the STAC index rather than assumed.
project_uav <- tab_uav |>
dplyr::filter(region == params$project_region)
# how many distinct items are there
# length(unique(project_uav$item))
# Burn to sqlite
conn <- readwritesqlite::rws_connect("data/bcfishpass.sqlite")
readwritesqlite::rws_list_tables(conn)
readwritesqlite::rws_drop_table("project_uav", conn = conn)
readwritesqlite::rws_write(project_uav, exists = F, delete = TRUE,
conn = conn, x_name = "project_uav")
readwritesqlite::rws_disconnect(conn)# Guarded because this table is burned by a chunk the build never runs, so a
# spawned report inherits whatever its ancestor committed. An empty table should
# read as "no imagery" rather than render an empty widget.
if (!exists("project_uav") || is.null(project_uav) || nrow(project_uav) == 0) {
knitr::asis_output(
paste0("No orthoimagery is currently registered for the ", params$project_region,
" region.")
)
} else {
project_uav |>
my_dt_table(cols_freeze_left = 2, escape = FALSE)
}