# What is the Formula to get an Image's Bounding Box from it's GDAL GeoTransform Array?

I have a process which needs to read in an Image's GeoTransform Array, and convert it to the Bounding Box

i.e. If the Input is:

``````<GeoTransform>
7.8087700868360430e+05,  9.9974951285737870e+00,  0.0000000000000000e+00,
2.0276558410121971e+06,  0.0000000000000000e+00, -1.0000024189695811e+01
</GeoTransform>
``````

I need the Output as

``````Upper Left:780877.009, 2027655.841
Lower Left:780877.009, 2010425.799
Upper Right:799692.295, 2027655.841
Lower Right:799692.295, 2010425.799
``````

I see that you can do this using GDAL's Python bindings, but I need to do this without any dependencies.

Is there a formula that could be applied to get the expected Bounding Box?

## 1 Answer

You need both the geotransform and the number of rows and columns. If you look at your output, you'll see that a couple of elements of the geotransform correspond to the UL coordinates. So to get the extent you can just do

``````xmin = min(geo_t, geo_t + x_size * geo_t)
xmax = max(geo_t, geo_t + x_size * geo_t)
ymin = min(geo_t, geo_t + y_size * geo_t)
ymax = max(geo_t, geo_t + y_size * geo_t)
``````

where `x_size` and `y_size` are the columns and rows, and geo_t is a (zero-indexed) array with the geotransform. In fact, this is valid Python code ;-)

As per @user30184 if there is a rotation in the geotransform, you need to take it into account. The formula for getting the coordinates of (`x_coord`, `y_coord`) as a function of the row/column pixel locations( `x_pix`, `y_pix`) is

``````x_coord = geo_t + x_pix*geo_t + y_pix*geo_t
y_coord = geo_t + y_pix*geo_t + x_pix*geo_t
``````

In the question above, elements 2 and 4 are 0, so the first set of equations still hold.

• It is not quite so simple if the image is rotated and the two corresponding parameters are not zeroes. – user30184 Aug 3 '18 at 11:47
• As @user30184 says, since there is are rotation parameters `geo_t & geo_t` too need to be used. – Devdatta Tengshe Aug 3 '18 at 12:28