Skip to main content
naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

How to read .tif image coordinates with pythonPython

I want to read the coordinates of a .tif file in order to use them inside pythonPython code. Although gdalinfogdalinfo command on Ubuntu terminal displays a lot of information, it is useless since I cannot use them inside larger pythonPython 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?

How to read .tif image coordinates with python

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?

How to read .tif image coordinates with Python

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?

deleted 5 characters in body
Source Link
Steven
  • 137
  • 2
  • 10

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 more 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?

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 more 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?

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?

Source Link
Steven
  • 137
  • 2
  • 10

How to read .tif image coordinates with python

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 more 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?