[gdal-dev] GDAL Python API translation options for clipping an
image?
Frank Warmerdam
warmerdam at pobox.com
Sat Jun 20 06:57:43 EDT 2009
Bob Bruce wrote:
> Hi:
> I am working on a Quantum GIS plugin to clip individual images.
> I am trying to figure out how to issue a command from the Python API
> which is the equivalent of:
>
> gdal_translate -a_srs "EPSG:26914" -a_nodata 0 -of GTiff -prjwin 370600
> 6021200 327700 6023350 MB07005-83-R-modified.tif
> MB07005-83-R-modifiedTrim.tif
>
> I see that the creation options are accessible in the CreateCopy method
> of the GDALDriver class but I cannot see where the other GDAL_translate
> options are available. What should I do to perform this kind of
> translation via the GDAL Python API?
Bob,
The gdal_translate command accomplishes this by constructing an
intermediate virtual dataset which references only a subwindow
of the source dataset. This is also how it accomplishes band
subsetting/rearranging. I would suggest you skim the gdal_translate
code to get a sense of how this is accomplished.
Looking at gdal_translate I see it uses direct access to the VRT
API to accomplish some of the steps to construct a virtual dataset.
I don't think this API is exposed in Python, but the same effect can
be accomplished by assembling VRT XML as described at:
http://www.gdal.org/gdal_vrttut.html
You might also find it helpful to review the code for the OpenEV Export
Tool which provides functionality fairly similar to gdal_translate from a
Python managed GUI. It also construct VRT XML. Hmm, on reflection I see
OpenEV abstracts most of the VRT portion of things into a vrtutils.py
module that might be useful with modification. I have attached it for
reference,
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vrtutils.py
Type: text/x-python
Size: 48402 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090620/b4e325b8/vrtutils-0001.py
More information about the gdal-dev
mailing list