Skip to content

Commit

Permalink
start distance from shore function
Browse files Browse the repository at this point in the history
  • Loading branch information
jflowernet committed Feb 8, 2024
1 parent 2f695e1 commit 01df2c4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions R/get_dist_shore.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
get_dist_shore <- function(spatialgrid){
if(!any(check_raster(spatialgrid) & check_sf(spatialgrid))) stop("spatialgrid must be in raster or sf format")

#get high res land polygons from Natural Earth
ne_data_filename <- "ne_land_data.zip"

if(!file.exists(file.path(tempdir(), "ne_10m_land.shp"))){
utils::download.file(url = "https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_land.zip", destfile = file.path(tempdir(), ne_data_filename), mode = "wb", quiet = TRUE)
utils::unzip(file.path(tempdir(), ne_data_filename), exdir = tempdir())
}

ne_data <- sf::read_sf(file.path(tempdir(), "ne_10m_land.shp")) %>%
sf::st_geometry() %>%
sf::st_combine() %>%
sf::st_sf() %>%
sf::st_make_valid() %>%
terra::vect()
}

0 comments on commit 01df2c4

Please # to comment.