0

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.

1
  • What exactly are you trying to achieve? Feeding the categories obtained via levels() to classify() does not make sense and also would not work since rcl 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 in rat sounds very suspicous and not correct, by the way.
    – dimfalk
    Commented Mar 30 at 12:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.