【发布时间】:2021-11-25 05:14:37
【问题描述】:
我希望通过属性来分解空间线数据框。在我的数据集中,有一条河线,其中多个线段穿过相同的栖息地类型,我希望每个栖息地类型都有一个连续的线段。
raster:aggregate 非常适用于空间多边形,虽然文档提到了 spatialpolygons/lines,但描述和示例只提到了空间多边形。
每当我在空间线数据帧上运行时,我都会收到错误消息: h(simpleError(msg, call)) 中的错误: 在为函数“spChFIDs”选择方法时评估参数“obj”时出错:在为函数“bbox”选择方法时评估参数“obj”时出错:“字符”类对象的分配对插槽无效“空间”类的对象中的“proj4string”;是(值,“CRS”)不是 TRUE 另外:警告信息: 在 proj4string(x) 中:CRS 对象有注释,在输出中丢失:
一些分享友好的代码来突出问题:
library(raster)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
x <- rasterToContour(r)
#create duplicate data that is slightly shifted so there is still some spatial overlap
x2 <- shift(x, dx=100, dy=-100)
#combine the two spatial dataframes
x3 <- raster::bind(x, x2)
#aggreate or "dissolve" the features by "level"
test <- raster::aggregate(x3, by = "level")
#vs how it works on a spatial polygon
p <- shapefile(system.file("external/lux.shp", package="raster"))
test2 <- raster::aggregate(p, by = "NAME_1")
谢谢
【问题讨论】:
标签: aggregate line raster spatial