Skip to content
Prev 23231 / 29559 Next

Raster Export as PNG

I would use rgdal::writeGDAL to create the png, rather than drawing to the
png device.

What you need to do depends on how to display your data, since you'll
either have to modify the raster to replace its data with colour values
(either as a palette or greyscale or rgb). I routinely convert raster data
via a colour map, and I think you could get close to your plot with

scl <- function(x) (x - min(na.omit(x)))/diff(range(na.omit(x)))
cols <- rev(terrain.colors(256)[scl(values(yidw))])
img <- setValues(brick(yidw, yidw, yidw), cbind(cols, cols, cols))

rgdal::writeGDAL(as(img, "SpatialGridDataFrame"), "outputRGB.png",
drivername = "PNG", type = "Byte")

That is untested though, it aims to replace your single band raster with a
RGB version with the colours all expanded out. You can see what the image
file will look like with plotRGB(img).

It's possibly wasteful to build a full RGB if the dynamic range does not
require it, but  the details of your specific data matter here.

Cheers, Mike.
On Mon, 17 Aug 2015 at 04:56 Alper Din?er <alperd.web at gmail.com> wrote: