How to get extent out of GeoTiff

Building on what @David mentioned you may use open source gdal library using python module to get image extent like this:

import gdal
from gdalconst import GA_ReadOnly

data = gdal.Open('C:/Temp/myimage.tif', GA_ReadOnly)
geoTransform = data.GetGeoTransform()
minx = geoTransform[0]
maxy = geoTransform[3]
maxx = minx + geoTransform[1] * data.RasterXSize
miny = maxy + geoTransform[5] * data.RasterYSize
print [minx, miny, maxx, maxy]
data = None

[-86.20782844487971, 40.7246942570317, -84.5446284448797, 41.8290942570317]

Reference: Find Extents of GDAL Raster


You can use Rasterio to get the bounding box as follows:

>>> import rasterio

>>> dataset = rasterio.open('example.tif')

>>> dataset.bounds
BoundingBox(left=358485.0, bottom=4028985.0, right=590415.0, top=4265115.0)

The tags you're interested in are: ModelTiepointTag, ModelPixelScaleTag, and ModelTransformationTag. The specification describes how they stored the information:

http://docs.opengeospatial.org/is/19-008r4/19-008r4.html#_raster_to_model_coordinate_transformation_requirements

For most common applications, the transformation between raster space and model space may be defined with a set of raster-to-model tiepoints and scaling parameters. The ModelTiepointTag and ModelPixelScaleTag may be used for this purpose.

Alternatively, the ModelTransformationTag may be used to specify the transformation matrix between the raster space (and its dependent pixel-value space) and the (possibly 3D) model space.

The ModelTiepointTag SHALL have 6 values for each of the tiepoints

The ModelPixelScaleTag SHALL have 3 values representing the scale factor in the X, Y, and Z directions

The ModelTransformationTag SHALL have 16 values representing the terms of the 4 by 4 transformation matrix. The terms SHALL be in row-major order

You could have a look at how GDAL implements them in this file:

http://trac.osgeo.org/gdal/browser/trunk/gdal/frmts/gtiff/geotiff.cpp

Tags:

Geotiff Tiff