Skip to contents

The code takes a sf object and return it updated with a new coastDistance column. The output inherits the crs from this sf object so ensure it is in the correct projection for your needs

Usage

splnr_get_distCoast(dat_sf, custom_coast = NULL, res = NULL)

Arguments

dat_sf

An sf object.

custom_coast

An sf coastline object (optional)

res

Allow user to choose resolution (small, medium, large) of rnaturalearth data used for coastline.

Value

An sf object with distances to the nearest coast

Details

Written by Kristine Buenafe Written: March/April 2023 Modified by Kilian Barreiro Updated: December 2023

Examples

bbox <- sf::st_bbox(c(xmin = 0, ymin = 0, xmax = 3, ymax = 3))
grid <- sf::st_make_grid(bbox, n = c(3, 3), what = "polygons")
grid <- sf::st_sf(geometry = grid) %>%
  sf::st_set_crs("EPSG:4326")
splnr_get_distCoast(grid)
#> Simple feature collection with 9 features and 1 field
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 0 ymin: 0 xmax: 3 ymax: 3
#> Geodetic CRS:  WGS 84
#>                         geometry coastDistance_km
#> 1 POLYGON ((0 0, 1 0, 1 1, 0 ...         544.9762
#> 2 POLYGON ((1 0, 2 0, 2 1, 1 ...         553.2552
#> 3 POLYGON ((2 0, 3 0, 3 1, 2 ...         442.2715
#> 4 POLYGON ((0 1, 1 1, 1 2, 0 ...         438.7047
#> 5 POLYGON ((1 1, 2 1, 2 2, 1 ...         480.9762
#> 6 POLYGON ((2 1, 3 1, 3 2, 2 ...         462.5574
#> 7 POLYGON ((0 2, 1 2, 1 3, 0 ...         335.6332
#> 8 POLYGON ((1 2, 2 2, 2 3, 1 ...         371.9517
#> 9 POLYGON ((2 2, 3 2, 3 3, 2 ...         406.2456

cCRS <- "ESRI:54009"

Bndry <- splnr_get_boundary(Limits = "Coral Sea",
                            Type = "Oceans",
                            cCRS = cCRS)
#> Reading layer `ne_10m_geography_marine_polys' from data source 
#>   `/private/var/folders/_r/mcmw_qtn0m7cd23cbdqfszl40000gp/T/RtmpmU1Uiz/ne_10m_geography_marine_polys.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 306 features and 37 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -180 ymin: -85.19206 xmax: 179.9999 ymax: 90
#> Geodetic CRS:  WGS 84

landmass <- rnaturalearth::ne_countries(
  scale = "medium",
  returnclass = "sf"
) %>%
  sf::st_transform(cCRS)