Getting GPS EXIF Data With Python
Let's pull some data.
Join the DZone community and get the full member experience.Join For Free
Did you know that you can get EXIF data from JPG image files using the Python programming language? You can use Pillow, the Python Imaging Library's friendly fork to do so. You can read an article about that on this website if you want to.
Here is some example code for getting regular EXIF data from a JPG file:
This code was run using the following image:
In this article, you will focus on how to extract GPS tags from an image. These are special EXIF tags that are only present if the camera that took the photo had its location information turned on for the camera. You can also add GPS tags on your computer after the fact.
For example, I added GPS tags to this photo of Jester Park, which is in Granger, IA:
To get access to those tags, you'll need to take the earlier code example and do some minor adjustments:
To get access to the GPS tags, you need to import GPSTAGS from PIL.ExifTags. Then after parsing the regular tags from the file, you add a second loop to look for the "GPSInfo" tag. If that's present, then you have GPS tags that you can extract.
When you run this code, you should see the following output:
You can take this information and use it to load a Google map with Python or work with one of the popular GIS-related Python libraries.
Published at DZone with permission of Mike Driscoll, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.