在R中提取栅格配置文件会发出警告:“结果列数不是矢量长度的倍数”

时间:2014-08-01 14:41:12

标签: r raster

我遇到了沿着一条线提取栅格值的问题。下面的代码说明。非常感谢您的帮助。

require(raster)
require(sp)

r = raster(volcano)
extent(r) = c(-2,1,50,54)
crs(r) = CRS('+proj=longlat +datum=WGS84')
plot(r, asp=T)

pts = data.frame(name=c('A','B','C','D'), lon=c(-1.5,-0.5,0,0.5), lat=c(51,52,53,53.8))
coordinates(pts) = ~ lon + lat
plot(pts, add=T)

path = list()
for(i in 2:4) path[[i-1]] = Line(pts[(i-1):i,])
path = SpatialLines(list(Lines(path, ID = 'id')), proj4string=CRS('+proj=longlat +datum=WGS84'))
plot(path, add=T)

产生..

enter image description here

使用extract()获取该行的值:

topo_profile = extract(x=r, y=path, along=TRUE)[[1]]
plot(topo_profile, type='l')

发出以下警告:

Warning messages:
1: In rbind(vv, v) :
  number of columns of result is not a multiple of vector length (arg 1)
2: In rbind(vv, v) :
  number of columns of result is not a multiple of vector length (arg 1)

并产生看起来只是折线的一段的轮廓..

enter image description here

知道为什么提取物不能按预期工作吗?

1 个答案:

答案 0 :(得分:0)

解决了 - 我的线条创作有点不同寻常。此版本的path有效:

path = SpatialLines(list(Lines(Line(pts[,2:3]),'id')))

enter image description here