terra::classify 保留切点并将其用作 terra::as.polygon 中的类名
下面是一些显示问题的代码:
1 -- 重新分类栅格
建立类限制向量
class.limits
#[1] 45.16490 50.12986 51.40991 52.68021 54.00000 55.42731 57.71864 60.14900 69.57393
使用这些进行分类
class(sg.crop)
#[1] "SpatRaster"
#attr(,"package")
#[1] "terra"
sg.class <- terra::classify(sg.crop, rcl=class.limits)
查看重新分类的值:
table(values(sg.class))
# 0 1 2 3 4 5 6 7
#747 1164 1054 829 607 772 770 937
到目前为止,一切都很好...但请注意:
levels(sg.class$class)
#[[1]]
#[1] "(45.164902–50.12986]" "(50.12986–51.409912]" "(51.409912–52.68021]" "(52.68021–54]" "(54–55.427315]"
#[6] "(55.427315–57.718636]" "(57.718636–60.148998]" "(60.148998–69.573929]"
类限制保持为 并且,尝试通过分配给该向量来更改名称是行不通的:
levels(sg.class$class)[[1]] <- 1:8
#Error: [subset] undefined layer(s) selected: deepcopy
我不知道这意味着什么。但问题来了:
2 - 多边形化分类地图
sg.poly <- terra::as.polygons(sg.class, values = TRUE, dissolve=TRUE)
values(sg.poly)
# class
#1 (45.164902–50.12986]
#2 (50.12986–51.409912]
#3 (51.409912–52.68021]
#4 (52.68021–54]
#5 (54–55.427315]
#6 (55.427315–57.718636]
#7 (57.718636–60.148998]
#8 (60.148998–69.573929]
所以现在多边形栅格的标签是类限制,而不是类,这是返回的值
terra::classify.
我不知道如何改变这些。在我看来,类标签,而不是切点值,应该是多边形的值。我相当肯定,大约一年前,当我第一次进行此分析时,情况就是这样。
Here is some code to show the issue:
1 -- reclassify a raster
establish a vector of class limits
class.limits
#[1] 45.16490 50.12986 51.40991 52.68021 54.00000 55.42731 57.71864 60.14900 69.57393
use these to classify
class(sg.crop)
#[1] "SpatRaster"
#attr(,"package")
#[1] "terra"
sg.class <- terra::classify(sg.crop, rcl=class.limits)
see the reclassified values:
table(values(sg.class))
# 0 1 2 3 4 5 6 7
#747 1164 1054 829 607 772 770 937
So far, so good... but notice:
levels(sg.class$class)
#[[1]]
#[1] "(45.164902–50.12986]" "(50.12986–51.409912]" "(51.409912–52.68021]" "(52.68021–54]" "(54–55.427315]"
#[6] "(55.427315–57.718636]" "(57.718636–60.148998]" "(60.148998–69.573929]"
The class limits are kept as reference. And, trying to change the names by assigning to this vector does not work:
levels(sg.class$class)[[1]] <- 1:8
#Error: [subset] undefined layer(s) selected: deepcopy
I don't know what this means. But here comes the problem:
2 - Polygonize the classified map
sg.poly <- terra::as.polygons(sg.class, values = TRUE, dissolve=TRUE)
values(sg.poly)
# class
#1 (45.164902–50.12986]
#2 (50.12986–51.409912]
#3 (51.409912–52.68021]
#4 (52.68021–54]
#5 (54–55.427315]
#6 (55.427315–57.718636]
#7 (57.718636–60.148998]
#8 (60.148998–69.573929]
So now the polygonized raster has labels that are the class limits, not the classes, which were the values returned by
terra::classify.
And I can not figure out how to change these. It seems to me that the class labels, not the cutpoint values, should be the values of the polygons. And I am fairly sure it was this way about a year ago when I first ran this analysis.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是一些示例数据(来自
?classify
)您可以创建多边形并添加感兴趣的变量
您还可以从 SpatRaster 中删除类别,如下所示:
Here is some example data (from
?classify
)You can create polygons and add variables of interest
You can also remove the categories from the SpatRaster like this: