14

Every time I open and close a Raster layer in QGIS it creates an XML-file for that raster when closing.

While I do a lot of automatic processing this really bugs me, since I have to add every time when I request a file list to exclude XML-files. I just want QGIS to stop doing this, so do any of you know where to turn this off?

0

3 Answers 3

17

Are the xml files *.aux.xml?

If so, it's not QGIS creating them, it's the GDAL library which uses them to store metadata, including statistics. You can disable completely by setting the environment variable GDAL_PAM_ENABLED=NO though I don't advise this if you'll be displaying the rasters again as there won't be any statistics cached.

5
  • Hi Luke, it does indeed create an aux.xml file. Could you tell me how to change these settings of GDAL? I'm working on Ubuntu and I tried adding it to the .bashrc file, but with no effect.
    – geotics
    Commented Feb 24, 2015 at 6:28
  • 1
    Found it in QGIS-Settings-Environment Settings
    – geotics
    Commented Feb 24, 2015 at 8:37
  • @jonasvanduijvenbode setting the environment variable in the settings had no effect for me. Did it work for you?
    – cmosig
    Commented Sep 4, 2023 at 13:31
  • If QGIS is creating *.aux.xml files, changing GDAL_PAM_PROXY_DIR will have no effect. According to the GDAL docs, the variable only works if you don't have write permissions to the original directory. Commented Sep 18, 2023 at 2:10
  • @AaronZuspan according to the doc that is correct now. However, eight years ago this very old answer worked (and was marked correct). Feel free to add a more up to date answer or edit this one.
    – user2856
    Commented Sep 18, 2023 at 6:19
4

To disable the creation of .aux.xml files after deleting the raster layer - place the startup.py file in the C:\Users\%USERNAME%\AppData\Roaming\QGIS\QGIS3 folder with this code:

from osgeo import gdal
gdal.SetConfigOption("GDAL_PAM_ENABLED", "NO")
2
  • 1
    you can also add this file to ~/.local/share/QGIS/QGIS3/profiles/default (for linux) and with from osgeo import gdal instead of import gdal as the first line. Commented Jul 18, 2023 at 15:54
  • 1
    I think it's better to add this as an environment variable. It be done using QGIS graphical interface in your settings. Just another way to do it.
    – etrimaille
    Commented Jul 18, 2023 at 17:43
3

The *.aux.xml files are called persistent auxiliary metadata (PAM), and are created by GDAL to cache image statistics and speed up subsequent reads. If you want to disable their creation through QGIS, you can go into Settings > Options > System > Environment and add a new variable GDAL_PAM_ENABLED=NO. QGIS will need to be restarted for the change to take effect.

QGIS options dialog

Note that setting GDAL_PAM_PROXY_DIR will not affect creation of *.aux.xml files in most cases, as explained in the GDAL docs:

GDAL_PAM_PROXY_DIR=value: Directory to which .aux.xml files will be written when accessing files from a location where the user does not have write permissions. Has no effect when accessing files from locations where the user does have write permissions.

1
  • This is a good answer. Commented Feb 6 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.