Skip to content

Commit

Permalink
Add T/UT to station_grid
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-rohan-NOAA committed Feb 7, 2025
1 parent 8c351fa commit c19f71f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 52 deletions.
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
akgfmaps 4.1.0 (In development)
----------------------------------------------------------------

IMPROVEMENTS

- Add trawlable/untrawlable designations to survey grid table.


akgfmaps 4.0.2 (January 22, 2025)
----------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion R/get_base_layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ get_base_layers <- function(select.region,
survey.grid <- sf::st_read(
system.file("extdata", "afsc_bottom_trawl_surveys.gpkg", package = "akgfmaps"),
query = paste0("SELECT SURVEY_DEFINITION_ID, DESIGN_YEAR, GRID_ID,
STATION, AREA_M2, GEOM AS geometry
STATION, TRAWLABLE, AREA_M2, GEOM AS geometry
FROM SURVEY_GRID WHERE SURVEY_DEFINITION_ID IN (",
paste(survey_definition_id, collapse = ", "), ")"
),
Expand Down
50 changes: 50 additions & 0 deletions analysis/akgfmaps4/add_gpkg_to_oracle.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
library(akgfmaps)
library(gapindex)

user <- "rohans"

gpkg_path <- system.file("extdata", "afsc_bottom_trawl_surveys.gpkg", package = "akgfmaps")

channel <- gapindex::get_connected()

# View the layers in the geopackage
gpkg_layers <- sf::st_layers(gpkg_path)

for(ii in 1:length(gpkg_layers)) {

# Convert Alaska Albers Equal Area to NAD83
station_table <- sf::st_read(
gpkg_path,
layer = gpkg_layers$name[ii]
) |>
sf::st_transform(crs = "NAD83") |>
dplyr::mutate(SURVEY_DEFINITION_ID = as.integer(SURVEY_DEFINITION_ID),
AREA_ID = as.integer(SURVEY_DEFINITION_ID),
DESIGN_YEAR = as.integer(DESIGN_YEAR))

# Convert feature geometries to well-known text
station_table$WKT_NAD83 <- sf::st_as_text(station_table$geom)

# Well-known binary could be a more compact alternative to WKT using this
wkb_example <- sf::st_as_binary(station_table$geom)

# Drop table if it exists
try(
RODBC::sqlDrop(channel = channel,
sqtable = paste0(user, gpkg_layers$name[ii]))
)

RODBC::sqlSave(channel = channel,
dat = sf::st_drop_geometry(station_table),
tablename = paste0(user, gpkg_layers$name[ii]),
append = TRUE, # need append = TRUE because of access permissions
rownames = FALSE,
colnames = FALSE,
verbose = FALSE,
safer = FALSE,
addPK = TRUE,
fast = TRUE,
test = FALSE,
nastring = NULL)
}

102 changes: 51 additions & 51 deletions analysis/akgfmaps4/make_bt_gpkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,6 @@

library(akgfmaps)

# Gulf of Alaska 1984 design ----
goa_layers <- akgfmaps:::get_base_layers_v3(select.region = "goa",
set.crs = "EPSG:3338")

goa_layers$survey.area |>
dplyr::mutate(AREA_M2 = AREA_KM2*1e6,
SURVEY_DEFINITION_ID = 47,
DESIGN_YEAR = 1984,
AREA_ID = 99903,
AREA_TYPE = "REGION",
SURVEY_NAME = "Gulf of Alaska Bottom Trawl Survey") |>
dplyr::select(AREA_TYPE, SURVEY_NAME, SURVEY_DEFINITION_ID, DESIGN_YEAR, AREA_ID, AREA_M2) |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_area",
append = FALSE,
delete_dsn = TRUE)

goa_layers$survey.strata |>
sf::st_transform(crs = "EPSG:3338") |>
akgfmaps:::fix_geometry() |>
dplyr::group_by(STRATUM) |>
dplyr::summarise(AREA_M2 = sum(AREA_KM2*1e6), do_union = TRUE) |>
dplyr::ungroup() |>
dplyr::mutate(DESIGN_YEAR = 1984,
AREA_TYPE = "STRATUM",
SURVEY_DEFINITION_ID = 47) |>
dplyr::select(AREA_TYPE, SURVEY_DEFINITION_ID, DESIGN_YEAR, AREA_ID = STRATUM, AREA_M2) |>
dplyr::group_by(AREA_TYPE, SURVEY_DEFINITION_ID, DESIGN_YEAR, AREA_ID) |>
dplyr::summarise(AREA_M2 = sum(AREA_M2), do_union = TRUE) |>
dplyr::ungroup() |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_strata",
append = FALSE,
delete_dsn = FALSE)

goa_layers$survey.grid |>
dplyr::mutate(AREA_M2 = AREA_KM2*1e6,
DESIGN_YEAR = 1984,
AREA_TYPE = "STATION",
SURVEY_DEFINITION_ID = 47) |>
dplyr::select(AREA_TYPE, SURVEY_DEFINITION_ID, DESIGN_YEAR, GRID_ID = GOAGRID_ID, STATION = ID, AREA_M2) |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_grid",
append = FALSE,
delete_dsn = FALSE)


