File: Class-Spatial.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 (38 lines) | stat: -rw-r--r-- 1,447 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
# Lancaster, Thu Nov  4 14:44:00 GMT 2004, fresh start from icelfloe
setClass("Spatial",
	representation(bbox = "matrix", proj4string = "CRS"),
	prototype = list(bbox = matrix(rep(NA, 6), 3, 2, dimnames = list(NULL, c("min","max"))),
		proj4string = CRS(as.character(NA))), # prototype should not pass validity
	validity = function(object) {
# print("Entering validation: Spatial")
		bb = bbox(object)
		if (!is.matrix(bb))
			return("bbox should be a matrix")
		n = dimensions(object)
		if (n < 2)
			return("spatial.dimension should be 2 or more") 
		if (any(is.na(bb)))
			return("bbox should never contain NA values")
		if (any(!is.finite(bb)))
			return("bbox should never contain infinite values")
		if (any(bb[,"max"] < bb[,"min"]))
			return("invalid bbox: max < min")
		if (!is(object@proj4string, "CRS"))
			return("proj4string slot should be of class CRS")
		p4str <- object@proj4string@projargs
		if (!is.na(p4str) && nchar(p4str) > 0) {
			res <- grep("longlat", p4str, fixed=TRUE)
			if (length(res) != 0) # unprojected,
			  if (!.ll_sanity(bb))
			  stop("Geographical CRS given to non-conformant data")
# split out from proj4string<- and Spatial validity to cover numerical fuzz
# RSB 070216
#		    		&& any(bb[1,1] < -180 || bb[1,2] > 360 || 
#					bb[2,1] < -90 || bb[2,2] > 90))
#				return("Geographical CRS given to non-conformant data")
		}
		# validate proj4string here? -- no, that's rdgal's business
		return(TRUE)
	}
)