2017-10-13 20 views
1

빈 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"))) 

답변

1

재미있는 질문!

내가 해결할 수 있었던 유일한 방법은 더미 라인을 작성하고 다음과 같이 제거하여이었다

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