File: Class-SpatialLines.R

package info (click to toggle)
r-cran-sp 1%3A0.9-66-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,696 kB
  • ctags: 123
  • sloc: ansic: 1,475; sh: 6; makefile: 5
file content (64 lines) | stat: -rw-r--r-- 1,819 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
setClass("Line", 
	representation(coords = "matrix"),
	prototype = list(coords = matrix(0)),
	validity = function(object) {
		if (any(is.na(object@coords)))
			stop("coords cannot contain missing values")
		if (ncol(object@coords) != 2)
			return("coords should have 2 columns")
#		if (nrow(object@coords) < 2)
#			return("Line should have at least 2 points")
		return(TRUE)
	}
)

setClass("Lines",
	representation(Lines = "list", ID = "character"),
	validity = function(object) {
		if (any(sapply(object@Lines, function(x) !is(x, "Line"))))
			stop("not a list of Line objects")
		return(TRUE)
})

setClass("SpatialLines",
	representation("Spatial", lines = "list"),
	prototype = list(bbox = matrix(rep(NA, 2), 2, 2, 
			dimnames = list(NULL, c("min","max"))),
		proj4string = CRS(as.character(NA)),
		lines = list()),
	validity = function(object) {
		if (any(unlist(lapply(object@lines, function(x) 
			!is(x, "Lines"))))) stop("lines not Lines objects")
                IDs <- sapply(slot(object, "lines"), function(i) slot(i, "ID"))
		if (anyDuplicated(IDs))
			return("non-unique Lines ID slot values")
#		if (length(object@lines) != 
#			length(unique(sapply(slot(object, "lines"),
#                            function(x) slot(x, "ID"))))) 
#				return("non-unique Lines ID slot values")
		return(TRUE)
	}
)

getSLlinesSlot <- function(SL) {
    .Deprecated("slot", msg="use *apply and slot directly")
    SL@lines
}

getLinesLinesSlot <- function(SL) {
    .Deprecated("slot", msg="use *apply and slot directly")
    SL@Lines
}

getLinesIDSlot <- function(Lines) {
    .Deprecated("slot", msg="use *apply and slot directly")
    Lines@ID
}

getSLLinesIDSlots <- function(SL) {
        .Deprecated("slot", msg="use *apply and slot directly")
	Sls <- slot(SL, "lines")
	sapply(Sls, function(x) slot(x, "ID"))
}