[R-sig-Geo] Raster attribute with multiple attribute columns in terra

nevil amos nev||@@mo@ @end|ng |rom gm@||@com
Thu Oct 27 09:39:37 CEST 2022


Hi,

I have been trying to figure out how to construct a raster attribute table
with multiple columns  in a SpatRaster in terra.

I have the process in raster::raster(), but when attempting in terra only
the first attribute is retained in the table.

I have seen the posting here:
https://gis.stackexchange.com/questions/391215/attribute-table-in-r-terra-package
that deals with one attribute.
I cannot see the mentioned extended workaround –
Robert Hijmans <https://gis.stackexchange.com/users/8993/robert-hijmans>
 Mar 30, 2021 at 3:59
<https://gis.stackexchange.com/questions/391215/attribute-table-in-r-terra-package#comment642240_392453>
 that may deal with multiple attribute columns .

r<-terra::rast(matrix(sample(1:3,100,replace=T),10,10))
R<-raster::raster(r)

rat<-data.frame(ID=1:3,Val1=letters[1:3],Val2=LETTERS[8:10])

#Assign rat to r
levels(r)<-rat

# r has categories Val1, Val2  but table only shows column for ID and Val1
r
levels(r)

#in package raster full attribute table is attached

R<-raster::ratify(R)
levels(R)<-rat
R
levels(R)

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list