我正在使用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)
Run Code Online (Sandbox Code Playgroud)
错误信息:
(函数(classes,fdef,mtable)中的错误:无法为签名'"NULL"找到函数'proj4string'的继承方法
如何解决这个问题?
方法是:
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
Run Code Online (Sandbox Code Playgroud)
你在找什么?