Skip to content

Commit

Permalink
Fix a case where data argument produced too wide boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
MikkoVihtakari committed Nov 2, 2023
1 parent 5608ed8 commit 44628cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ggOceanMaps
Type: Package
Title: Plot Data on Oceanographic Maps using 'ggplot2'
Version: 2.1.6
Date: 2023-10-30
Version: 2.1.7
Date: 2023-11-02
Authors@R: c(person("Mikko", "Vihtakari", email = "mikko.vihtakari@hi.no",
role = c("aut", "cre"),
comment = c(affiliation = "Institute of Marine Research",
Expand Down
32 changes: 20 additions & 12 deletions R/basemap_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ basemap_data_detect_case <- function(limits = NULL, data = NULL, shapefiles = NU


## Define shapefiles ####
basemap_data_define_shapefiles <- function(limits = NULL, data = NULL, shapefiles = NULL, crs = NULL, bathymetry = FALSE, bathy.type = NULL, downsample = 0, glaciers = FALSE, rotate = FALSE, expand.factor = 1.1, verbose = FALSE) {
basemap_data_define_shapefiles <- function(limits = NULL, data = NULL, shapefiles = NULL, crs = NULL, bathymetry = FALSE, bathy.type = NULL, downsample = 0, glaciers = FALSE, rotate = FALSE, expand.factor = 1, verbose = FALSE) {

# Switches and checks ####

Expand Down Expand Up @@ -511,9 +511,11 @@ basemap_data_define_shapefiles <- function(limits = NULL, data = NULL, shapefile
crs <- rotate_crs(crs, limits[1:2])
clip_shape <- dd_clip_boundary(limits, crs, expand.factor)
} else {

clip_shape <- dd_clip_boundary(limits, crs, expand.factor)


## This approach produces too wide boundaries in some cases
# clip_shape <- dd_clip_boundary(limits, crs, expand.factor)

## This approach does not work for antimeridian
# tmp <- sf::st_bbox(sf::st_transform(data, crs))
#
# if(!is.null(expand.factor)) {
Expand All @@ -530,14 +532,20 @@ basemap_data_define_shapefiles <- function(limits = NULL, data = NULL, shapefile
#
# clip_shape <- sf::st_as_sfc(tmp)

## Previous code. There was probably a reason why I wrote this
# if(sf::st_crs(data) == crs) {
# clip_shape <- sf::st_as_sfc(sf::st_bbox(data))
# clip_shape <- sf::st_as_sfc(sf::st_bbox(sf::st_buffer(clip_shape, dist = 0.01*sqrt(sf::st_area(clip_shape)))))
# } else {
# clip_shape <- sf::st_as_sfc(sf::st_bbox(sf::st_transform(data, crs)))
# clip_shape <- sf::st_as_sfc(sf::st_bbox(sf::st_buffer(clip_shape, dist = 0.01*sqrt(sf::st_area(clip_shape)))))
# }
## Previous code. There was probably a reason why I wrote this, but this probably does not work either
if(sf::st_crs(data) == crs) {
clip_shape <- sf::st_as_sfc(sf::st_bbox(data))
} else {
clip_shape <- sf::st_as_sfc(sf::st_bbox(sf::st_transform(data, crs)))
}
clip_shape <-
sf::st_as_sfc(
sf::st_bbox(
sf::st_buffer(
clip_shape, dist = (expand.factor-1)*sqrt(sf::st_area(clip_shape))
)
)
)
}

} else if(case %in% c("limits_proj", "data_proj")) { ## Projected limits/data ####
Expand Down

0 comments on commit 44628cc

Please sign in to comment.