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

Shaw, Jonathan-P29740 Jonathan.Shaw at gdc4s.com
Tue Mar 30 18:43:52 EDT 2010


Good suggestion... I tried that, also, but the .aux.xml file is still
written to the normal location unless the file system rejects it (due to
being on a read-only directory or device, for instance).

Jonathan


-----Original Message-----
From: Pinner, Luke [mailto:Luke.Pinner at environment.gov.au] 
Sent: Tuesday, March 30, 2010 3:33 PM
To: gdal-dev at lists.osgeo.org
Subject: RE: [gdal-dev] Preventing .aux.xml output without disabling PAM

Perhaps set the GDAL_PAM_PROXY_DIR environment var to some temp
directory and delete the directory after processing?

Luke

-----Original Message-----
From: gdal-dev-bounces at lists.osgeo.org
Sent: Wednesday, 31 March 2010 7:59 AM
To: gdal-dev at lists.osgeo.org
Subject: [gdal-dev] Preventing .aux.xml output without disabling PAM

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
change.

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)
{
    GDALAllRegister();

    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;
        pamDs->SetPamFlags(pamFlags);

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

    // causes a change to the PAM dataset that makes it "dirty"
    ds->SetProjection(SRS_WKT_WGS84);

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

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

        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

    GDALDestroyDriverManager();
}


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.


Thanks,
Jonathan




More information about the gdal-dev mailing list