2

I need extract metadata from file .tiff but specifically I need get corner coordinates, and after convert this to lat-long.

3

One way to do this is to use the osgeo module, specifically gdal. Below is a sample:

from osgeo import gdal

ds = gdal.Open("my_tiff.tif")
x = ds.GetGeoTransform()[0]
y = ds.GetGeoTransform()[3]

This returns the coordinate of the top left corner of the top left pixel.

It would depend on what georeferencing is used in your tiff file to convert to Lat/Lon. If it is in utm, for example, you could use the utm module's utm.from_latlon(lat, lon). To convert the coordinates.

| improve this answer | |
3

Other way is using rasterio module for getting coordinates, and pyproj module for converting them. Example:

import rasterio
import pyproj

my_file = rasterio.open('file.tif')
bounbox = my_file.bounds
my_proj = pyproj.Proj("+init=epsg:5514")#your data crs

left_bottom = my_proj(bounbox[0],bounbox[1], inverse=True)
right_top = my_proj(bounbox[2],bounbox[3], inverse=True)
| improve this answer | |
  • Can you please post some example? – Julian Linares Dec 15 '16 at 19:36
  • 1
    In my answer is example. I have data ('file.tif') in EPSG:5514 CRS, after runnig this code I get the corner coordinates (lat-long) in WGS – Oto Kaláb Dec 15 '16 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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