3

I've been given a large raster with an in-built RAT with all sorts of RGB data and classes etc etc, but it's been done a bit poorly and I would like to quickly rebuild it myself.

When i read into R and then writeRaster to GeoTiff, it's a right old mess, so i'd like to remove the RAT entirely, how is this done?

# here's a raster with RAT
require(raster)
r <- raster(ncol=10,nrow=10,xmn=0,xmx=10,ymn=0,ymx=10)
r[] <- sample(1:4,100,rep=T)

# ratify and add some attributes
r <- ratify(r)
rat <- levels(r)[[1]]
rat$letters <- LETTERS[1:4]
rat$names <- c("Tom","Tim","Jane","Jessica")
rat$vals <- c(0.265,0.456,0.037,0.756)

# set RAT
levels(r) <- rat

How do i get rid of the RAT?

2

Could it be as easy as that?

s <- setValues(raster(r), r[])
s

class       : RasterLayer 
dimensions  : 10, 10, 100  (nrow, ncol, ncell)
resolution  : 1, 1  (x, y)
extent      : 0, 10, 0, 10  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : layer 
values      : 1, 4  (min, max)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.