Drone Image Utilities for R

Andy Lyons

June 2024


https://ucanr-igis.github.io/uasimg



Motivation

Drone mapping takes a lots of images…


…but it’s not just images that you have to keep track of!

flight logs
study area outline
GCP coordinates
telemetry files
field data
other photos
video files basemap layers

I know it’s here somewhere.

Yeah, I remember hearing someone
from UCSB flew that site.

Did you ask Brandon?

I found the images, but I can’t reproduce the stitching. It looks funny.

Maybe your overlap was too low?

We have to report how many acres we’ve flown with each type of camera for the USDA report.

Whatdyathink?

How do we get our drone data to be FAIR compliant?

uasimg Overview

R package with functions to help you:


Sample Data Catalogs

UC Merced Vernal Pool and Grassland Reserve

Point Pinole Regional Shortline Eucalyptus Grove

Hopland River Fire Revegetation Study


Origins


https://is.gd/uas_data_aag2019


Why R?


Image Metadata vs Flight Metadata

Image metadata


Flight metadata


Catloging Workflow

https://ucanr-igis.github.io/uasimg/articles/catalog_wrkflw.html


Create Flight Info Objects

Step 1. Extract Image Metadata

ptpinole_info = uas_info("d:/uas/ptpinole/west/march2020/dcim")

This will:

  1. extract the image coordinates
  2. read the sensor type, location, yaw, focal length, etc.
  3. compute image footprints
  4. create an minimum convex polygon (MCP) for the entire flight
  5. read flight metadata
  6. cache all the results
  7. return a “Flight Info” object

You can process multiple directories at once

A “Flight Info” object by itself is not very useful!


Step 2. Entering Flight Metadata

Recommended way to record flight metadata - text editor

uas_flds_oem()
##  [1] "name_short"  "name_long"   "description" "proj"        "loc"        
##  [6] "pilot"       "contact"     "uav"         "data_url"    "tags"       
## [11] "notes"


Flight Metadata Helper Function

You don’t have to start from scratch!

uas_metadata_make(ptpinole_info)

TIP: Re-run uas_info() after you edit flight metadata text files!


Organize Your Files

Parse an image collection into individual flights

uas_grp_flt()

Create separate Flight Info objects if you have:


Rename Files

uas_rename()

Rename files based on a template, such as:

{proj}-{loc}_{camera_abbrev}_{Y}{m}{d}_{H}{M}{S}

Fields available:


Move Your Data into Standard Directory Trees

You can move your data by hand or with a function:

uas_move()

Options:

{proj}/{loc}/{subloc}/imgs/{flt_date}/{flt_start}-{flt_end}_{camera_abbrev}
{proj}/{loc}/{subloc}/gis
{proj}/{loc}/{subloc}/p4d
{proj}/{loc}/{subloc}/documents


Export Flight Geometry as GIS files

uas_exp_kml(ptpinole_infox)
uas_exp_shp(ptpinole_info)

Geometries you can export:


Catalog Your Data

Create Individual Flight Summary Reports

Create HTML flight summary for one or more Flight Info object(s):

uas_report(ptpinole_info)

Report options:


Group Flight Summaries into Catalogs

Feed a list of Flight Summary HTML files.

uas_toc(c("d:/uas/ptpinole/west/march2020/dcim/map/ptpinole_mar2020.html",
          "d:/uas/ptpinole/west/jul2020/dcim/map/ptpinole_jul2020.html",
          "d:/uas/ptpinole/west/oct2020/dcim/map/ptpinole_oct2020.html"))

It will extract flight metadata fields from the HTML file for the table-of-contents.

Function options:

Example: http://uas.igis-data.click/hrec/watershed2/


Sample Script

library(uasimg)

## Define the subdirectories that have the images
hrec_dirs <- c("D:/Pix4D/HREC/Watershed1/Data/2017-01-16_X5/Flight01_1514_1526_400ft",
               "D:/Pix4D/HREC/Watershed1/Data/2017-01-16_X5/Flight02_1532_1540_400ft")
file.exists(hrec_dirs)

## Create/edit metadata text files
# uas_metadata_make(hrec_dirs, make_new = TRUE, overwrite = FALSE, open = TRUE, use_system_editor = TRUE)

## Extract image and flight metadata
hrec_info <- uas_info(hrec_dirs, fp = TRUE)

## Create image thumbnails (optional)
uas_thumbnails_make(hrec_info, rotate = TRUE, stats = TRUE, overwrite = FALSE)

## Create flight summary reports
hrec_rpts <- uas_report(hrec_info,
                        thumbnails = TRUE,
                        attachments = c("mcp_kml", "ctr_kml"),
                        footer_html = "D:/Pix4D/catalog/headers_footers/footer_igis.html",
                        tbm_use = TRUE,
                        tbm_src = "Google",
                        tbm_api_key = getOption("ANDYS_GOOGLE_STATIC_MAPS_KEY"),
                        tbm_overwrite = FALSE,
                        group_img = FALSE,
                        show_local_dir = TRUE,
                        overwrite_html = TRUE,
                        open_report = TRUE)

## Create a TOC
hrec_toc <- uas_toc(hrec_rpts,
                    toc_title = "HREC Watershed 1, January 2017",
                    output_dir = "D:/Data/uas.igis-data/hrec/watershed1",
                    gather = ".",
                    fltmap_base = list(list(kml_fn = "D:/Pix4D/HREC/Baselayers/hopland.kml",
                                            color = "yellow",
                                            weight = 2)),
                    fltmap_kml = TRUE,
                    footer_html = "D:/Pix4D/catalog/headers_footers/footer_igis.html",
                    open_toc = TRUE,
                    overwrite_toc = TRUE)

## Output: http://uas.igis-data.click/hrec/watershed1/

Utilities for Individual Images

World Files

‘World Files’ are plain-text files (also called sidecar files) with location and projection info.

GIS software like ArcGIS Pro and QGIS use these files to display images in the proper place and size.

Generate with:

uas_worldfile(ptpinole_info)

Options:

Output:


With World files, your images will just “pop” into place (approximately) in your GIS software:


Crop Out Overlap

If your images can’t be stitched, life is not over!

This function will crop each image, keeping the center part (least distorted)

uas_cropctr(ptpinole_info)

Function options:

Example Output:

Not great, but…


Convert between file formats

Convert between JPG, TIF, and DNG without losing all the image metadata (EXIF info):

uas_convert()


Save Images as Pseudo-Georeferenced GeoTIFFs

uas_exp_geotiff()

Open images with remote sensing tools for:


In the pipeline…

Scaling for Production


Making your data discoverable



Summary

The need for data management tools and workflows increases as you:

  • accumulate more and more data
  • work in a team
  • are mandated to archive your data for the long term
  • are mandated to make the existence of your data known to others


https://ucanr-igis.github.io/uasimg/


Data management and creating metadata will never be fun, but

We all stand to gain if we get better at this.