[gdal-dev] Writing an Image to a file.

Frank Warmerdam warmerdam at pobox.com
Fri May 16 15:16:00 EDT 2008


Courtney Schitka wrote:
> Hi List;
> 
> Here is the procedure I am attempting to perform.
> 
> 1. Open an image (tif or whatever)
> 2. Read the image in from a file and perform some manipulations
> 3. Write the image back out as a Tif/JPeg, etc.
> 
> Parts 1  & 2 work well. My question is, the person that wrote this code 
> before me, wrote it using the CreateCopy command in the 
> GDalDataSet....Is that the best approach or is there a better way to do 
> this?

Courtney,

The more conventional approach would be to use GDALCreate() to create the
output dataset, and then you can read a chunk from the input file, process
it, and write the result chunk to the output file.

However, only some drivers support the Create() method since the application
is unconstrained in what order it writes data.  Some drivers, such as JPEG,
only support CreateCopy().  If you want to directly support the maximum number
of output drivers you might want to use CreateCopy() but then you need to
implement some sort of virtual dataset to pass to CreateCopy() that can do
your processing as data is requested.  This is generally fairly messy.

Another approach is to create a memory dataset (using the MEM driver) into
which to write your results, and then pass that to CreateCopy().  This is
fairly straightforward, but it presumes you can hold your whole processed
image in memory.

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    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list