DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Data Privacy and Security: A Developer's Guide to Handling Sensitive Data With DuckDB
  • How to Simplify Complex Conditions With Python's Match Statement
  • Unleashing the Power of Gemini With LlamaIndex
  • Utilizing Multiple Vectors and Advanced Search Data Model Design for City Data

Trending

  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Apache Doris vs Elasticsearch: An In-Depth Comparative Analysis
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • A Modern Stack for Building Scalable Systems
  1. DZone
  2. Data Engineering
  3. Data
  4. Getting GPS EXIF Data With Python

Getting GPS EXIF Data With Python

Let's pull some data.

By 
Mike Driscoll user avatar
Mike Driscoll
·
Jan. 24, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
13.7K Views

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:

Python
 




x
19


 
1
# exif_getter.py
2
 
           
3
from PIL import Image
4
from PIL.ExifTags import TAGS
5
 
           
6
 
           
7
def get_exif(image_file_path):
8
    exif_table = {}
9
    image = Image.open(image_file_path)
10
    info = image.getexif()
11
    for tag, value in info.items():
12
        decoded = TAGS.get(tag, tag)
13
        exif_table[decoded] = value
14
    return exif_table
15
 
           
16
 
           
17
if __name__ == "__main__":
18
    exif = get_exif("bridge.JPG")
19
    print(exif)



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:

Python
 




xxxxxxxxxx
1
25


 
1
# gps_exif_getter.py
2
 
           
3
from PIL import Image
4
from PIL.ExifTags import TAGS, GPSTAGS
5
 
           
6
 
           
7
def get_exif(image_file_path):
8
    exif_table = {}
9
    image = Image.open(image_file_path)
10
    info = image.getexif()
11
    for tag, value in info.items():
12
        decoded = TAGS.get(tag, tag)
13
        exif_table[decoded] = value
14
 
           
15
    gps_info = {}
16
    for key in exif_table['GPSInfo'].keys():
17
        decode = GPSTAGS.get(key,key)
18
        gps_info[decode] = exif_table['GPSInfo'][key]
19
 
           
20
    return gps_info
21
 
           
22
 
           
23
if __name__ == "__main__":
24
    exif = get_exif("jester.jpg")
25
    print(exif)



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:

JSON
 




xxxxxxxxxx
1


 
1
{'GPSLatitudeRef': 'N',
2
 'GPSLatitude': (41.0, 47.0, 2.17),
3
 'GPSLongitudeRef': 'W',
4
 'GPSLongitude': (93.0, 46.0, 42.09)}



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.

Python (language) Exif Data (computing)

Published at DZone with permission of Mike Driscoll, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Data Privacy and Security: A Developer's Guide to Handling Sensitive Data With DuckDB
  • How to Simplify Complex Conditions With Python's Match Statement
  • Unleashing the Power of Gemini With LlamaIndex
  • Utilizing Multiple Vectors and Advanced Search Data Model Design for City Data

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!