2017-10-15 48 views
0

我已经收到一个.tif文件,其中包含有关每个值的颜色信息(例如,森林是绿色的,云是黑色的).qml文件。levelplot绘制错误的分类颜色

library(raster) 
library(rasterVis) 

sm <- raster("UT_classification_coded.tif") 

########## Classify raster/build attribute table 
    sm <- ratify(sm) 
    rat_sm <-levels(sm)[[1]] 
    # Create categories 
    rat_sm$landcover <- c('Forest', 'Active vegetation', 'Senescent vegetation', 'Disturbed', 'Rice flooded', 'Rice growing', 'Settlement', 'Water', 'Cloud', 'Cloud shadow', 'Forest') 
    levels(sm) <- rat_sm 




##### plot the colours using the .qml file 
    levelplot(sm, col.regions=c("#00b144", "#00ff00", "#ffc0a0", "#00ebeb", "#86b1ec", "#de57ff", "#ffff00", "#0000ff", "#000000", "#000000", "#008000"), xlab=NULL, ylab=NULL, scales=list(draw=FALSE), maxpixels=6e6) 

的问题是,levelplot“相信”,土地利用类别(森林,稻水淹没等)都在相反的字母顺序,等等都是颜色。因此颜色被分配到错误的类别。例如,最后三种颜色(“#000000”,“#000000”,“#008000”)被分配给水,沉降,景物植被。

感谢任何建议,以解决这个问题(除了绘制反向字母顺序的颜色,这是乏味的,因为这不是如何.qml文件呈现信息)。

编辑:这里的.tif文件

class  : RasterLayer 
dimensions : 10981, 10981, 120582361 (nrow, ncol, ncell) 
resolution : 10, 10 (x, y) 
extent  : 299993, 409803, 9190235, 9300045 (xmin, xmax, ymin, ymax) 
coord. ref. : +proj=utm +zone=18 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : C:\Users\Documents\UT_classification_coded.tif 
names  : UT_classification_coded 
values  : 1, 15 (min, max) 
+0

参见:https://github.com/oscarperpinan/rastervis/issues/26#issuecomment-335011814 – Matifou

回答

2

我犯了changes in the code来解决这个问题的描述。请尝试包的开发版:

## install.packages('remotes') 
remotes::install_github('oscarperpinan/rasterVis') 
+0

谢谢你,它的工作要好得多。最后的观察:图的图例是这样的,图例的第一个值是在'rat_sm $ landcover'中分配的最后一个值(即它们的显示仍然与'rat_sm $ landcover'矢量相反) – pdx