exif-py
exif-py copied to clipboard
Not a bug, just a question about the GPS tags
Hi
First of all, thank you for this nice python module! I am new to EXIF data, so this is probably a very simple question. I have been having some trouble understanding the GPS tag information.
These are the GPS tags I am getting: {'GPS GPSLatitude': (0x0002) Ratio=[5, 5685623/100000, 0] @ 1422} {'GPS GPSAltitudeRef': (0x0005) Byte=0 @ 1402} {'GPS GPSLongitudeRef': (0x0003) ASCII=E @ 1378} {'GPS GPSLatitudeRef': (0x0001) ASCII=N @ 1354} {'GPS GPSLongitude': (0x0004) Ratio=[23, 2763129/50000, 0] @ 1446} {'GPS GPSAltitude': (0x0006) Ratio=648 @ 1470}
I would like to decode the GPS information into the coordinates that you can put into google maps. I can see the N for North and the E for East but the rest I don't really understand.
Thanks a lot :)!
Hi LindaSt,
I actually wanted to do the same thing. Personally I think it'd be nice if there was something to do it automatically. If anyone wants, or if no one is against, I might do pull request on adding this feature.
Here is a quick function that maybe some will find helpful:
def get_coordinates(tags):
lng_ref_tag_name = "GPS GPSLongitudeRef"
lng_tag_name = "GPS GPSLongitude"
lat_ref_tag_name = "GPS GPSLatitudeRef"
lat_tag_name = "GPS GPSLatitude"
# Check if these tags are present
gps_tags = [lng_ref_tag_name,lng_tag_name,lat_tag_name,lat_tag_name]
for tag in gps_tags:
if not tag in tags.keys():
print "Skipping file. Tag {} not present.".format(tag)
return None
convert = lambda ratio: float(ratio.num)/float(ratio.den)
lng_ref_val = tags[lng_ref_tag_name].values
lng_coord_val = [convert(c) for c in tags[lng_tag_name].values]
lat_ref_val = tags[lat_ref_tag_name].values
lat_coord_val = [convert(c) for c in tags[lat_tag_name].values]
lng_coord = sum([c/60**i for i,c in enumerate(lng_coord_val)])
lng_coord *= (-1)**(lng_ref_val=="W")
lat_coord = sum([c/60**i for i,c in enumerate(lat_coord_val)])
lat_coord *= (-1)**(lat_ref_val=="S")
return (lng_coord, lat_coord)
Use case is:
tags = exifread.process_file(open(file_name, 'rb'))
coordinates = get_coordinates(tags)
Maybe just to mention that there was a pull request #69 with this issue. Now one can do:
import exifread
from exifread.utils import get_gps_coords
filename = "test_photo.jpg"
tags = exifread.process_file(open(filename, 'rb'))
gps_coords = get_gps_coords(tags)
from exifread.utils import get_gps_coords
ImportError: cannot import name 'get_gps_coords'
Hi LindaSt,
I actually wanted to do the same thing. Personally I think it'd be nice if there was something to do it automatically. If anyone wants, or if no one is against, I might do pull request on adding this feature.
Here is a quick function that maybe some will find helpful:
def get_coordinates(tags): lng_ref_tag_name = "GPS GPSLongitudeRef" lng_tag_name = "GPS GPSLongitude" lat_ref_tag_name = "GPS GPSLatitudeRef" lat_tag_name = "GPS GPSLatitude" # Check if these tags are present gps_tags = [lng_ref_tag_name,lng_tag_name,lat_tag_name,lat_tag_name] for tag in gps_tags: if not tag in tags.keys(): print "Skipping file. Tag {} not present.".format(tag) return None convert = lambda ratio: float(ratio.num)/float(ratio.den) lng_ref_val = tags[lng_ref_tag_name].values lng_coord_val = [convert(c) for c in tags[lng_tag_name].values] lat_ref_val = tags[lat_ref_tag_name].values lat_coord_val = [convert(c) for c in tags[lat_tag_name].values] lng_coord = sum([c/60**i for i,c in enumerate(lng_coord_val)]) lng_coord *= (-1)**(lng_ref_val=="W") lat_coord = sum([c/60**i for i,c in enumerate(lat_coord_val)]) lat_coord *= (-1)**(lat_ref_val=="S") return (lng_coord, lat_coord)
Use case is:
tags = exifread.process_file(open(file_name, 'rb')) coordinates = get_coordinates(tags)
Very nice, I would reverse the return values. Latitude is the value given first.