[FWTools] Get extent from rasters
Susana Iraiis Delgado Rodriguez
susana.delgado_s at utzmg.edu.mx
Mon Oct 25 09:12:26 EST 2010
Hello Travis!
Thank you for your help, I already took a look to the links you suggested
me, I found them interesting and help me a little with my problem, the
second link hepeld me a lot because I can solved 2 of the coordinates I
need. But now I don't know how to define x_max and y_min, I developed a
operation to find it, but this will only work if the rasters pixel is in
meters:
import os
from osgeo import gdal
from osgeo.gdalconst import *
dataset = gdal.Open(filepath, GA_ReadOnly)
geotransform = dataset.GetGeoTransform()
x_min = geotransform[0]
y_max = geotransform[3]
pixel_width = geotransform[1]
pixel_height = geotransform[5]
rows = dataset.RasterYSize
cols = dataset.RasterXSize
bands = dataset.RasterCount
x_max = (cols*pixel_width) + x_min
y_min = y_max + (rows*pixel_height)
The last two lines work for those coordinates, but won't work for all cases.
2010/10/21 Travis Kirstine <tkirstine at firstbasesolutions.com>
> Susana,
> The GetGeoTransform will return the upper left coordinate and pixel size.
> RasterXSize and RasterYSize will return the number of pixels. You can
> calculate the extents from all this information.
>
> http://www.gdal.org/gdal_tutorial.html
> http://www.gdal.org/classGDALDataset.html#f9593cc241e7d140f5f3c4798a43a668
>
>
> Regards
>
>
>
>
> Susana Iraiis Delgado Rodriguez wrote:
>
>> Hello list!
>> I´m working in a python module to read rasters and get information out of
>> them. I'm using GDAL and some of the osgeo libraries. I already have the
>> ratsers' projection, but I also need its extent (x_min, y_min, x_max,
>> y_max).
>> I have been searching in google and don't have any results. My code is:
>> from osgeo import gdal
>> from osgeo.gdalconst import *
>> gdal.AllRegister()
>> dataset = gdal.Open(filepath, GA_ReadOnly)
>> if dataset:
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> FWTools mailing list
>> FWTools at lists.maptools.org
>> http://lists.maptools.org/mailman/listinfo/fwtools
>> http://fwtools.maptools.org/
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/fwtools/attachments/20101025/6aeaf285/attachment.htm
More information about the FWTools
mailing list