Skip to content

Instantly share code, notes, and snippets.

@dill
Created November 8, 2015 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dill/a99c4066c7247ad49f82 to your computer and use it in GitHub Desktop.
Save dill/a99c4066c7247ad49f82 to your computer and use it in GitHub Desktop.
Goofy plotting of EXIF data
# get EXIF and make a map
library(leaflet)
library(lubridate)
library(plyr)
# all my photos are in a directory pre with subdirectories
pre <- "~/Dropbox/Photos/"
paths_to_photos <- c("some_sub_directory"
)
# iterate over the directories and get the data
exif_data <- lapply(paths_to_photos, function(x){
# call to exiftool to extract lat, long, altitude and date to tsv
cmd <- paste0("exiftool -n -gpslatitude -gpslongitude -gpsaltitude -createdate -T ",
pre, x, "*.JPG")
# execute the command on the given directory and read into R
exif_data <- read.table(pipe(cmd), header=FALSE, sep="\t",
stringsAsFactors = FALSE)
# name the columns
names(exif_data) <- c( "latitude","longitude", "altitude", "date")
# get the format of the columns right
exif_data$longitude <- as.numeric(exif_data$longitude)
exif_data$latitude <- as.numeric(exif_data$latitude)
exif_data$altitude <- as.numeric(exif_data$altitude)
exif_data$date <- ymd_hms(exif_data$date)
return(exif_data)
})
# convert list of data.frames to one big data.frame
exif_data <- ldply(exif_data)
# remove rows with no geodata
exif_data <- exif_data[!is.na(exif_data$latitude),]
# sort by date
exif_data <- exif_data[order(exif_data$date),]
# plot using leaflet
leaflet(exif_data) %>%
addTiles() %>%
addPolylines(~longitude, ~latitude, weight=1)
# or do an rgl plot too
library(rgl)
plot3d(x=exif_data$latitude, y=exif_data$long, z=exif_data$altitude)
@daijiang
Copy link

daijiang commented Nov 8, 2015

For sorting, if plyr is loaded, I usually prefer arrange(exif_data, date). Just personal taste ^_^.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment