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?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Sep 21, 2021 at 17:21
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. Commented 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])
answered Sep 21, 2021 at 19:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.