Using GDAL in Python, how do you get the latitude and longitude of a GeoTIFF file?
GeoTIFF's do not appear to store any coordinate information. Instead, they store the XY Origin coordinates. However, the XY coordinates do not provide the latitude and longitude of the top left corner and bottom left corner.
It appears I will need to do some math to solve this problem, but I don't have a clue on where to start.
What procedure is required to have this performed?
I know that the GetGeoTransform()
method is important for this, however, I don't know what to do with it from there.
I don't know if this is a full answer, but this site says:
so they may actually be longitude and latitude.
To get the coordinates of the corners of your geotiff do the following:
However, these might not be in latitude/longitude format. As Justin noted, your geotiff will be stored with some kind of coordinate system. If you don't know what coordinate system it is, you can find out by running
gdalinfo
:Which outputs:
This output may be all you need. If you want to do this programmaticly in python however, this is how you get the same info.
If the coordinate system is a
PROJCS
like the example above you are dealing with a projected coordinate system. A projected coordiante system is a representation of the spheroidal earth's surface, but flattened and distorted onto a plane. If you want the latitude and longitude, you need to convert the coordinates to the geographic coordinate system that you want.Sadly, not all latitude/longitude pairs are created equal, being based upon different spheroidal models of the earth. In this example, I am converting to WGS84, the geographic coordinate system favoured in GPSs and used by all the popular web mapping sites. The coordinate system is defined by a well defined string. A catalogue of them is available from spatial ref, see for example WGS84.
Hopefully this will do what you want.