Background:
When writing .png
rasters to disc using the terra
R package, not only the intended raster is written, but also auxiliary files (.png.aux.xml
and .png.aux.json
files, depending on version of the package) with geographic information (since the PNG file standard does not support that).
Problem
Those files causes me a bit of a pain, since I'm writing many thousand small rasters and have no interest in the auxiliary information. Currently I am relying on code removing the newly written aux.xml
and aux.json
, but I believe this is a terribly inefficient solution (that, in the end, consumes quite a bit of time given the large amount of files). Further, the aux-files take up multiple times the disk space that my rasters do, so leaving the problem unaddressed is not really a good option.
Question
I cannot seem to find any option turning this feature off. Is there an option that I am missing? or any other ways to solve this?
Minimal reproducible example:
library(terra)
# Make raster:
test_raster <- rast(nrows=5, ncols=5, vals=1:25)
# Create a temporary folder and path to write to:
folder_path <- paste0(tempdir(),"\\rasters")
dir.create(folder_path, showWarnings = F)
# Write raster
writeRaster(test_raster, file.path(folder_path, "raster.png"), overwrite=TRUE)
# List files: (will show both .png and .png.aux.xml)
list.files(folder_path)
(The example works on my Windows machine, but I have not checked if the files paths are suitable for other systems.)
list.files(getwd(), "png$")
to limit returned files to those ending with the file extension.