| 1 |
# Lancaster, Thu Nov 4 14:44:00 GMT 2004, fresh start from icelfloe |
| 2 |
setClass("Spatial", |
| 3 |
slots = c(bbox = "matrix", proj4string = "CRS"), |
| 4 |
validity = function(object) { |
| 5 |
# print("Entering validation: Spatial") |
| 6 |
bb = bbox(object) |
| 7 |
if (!is.matrix(bb)) |
| 8 |
return("bbox should be a matrix") |
| 9 |
if (!mode(bb) == "numeric") |
| 10 |
return("bbox should be a numeric matrix") |
| 11 |
n = dimensions(object) |
| 12 |
if (n < 2) |
| 13 |
return("spatial.dimension should be 2 or more") |
| 14 |
if (any(is.na(bb))) |
| 15 |
return("bbox should never contain NA values") |
| 16 |
if (any(!is.finite(bb))) |
| 17 |
return("bbox should never contain infinite values") |
| 18 |
if (any(bb[,"max"] < bb[,"min"])) |
| 19 |
return("invalid bbox: max < min") |
| 20 |
if (!is(object@proj4string, "CRS")) |
| 21 |
return("proj4string slot should be of class CRS") |
| 22 |
p4str <- object@proj4string@projargs |
| 23 |
if (nrow(bb) > 0 && !is.na(p4str) && !nzchar(p4str)) { |
| 24 |
res <- grep("longlat", p4str, fixed=TRUE) |
| 25 |
if (length(res) != 0) {# unprojected, |
| 26 |
ll_sanity_res <- .ll_sanity(bb) |
| 27 |
if (!ll_sanity_res) { |
| 28 |
lst <- sapply(attr(ll_sanity_res, "details"), |
| 29 |
attr, "out") |
| 30 |
out <- paste(format(unlist(lst), digits=12), collapse=" ") |
| 31 |
mess <- paste("Geographical CRS given to", |
| 32 |
"non-conformant data:", out) |
| 33 |
if (get_ll_warn()) |
| 34 |
warning(mess) |
| 35 |
else |
| 36 |
stop(mess) |
| 37 |
} |
| 38 |
} |
| 39 |
# split out from proj4string<- and Spatial validity to cover numerical fuzz |
| 40 |
# RSB 070216 |
| 41 |
# && any(bb[1,1] < -180 || bb[1,2] > 360 || |
| 42 |
# bb[2,1] < -90 || bb[2,2] > 90)) |
| 43 |
# return("Geographical CRS given to non-conformant data") |
| 44 |
} |
| 45 |
# validate proj4string here? -- no, that's rdgal's business |
| 46 |
return(TRUE) |
| 47 |
} |
| 48 |
) |