diff --git a/R/SOcrs.R b/R/SOcrs.R index 2aa08f1..c551d5c 100644 --- a/R/SOcrs.R +++ b/R/SOcrs.R @@ -19,3 +19,15 @@ SOcrs <- function(crs = NULL) { if (is.null(crs)) warning("No SOmap.crs.inuse") crs } + + +SOextent <- function(extent = NULL) { + if (!is.null(extent)) { + options(SOmap.extent.inuse = extent) + return(extent) + } + extent <- getOption("SOmap.extent.inuse") + if (is.null(crs)) warning("No SOmap.extent.inuse") + extent + +} diff --git a/R/SOmap.R b/R/SOmap.R index 6d0a51f..f036b5b 100644 --- a/R/SOmap.R +++ b/R/SOmap.R @@ -164,6 +164,7 @@ print.SOmap <- function(x, ...) { #on.exit(par(op)) ## record current CRS SOcrs(x$projection) + SOextent(c(-180, 180, -90, x$trim)) ## iterate through plot_sequence plot_all(x) invisible(x) diff --git a/R/SOplot.R b/R/SOplot.R index 76a35ae..8320fbc 100644 --- a/R/SOplot.R +++ b/R/SOplot.R @@ -22,10 +22,22 @@ #' } #' @export SOplot<-function(x, y = NULL, target = NULL, ..., source = NULL, add=TRUE) { - if (is.null(y) && is.data.frame(x) && !inherits(x, c("sf", "Spatial"))) { + if (is.null(y) && is.data.frame(x) && !inherits(x, c("sf", "Spatial", "RasterLayer"))) { y <- x[[2]] x <- x[[1]] + ## check extent #98 + ext <- SOextent() + + if (!all(x >= ext[1] & x <= ext[2])) { + message(sprintf('some longitudes outside the existing plot range (? %.3f,%.3f', ext[1], ext[2])) + } + if (!all(y >= ext[3] & y <= ext[4])) { + message(sprintf('some latitudes outside the existing plot range (? %.3f,%.f)', ext[3], ext[4])) + } + + } + SObj <- SOproj(x = x, y = y, target = target, source = source, ...) everything <- par(no.readonly = TRUE) if (add && (is.matrix(x) || (is.numeric(x) && is.numeric(y)))) { diff --git a/R/SOproj.R b/R/SOproj.R index ee50e9d..099c71c 100644 --- a/R/SOproj.R +++ b/R/SOproj.R @@ -37,6 +37,7 @@ #' @importFrom sp coordinates<- SOproj <- function(x, y = NULL, target = NULL, data, ..., source = NULL) { ## wrap in `quietly` to suppress unwanted warnings + if (is.null(source)) source <- "+proj=longlat +datum=WGS84" quietly(SOproj_inner(x = x, y = y, target = target, data = data, ..., source = source)) } @@ -87,6 +88,7 @@ SOproj_inner <- function(x, y, target, data, ..., source) { source <- "+proj=longlat +datum=WGS84" } #browser() + xy0 <- reproj::reproj(cbind(x, y), target = target, source = source) out <- data.frame(x = xy0[,1], y = xy0[,2], data = data) sp::coordinates(out) <- c("x", "y") diff --git a/R/new_automap.R b/R/new_automap.R index 40d35ef..7cec869 100644 --- a/R/new_automap.R +++ b/R/new_automap.R @@ -241,6 +241,6 @@ automap_maker <- } #bathymetry <- raster::trim(bathymetry) SOcrs(raster::projection(bathymetry)) - + SOextent(c(raster::xmin(src_extent), raster::xmax(src_extent), raster::ymin(src_extent), raster::ymax(src_extent))) return(list(target = bathymetry, xy = xy)) } diff --git a/inst/examples/new_automap_examples.R b/inst/examples/new_automap_examples.R index 1829af7..09e56a1 100644 --- a/inst/examples/new_automap_examples.R +++ b/inst/examples/new_automap_examples.R @@ -40,13 +40,13 @@ SOplot(sst, col = palr::sstPal(100)) #SOplot(sst, col = palr::sstPal(100)) SOmap_auto(ice, target = "laea", centre_lon = 147, centre_lat = -42) -SOplot(ice, col = palr::icePal(100)) +SOplot(ice, col = palr::ice_pal(100)) SOmap_auto(ice, centre_lon = 147, centre_lat = -42) -SOplot(ice, col = palr::icePal(100)) +SOplot(ice, col = palr::ice_pal(100)) SOmap_auto(ice, target = "merc", centre_lon = 147, centre_lat = -42) -SOplot(ice, col = palr::icePal(100)) +SOplot(ice, col = palr::ice_pal(100)) ramp2 <- grDevices::colorRampPalette(c("#54A3D1","#60B3EB","#78C8F0","#98D1F5","#B5DCFF","#BDE1F0","#CDEBFA","#D6EFFF","#EBFAFF","grey92","grey94","grey96", "white")) bluepal <- ramp2(45) diff --git a/man/SOmap_auto.Rd b/man/SOmap_auto.Rd index 9820a7b..ea1981d 100644 --- a/man/SOmap_auto.Rd +++ b/man/SOmap_auto.Rd @@ -10,8 +10,7 @@ SOmap_auto( centre_lon = NULL, centre_lat = NULL, target = "stere", - dimXY = c(1024, 1024), - + dimXY = c(512, 512), bathy = TRUE, land = TRUE, land_col = "black", diff --git a/vignettes/many-automap-examples.Rmd b/vignettes/many-automap-examples.Rmd index eae92e7..1465535 100644 --- a/vignettes/many-automap-examples.Rmd +++ b/vignettes/many-automap-examples.Rmd @@ -73,19 +73,19 @@ SOmap_auto(ice) ```{r examples13, eval=FALSE} SOmap_auto(ice, target = "laea", centre_lon = 147, centre_lat = -42) -SOplot(ice, col = palr::icePal(100)) +SOplot(ice, col = palr::ice_pal(100)) ``` ```{r examples14, eval = TRUE} SOmap_auto(ice, centre_lon = 147, centre_lat = -42) -SOplot(ice, col = palr::icePal(100)) +SOplot(ice, col = palr::ice_pal(100)) ``` ```{r examples15, eval = TRUE} SOmap_auto(ice, target = "merc", centre_lon = 147, centre_lat = -42) -SOplot(ice, col = palr::icePal(100)) +SOplot(ice, col = palr::ice_pal(100)) ``` ```{r examples16, eval = TRUE}