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
|
# Copyright (c) 2003-8 by Barry Rowlingson and Roger Bivand
if (!is.R()) {
strsplit <- function(a,b) {
if (a == as.character(NA))
return(as.character(NA))
else list(unlist(unpaste(a, b)))
}
}
"CRS" <- function(projargs) {
if (nchar(projargs) == 0) projargs <- as.character(NA)
if (is.na(projargs)) uprojargs <- projargs
else uprojargs <- paste(unique(unlist(strsplit(projargs, " "))),
collapse=" ")
if (length(grep("= ", uprojargs)) != 0)
stop(paste("No spaces permitted in PROJ4 argument-value pairs:",
uprojargs))
if (length(grep(" [:alnum:]", uprojargs)) != 0)
stop(paste("PROJ4 argument-value pairs must begin with +:",
uprojargs))
# if (length(grep("rgdal", search()) > 0) &&
# (sessionInfo()$otherPkgs$rgdal$Version > "0.4-2")) {
# sessionInfo()/read.dcf() problem in loop 080307
if ("rgdal" %in% .packages()) {
if (!is.na(uprojargs)) {
res <- .Call("checkCRSArgs", uprojargs,
PACKAGE="rgdal")
} else res <- list(TRUE, as.character(NA))
if (!res[[1]]) stop(res[[2]])
else uprojargs <- res[[2]]
}
res <- new("CRS", projargs=uprojargs)
res
}
"print.CRS" <- function(x, ...)
{
pst <- paste(strwrap(x@projargs), collapse="\n")
if (nchar(pst) < 40) cat(paste("CRS arguments:", pst, "\n"))
else cat(paste("CRS arguments:\n", pst, "\n"))
invisible(pst)
}
setMethod("show", "CRS", function(object) print.CRS(object))
|