knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(uasimg)
library(htmltools)

gv2svg <- function(gr, width = 300) {

  if (!requireNamespace("DiagrammeRsvg", quietly = TRUE)) stop("DiagrammeRsvg is required")
  if (!requireNamespace("xml2", quietly = TRUE)) stop("xml2 is required")
  library(magrittr)

  svg_char <- DiagrammeRsvg::export_svg(gr)

  ## Create an xml object so we can parse it
  svg_xml <- xml2::read_xml(svg_char)

  svg_node <- svg_xml %>% xml2::xml_find_first("//d1:svg")

  ## Get the width (which is saved in pts)
  width_orig_pts <- svg_node %>%
    xml2::xml_attr("width") %>%
    gsub("pt$", "", .) %>%
    as.numeric()

  ## Get the width (which is saved in pts)
  height_orig_pts <- svg_node %>%
    xml2::xml_attr("height") %>%
    gsub("pt$", "", .) %>%
    as.numeric()

  ## Get the ratio
  height_width_ratio <- height_orig_pts / width_orig_pts

  ## Compute the required width and height in pts
  width_desired_pts <- (width / 1.333333) %>% round()
  height_desired_pts <- (width_desired_pts * height_width_ratio) %>% round()

  ## Update the height and width attributes
  xml2::xml_attr(svg_node, "height") <- paste0(height_desired_pts, "pt")
  xml2::xml_attr(svg_node, "width") <- paste0(width_desired_pts, "pt")

  ## Return the text, cleaning up some non-printing stuff
  svg_xml %>%
    as.character() %>%
    gsub("<!--.*?-->", "", .) %>%
    gsub("\\n", "", .)

}

```{css echo=FALSE} span.optional { border-radius: 3px; padding: 4px; margin-right: 1em; background-color:#18bc9c; }

This article presents a workflow for using `uasimg` to create a **catalog of drone images** from multiple flights that are part of a bigger mapping project / campaign. An example of the final output is [here](http://uas.igis-data.click/hrec/watershed2/){target="_blank" rel="noopener"}. Although the workflow is presented a sequence of steps, in practice your workflow will probably *not* be linear. Some of the steps below are optional and others may have to be repeated. But the outline presents a typical order of the steps.

\

```r
library(DiagrammeR)

wrkflow_gv <- grViz("digraph flowchart {
      node [fontname = Helvetica, shape = rectangle]
      tab1 [label = '@@1']
      tab2 [label = '@@2']
      tab3 [label = '@@3']
      tab4 [label = '@@4']
      tab5 [label = '@@5']
      tab6 [label = '@@6']
      tab7 [label = '@@7']
      tab8 [label = '@@8']
      tab9 [label = '@@9']
      tab10 [label = '@@10']
      tab11 [label = '@@11']

      # edge definitions with the node IDs
      tab1 -> tab2 -> tab3 -> tab4 -> tab5 -> tab6 -> tab7 -> tab8 -> tab9 -> tab10 -> tab11;
      }

      [1]: 'Copy images to a hard drive'
      [2]: 'Extract image info for each folder of images'
      [3]: 'Create flight metadata text files for each folder'
      [4]: 'Edit and save flight metadata text files in a text editor'
      [5]: 'Delete or move oddball images into subfolders'
      [6]: 'Split and merge folders'
      [7]: 'Re-run uas_info() to update the flight metadata'
      [8]: 'Move images into a structured directory tree'
      [9]: 'Export flight geometries to shp / kml files'
      [10]: 'Create individual flight summaries'
      [11]: 'Create Table of Content page(s) for related flight summaries'
      ") 

# source("gv2svg.R")

wrkflow_html <- wrkflow_gv %>% 
  gv2svg(width = 400) 

htmltools::HTML(paste0("<center>",
                       wrkflow_html,
                       "</center>"))

\

