0

我收到了一个 .tif 文件和一个 .qml 文件,其中包含有关每个值的颜色信息(例如,森林是绿色,云是黑色)。

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)
4

1 回答 1

3

我已提交代码更改以解决此问题。请尝试软件包的开发版本:

## install.packages('remotes')
remotes::install_github('oscarperpinan/rasterVis')
于 2017-10-15T22:04:22.977 回答