Extracting exif data from photos using R

November 13, 2016
By

(This article was first published on Bluecology blog, and kindly contributed to R-bloggers)

Part 1: Extracting exif data from photos using R

See the other parts in this series of blog posts.

My camera comes with an inbuilt GPS allowing you to geo-reference photos you take. Here is a simple example for how we can use this feature to create an interactive web map in R.

The photos come from a survey I did of oysters on a rocky shoreline. I took photos of each quadrat enabling me to geolocate the quadrats as well as record what occurred within them.

First get your hands on a few packages, exif for extracting exif info in R, dplyr for data management and leaflet for making maps:

library(exifr)
library(dplyr)
library(leaflet)

Now set your working director the a folder that holds the photos in questions. We can then get the names of all the photos straight into R’s memory like this:

files <- list.files(pattern = "*.JPG")
dat <- exifr(files)

The pattern argument ensures we just grab the jpegs from the folder and nothing else.
Neat, we have our exif info as a dataframe. Now let’s select just the useful columns:

dat2 <- select(dat,
	SourceFile, DateTimeOriginal,
	GPSLongitude, GPSLatitude,
	GPSTimeStamp)

	write.csv(dat2, 'Exifdata.csv',
	row.names = F)

NB the select function comes from the dplyr package. You can do this with base R too, but I prefer dplyr. (You can get my dataframe here)

You can make a quick map of locations like this:

plot(dat$GPSLongitude, dat$GPSLatitude)

Make an interactive map

Interactive web maps are easy with the leaflet package. We can plot the same points over and ESRI provided satellite image like this:

leaflet(dat2) %>%
addProviderTiles("Esri.WorldImagery") %>%
addMarkers(~ GPSLongitude, ~ GPSLatitude)  

And here’s what it should look like:

Next up we will look at how to match these locations to the quadrat data I collected.

To leave a comment for the author, please follow the link and comment on their blog: Bluecology blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)