# Gulf of ALaska 2025 ----
goa_stratum_2025 <- sf::st_read(here::here("analysis", "goa_strata_2025", "goa_strata_2025.gpkg")) |>
sf::st_set_geometry( "geometry") |>
Expand All @@ -61,8 +14,8 @@ goa_stratum_2025 <- sf::st_read(here::here("analysis", "goa_strata_2025", "goa_s
goa_stratum_2025 |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_strata",
append = TRUE,
delete_dsn = FALSE)
append = FALSE,
delete_dsn = TRUE)

goa_stratum_2025 |>
dplyr::select(SURVEY_DEFINITION_ID) |>
Expand All @@ -78,7 +31,7 @@ goa_stratum_2025 |>
dplyr::select(AREA_TYPE, SURVEY_NAME, SURVEY_DEFINITION_ID, DESIGN_YEAR, AREA_ID, AREA_M2) |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_area",
append = TRUE,
append = FALSE,
delete_dsn = FALSE)

goa_station_grid_2025 <-
Expand All @@ -87,9 +40,56 @@ goa_station_grid_2025 <-
SURVEY_DEFINITION_ID = 47,
DESIGN_YEAR = 2025,
AREA_TYPE = "STATION") |>
dplyr::select(AREA_TYPE, SURVEY_DEFINITION_ID, DESIGN_YEAR, GRID_ID = GRIDID, STATION, AREA_M2)
dplyr::select(AREA_TYPE, SURVEY_DEFINITION_ID, DESIGN_YEAR, GRID_ID = GRIDID, STATION, TRAWLABLE, AREA_M2)

goa_station_grid_2025 |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_grid",
append = FALSE,
delete_dsn = FALSE)

# Gulf of Alaska 1984 design ----
goa_layers <- akgfmaps:::get_base_layers_v3(select.region = "goa",
set.crs = "EPSG:3338")

goa_layers$survey.area |>
dplyr::mutate(AREA_M2 = AREA_KM2*1e6,
SURVEY_DEFINITION_ID = 47,
DESIGN_YEAR = 1984,
AREA_ID = 99903,
AREA_TYPE = "REGION",
SURVEY_NAME = "Gulf of Alaska Bottom Trawl Survey") |>
dplyr::select(AREA_TYPE, SURVEY_NAME, SURVEY_DEFINITION_ID, DESIGN_YEAR, AREA_ID, AREA_M2) |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_area",
append = TRUE,
delete_dsn = FALSE)

goa_layers$survey.strata |>
sf::st_transform(crs = "EPSG:3338") |>
akgfmaps:::fix_geometry() |>
dplyr::group_by(STRATUM) |>
dplyr::summarise(AREA_M2 = sum(AREA_KM2*1e6), do_union = TRUE) |>
dplyr::ungroup() |>
dplyr::mutate(DESIGN_YEAR = 1984,
AREA_TYPE = "STRATUM",
SURVEY_DEFINITION_ID = 47) |>
dplyr::select(AREA_TYPE, SURVEY_DEFINITION_ID, DESIGN_YEAR, AREA_ID = STRATUM, AREA_M2) |>
dplyr::group_by(AREA_TYPE, SURVEY_DEFINITION_ID, DESIGN_YEAR, AREA_ID) |>
dplyr::summarise(AREA_M2 = sum(AREA_M2), do_union = TRUE) |>
dplyr::ungroup() |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_strata",
append = TRUE,
delete_dsn = FALSE)

goa_layers$survey.grid |>
dplyr::mutate(AREA_M2 = AREA_KM2*1e6,
DESIGN_YEAR = 1984,
AREA_TYPE = "STATION",
SURVEY_DEFINITION_ID = 47,
TRAWLABLE = NA) |>
dplyr::select(AREA_TYPE, SURVEY_DEFINITION_ID, DESIGN_YEAR, GRID_ID = GOAGRID_ID, STATION = ID, TRAWLABLE, AREA_M2) |>
sf::st_write(dsn = here::here("inst", "extdata", "afsc_bottom_trawl_surveys.gpkg"),
layer = "survey_grid",
append = TRUE,
Expand Down
Binary file modified inst/extdata/afsc_bottom_trawl_surveys.gpkg
Binary file not shown.

0 comments on commit c19f71f

Please sign in to comment.