2

I want to read the coordinates of a .tif file in order to use them inside Python code. Although gdalinfo command on Ubuntu terminal displays a lot of information, it is useless since I cannot use them inside larger Python code, unless I put them manually, which does not work on my occasion. I found and use this code:

import exifread
# Open image file for reading (binary mode)
f = open('image.tif', 'rb')

# Return Exif tags
tags = exifread.process_file(f)

# Print the tag/ value pairs
for tag in tags.keys():
    if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'):
        print("Key: %s, value %s" % (tag, tags[tag]))

from here: https://stackoverflow.com/questions/46477712/reading-tiff-image-metadata-in-python

The problem that I face is that I cannot get all the coordinates or at least 2 critical of them (such as upper left corner and right down corner), so that I can calculate all 4. What I get with the above mentioned code is only the upper left corner's coordinates... How can I fix that? How can I get and the right down corner's coordinates?

1
  • What EXIF tag is giving you an upper left corner? The GPS coordinates from a geotagged image ought to be the location of the camera GPS at the time of capture.
    – GBG
    Sep 21, 2021 at 20:01

1 Answer 1

4

Rasterio would be an easy choice to get the information you need via Python. This code gets the bounding geometry of a geotiff.

import rasterio
dataset = rasterio.open('/home/gerry/Drone/MedTest/referencedimages/warped_DJI_0001.TIF')
#left edge
print(dataset.bounds[0])
#bottom edge
print(dataset.bounds[1])
#right edge
print(dataset.bounds[2])
#top edge
print(dataset.bounds[3])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.