Skip to content

Commit

Permalink
fixes #317
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Sep 29, 2021
1 parent 3b65b30 commit e904e60
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
28 changes: 24 additions & 4 deletions R/crs.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,37 @@ is.proj <- function(crs) {
warn("crs<-", "Only the WGS84, NAD83 and NAD27 datums can be used with a PROJ.4 string. Use WKT2, authority:code, or +towgs84= instead")
}
}
d <- grep("towgs84=", x, value=TRUE)
if (length(d) > 0) {
warn("crs<-", "+towgs84 parameters in a PROJ4 string are ignored")
}
#d <- grep("towgs84=", x, value=TRUE)
#if (length(d) > 0) {
# warn("crs<-", "+towgs84 parameters in a PROJ4 string are ignored")
#}
}


.proj4 <- function(x) {
x@ptr$get_crs("proj4")
}

.name_or_proj4 <- function(x) {
d <- .srs_describe(x@ptr$get_crs("wkt"))
r <- x@ptr$get_crs("proj4")
if (d$name != "unknown") {
if (substr(r, 1, 13) == "+proj=longlat") {
r <- paste("lon/lat", d$name)
} else {
r <- d$name
}
if (!is.na(d$EPSG)) {
r <- paste0(r, " (EPSG:", d$EPSG, ")")
}
} else {
r <- x@ptr$get_crs("proj4")
}
r
}



.srs_describe <- function(srs) {
info <- .SRSinfo(srs)
names(info) <- c("name", "EPSG", "area", "extent")
Expand Down
8 changes: 5 additions & 3 deletions R/show.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ setMethod ("show" , "SpatVector",
d <- dim(object)
cat(" dimensions : ", d[1], ", ", d[2], " (geometries, attributes)\n", sep="" )
cat(" extent : ", e[1], ", ", e[2], ", ", e[3], ", ", e[4], " (xmin, xmax, ymin, ymax)\n", sep="")
cat(" coord. ref. :", .proj4(object), "\n")
cat(" coord. ref. :", .name_or_proj4(object), "\n")
if (all(d > 0)) {
dd <- as.data.frame(object)
printDF(dd, 3, TRUE)
Expand Down Expand Up @@ -152,7 +152,9 @@ setMethod ("show" , "SpatRaster",
e <- as.vector(ext(object))
cat("extent : " , e[1], ", ", e[2], ", ", e[3], ", ", e[4], " (xmin, xmax, ymin, ymax)\n", sep="")
}
cat("coord. ref. :" , .proj4(object), "\n")


cat("coord. ref. :" , .name_or_proj4(object), "\n")


if (hasValues(object)) {
Expand Down Expand Up @@ -384,7 +386,7 @@ setMethod("show" , "SpatRasterDataset",
cat("extent : " , e[1], ", ", e[2], ", ", e[3], ", ", e[4], " (xmin, xmax, ymin, ymax)\n", sep="")


cat("coord. ref. :" , .proj4(object[1]), "\n")
cat("coord. ref. :" , .name_or_proj4(object[1]), "\n")

s <- unlist(lapply(1:ns, function(i) .sources(object[i])))
s <- unique(s)
Expand Down

0 comments on commit e904e60

Please sign in to comment.