[gdal-dev] Retrieving pixel corners through Python-gdal

Kralidis,Tom [Ontario] Tom.Kralidis at ec.gc.ca
Tue Jun 29 10:01:09 EDT 2010


 

> -----Original Message-----
> From: gdal-dev-bounces at lists.osgeo.org 
> [mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Monica Buescu
> Sent: Tuesday, 29 June 2010 09:49
> To: gdal-dev at lists.osgeo.org
> Subject: [gdal-dev] Retrieving pixel corners through Python-gdal
> 
> Greetings
> 
> I'm a kind of newbie in GDAL specially in Python-GDAL. I'm 
> doing a script to do some minor image processing but I need 
> to retrieve, in a Python Scrpt, coorners coordinates 
> (top-left; bottom-right). Is there any way to retrieve this 
> using gdalpython?
> 
> Thanks
> 
> Monica
> 

This has worked for me:

import osgeo.gdal as gdal

ds = gdal.Open('foo.tif')
gt = ds.GetGeoTransform()
width = ds.RasterXSize
height = ds.RasterYSize
miny = gt[3] + width*gt[4] + height*gt[5] 
maxx = gt[0] + width*gt[1] + height*gt[2]
# bbox of raster (minx, miny, maxx, maxy)
bbox = (gt[0], miny, maxx, gt[3])

..Tom


More information about the gdal-dev mailing list