[gdal-dev] Preventing .aux.xml output without disabling PAM

Shaw, Jonathan-P29740 Jonathan.Shaw at gdc4s.com
Tue Mar 30 16:59:29 EDT 2010

I need to override the projection and geotransform for some of the
sources I process, but I want my changes effective in memory only. The
following code should do that (or so I thought), but it causes the file
S:\Maps\aux_test.bmp.aux.xml to be generated, even though I am trying to
prevent that by opening the file read only, setting the GPF_NOSAVE flag,
and even going so far as clearing the GPF_DIRTY flag after making a

I leave GDAL_PAM_ENABLED turned on because, in the same application, I
process other map sources which do supply .aux or .aux.xml files.

I am using FWTools 2.4.7 on Windows.

Any suggestions?

#include <iostream>
#include <ogr_srs_api.h> // for SRS_WKT_WGS84
#include <gdal.h>
#include <gdal_priv.h> // for GDALDataset
#include <gdal_pam.h> // for GDALPamDataset

int main(int argc, char **argv)

    GDALDataset *ds = (GDALDataset *)GDALOpenShared(
        "S:\\Maps\\test.bmp", GA_ReadOnly);

    GDALPamDataset *pamDs = dynamic_cast<GDALPamDataset *>(ds);
    if (pamDs != NULL)
        std::cout << "Initial flags: "
            << pamDs->GetPamFlags() << std::endl;

        int pamFlags = pamDs->GetPamFlags();
        pamFlags |= GPF_NOSAVE;

        std::cout << "GPF_NOSAVE set: "
            << pamDs->GetPamFlags() << std::endl;

    // causes a change to the PAM dataset that makes it "dirty"

    if (pamDs != NULL)
        std::cout << "After SetProjection(): "
            << pamDs->GetPamFlags() << std::endl;

        int pamFlags = pamDs->GetPamFlags();
        pamFlags &= ~GPF_DIRTY;

        std::cout << "GPF_DIRTY cleared: "
            << pamDs->GetPamFlags() << std::endl;
        // 16 is output; 16 is value of GPF_NOSAVE

    GDALClose(ds); // causes test.bmp.aux.xml to be written


Interestingly, the output is:

Initial flags: 0
GPF_NOSAVE set: 16
After SetProjection(): 16
GPF_DIRTY cleared: 16

I would have expected 0, 16 (nosave), 17 (dirty & nosave), 16.


More information about the gdal-dev mailing list