Stefano Tripi Intelligent government.

Mapping photo locations in Google Maps with R

Geotagging mania

Geotagging is everywhere; leaving alone security and cyber security issues, we are surrounded with geodata, especially through our multimedia devices and smartphones.
For every photo we take, modern cameras and phones save our geodata as EXIF data inside the file.
What can we do with this data?

The problem

There are lots of online applications and offline software with interesting features for showing geodata on a map, for instance, for the creation of georeferenced city issue reporting, holiday travel slideshows, and so on.
The problem, from my point of view, is that most of these solutions are proprietary software, and they require specific applications to be running in order to view the data of the photos on a map. You could export your final work as a movie, for instance, but you would still need a movie player to look at it.
There is a need for a solution to programmatically create usable map visualizations from geotagged photos.

The solution

I couldn’t find any software ready for use, so I tried to take a look at different packages from the R statistical programming software, and I tried to combine them together.
It worked!

Source photo:
Source photo

Map of the EXIF geodata:
EXIF geodata map

By using the exifr and ggmap libraries, it is possible to read the geodata from a .JPG image and plot a Google Map of the exact position in which the photo was taken. You could then automatically save this map as a standalone .JPG file, for instance.
This will allow to work on an interesting future project, to programmaticaly create “geodata photo slideshows”.

The details

To take a look at the complete source code with a walkthrough and additional examples, please visit the following RPubs link:

The script uses a call to exifr to save geodata from the picture inside a data frame; this data is then used to call get_googlemap and, finally, the ggmap and geom_point ggplot2 commands to plot and annotate the final map.

Share this: