Search code examples
rpngrgdal

Create PNG using writeGDAL without georeference (.aux.xml)


When creating a PNG file using writeGDAL, a georeferencing file is created (.aux.xml) along with the PNG file. Is there a way to prevent this from happening?

The following code creates the files as explained above.

library(raster)
library(rgdal)

r <- raster(xmn=742273.5, xmx=742702.5, ymn=6812515.5, ymx=6812995.5, ncols=144, nrows=161)
r <- setValues(r, 1:ncell(r))

rSpdf <- as(r, 'SpatialPixelsDataFrame')
rSpdf$colors <- as.numeric(cut(rSpdf$layer, breaks = 10))

writeGDAL(rSpdf[, 'colors'], 'test.png', drivername = 'PNG', type = 'Byte', mvFlag = 0, colorTables = list(colorRampPalette(c('black', 'white'))(11)))

Solution

  • By setting rgdal::setCPLConfigOption("GDAL_PAM_ENABLED", "FALSE") the .aux.xml file is not created. Thank you Val for pointing me to the post.

    library(raster)
    library(rgdal)
    
    rgdal::setCPLConfigOption("GDAL_PAM_ENABLED", "FALSE")
    
    r <- raster(xmn=742273.5, xmx=742702.5, ymn=6812515.5, ymx=6812995.5, ncols=144, nrows=161)
    r <- setValues(r, 1:ncell(r))
    
    rSpdf <- as(r, 'SpatialPixelsDataFrame')
    rSpdf$colors <- as.numeric(cut(rSpdf$layer, breaks = 10))
    
    writeGDAL(rSpdf[, 'colors'], 'test.png', drivername = 'PNG', type = 'Byte', mvFlag = 0, colorTables = list(colorRampPalette(c('black', 'white'))(11)))