I downloaded a map in TIF format that came with the following files: a2_LOt_12.tif.vat.cpg; a2_LOt_12_v170321.tfw; a2_LOt_12_v170321.tif; a2_LOt_12_v170321.tif.aux; a2_LOt_12_v170321.tif.ovr a2_LOt_12_v170321.tif.vat.dbf; a2_LOt_12_v170321.tif (XML doc). In ArcGIS the file opens fine and I can access the attribute table: However, I am having a tough time opening that table in R. I expected "levels()" to work, but it returns "NULL":
Is there another way to access that attribute table in R? asked Mar 2, 2018 at 19:20 215 2 2 silver badges 9 9 bronze badgesThe value attribute table (VAT) of ArcGIS is not usually a standard part of raster models. Since the dBase-III+ file exists in your data sample (as .tif.vat.dbf ), you can likely find some way of opening it, but treating it as a natural part of the raster might not be the best process.
Commented Mar 2, 2018 at 22:07Per the raster documentation, adding 'RAT = TRUE' when reading in the file should solve your problem, so long as the .tif.aux.xml file holds category data. Demo:
library(raster) options(stringsAsFactors = FALSE) test
The tif.aux.xml generated by writeRaster above looks like:
cat dog banana ship egg tree beer shoe light pen
so if your file looks similar you should be fine.
EDIT:
If the attribute data is in a dbf, try something like this:
# read the tif in with RAT = TRUE. Should get an ID column at least in the resulting object. data_tif
Have a look at levels(data_tif)[[1]] and compare with data_dbf . Make sure number of rows matches, and look for columns in common (ID in the RAT may match VALUE in the dbf, for instance). You can then use base::merge or dplyr::left_join to append the dbf data to the RAT.
Thanks to this question for providing some data I could test with.