Skip to content

Commit

Permalink
new internal SOextent, and check for #98, #99
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Nov 17, 2021
1 parent 56d6546 commit c493237
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 10 deletions.
12 changes: 12 additions & 0 deletions R/SOcrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
1 change: 1 addition & 0 deletions R/SOmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion R/SOplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))) {
Expand Down
2 changes: 2 additions & 0 deletions R/SOproj.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion R/new_automap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
6 changes: 3 additions & 3 deletions inst/examples/new_automap_examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions man/SOmap_auto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vignettes/many-automap-examples.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit c493237

Please sign in to comment.