Say I have a raster with a raster attribute table:
library(terra)
r <- rast("whateverfilepath.tif")
rat <- levels(r)
I would like to create a new layer based upon a value from the raster attribute table. I am currently doing that via classify()
:
rcl <- matrix(c(rat$Value, rat$FieldOfInterest), ncol=2)
newr <- classify(r, rcl)
It seems like there has to be a faster way? I expect this will succeed, but the reclassification is taking a lonnnng time (55 thousand row RAT, and thus 55 thousand row reclassification table).
Effectively, looking for something similar to the ArcGIS lookup tool in terra.
levels()
toclassify()
does not make sense and also would not work sincercl
would consist of characters, and you would need an integer matrix. You probably would have noticed with the upper example being reproducible. Have a look at?terra::classify
for some examples. However, what is your goal? Assuming you had a SpatRaster object witth n categories, do you want to extract category x (let's say, forest areas) to a new object? And 55,000 rows inrat
sounds very suspicous and not correct, by the way.