简体   繁体   English

如何在栅格分类地图中访问类名

[英]How to access class names in a raster categorical map

I have some classified raster layers as categorical land cover maps. 我有一些分类的栅格图层作为分类的土地覆盖图。 All the layers having exactly the same categories (lets say: "water", "Trees", "Urban","bare soil" ) but they are from different time points (eg 2005 and 2015) I load them into memory using the raster function like this: 所有层具有完全相同的类别(让我们说: "water", "Trees", "Urban","bare soil" ),但是它们来自不同的时间点(例如2005和2015),我使用栅格将它们加载到内存中像这样的功能:

comp <- raster("C:/workingDirectory4R/rasterproject/2005marsh3.rst")
ref <-  raster("C:/workingDirectory4R/rasterproject/2013marsh3.rst")

"comp" is the comparison map at time t+1 and "ref" is the reference map from time t . "comp"是时间t+1comparison map"ref"是时间treference map Then I used the crosstab function to generate the confusion table . 然后,我使用了crosstab函数来生成confusion table This table can be used to explore the changes in categories through the time interval. 该表可用于浏览时间间隔内类别的变化。

contingency.Matrix <- crosstab(comp, ref)

The result is in the matrix format with the "comp" categories in the column and "ref" in the rows . 结果为matrix格式,在column具有"comp"类别, rows中具有"ref" And column and row names labeled with numbers numbers 1 to 4 . columnrow名标有数字1 to 4

Now I have 2 questions and I really appreciate any help on how to solve them. 现在,我有2个问题,我非常感谢您提供有关如何解决这些问题的帮助。

1- I want to assign the category names to the columns and rows of the matrix to facilitate it's interpretation. 1-我想将类别名称分配给matrix的列和行,以方便其解释。

2- Now let's say I have three raster layers for 2005, 2010 and 2015. This means I would have two confusion tables one for 2005-2010 and another one for 2010-2015. 2-现在让我们说我有raster layers和2015的三个raster layers 。这意味着我将有两个confusion tables一个用于2005-2010,另一个用于2010-2015。 What's the best procedure to automate this process with the minimal interaction from user. 用最少的用户交互来自动执行此过程的最佳过程是什么。

I thought to ask the user to load the raster layers, then the code save them in a list. 我想让用户加载栅格图层,然后代码将它们保存在列表中。 Then I ask for a vector of years from the user but the problem is how can I make sure that the order of raster layers and the years are the same? 然后,我要求用户提供年份的向量,但是问题是如何确保栅格图层的顺序和年份相同? And is there a more elegant way to do this. 并有一种更优雅的方式来执行此操作。

Thanks 谢谢

I found a partial answer to my first question. 我找到了第一个问题的部分答案。 If the categorical map is created in TerrSet(IDRISI) software with the ".rst" extention then I can extract the category names like this: 如果在TerrSet(IDRISI)软件中以“ .rst”扩展名创建了分类映射,那么我可以像这样提取类别名称:

comp <- raster("C:/rasterproject/2005subset.rst")
attributes <- data.frame(comp@data@attributes)
categories <- as.character(attributes[,8])

and I get a vector with the name of categories. 我得到一个带有类别名称的向量。 However if the raster layers are created with a different extension then the code won't work. 但是,如果使用不同的扩展名创建栅格图层,则代码将无法工作。 For instance if the raster is created in ENVI then the third line of the code should get changed to: 例如,如果栅格是在ENVI中创建的,则代码的第三行应更改为:

categories <- as.character(attributes[,2])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM