Skip to content

Commit ca73463

Browse files
committedMay 3, 2024·
fixes #1492
1 parent 07233c3 commit ca73463

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed
 

‎R/plot_raster.R

+16-8
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,17 @@
7171
}
7272

7373

74-
.as.raster.continuous <- function(out, x, type) {
74+
.as.raster.continuous <- function(out, x, type, Z=NULL) {
75+
76+
if (is.null(Z)) {
77+
Z <- as.matrix(x, wide=TRUE)
78+
Z[is.nan(Z) | is.infinite(Z)] <- NA
79+
}
7580

7681
Z <- as.matrix(x, wide=TRUE)
7782
Z[is.nan(Z) | is.infinite(Z)] <- NA
78-
83+
Z[] <- round(Z, 12)
84+
7985
# loss of precision
8086
# z <- stats::na.omit(round(as.vector(Z), 12))
8187
z <- stats::na.omit(as.vector(Z))
@@ -87,14 +93,14 @@
8793
return(out)
8894
}
8995

90-
uzi <- round(unique(z), 12)
96+
uzi <- unique(z)
9197

9298
if (type == "depends") {
9399
if (length(uzi) < 9) {
94-
return (.as.raster.classes(out, x))
100+
return (.as.raster.classes(out, x, Z=Z))
95101
}
96102
} else if ((length(uzi) == 1) && is.null(out$range)) {
97-
return (.as.raster.classes(out, x))
103+
return (.as.raster.classes(out, x, Z=Z))
98104
}
99105

100106
if (is.null(out$range)) {
@@ -146,10 +152,12 @@ prettyNumbs <- function(x, digits) {
146152
gsub("\\.$", "", x)
147153
}
148154

149-
.as.raster.classes <- function(out, x, ...) {
155+
.as.raster.classes <- function(out, x, Z=NULL, ...) {
150156

151-
Z <- as.matrix(x, wide=TRUE)
152-
Z[is.nan(Z) | is.infinite(Z)] <- NA
157+
if (is.null(Z)) {
158+
Z <- as.matrix(x, wide=TRUE)
159+
Z[is.nan(Z) | is.infinite(Z)] <- NA
160+
}
153161
if (all(is.na(Z))) {
154162
#out$values = FALSE
155163
out$range <- c(NA, NA)

0 commit comments

Comments
 (0)
Please sign in to comment.