From c947c0dbbb6ac786aeb6b4103575398b2a614701 Mon Sep 17 00:00:00 2001 From: Sean Rohan Date: Fri, 13 Dec 2024 15:28:43 -0800 Subject: [PATCH 1/2] Recover gbl 3.6 --- R/get_base_layers.R | 72 +++++++++++++++++------------- man/get_base_layers.Rd | 99 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 136 insertions(+), 35 deletions(-) diff --git a/R/get_base_layers.R b/R/get_base_layers.R index af47006..d462d22 100644 --- a/R/get_base_layers.R +++ b/R/get_base_layers.R @@ -214,7 +214,7 @@ get_base_layers <- function(select.region, survey.strata <- sf::st_read(system.file("extdata", "ebs_strata.shp", package = "akgfmaps"), quiet = TRUE) - survey.strata <- survey.strata[survey.strata$STRATUM %in% c(10, 20, 31, 32, 41, 42, 43, 50, 61, 62, 82, 90), ] + survey.strata <- survey.strata[survey.strata$Stratum %in% c(10, 20, 31, 32, 41, 42, 43, 50, 61, 62, 82, 90), ] survey.grid <- sf::st_read(system.file("extdata", grid.file, package = "akgfmaps"), quiet = TRUE) @@ -229,7 +229,6 @@ get_base_layers <- function(select.region, quiet = TRUE) survey.strata <- sf::st_read(system.file("extdata", "ebs_strata.shp", package = "akgfmaps"), quiet = TRUE) - survey.grid <- sf::st_read(system.file("extdata", grid.file, package = "akgfmaps"), quiet = TRUE) @@ -247,7 +246,7 @@ get_base_layers <- function(select.region, survey.strata <- sf::st_read(system.file("extdata", "ebs_strata.shp", package = "akgfmaps"), quiet = TRUE) - survey.strata <- survey.strata[survey.strata$STRATUM %in% c(81, 70, 71), ] + survey.strata <- survey.strata[survey.strata$Stratum %in% c(81,70,71), ] survey.grid <- sf::st_read(system.file("extdata", "bs_grid_w_corners.shp", package = "akgfmaps"), quiet = TRUE) @@ -308,6 +307,9 @@ get_base_layers <- function(select.region, survey.strata <- sf::st_read(system.file("extdata", "ai_strata.shp", package = "akgfmaps"), quiet = TRUE) survey.grid <- sf::st_read(system.file("extdata", "ai_grid.shp", package = "akgfmaps"), quiet = TRUE) + survey.strata <- survey.strata[survey.strata$STRATUM < 800 & survey.strata$STRATUM > 0, ] + survey.grid <- survey.grid[survey.grid$STRATUM < 800 & survey.grid$STRATUM > 0, ] + inpfc.strata <- get_inpfc_strata(select.region = "ai", set.crs = set.crs) lon.breaks <- c(170, 175, -180, -175, -170, -165, -160) @@ -320,6 +322,9 @@ get_base_layers <- function(select.region, survey.strata <- sf::st_read(system.file("extdata", "ai_strata.shp", package = "akgfmaps"), quiet = TRUE) survey.grid <- sf::st_read(system.file("extdata", "ai_grid.shp", package = "akgfmaps"), quiet = TRUE) + survey.strata <- survey.strata[survey.strata$STRATUM < 800 & survey.strata$STRATUM > 0, ] + survey.grid <- survey.grid[survey.grid$STRATUM < 800 & survey.grid$STRATUM > 0, ] + inpfc.strata <- get_inpfc_strata(select.region = "ai", set.crs = set.crs) lon.breaks <- seq(-176, -164, 2) @@ -329,11 +334,12 @@ get_base_layers <- function(select.region, # Aleutian Islands - Central --------------------------------------------------------------------- if(select.region[1] == "ai.central") { survey.area <- sf::st_read(system.file("extdata", "ai_area.shp", package = "akgfmaps"), quiet = TRUE) - survey.strata <- sf::st_read(system.file("extdata", "ai_strata.shp", package = "akgfmaps"), quiet = TRUE) - survey.grid <- sf::st_read(system.file("extdata", "ai_grid.shp", package = "akgfmaps"), quiet = TRUE) + survey.strata <- survey.strata[survey.strata$STRATUM < 800 & survey.strata$STRATUM > 0, ] + survey.grid <- survey.grid[survey.grid$STRATUM < 800 & survey.grid$STRATUM > 0, ] + inpfc.strata <- get_inpfc_strata(select.region = "ai", set.crs = set.crs) lon.breaks <- c(176, 178, 180, seq(-178, -170, 2)) @@ -343,11 +349,12 @@ get_base_layers <- function(select.region, # Aleutian Islands - West --------------------------------------------------------------------- if(select.region[1] == "ai.west") { survey.area <- sf::st_read(system.file("extdata", "ai_area.shp", package = "akgfmaps"), quiet = TRUE) - survey.strata <- sf::st_read(system.file("extdata", "ai_strata.shp", package = "akgfmaps"), quiet = TRUE) - survey.grid <- sf::st_read(system.file("extdata", "ai_grid.shp", package = "akgfmaps"), quiet = TRUE) + survey.strata <- survey.strata[survey.strata$STRATUM < 800 & survey.strata$STRATUM > 0, ] + survey.grid <- survey.grid[survey.grid$STRATUM < 800 & survey.grid$STRATUM > 0, ] + inpfc.strata <- get_inpfc_strata(select.region = "ai", set.crs = set.crs) lon.breaks <- seq(168, 180, 2) @@ -358,11 +365,12 @@ get_base_layers <- function(select.region, # Gulf of Alaska --------------------------------------------------------------------------------- if(select.region[1] == "goa") { survey.area <- sf::st_read(system.file("extdata", "goa_area.shp", package = "akgfmaps"), quiet = TRUE) - survey.strata <- sf::st_read(system.file("extdata", "goa_strata.shp", package = "akgfmaps"), quiet = TRUE) - survey.grid <- sf::st_read(system.file("extdata", "goa_grid.shp", package = "akgfmaps"), quiet = TRUE) + survey.strata <- survey.strata[survey.strata$STRATUM > 0, ] + survey.grid <- survey.grid[survey.grid$STRATUM > 0, ] + inpfc.strata <- get_inpfc_strata(select.region = "goa", set.crs = set.crs) lon.breaks <- seq(-175, -130, 5) @@ -372,11 +380,12 @@ get_base_layers <- function(select.region, # Gulf of Alaska - West -------------------------------------------------------------------------- if(select.region[1] == "goa.west") { survey.area <- sf::st_read(system.file("extdata", "goa_area.shp", package = "akgfmaps"), quiet = TRUE) - survey.strata <- sf::st_read(system.file("extdata", "goa_strata.shp", package = "akgfmaps"), quiet = TRUE) - survey.grid <- sf::st_read(system.file("extdata", "goa_grid.shp", package = "akgfmaps"), quiet = TRUE) + survey.strata <- survey.strata[survey.strata$STRATUM > 0, ] + survey.grid <- survey.grid[survey.grid$STRATUM > 0, ] + inpfc.strata <- get_inpfc_strata(select.region = "goa", set.crs = set.crs) lon.breaks <- seq(-174, -144, 2) @@ -386,11 +395,12 @@ get_base_layers <- function(select.region, # Gulf of Alaska - East -------------------------------------------------------------------------- if(select.region[1] == "goa.east") { survey.area <- sf::st_read(system.file("extdata", "goa_area.shp", package = "akgfmaps"), quiet = TRUE) - survey.strata <- sf::st_read(system.file("extdata", "goa_strata.shp", package = "akgfmaps"), quiet = TRUE) - survey.grid <- sf::st_read(system.file("extdata", "goa_grid.shp", package = "akgfmaps"), quiet = TRUE) + survey.strata <- survey.strata[survey.strata$STRATUM > 0, ] + survey.grid <- survey.grid[survey.grid$STRATUM > 0, ] + inpfc.strata <- get_inpfc_strata(select.region = "goa", set.crs = set.crs) lon.breaks <- seq(-160, -124, 2) @@ -549,23 +559,23 @@ get_base_layers <- function(select.region, "Exploitabl", "Active"), names(survey.grid) - ) - ] <- c("STATION_NUMBER", - "REGION", - "STATION_TYPE", - "STATION_DEPTH", - "GEOGRAPHIC_AREA", - "GEOGRAPHIC_AREA_NUMBER", - "NPFMC_MANAGEMENT_AREA", - "NPFMC_SABLEFISH_AREA", - "REP_AREA", - "FMP_MANAGEMENT_AREA", - "INPFC_MANAGEMENT_AREA", - "HABITAT_TYPE", - "LAT", - "LONG", - "EXPLOITABLE", - "ACTIVE") + ) + ] <- c("STATION_NUMBER", + "REGION", + "STATION_TYPE", + "STATION_DEPTH", + "GEOGRAPHIC_AREA", + "GEOGRAPHIC_AREA_NUMBER", + "NPFMC_MANAGEMENT_AREA", + "NPFMC_SABLEFISH_AREA", + "REP_AREA", + "FMP_MANAGEMENT_AREA", + "INPFC_MANAGEMENT_AREA", + "HABITAT_TYPE", + "LAT", + "LONG", + "EXPLOITABLE", + "ACTIVE") survey.area <- survey.strata[, "geometry"] |> sf::st_union(by_feature = FALSE) |> @@ -719,7 +729,7 @@ get_base_layers <- function(select.region, place.labels <- akgfmaps::transform_data_frame_crs(place.labels, out.crs = set.crs) - # Correct remaining degenerate geometry and dateline wrapping issues ----------------------------- + # Attempt to correct any remaining degenerate geometry and dateline wrapping issues -------------- if(fix.invalid.geom) { akland <- fix_geometry(x = akland) diff --git a/man/get_base_layers.Rd b/man/get_base_layers.Rd index 1693ebd..4f1822d 100644 --- a/man/get_base_layers.Rd +++ b/man/get_base_layers.Rd @@ -1,23 +1,37 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_base_layers.R +% Please edit documentation in R/get_base_layers.R, R/get_base_layers_v4.R \name{get_base_layers} \alias{get_base_layers} \title{Function to get base layers for bottom trawl and longline survey regions, bathymetry, and land} \usage{ get_base_layers( select.region, + design.year = NULL, set.crs = "EPSG:4269", use.survey.bathymetry = TRUE, - include.corners = NULL, + include.corners = FALSE, + split.land.at.180 = TRUE, + fix.invalid.geom = TRUE, + high.resolution.coast = FALSE +) + +get_base_layers( + select.region, + design.year = NULL, + set.crs = "EPSG:4269", + use.survey.bathymetry = TRUE, + include.corners = FALSE, split.land.at.180 = TRUE, fix.invalid.geom = TRUE, high.resolution.coast = FALSE ) } \arguments{ -\item{select.region}{Character vector indicating which region to retrieve. Bottom trawl survey options: ebs or bs.all, sebs or bs.south, nbs or bs.north, ecs, ebs.ecs, ai, ai.west, ai.central, ai.east, goa, goa.west, goa.east, ebs.slope, bssa1, bssa2, bssa3, bssa4, bssa5, bssa6. Longline survey options: ll.ebs, ll.bssa1, ll.bssa2, ll.bssa3, ll.bssa4, ll.bssa5, ll.ai, ll.ai.west, ll.ai.central, ll.goa, ll.goa.west, ll.goa.central, ll.goa.east} +\item{select.region}{Character vector indicating which region to retrieve. Bottom trawl survey options: ebs or bs.all, sebs or bs.south, nbs or bs.north, ecs, ai, ai.west, ai.central, ai.east, goa, goa.west, goa.east, ebs.slope, bssa1, bssa2, bssa3, bssa4, bssa5, bssa6. Longline survey options: ll.ebs, ll.bssa1, ll.bssa2, ll.bssa3, ll.bssa4, ll.bssa5, ll.ai, ll.ai.west, ll.ai.central, ll.goa, ll.goa.west, ll.goa.central, ll.goa.east} -\item{set.crs}{Which coordinate reference system should be used? If 'auto', Alaska Albers Equal Area (EPSG:3338) will be used.} +\item{design.year}{Survey design year for files to retrieve. Returns the most recent year when NULL.} + +\item{set.crs}{Which coordinate reference system should be used? If 'auto', Alaska Albers Equal Area (EPSG:3338) is used.} \item{use.survey.bathymetry}{Should survey bathymetry be used?} @@ -30,9 +44,13 @@ get_base_layers( \item{high.resolution.coast}{Should the State of Alaska polygon be a high resolution Alaska Department of Natural Resources 1:63360 scale polygon that includes smaller islands and a more detailed coastline? The higher resolution polygon (high.resolution.coast = TRUE) takes longer to load/plot and is recommended for spatial operations performed at high resolution (e.g., masking high resolution rasters). The lower resolution polygon (high.resolution.coast = FALSE) is recommended for general mapping and visualization purposes. Default = FALSE.} } \value{ +A list containing sf objects land, bathymetry, survey area boundary, survey strata, survey grid (or survey stations for the longline survey), a data frame of feature labels (for the EBS shelf bottom trawl survey), coordinate reference system, plot boundaryies, axis label breaks, and graticule. + A list containing sf objects land, bathymetry, survey area boundary, survey strata, survey grid (or survey stations for the longline survey), a data frame of feature labels (for the EBS shelf bottom trawl survey), coordinate reference system, plot boundaryies, axis label breaks, and graticule. } \description{ +This function retrieves layers that are commonly used for mapping and spatial analysis of AFSC bottom trawl survey and longline survey data. + This function retrieves layers that are commonly used for mapping and spatial analysis of AFSC bottom trawl survey and longline survey data. } \examples{ @@ -65,6 +83,79 @@ ggplot() + # coastline. High resolution coastline takes longer to load and plot but is recommended when land # polygons are used for spatial analysis +sebs_corners <- get_base_layers(select.region = "sebs", + set.crs = "EPSG:4269", + include.corners = TRUE, + high.resolution.coast = TRUE) + +ggplot() + + geom_sf(data = sebs_corners$akland) + + geom_sf(data = sebs_corners$survey.strata, + fill = NA, + mapping = aes(color = "Survey strata")) + + geom_sf(data = sebs_corners$survey.grid, + fill = NA, + mapping = aes(color = "Station grid")) + + geom_sf(data = sebs_corners$survey.area, + fill = NA, + mapping = aes(color = "Survey area")) + + geom_sf(data = sebs_corners$graticule, alpha = 0.3, linewidth = 0.5) + + scale_x_continuous(limits = sebs_corners$plot.boundary$x, + breaks = sebs_corners$lon.breaks) + + scale_y_continuous(limits = sebs_corners$plot.boundary$y, + breaks = sebs_corners$lat.breaks) + + theme_bw() + +# EBS slope, Aleutian Islands, and Gulf of Alaska surveys have subarea options +ai_west <- get_base_layers(select.region = "ai.west", + set.crs = "EPSG:3338") + +ggplot() + + geom_sf(data = ai_west$akland) + + geom_sf(data = ai_west$survey.strata, + fill = NA, + mapping = aes(color = "Survey strata")) + + geom_sf(data = ai_west$survey.grid, + fill = NA, + mapping = aes(color = "Station grid")) + + geom_sf(data = ai_west$survey.area, + fill = NA, + mapping = aes(color = "Survey area")) + + geom_sf(data = ai_west$graticule, alpha = 0.3, linewidth = 0.5) + + scale_x_continuous(limits = ai_west$plot.boundary$x, + breaks = ai_west$lon.breaks) + + scale_y_continuous(limits = ai_west$plot.boundary$y, + breaks = ai_west$lat.breaks) + + theme_bw()} +\dontrun{ +library(akgfmaps) + +# EBS bottom trawl survey layers in Alaska Albers Equal Area projection (EPSG:3338) +sebs <- get_base_layers(select.region = "sebs", + set.crs = "EPSG:3338") + +ggplot() + + geom_sf(data = sebs$akland) + + geom_sf(data = sebs$survey.strata, + fill = NA, + mapping = aes(color = "Survey strata")) + + geom_sf(data = sebs$survey.grid, + fill = NA, + mapping = aes(color = "Station grid")) + + geom_sf(data = sebs$survey.area, + fill = NA, + mapping = aes(color = "Survey area")) + + geom_sf(data = sebs$graticule, alpha = 0.3, linewidth = 0.5) + + scale_x_continuous(limits = sebs$plot.boundary$x, + breaks = sebs$lon.breaks) + + scale_y_continuous(limits = sebs$plot.boundary$y, + breaks = sebs$lat.breaks) + + theme_bw() + +# EBS bottom trawl survey layers in NAD83 (EPSG:4269) with corner stations and high resolution +# coastline. High resolution coastline takes longer to load and plot but is recommended when land +# polygons are used for spatial analysis + sebs_corners <- get_base_layers(select.region = "sebs", set.crs = "EPSG:4269", include.corners = TRUE, From 9975899e85390334c56df028ddcbc0136a7f4259 Mon Sep 17 00:00:00 2001 From: Sean Rohan Date: Fri, 13 Dec 2024 15:40:24 -0800 Subject: [PATCH 2/2] Recover gbl 3.6 --- man/get_base_layers.Rd | 99 ++---------------------------------------- 1 file changed, 4 insertions(+), 95 deletions(-) diff --git a/man/get_base_layers.Rd b/man/get_base_layers.Rd index 4f1822d..1693ebd 100644 --- a/man/get_base_layers.Rd +++ b/man/get_base_layers.Rd @@ -1,37 +1,23 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_base_layers.R, R/get_base_layers_v4.R +% Please edit documentation in R/get_base_layers.R \name{get_base_layers} \alias{get_base_layers} \title{Function to get base layers for bottom trawl and longline survey regions, bathymetry, and land} \usage{ get_base_layers( select.region, - design.year = NULL, set.crs = "EPSG:4269", use.survey.bathymetry = TRUE, - include.corners = FALSE, - split.land.at.180 = TRUE, - fix.invalid.geom = TRUE, - high.resolution.coast = FALSE -) - -get_base_layers( - select.region, - design.year = NULL, - set.crs = "EPSG:4269", - use.survey.bathymetry = TRUE, - include.corners = FALSE, + include.corners = NULL, split.land.at.180 = TRUE, fix.invalid.geom = TRUE, high.resolution.coast = FALSE ) } \arguments{ -\item{select.region}{Character vector indicating which region to retrieve. Bottom trawl survey options: ebs or bs.all, sebs or bs.south, nbs or bs.north, ecs, ai, ai.west, ai.central, ai.east, goa, goa.west, goa.east, ebs.slope, bssa1, bssa2, bssa3, bssa4, bssa5, bssa6. Longline survey options: ll.ebs, ll.bssa1, ll.bssa2, ll.bssa3, ll.bssa4, ll.bssa5, ll.ai, ll.ai.west, ll.ai.central, ll.goa, ll.goa.west, ll.goa.central, ll.goa.east} +\item{select.region}{Character vector indicating which region to retrieve. Bottom trawl survey options: ebs or bs.all, sebs or bs.south, nbs or bs.north, ecs, ebs.ecs, ai, ai.west, ai.central, ai.east, goa, goa.west, goa.east, ebs.slope, bssa1, bssa2, bssa3, bssa4, bssa5, bssa6. Longline survey options: ll.ebs, ll.bssa1, ll.bssa2, ll.bssa3, ll.bssa4, ll.bssa5, ll.ai, ll.ai.west, ll.ai.central, ll.goa, ll.goa.west, ll.goa.central, ll.goa.east} -\item{design.year}{Survey design year for files to retrieve. Returns the most recent year when NULL.} - -\item{set.crs}{Which coordinate reference system should be used? If 'auto', Alaska Albers Equal Area (EPSG:3338) is used.} +\item{set.crs}{Which coordinate reference system should be used? If 'auto', Alaska Albers Equal Area (EPSG:3338) will be used.} \item{use.survey.bathymetry}{Should survey bathymetry be used?} @@ -44,13 +30,9 @@ get_base_layers( \item{high.resolution.coast}{Should the State of Alaska polygon be a high resolution Alaska Department of Natural Resources 1:63360 scale polygon that includes smaller islands and a more detailed coastline? The higher resolution polygon (high.resolution.coast = TRUE) takes longer to load/plot and is recommended for spatial operations performed at high resolution (e.g., masking high resolution rasters). The lower resolution polygon (high.resolution.coast = FALSE) is recommended for general mapping and visualization purposes. Default = FALSE.} } \value{ -A list containing sf objects land, bathymetry, survey area boundary, survey strata, survey grid (or survey stations for the longline survey), a data frame of feature labels (for the EBS shelf bottom trawl survey), coordinate reference system, plot boundaryies, axis label breaks, and graticule. - A list containing sf objects land, bathymetry, survey area boundary, survey strata, survey grid (or survey stations for the longline survey), a data frame of feature labels (for the EBS shelf bottom trawl survey), coordinate reference system, plot boundaryies, axis label breaks, and graticule. } \description{ -This function retrieves layers that are commonly used for mapping and spatial analysis of AFSC bottom trawl survey and longline survey data. - This function retrieves layers that are commonly used for mapping and spatial analysis of AFSC bottom trawl survey and longline survey data. } \examples{ @@ -83,79 +65,6 @@ ggplot() + # coastline. High resolution coastline takes longer to load and plot but is recommended when land # polygons are used for spatial analysis -sebs_corners <- get_base_layers(select.region = "sebs", - set.crs = "EPSG:4269", - include.corners = TRUE, - high.resolution.coast = TRUE) - -ggplot() + - geom_sf(data = sebs_corners$akland) + - geom_sf(data = sebs_corners$survey.strata, - fill = NA, - mapping = aes(color = "Survey strata")) + - geom_sf(data = sebs_corners$survey.grid, - fill = NA, - mapping = aes(color = "Station grid")) + - geom_sf(data = sebs_corners$survey.area, - fill = NA, - mapping = aes(color = "Survey area")) + - geom_sf(data = sebs_corners$graticule, alpha = 0.3, linewidth = 0.5) + - scale_x_continuous(limits = sebs_corners$plot.boundary$x, - breaks = sebs_corners$lon.breaks) + - scale_y_continuous(limits = sebs_corners$plot.boundary$y, - breaks = sebs_corners$lat.breaks) + - theme_bw() - -# EBS slope, Aleutian Islands, and Gulf of Alaska surveys have subarea options -ai_west <- get_base_layers(select.region = "ai.west", - set.crs = "EPSG:3338") - -ggplot() + - geom_sf(data = ai_west$akland) + - geom_sf(data = ai_west$survey.strata, - fill = NA, - mapping = aes(color = "Survey strata")) + - geom_sf(data = ai_west$survey.grid, - fill = NA, - mapping = aes(color = "Station grid")) + - geom_sf(data = ai_west$survey.area, - fill = NA, - mapping = aes(color = "Survey area")) + - geom_sf(data = ai_west$graticule, alpha = 0.3, linewidth = 0.5) + - scale_x_continuous(limits = ai_west$plot.boundary$x, - breaks = ai_west$lon.breaks) + - scale_y_continuous(limits = ai_west$plot.boundary$y, - breaks = ai_west$lat.breaks) + - theme_bw()} -\dontrun{ -library(akgfmaps) - -# EBS bottom trawl survey layers in Alaska Albers Equal Area projection (EPSG:3338) -sebs <- get_base_layers(select.region = "sebs", - set.crs = "EPSG:3338") - -ggplot() + - geom_sf(data = sebs$akland) + - geom_sf(data = sebs$survey.strata, - fill = NA, - mapping = aes(color = "Survey strata")) + - geom_sf(data = sebs$survey.grid, - fill = NA, - mapping = aes(color = "Station grid")) + - geom_sf(data = sebs$survey.area, - fill = NA, - mapping = aes(color = "Survey area")) + - geom_sf(data = sebs$graticule, alpha = 0.3, linewidth = 0.5) + - scale_x_continuous(limits = sebs$plot.boundary$x, - breaks = sebs$lon.breaks) + - scale_y_continuous(limits = sebs$plot.boundary$y, - breaks = sebs$lat.breaks) + - theme_bw() - -# EBS bottom trawl survey layers in NAD83 (EPSG:4269) with corner stations and high resolution -# coastline. High resolution coastline takes longer to load and plot but is recommended when land -# polygons are used for spatial analysis - sebs_corners <- get_base_layers(select.region = "sebs", set.crs = "EPSG:4269", include.corners = TRUE,