Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undesirable artefacts during map zooming/cropping for some CRS #120

Merged
merged 21 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions R/compilation.R
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ slim <- function(
-d 'OUTPUT_LOCATIONS=\"%s\"' \\
-d COALESCENT_ONLY=%s \\
-d MAX_ATTEMPTS=%i \\
%s",
binary,
%s 2>&1",
binary, # path to the SLiM binary on the command line
seed,
samples,
path.expand(model_dir),
Expand All @@ -490,7 +490,7 @@ slim <- function(

# execute the command, capture all log output and decide whether to print
# any of the log information to the console
log_output <- suppressWarnings(system(paste(slim_command, "2>&1"), intern = TRUE))
log_output <- suppressWarnings(system(slim_command, intern = TRUE))
log_warnings <- grep("WARNING", log_output, value = TRUE)
if (verbose)
cat(log_output, sep = "\n")
Expand Down
19 changes: 9 additions & 10 deletions R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -730,19 +730,18 @@ world <- function(xrange, yrange, landscape = "naturalearth", crs = NULL,
)
sf::st_agr(map_raw) <- "constant"

## transform the map (default geographic CRS) into the target CRS
map_transf <- tryCatch({
sf::st_transform(map_raw, crs) %>% sf::st_make_valid()
# define boundary coordinates in the target CRS
crop_bounds <- define_zoom(xrange, yrange, "EPSG:4326")

# crop the map to the boundary coordinates
map_cropped <- tryCatch({
sf::st_crop(sf::st_make_valid(map_raw), crop_bounds)
}, error = function(cond) {
sf::st_transform(map_raw, crs)
sf::st_crop(map_raw, crop_bounds)
})

## define boundary coordinates in the target CRS
zoom_bounds <- define_zoom(xrange, yrange, "EPSG:4326")
zoom_transf <- sf::st_transform(zoom_bounds, crs) %>% sf::st_make_valid()

## crop the map to the boundary coordinates
map <- sf::st_crop(map_transf, zoom_transf)
# transform the map into the target CRS if needed
map <- sf::st_transform(map_cropped, crs)
} else {
stop("Landscape has to be either 'blank', 'naturalearth' or an object of the class 'sf'",
call. = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ This makes it easier for us to define spatial features simply by reading the coo
africa <- region(
"Africa", map,
polygon = list(c(-18, 20), c(38, 20), c(30, 33),
c(20, 33), c(10, 38), c(-6, 36))
c(20, 33), c(10, 38), c(-6, 35))
)
europe <- region(
"Europe", map,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ This makes it easier for us to define spatial features simply by reading the coo
africa <- region(
"Africa", map,
polygon = list(c(-18, 20), c(38, 20), c(30, 33),
c(20, 33), c(10, 38), c(-6, 36))
c(20, 33), c(10, 38), c(-6, 35))
)
europe <- region(
"Europe", map,
Expand Down
41 changes: 19 additions & 22 deletions docs/articles/vignette-00-installation.html

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

24 changes: 11 additions & 13 deletions docs/articles/vignette-01-tutorial.html

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/articles/vignette-02-grid-model.html

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

Loading