Load

# packages
if (!require("librarian")){
  install.packages("librarian")
  library(librarian)
}
librarian::shelf(
  dplyr, DT, glue, here, mapview, sf)
select <- dplyr::select
mapviewOptions(fgb = FALSE)
source(here::here("libs/db.R")) # defines variables: con, dir_gdrive
gpkg <- file.path(dir_gdrive, "data/US-ocean-disposal-sites/OceanDisposalSite.gpkg")
st_layers(gpkg)
## Driver: GPKG 
## Available layers:
##          layer_name geometry_type features fields
## 1 OCEANDISPOSALSITE Multi Polygon     2148     11
dumps <- st_read(gpkg, "OCEANDISPOSALSITE") %>% 
  st_transform(4326)
## Reading layer `OCEANDISPOSALSITE' from data source 
##   `/Users/bbest/My Drive/projects/calcofi/data/US-ocean-disposal-sites/OceanDisposalSite.gpkg' 
##   using driver `GPKG'
## Simple feature collection with 2148 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -170.325 ymin: 13.56656 xmax: 145.7303 ymax: 64.50111
## Geodetic CRS:  NAD83
stations <- st_read(con, "stations")
hull <- st_convex_hull(st_union(stations))

x <- st_intersects(dumps, hull, sparse = F)[,1]
dumps_ply <- dumps[x,]

dumps_pts <- st_centroid(dumps_ply)

mapview(dumps_ply) +
  mapview(dumps_pts)
dumps_ply %>% 
  st_drop_geometry() %>% 
  datatable()