[gdal-dev] New to list and question (UNCLASSIFIED)

Lefman, Jonathan ERDC-TEC-VA Jonathan.Lefman at usace.army.mil
Tue Feb 8 11:24:18 EST 2011


Classification: UNCLASSIFIED
Caveats: NONE

Thank you Jorge.  That worked.  :)



-----Original Message-----
From: Jorge Arévalo [mailto:jorge.arevalo at deimos-space.com] 
Sent: Tuesday, February 08, 2011 11:15
To: Lefman, Jonathan ERDC-TEC-VA
Cc: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] New to list and question (UNCLASSIFIED)

Hi Jonathan,

On Tue, Feb 8, 2011 at 4:46 PM, Lefman, Jonathan ERDC-TEC-VA
<Jonathan.Lefman at usace.army.mil> wrote:
> Classification: UNCLASSIFIED
>
> Caveats: NONE
>
> Hi all,
>
> I joined this list today.  I have a question about using Python 
> bindings with GDAL to get info from a geotiff.
>
> What are the functions that I need to obtain coordinate extents of 
> raster data?  For example, if I have a rectangular area from 
> Washington, DC with coordinates in UTM format, how would I determine 
> the top-left and lower-right corners?  I was unable to find an example in
the documentation.
>
> Here's a snippet of my code of where I'm at:
>
> from osgeo import gdal
>
> gdaldata = gdal.Open(gtiff_filename)
>
> prj = gdaldata.GetProjection()
>
> trfm = gdaldata.GetGeoTransform()
>
> Thanks everyone,
>
> Jon
>
> Classification: UNCLASSIFIED
>
> Caveats: NONE
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>

Test this:

from osgeo import gdal

def calculate_geoxy(gt, xy):
    """Calculate georeferenced coordinate from given x and y"""
    xgeo = gt[0] + gt[1] * xy[0] + gt[2] * xy[1];
    ygeo = gt[3] + gt[4] * xy[0] + gt[5] * xy[1];

    return (xgeo, ygeo)

ds = gdal.Open(gtiff_filename)
prj = ds.GetProjection()
gt = tuple(list(ds.GetGeoTransform()))
dim = (
(0,0),(0,ds.RasterYSize),(ds.RasterXSize,0),(ds.RasterXSize,ds.RasterYSize)
)
ext = (calculate_geoxy(gt, dim[0]), calculate_geoxy(gt, dim[1]),
           calculate_geoxy(gt, dim[2]), calculate_geoxy(gt, dim[3]))


Best regards,

--
Jorge Arévalo
Internet & Mobilty Division, DEIMOS
jorge.arevalo at deimos-space.com
http://es.linkedin.com/in/jorgearevalo80
http://mobility.grupodeimos.com/
http://www.twitter.com/jorgeas80
http://gis4free.wordpress.com
http://geohash.org/ezjqgrgzz0g

Classification: UNCLASSIFIED
Caveats: NONE




More information about the gdal-dev mailing list