Debian Codegraph @

R/Class-SpatialLines.R

raw
1 setClass("Line",
2 slots = c(coords = "matrix"),
3 validity = function(object) {
4 if (any(is.na(object@coords)))
5 stop("coords cannot contain missing values")
6 if (ncol(object@coords) != 2)
7 return("coords should have 2 columns")
8 # if (nrow(object@coords) < 2)
9 # return("Line should have at least 2 points")
10 return(TRUE)
11 }
12 )
13
14 setClass("Lines",
15 slots = c(Lines = "list", ID = "character"),
16 validity = function(object) {
17 if (any(sapply(object@Lines, function(x) !is(x, "Line"))))
18 stop("not a list of Line objects")
19 return(TRUE)
20 })
21
22 setClass("SpatialLines",
23 contains = "Spatial",
24 slots = c(lines = "list"),
25 validity = function(object) {
26 if (any(unlist(lapply(object@lines, function(x)
27 !is(x, "Lines"))))) stop("lines not Lines objects")
28 IDs <- sapply(slot(object, "lines"), function(i) slot(i, "ID"))
29 if (anyDuplicated(IDs))
30 return("non-unique Lines ID slot values")
31 # if (length(object@lines) !=
32 # length(unique(sapply(slot(object, "lines"),
33 # function(x) slot(x, "ID")))))
34 # return("non-unique Lines ID slot values")
35 return(TRUE)
36 }
37 )
38
39 getSLlinesSlot <- function(SL) {
40 .Deprecated("slot", msg="use *apply and slot directly", package = "sp")
41 SL@lines
42 }
43
44 getLinesLinesSlot <- function(SL) {
45 .Deprecated("slot", msg="use *apply and slot directly", package = "sp")
46 SL@Lines
47 }
48
49 getLinesIDSlot <- function(Lines) {
50 .Deprecated("slot", msg="use *apply and slot directly", package = "sp")
51 Lines@ID
52 }
53
54 getSLLinesIDSlots <- function(SL) {
55 .Deprecated("slot", msg="use *apply and slot directly", package = "sp")
56 Sls <- slot(SL, "lines")
57 sapply(Sls, function(x) slot(x, "ID"))
58 }