8

I'm writing a dataset to file in ERMapper format (.ers) using the Raster package in R, but I'm having issues with the resulting .aux.xml auxiliary file (which I'm actually not interested in).

Simple example:

rst <- raster(ncols=15000,nrows=10000)
rst[] <- 1.234
writeRaster(rst, filename='_test.ers', overwrite=TRUE)

The writeRaster() line takes some time to execute, the data file is quite large, about 1.2GB on disk.

When checking what's happening while writeRaster() is executed, I find that the .ers file (header file + associated data file) is typically generated in about 20 sec. Then, it takes writeRaster() another 20 - 25 sec to generate the .aux.xml file, which only contains statistics such as min, max, mean, and st. dev. (which likely explains why it takes so long to compute).

Since I don't care about the .aux.xml file, I would like writeRaster() to not bother with it at all, and save me 20 - 25 sec of exec time (I'm writing lots of these datasets to disk so a 50% speedup in my code is quite substantial).

Anyone has any idea how to tell writeRaster() to not create a .aux.xml file? I suspect it's a GDAL-related issue, but haven't been able to find an answer yet after much research...

Any help most welcome!

dsp542
  • 83
  • 3
  • Using you code it takes 10 seconds on my setup (win7) and I get 3 files : _test.ers 606B, _test 1.11GB and _test.ers.aux 288B. – HubertL May 23 '17 at 00:20
  • Cool, thanks @HubertL. I'm actually writing the file(s) to a remote directory so a lot of the time is spent sending data over the network. This is actually good as it showed me that `writeRaster()` first transfers data to the data file, but then re-reads the data across the network from that saved dataset to compute the stats in the auxiliary file (!!). In any case, what's important to me is how long it takes the function to calculate the .aux.xml file, compared to the time taken to write the actual data. Is it also about half the time in your case? – dsp542 May 23 '17 at 00:27
  • if you provide argument `format="raster"` the .aux file is not written – HubertL May 23 '17 at 00:46
  • True, though that saves the data in 'Native' raster package format (.grd) instead of ERMapper format .ers. I'd then have to rename the data file (assuming the raw data is saved in the same manner) and re-create the .ers header from the .grd file... which could be a workable (though not ideal) option I guess. – dsp542 May 23 '17 at 01:05

1 Answers1

10

Options related to the GDAL file format drivers can be set using the (not so easy to find) rgdal::setCPLConfigOption function.

In your case,

rgdal::setCPLConfigOption("GDAL_PAM_ENABLED", "FALSE")

should disable the xml file creation.

HTH

lbusett
  • 5,801
  • 2
  • 24
  • 47