TransWikia.com

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

Geographic Information Systems Asked on May 15, 2021

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?

One 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[0], geo_t[0] + x_size * geo_t[1])
xmax = max(geo_t[0], geo_t[0] + x_size * geo_t[1])
ymin = min(geo_t[3], geo_t[3] + y_size * geo_t[5])
ymax = max(geo_t[3], geo_t[3] + y_size * geo_t[5])

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[0] + x_pix*geo_t[1] + y_pix*geo_t[2]
y_coord = geo_t[3] + y_pix*geo_t[5] + x_pix*geo_t[4]

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

Answered by Jose on May 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP