Skip to content

Commit

Permalink
add latmin, latlax parms to land masking
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondben committed Oct 11, 2023
1 parent 3c7feab commit d0353c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions R/landmask.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions man/gshhsMask.Rd

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

0 comments on commit d0353c9

Please sign in to comment.