Currently, executing this workflow in uasimg requires writing R commands (i.e., in a script). This requires a knowledge of R, and a general understanding of what the functions do (explained below). In a future release, uasimg will have a GUI (wizard) that walks users through data management steps.

\

1. Copy image files from the drone to a hard drive

Notes

Tips:

\

2. Extract image info

Sample code:

vegsrvy_dir <- c("c:/uas/hopland-veg-survey/flight01/DCIM",
                 "c:/uas/hopland-veg-survey/flight02/DCIM",
                 "c:/uas/hopland-veg-survey/flight03/DCIM")

vegsrvy_info <- uas_info(vegsrvy_dir)

Notes

\

3. Create flight metadata files

Flight metadata refers to info that isn't saved in the images. For example the name of the pilot, the project code, site name, etc. Creating flight metadata is strongly recommended if you wish to generate flight summary reports or move images into a structured directory tree. For additional info, see the Flight Metadata vignette.

The recommended way to enter and save flight metadata is to create a metadata.txt file in each directory. The function below gets you started, but then you have to manually continue editing the flight info using a text editor.

Sample code:

## Create the metadata text files and open them in a text editor
uas_metadata_make(vegsrvy_info, make_new = TRUE, overwrite = FALSE, open = TRUE)

In this case, uas_metadata_make(vegsrvy_info) will create a 'blank' metadata text file in each folder in vegsrvy_info (where vegsrvy_info was created by uas_info()).

Notes

\

4. Move oddball images into their own folders

Optional

'Oddball' images in this context are those images you aren't going stitch in your photogrammetry software. This include photos of calibration targets, images from aborted flights, test photos, drone selfies, etc. The idea is these should be separated (or deleted) so you don't have to mess with them during stitching process. You can move images with Windows Explorer.

Notes

\

5. Split and/or merge images across folders

Optional

Notes

\

6. (Re)run uas_info() to refresh the metadata

After you've created metadata text files, and moved oddball images out of directories, you need to pull out the location info again

Sample code (same as step 2):

my_img_dirs <- c("c:/uas/hopland-veg-survey/flight01/DCIM",
                 "c:/uas/hopland-veg-survey/flight02/DCIM",
                 "c:/uas/hopland-veg-survey/flight03/DCIM")

vegsrvy_info <- uas_info(my_img_dirs)

Notes

\

7. Move images into a structured directory tree

Optional

If desired, you can move your images into a structured directory tree to help make them easier to find. Creating structured directory trees requires that i) you've entered flight metadata for every flight, and ii) you've passed a template that specifies how the directory tree should be constructed.

Sample code:

uas_move(vegsrvy_info, 
         tree = "my_dir_tree_template.txt",
         outdir_base = "d:/uas_data",
         imgs_action = "copy")

Notes

\

8. Export flight geometries to GIS files

Optional

If desired, you can export the geometries of individual flights as KML and/or Shapefiles.

Sample code:

uas_exp_kml(vegsrvy_info, ctr = TRUE, mcp = TRUE)

uas_exp_shp(vegsrvy_info, ctr = TRUE, mcp = TRUE)

Notes

\

9. Create flight summaries

This step involves creating standalone HTML pages that summarize images in a single folder. These can be thought of as the individual 'pages' of a data catalog.

Sample code:

vegsrvy_rpt <- uas_report(vegsrvy_info)

Notes

\

10. Create a Table of Contents for all the flight summaries

If you have several flights in the same general area, the final step is to create a master Table of Contents (TOC) for a series of flight summaries. The TOC is a standalone HTML file with links to individual flight summaries.

Sample code:

toc_rgb_fn <- uas_toc(vegsrvy_rpt, 
                      output_dir = "c:/drone_data/catalogs/pt_pinole",
                      gather_dir = ".", fltmap_show = TRUE, open_toc = FALSE)

Notes



UCANR-IGIS/uasimg documentation built on Jan. 16, 2025, 10:29 p.m.