my geotagged pics in 2014 and between december 2011 and april 2015
For a while I wanted to map my flights and the locations I've spent time in throughout the year, so last night I downloaded my location data, which I thought I was tracking for a long time using a few apps. Unfortunately that was not the case. Turns out most apps were not running in the background, and I forgot to start others after rebooting my phone.
What to do? There's one thing I always do. Taking pictures. Everywhere. These days most pictures are geotagged, or at least the ones taken using smartphones. I found a couple of tutorials online on how to extract metadata from JPEGs in R and Python, and eventually worked with R since thanks to Nathan Yau and this post, I could make better looking maps. Another helpful post was on timelyportfolio, explaining how to extract exif metadata using exiftool and R.
I haven't tested much the code, but if you are lucky, this should be sufficient to make your own map:
Here are a few more details on how the whole process works. Please refer to the code on github for an updated version, the code copied here was modified to fix a couple of bugs.
jpeg to coordinates
The script uses exiftool to get metadata from JPEG images. Exiftool lets you specify what to extract, so for this application we need only GPS coordinates and dates. Coordinates will be used to draw great circles between locations which are farther than a certain distance threshold, while coordinates together with dates (actually time spent in each place) will be used to draw filled circles on the locations themselves, as shown in the top picture. Extracted data is stored in a data frame called picsLocations:
Coordinates are retrieved in degrees, so we need to change the format to floats (needed by the R map):
The next step filters data. We might have a ton of pics in certain locations (holidays?) and very few in other places. However, we care only about the single locations, since they are used to draw great circles, representing flights. Also, since we want to plot filled circles representing time spent in each location, we need to cluster pics taken in the same place as a single data point. We do this in a rather simple way, by computing distances between consecutive coordinates and filtering out all points which are too close to each other (where close is defined as 300 kilometers for my map). Additionally, we determine the time spent and the amount of pictures taken in each location:
The helper function to compute distance between coordinates can be found on github at the beginning of the script. I also added an extra line of code to compute time spent in different places on a logarithmic scale. I find the visualization better looking this way, since different circles are "more similar", otherwise if you spend a long time in a single place you won't be able to see much else.
The data frame is complete. Time to plot it. Drawing the map is rather simple. As explained very well in this post. Here I simply added a few lines to plot filled circles depending on how much time we spent in each location, and changed a few colors:
You can remove the filled circles by commenting out the last line of code inside the for loop or edit thresholds, colors and transparencies easily.
Here I plotted all pictures on my phone. In the second plot I used a slightly different method (also available on github) to plot filled circles based on the number of pictures taken in each place, normalized by the time spent in that location. The map at the beginning of this post, where all locations are clustered by year, is also available on github.