gpt4 book ai didi

r - 如何创建 SpatialLine 对象

转载 作者:行者123 更新时间:2023-12-04 12:35:30 24 4
gpt4 key购买 nike

我正在使用 sp 包创建 SpatialLines 对象并将其保存在对象列表 allLines 中。稍后我需要将 SpatialLines 相互比较,但这超出了当前的问题。

到目前为止,我只需要构造SpatialLines 对象。这是基于 hrbrmstr 答案的最后一段代码:

library(sp)
allLines <- NULL
x <- c(1,5,4,8)
y <- c(1,3,4,7)
xy <- cbind(x,y)
xy.sp = sp::SpatialPoints(xy)
spl <- SpatialLines(list(Lines(Line(xy.sp), ID="a")))
allLines <- rbind(allLines,spl)

错误信息:

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘proj4string’ for signature ‘"NULL"’

如何解决这个问题?

最佳答案

是:

library(sp)

x <- c(1,5,4,8)
y <- c(1,3,4,7)
SpatialLines(list(Lines(Line(cbind(x,y)), ID="a")))

## An object of class "SpatialLines"
## Slot "lines":
## [[1]]
## An object of class "Lines"
## Slot "Lines":
## [[1]]
## An object of class "Line"
## Slot "coords":
## x y
## [1,] 1 1
## [2,] 5 3
## [3,] 4 4
## [4,] 8 7
##
##
##
## Slot "ID":
## [1] "a"
##
##
##
## Slot "bbox":
## min max
## x 1 8
## y 1 7
##
## Slot "proj4string":
## CRS arguments: NA

你在找什么?

关于r - 如何创建 SpatialLine 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27998952/

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