[Gdal-dev] Copying meta data

Frank Warmerdam warmerdam at pobox.com
Fri Nov 17 18:14:09 EST 2006

Matt Hanson wrote:
> Hi,
> I'm reading in a GDAL dataset, doing some processing, and outputting it to
> another file.  The output file is created using the Create() function, but I
> want to make sure I copy over all the metadata from the source.
> What do I need to do to ensure I've copied over all metadata and geographic
> info?    Is GetMetaData(), GetProjectionRef(), and GetGeoTransform() all I
> need, followed by subsequent calls to SetMetaData(), SetProjectionRef(), and
> SetGeoTransform() ?


That will mostly do the trick, with the caveat that bands can also have
metadata, so it should also be done for them.

Note that most formats do not actually support writing metadata.  GeoTIFF
and VRT being the two exceptions that come to mind.  If you want a general
mechanism to preserve metadata, coordinate systems and other auxilary
information for formats that don't normally support it, you can use
"persistent auxilary metadata" files.  Set the configuration option
GDAL_PAM_ENABLED to YES (via environment, or CPLSetConfigOption()) and
you will find that GDAL starts writing out .aux.xml files to store
info like metadata that can't be stored in the target files.

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