Our next R course is at University of Queensland (Australia) from 18th Feburary 2020. Beginner, intermediate and advanced classes available.
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)
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:
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. I will also show you how to add photos to the pop-ups at the site locations.