Skip to content

Commit

Permalink
feat: add a layer with ices_division borders
Browse files Browse the repository at this point in the history
Issue: #158
  • Loading branch information
PMHLambert committed May 1, 2023
1 parent 96513bc commit 4197fa1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
9 changes: 8 additions & 1 deletion R/fct_mongo.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ launch_mongo <- function(session = getDefaultReactiveDomain()) {
tm_catchmment,
cache = session$userData$mongo_cache
)
session$userData$tm_ices_division_m <- memoise::memoise(
tm_ices_division,
cache = session$userData$mongo_cache
)
}
get_data_ocean_m <- function(session = getDefaultReactiveDomain()) {
session$userData$data_ocean_m
Expand All @@ -62,4 +66,7 @@ get_data_continent_m <- function(session = getDefaultReactiveDomain()) {
}
get_tm_catchmment_m <- function(session = getDefaultReactiveDomain()) {
session$userData$tm_catchmment_m
}
}
get_tm_ices_division_m <- function(session = getDefaultReactiveDomain()) {
session$userData$tm_ices_division_m
}
17 changes: 16 additions & 1 deletion R/mod_a_first_fct_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ tm_ocean <- function(dataOcean,
title = paste0(title, "\n(", yearStart, "-", yearEnd, ")"),
palette = c("#F7FBFF", "#C6DBEF", "#9ECAE1", "#4292C6", "#08519C", "#08306B"),
n = 6,
border.col = "gray90",
labels = c(
"Not recorded in the period" %>% with_i18("absent") %>% as.character(),
"[1, 3]",
Expand All @@ -50,6 +51,13 @@ tm_ocean <- function(dataOcean,
)
}

#' @importFrom tmap tm_shape tm_borders
#' @noRd
tm_ices_division <- function(ices_division) {
tm_shape(ices_division) +
tm_borders(col = 'grey70', lwd = 1)
}

#' @importFrom dplyr left_join filter
#' @noRd
data_continent <- function(catchment_geom,
Expand Down Expand Up @@ -112,10 +120,16 @@ tm_draw <- function(species_latin_name,
catchment_geom,
dataALL,
ices_geom,
ices_division,
session = shiny::getDefaultReactiveDomain()) {
# =====================================================================================
# ----------------------------------------- country frontier

# -----------------------------------------ices division border
tm_ices_division <- get_tm_ices_division_m(
session = session
)(
ices_division
)
#--------------------------- data in ocean
dataOcean <- get_data_ocean_m(
session = session
Expand Down Expand Up @@ -155,6 +169,7 @@ tm_draw <- function(species_latin_name,
# ------------------------------------------ display the map
tm_graticules() +
tm_ocean +
tm_ices_division +
tm_frontiers +
tm_catchmment +
tm_layout(
Expand Down
7 changes: 7 additions & 0 deletions R/utils_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ generate_datasets <- function(con) {
sf::st_transform("+proj=wintri") # %>%
# rmapshaper::ms_simplify()

ices_division <- sf::st_read(
con,
query = "SELECT area_full AS icesname, simplified_geom FROM diadesatlas.ices_area;"
) %>%
sf::st_transform("+proj=wintri") # %>%

species_order <- c(
"Alosa alosa",
"Alosa fallax",
Expand Down Expand Up @@ -263,6 +269,7 @@ generate_datasets <- function(con) {
catchment_geom = catchment_geom,
dataALL = dataALL,
ices_geom = ices_geom,
ices_division = ices_division,
species_list = species_list,
countries_mortalities_list = countries_mortalities_list
)
Expand Down
3 changes: 3 additions & 0 deletions data-raw/bb-page1-catch-bycatch.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ tm_draw(
catchment_geom = datasets$catchment_geom,
dataALL = datasets$dataALL,
ices_geom = datasets$ices_geom,
ices_division = datasets$ices_division,
session = session
)
Expand All @@ -92,6 +93,7 @@ tm_draw(
catchment_geom = datasets$catchment_geom,
dataALL = datasets$dataALL,
ices_geom = datasets$ices_geom,
ices_division = datasets$ices_division,
session = session
)
Expand All @@ -103,6 +105,7 @@ tm1 <- tm_draw(
catchment_geom = datasets$catchment_geom,
dataALL = datasets$dataALL,
ices_geom = datasets$ices_geom,
ices_division = datasets$ices_division,
session = session
)
tm1 + diades.atlas::tm_frontiers
Expand Down

0 comments on commit 4197fa1

Please sign in to comment.