Processing hundreds of photos in seconds using this Python Programme

Back in my 20’s I spent a long period of time travelling the world and as you can imagine a lot of photos were taken during that time! The images were stored in my Google Drive for many years but recently I have decided that it would be rather nice if I could gather all my photos and display them all in one place on a single map. But of course in order to add the images using geolocation as the marker, you need to ensure the geolocation data is available for every image. This is where the problem lies, it turns out that none of my travel photos contain the geolocation data….. After spending some time researching the various options available I decided to put my python programming skills to the test and create a programme to solve this problem. The plan was to write a programme that would loop through every image with missing geolocation data and insert this missing information, save it all on a  single csv file to then upload into Google My Map. After many iterations of this programme, I finally succeeded and in this post I will be sharing this code in the hope that if you also have a similar problem then this could also be a solution for you, happy coding!

Step 1: Creating a Function to add Geolocation

As each of my images have been saved into different folders named after the country/city the image was captured in, I needed to create a function that would loop through each image checking whether geolocation is captured in the metadata, if not then the corresponding geolocation data would be added.  

The code for this function can be found in geolocation.py

I initially wanted to write a programme that was able to use the country/city folder as input to automatically retrieve the correlating latitude and longitude coordinates but this proved to be challenging due to lack of suitable API for this so at end I decided to doing this manually. But this could be a useful additional feature that could be added to the programme in the future.

Step 2: Collate all the information into a single document

Once the geolocation (latitude, longitude) has been successfully added to every image, it’s time to collate all the information into one Json file, I have found that adding this additional step rather than extracting the data from each image and saving it to a CSV file directly to be the most efficient method for data extraction.

The code for this function can be found in combine.py

Step 3: Almost there!

Next extract the geolocation data and links to the images to a CSV file, the reason for this is that the plan was to visualise this data using Google My Map which accepts CSV files and not JSON.

The code for this function can be found in group.py

Now you have your CSV file containing the geolocation and photo links, this document can be uploaded to Google My Map, below is the map that I created displaying all the photos captured over the years, using the geolocation data as markers:

Full code available on GitHub:

https://github.com/Hey-El/Geolocation/tree/main

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *