Skip to content
Merged

Devel #148

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/MacOS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
any::rcmdcheck
any::remotes
any::lpsymphony
any::slam
needs: check

- uses: r-lib/actions/check-r-package@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
any::rcmdcheck
any::remotes
any::lpsymphony
any::slam
needs: check

- uses: r-lib/actions/check-r-package@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
any::rcmdcheck
any::remotes
any::lpsymphony
any::slam
needs: check

- uses: r-lib/actions/check-r-package@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
any::rcmdcheck
any::remotes
any::lpsymphony
any::slam
needs: coverage

- name: Test coverage
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,16 @@ importFrom(dplyr,summarise)
importFrom(dplyr,summarize)
importFrom(dplyr,tibble)
importFrom(dplyr,ungroup)
importFrom(forcats,fct_relevel)
importFrom(ggnewscale,new_scale_colour)
importFrom(ggnewscale,new_scale_fill)
importFrom(ggplot2,aes)
importFrom(ggplot2,after_stat)
importFrom(ggplot2,annotate)
importFrom(ggplot2,coord_polar)
importFrom(ggplot2,coord_sf)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_line)
importFrom(ggplot2,element_rect)
importFrom(ggplot2,element_text)
importFrom(ggplot2,expansion)
importFrom(ggplot2,geom_abline)
importFrom(ggplot2,geom_bar)
importFrom(ggplot2,geom_segment)
Expand Down
30 changes: 15 additions & 15 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Planning Units
#'
#' An sf dataframe of planning units for spatial prioritisation
#' An sf dataframe of Planning Units for spatial prioritization
#'
#' @format `dat_PUs`
#' A data frame with XXXX rows and XXX columns:
Expand All @@ -14,9 +14,9 @@

# -------------------------------------------------------------------------

#' Boundary of planning units
#' Boundary of Planning Units
#'
#' An sf dataframe of planning units for spatial prioritisation
#' An sf dataframe of Planning Units for spatial prioritization
#'
#' @format `dat_bndry`
#' A data frame with XXXX rows and XXX columns:
Expand All @@ -32,7 +32,7 @@

#' Regionalisation
#'
#' An sf dataframe of planning units for spatial prioritisation
#' An sf dataframe of Planning Units for spatial prioritization
#'
#' @format `dat_region`
#' A data frame with XXXX rows and XXX columns:
Expand All @@ -47,7 +47,7 @@

#' Binary Species Data
#'
#' An sf dataframe of planning units for spatial prioritisation
#' An sf dataframe of Planning Units for spatial prioritization
#'
#' @format `dat_species_bin`
#' A data frame with XXXX rows and XXX columns:
Expand All @@ -63,7 +63,7 @@

#' Binary Species Data 2
#'
#' An sf dataframe of planning units for spatial prioritisation
#' An sf dataframe of Planning Units for spatial prioritization
#'
#' @format `dat_species_bin2`
#' A data frame with XXXX rows and XXX columns:
Expand All @@ -79,7 +79,7 @@

#' Probability Species Data
#'
#' An sf dataframe of planning units for spatial prioritisation
#' An sf dataframe of Planning Units for spatial prioritization
#'
#' @format `dat_species_prob`
#' A data frame with XXXX rows and XXX columns:
Expand All @@ -93,9 +93,9 @@

# -------------------------------------------------------------------------

#' MPA Data
#' Marine Protected Areas (MPAs) Data
#'
#' An sf dataframe of planning units for spatial prioritisation
#' An sf dataframe of Planning Units for spatial prioritization
#'
#' @format `dat_mpas`
#' A data frame with XXXX rows and XXX columns:
Expand All @@ -117,7 +117,7 @@
#' @format `dat_category`
#' A data frame with XXXX rows and XXX columns:
#' \describe{
#' \item{feature}{all features available for spatial prioritisation}
#' \item{feature}{all features available for spatial prioritization}
#' \item{category}{the categories of all features}
#' ...
#' }
Expand All @@ -135,7 +135,7 @@
#' @format `dat_category2`
#' A data frame with XXXX rows and XXX columns:
#' \describe{
#' \item{feature}{all features available for spatial prioritisation}
#' \item{feature}{all features available for spatial prioritization}
#' \item{category}{the categories of all features}
#' ...
#' }
Expand All @@ -148,7 +148,7 @@

#' Climate metric data
#'
#' An sf dataframe of planning units for spatial prioritisation
#' An sf dataframe of Planning Units for spatial prioritization
#'
#' @format `dat_clim`
#' A data frame with 780 rows and 3 columns:
Expand Down Expand Up @@ -179,14 +179,14 @@
# -------------------------------------------------------------------------


#' Current MPAs of the Coral Sea
#' Current Marine Protected Areas (MPAs) of the Coral Sea
#'
#' sf file containing the current marine protected areas of the coral sea
#' sf file containing the current Marine Protected Areas (MPAs) of the coral sea
#'
#' @format `MPAsCoralSea`
#' A data frame with 397 rows and 17 columns:
#' \describe{
#' \item{wdpa}{binary vector denoting presence or absence of a current marine protected area}
#' \item{wdpa}{binary vector denoting presence or absence of a current MPA}
#' ...
#' }
#' @source https://www.protectedplanet.net/en/thematic-areas/wdpa?tab=WDPA
Expand Down
14 changes: 7 additions & 7 deletions R/splnr_get_distCoast.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @description
#' This function calculates the shortest distance from the centroid of each
#' planning unit in an `sf` object to the nearest coastline. It can use either
#' Planning Unit in an `sf` object to the nearest coastline. It can use either
#' a default coastline from the `rnaturalearth` package or a custom-provided
#' coastline `sf` object.
#'
Expand All @@ -13,7 +13,7 @@
#' a suitable projected CRS for accurate distance calculations.
#'
#' @param dat_sf `[sf]` \cr An `sf` object containing polygon or point features
#' representing the planning units. Must have a valid CRS.
#' representing the Planning Units. Must have a valid CRS.
#' @param custom_coast `[sf]` \cr An optional `sf` object representing a
#' custom coastline. If `NULL` (the default), the coastline is downloaded
#' from `rnaturalearth`.
Expand Down Expand Up @@ -99,20 +99,20 @@ splnr_get_distCoast <- function(dat_sf, custom_coast = NULL, res = "medium") {
sf::st_transform(crs = sf::st_crs(dat_sf))
}

# Calculate centroids of the planning units
# Using centroids is a standard approach to represent the location of each planning unit
message("Calculating centroids for planning units.")
# Calculate centroids of the Planning Units
# Using centroids is a standard approach to represent the location of each Planning Unit
message("Calculating centroids for Planning Units.")
grid_centroid <- sf::st_centroid(sf::st_geometry(dat_sf))

# Calculate the distance matrix between each planning unit centroid and the coastline
# Calculate the distance matrix between each Planning Unit centroid and the coastline
message("Calculating distances to coastline.")
dist_mat <- sf::st_distance(grid_centroid, coast) %>%
# Explicitly set the distance units to kilometers
units::set_units("km") %>%
# Drop the units class to get a numeric matrix for easier computation
units::drop_units()

# Find the minimum distance for each planning unit (each row in the matrix)
# Find the minimum distance for each Planning Unit (each row in the matrix)
# This identifies the shortest distance from each centroid to any part of the coastline
message("Finding minimum distances and adding to dataframe.")
dat_sf$coastDistance_km <- do.call(pmin, as.data.frame(dist_mat))
Expand Down
Loading
Loading