R: how to write a raster to disk without auxiliary file?

家住魔仙堡 提交于 2019-12-01 20:26:17

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/44123832/r-how-to-write-a-raster-to-disk-without-auxiliary-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!