From d0353c9b01da1613bd70cb82661434b4278b9d8b Mon Sep 17 00:00:00 2001 From: Ben Raymond Date: Wed, 11 Oct 2023 15:10:28 +1100 Subject: [PATCH] add latmin, latlax parms to land masking --- R/landmask.R | 11 ++++------- man/gshhsMask.Rd | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/R/landmask.R b/R/landmask.R index 17f6c5c..dafe03c 100644 --- a/R/landmask.R +++ b/R/landmask.R @@ -13,21 +13,18 @@ #' mask(0, c(100, -65)) ## test point lon,lat #' #' @export -gshhsMask <- function(res = 0.1) { - if (!res %in% c(0.1, 0.05)) { - res <- 0.1 - } +gshhsMask <- function(res = 0.1, latmin = -90, latmax = 90) { + if (!res %in% c(0.1, 0.05)) res <- 0.1 land.mask <- readPNG(system.file("extdata", paste0("land_mask_gshhs-", res, ".png"), package = "availability")) ## 0 = land, 1 = ocean if (length(dim(land.mask)) > 1) land.mask <- land.mask[, , 1] land.lon <- seq(from = -180+res/2, to = 180-res/2, length.out = dim(land.mask)[2]) land.lat <- seq(from = 90-res/2, to = -90+res/2, length.out = dim(land.mask)[1]) function(tm, pt) { - lonidx <- which.min(abs(land.lon-((pt[[1]]+180)%%360-180))) - latidx <- which.min(abs(land.lat-pt[[2]])) - land.mask[latidx, lonidx] > 0 + (pt[[2]] > latmin) & (pt[[2]] < latmax) & (land.mask[which.min(abs(land.lat-pt[[2]])), which.min(abs(land.lon-((pt[[1]]+180)%%360-180)))] > 0) } } + ##' @rdname gshhsMask ##' @export landmask_init <- gshhsMask diff --git a/man/gshhsMask.Rd b/man/gshhsMask.Rd index 074b97a..65f7959 100644 --- a/man/gshhsMask.Rd +++ b/man/gshhsMask.Rd @@ -5,9 +5,9 @@ \alias{landmask_init} \title{A land mask based on the GSHHS data set} \usage{ -gshhsMask(res = 0.1) +gshhsMask(res = 0.1, latmin = -90, latmax = 90) -landmask_init(res = 0.1) +landmask_init(res = 0.1, latmin = -90, latmax = 90) } \arguments{ \item{res}{numeric: the spatial resolution of the mask, in degrees (either 0.1 or 0.05)}