<br><font size=2 face="sans-serif">I would recommend looking at gdalinfo.py
(by Even Rouault) from:</font>
<br><a href=http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples><font size=2 face="sans-serif">http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples</font></a>
<br>
<br><font size=2 face="sans-serif">specifically the section</font>
<br><font size=2 face="Courier New">#/* --------------------------------------------------------------------
*/<br>
#/* Report corners.
*/<br>
#/* --------------------------------------------------------------------
</font>
<br>
<br>
<br><font size=2 face="sans-serif">Regards,</font>
<br><font size=2 face="sans-serif">Trent</font>
<br>
<br>
<br>
<br><font size=2 face="sans-serif">--------------------------</font>
<br>
<br><font size=2 face="sans-serif">"Bonus" section with more
information than you needed. I already wrote it up so here it is. If there
is a better method to do this I would like to hear it.</font>
<br>
<br><font size=2 face="sans-serif">If the image has a large collar of NoDATA
this can lead to unpredictable bounds. Using a couple gdal tricks you can
get to the exact footprint (and bounds) by converting to a shapefile or
other vector format.</font>
<br>
<br><font size=2 face="sans-serif"><b>1.) First map all pixels non-nodata
values (values > 0) to 255.</b></font>
<br><font size=2 face="sans-serif">> val_repl_greater.py -innd
0 -outnd 255 input.tif binary_image.tif</font>
<br><font size=2 face="sans-serif">--This routine maps all values greater
than 0 to 255. Here 255 can be any value say if you want to tag an image
with a value. e.g. Image #1, image #34.</font>
<br>
<br><font size=2 face="sans-serif">The routine "val_repl_greater.py"
is simply the sample "val_repl.py" (from link above) with one
line change</font>
<br><font size=2 face="sans-serif">replace </font>
<br><tt><font size=2> scanline = numpy.choose(numpy.equal(scanline,inNoData),(scanline,outNoData))</font></tt>
<br><font size=2 face="sans-serif">with</font>
<br><tt><font size=2> scanline = numpy.choose(numpy.greater(scanline,inNoData),(scanline,outNoData))</font></tt>
<br>
<br><font size=2 face="sans-serif"><b>2.) create polygon</b>, The pixel
value set above will be pushed into a field. In this case Field "DN"
will have 255.</font>
<br><font size=2 face="sans-serif"><b>a.)</b> If there is NO Nodata set,
but the background value is 0 then you can "mask" using itself.</font>
<br><font size=2 face="sans-serif">> gdal_polygonize -mask binary_image.tif
binary_image.tif -f "ESRI Shapefile" footprint1.shp</font>
<br>
<br><font size=2 face="sans-serif"><b>b.)</b> if Nodata is explicitly defined,
then you can skip using the mask</font>
<br><font size=2 face="sans-serif">> gdal_polygonize binary_image.tif
-f "ESRI Shapefile" footprint1.shp</font>
<br><font size=2 face="sans-serif">note: I haven't looked into how to add
in the filename into a polygon field which would be needed before merging.
But as a work around you can use the index trick mentioned in step 1.</font>
<br>
<br><font size=2 face="sans-serif">tip: here I guess you could use the
sample ogrinfo.py to now report the polygon's extent. Which should be the
raster's true pixel extent without the NoDATA collar.</font>
<br>
<br><font size=2 face="sans-serif"><b>3.) to merge many images footprints</b>
(probably should be same projection). </font>
<br><font size=2 face="sans-serif">#copy first file into new file</font>
<br><font size=2 face="sans-serif">> ogr2ogr -f "ESRI Shapefile"
toMerged.shp footprint1.shp</font>
<br><font size=2 face="sans-serif"># now append remaining.</font>
<br><font size=2 face="sans-serif">> ogr2ogr -f "ESRI Shapefile"
-update -append -nln toMerged toMerged.shp footprint2.shp</font>
<br><font size=2 face="sans-serif">> ogr2ogr -f "ESRI Shapefile"
-update -append -nln toMerged toMerged.shp footprint3.shp</font>
<br><font size=2 face="sans-serif">> ogr2ogr -f "ESRI Shapefile"
-update -append -nln toMerged toMerged.shp footprint4.shp</font>
<br><font size=2 face="sans-serif">...</font>
<br><font size=2 face="sans-serif">from: </font><a href=http://www.gdal.org/ogr/drv_shapefile.html><font size=2 face="sans-serif">http://www.gdal.org/ogr/drv_shapefile.html</font></a>
<br>
<br>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">From:</font>
<td><font size=1 face="sans-serif">Susana Iraiis Delgado Rodriguez <susana.delgado_s@utzmg.edu.mx></font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">To:</font>
<td><font size=1 face="sans-serif">fwtools@lists.maptools.org</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Date:</font>
<td><font size=1 face="sans-serif">10/21/2010 08:12 AM</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Subject:</font>
<td><font size=1 face="sans-serif">[FWTools] Get extent from rasters</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Sent by:</font>
<td><font size=1 face="sans-serif">fwtools-bounces@lists.maptools.org</font></table>
<br>
<hr noshade>
<br>
<br>
<br><font size=3>Hello list!</font>
<br><font size=3> </font>
<br><font size=3>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).</font>
<br><font size=3>I have been searching in google and don't have any results.
My code is:</font>
<br><font size=3> </font>
<br><font size=3>from osgeo import gdal<br>
from osgeo.gdalconst import *</font>
<br><font size=3> </font>
<br><font size=3>gdal.AllRegister()</font>
<br><font size=3>dataset = gdal.Open(filepath, GA_ReadOnly)</font>
<br><font size=3>if dataset:</font>
<br><font size=3> </font><tt><font size=2>_______________________________________________<br>
FWTools mailing list<br>
FWTools@lists.maptools.org<br>
</font></tt><a href=http://lists.maptools.org/mailman/listinfo/fwtools><tt><font size=2>http://lists.maptools.org/mailman/listinfo/fwtools</font></tt></a><tt><font size=2><br>
</font></tt><a href=http://fwtools.maptools.org/><tt><font size=2>http://fwtools.maptools.org/</font></tt></a><tt><font size=2><br>
</font></tt>
<br>
<br>