-
-
Save maxbellec/dbb60d136565e3c4b805931f5aad2c6d to your computer and use it in GitHub Desktop.
Get Latitude and Longitude from EXIF using PIL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PIL.Image | |
get_float = lambda x: float(x[0]) / float(x[1]) | |
def convert_to_degrees(value): | |
d = get_float(value[0]) | |
m = get_float(value[1]) | |
s = get_float(value[2]) | |
return d + (m / 60.0) + (s / 3600.0) | |
def get_lat_lon(info): | |
try: | |
gps_latitude = info[34853][2] | |
gps_latitude_ref = info[34853][1] | |
gps_longitude = info[34853][4] | |
gps_longitude_ref = info[34853][3] | |
lat = convert_to_degrees(gps_latitude) | |
if gps_latitude_ref != "N": | |
lat *= -1 | |
lon = convert_to_degrees(gps_longitude) | |
if gps_longitude_ref != "E": | |
lon *= -1 | |
return lat, lon | |
except KeyError: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
what is 'info' in the argument?
Is it gps exif info?