gpt4 book ai didi

r - 创建空空间线对象

转载 作者:行者123 更新时间:2023-12-04 03:08:55 25 4
gpt4 key购买 nike

我正在尝试创建一个空的 SpatialLines 对象。使用多边形很容易:

SpatialPolygons(list())

对于空间线这不起作用:

SpatialLines(LinesList = list())
Error in bb[1, ] : incorrect number of dimensions
SpatialLines(LinesList = Lines(list(),ID = "a"))
Error in as.list.default(X) :
no method for coercing this S4 class to a vector
SpatialLines(LinesList = Lines(slinelist = Line(coords = cbind(x = c(), y = c())), ID = c()))
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘coordinates’ for signature ‘"NULL"’

有人知道如何创建一个空的 SpatialLines 对象吗?

解决方法

我找到了一个可能不是最好的解决方法。我生成了一条没有长度的空间线:

SpatialLines(list(Lines(Line(coords = cbind(x = c(0,0), y = c(0,0))), ID = "A")))

最佳答案

有趣的问题!

我能够解决的唯一方法是创建一条虚拟线并将其删除,如下所示:

sl <- SpatialLines(LinesList = list(Lines(Line(matrix(0, ncol = 2)), ID = NA)))
sl <- sl[0]
length(sl)
# [1] 0

添加虚拟行时,长度按预期返回为 1:

length(rbind.SpatialLines(sl, SpatialLines(list(Lines(Line(coords = cbind(x = c(0,0), 
y = c(0,0))),
ID = "A")))))
# [1] 1

关于r - 创建空空间线对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46724808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com