0

I use raster::raster("test.tiff", RAT = T) to read the file with the format of TIFF. The TIFF is derived from ArcGIS pro generating using Feature to Raster -> raster -> tiff. ArcGIS TIFF's attribution table as below:

enter image description here

As you can see, the fields of OID, Value, Count are not allowed to edit in ArcGIS Pro. But I really need to make Value <- Name. Thus, though ArcGIS Pro doesn't allow I to modify Value field, I could use other platform like Python or R to edit the value , and finally I resave the modified data to the TIFF But I don't know how to resave the TIFF. And I learned another way as below:

db = read.dbf('test.tif.vat.dbf')
db$Value = factor(db$Name)
write.dbf(db,'test.tif.vat.dbf')

Even though I can save without any warning, but finally , when I open the TIFF in ArcGIS Pro , there's any change in attribution table .

The reason that I want to modify the value of attribute

enter image description here

Can you tell me what should I do ?

0

This post may help with working with raster attribute tables (RAT) in R. The key is in working with levels. If you have an associated attribute table you can access it using levels(x)[[1]] or for a specific attribute (eg., colors column for plotting) levels(x)[[1]]$color. So, if you want to modify the raster attributes you could coerce it to a data.frame, operate on it, put it back into the correct slot, and then write out the raster. Something along the lines of:

library(raster)
r <- raster(extent(571823, 616763, 4423540, 4453690), resolution=100)
  r[] <- sample(c(1:4), ncell(r), replace = TRUE) 
    r <- ratify(r)

Here we modify the attribute table

( r.df <- levels(r)[[1]] )
  ( r.df <- data.frame(r.df, y=runif(nrow(r.df))) )

Now, put the modified data.frame back into the attribute slot. Please note that first column must be ID with values that correspond with the values in the raster. Then you can write out the raster using raster::writeRaster

levels(r) <- r.df
  levels(r)  
2
  • It sounds you are right. And thank you . But it's sitll abstract for me because I am a beginner in raster package. I wish someone could help me guide me in the first case. Really thank you . Example: I have a 'reg21.tiff'. And I access it with ArcGIS. And I found its VALUEis as below: VALUE 100 300 400 500 600 700 I want to modify its VALUE: VALUE 1 3 4 5 6 7 .So can you help me How to use Raster to modify. If you are convenient, please show your code. Thank you in advance. This is the reg21.tif Link:pan.baidu.com/s/1YGjCBgKaRsKPZqiTzvIJzg extract code:m8iu
    – user173675
    Dec 5 '20 at 17:26
  • Ah, also , I need to rewrite new name as 'reg.tif'. If you can do it, please show the whole code. Hope you have a good time. Thank you.
    – user173675
    Dec 5 '20 at 17:32

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.