diff --git a/DESCRIPTION b/DESCRIPTION index b09e5a4d..5ffc4548 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: spatialplanr Title: Help files for prioritzr Spatial Planning projects -Version: 0.6.7 +Version: 0.6.8 Authors@R: c( person( given = "Jason D.", @@ -30,7 +30,7 @@ Suggests: ggridges, irr, knitr, - oceandatr (>= 0.1.0), + oceandatr (>= 0.2.0), patchwork, prioritizr, RColorBrewer, @@ -61,7 +61,7 @@ Imports: rnaturalearth, scales, sf, - spatialgridr (>= 0.0.1), + spatialgridr (>= 0.0.2), stringr, terra, tibble, diff --git a/R/data.R b/R/data.R index 8285673a..83b1a7d3 100644 --- a/R/data.R +++ b/R/data.R @@ -5,7 +5,6 @@ #' @format `dat_PUs` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{geometry}{sf geometry column} #' ... #' } @@ -22,7 +21,6 @@ #' @format `dat_bndry` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{geometry}{sf geometry column} #' ... #' } @@ -39,7 +37,6 @@ #' @format `dat_region` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{geometry}{sf geometry column} #' ... #' } @@ -55,7 +52,6 @@ #' @format `dat_species_bin` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{geometry}{sf geometry column} #' ... #' } @@ -72,7 +68,6 @@ #' @format `dat_species_bin2` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{geometry}{sf geometry column} #' ... #' } @@ -89,7 +84,6 @@ #' @format `dat_species_prob` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{geometry}{sf geometry column} #' ... #' } @@ -106,7 +100,6 @@ #' @format `dat_mpas` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{geometry}{sf geometry column} #' \item{wdpa}{binary MPA information (1: MPA)} #' ... @@ -160,7 +153,6 @@ #' @format `dat_clim` #' A data frame with 780 rows and 3 columns: #' \describe{ -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{geometry}{sf geometry column} #' \item{metric}{climate metric information} #' ... @@ -178,7 +170,6 @@ # A data frame with 397 rows and 17 columns: # \describe{ # \item{Chelonia_mydas}{suitable habitat for Chelonia mydas} -# \item{cellID}{cell ID of planning units} # ... # } # @source Aquamaps.org @@ -196,7 +187,6 @@ #' 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{cellID}{cell ID of planning units} #' ... #' } #' @source https://www.protectedplanet.net/en/thematic-areas/wdpa?tab=WDPA @@ -233,7 +223,6 @@ #' @format `CoralSeaVelocity` #' A data frame with 397 rows and 3 columns: #' \describe{ -#' \item{cellID}{cell ID of the planning units} #' \item{vocMagg_transformed}{Climate velocity column} #' \item{geometry}{Geometry column of sf object} #' ... @@ -263,7 +252,6 @@ #' A data frame with bathymetry data #' \describe{ # -#' \item{cellID}{ID number for each row (or cell) of the dataset} #' \item{bathymetry}{Bathymetry data} #' \item{geometry}{sf geometry column} #' ... diff --git a/R/splnr_apply_cutoffs.R b/R/splnr_apply_cutoffs.R index 5005e8fc..910aacaa 100644 --- a/R/splnr_apply_cutoffs.R +++ b/R/splnr_apply_cutoffs.R @@ -23,7 +23,7 @@ splnr_apply_cutoffs <- function(features, Cutoffs, inverse = FALSE) { features <- features %>% dplyr::as_tibble() %>% dplyr::mutate(dplyr::across( - -dplyr::any_of(c("cellID", "geometry")), # Apply to all columns except geometry and cellID + -dplyr::any_of("geometry"), # Apply to all columns except geometry ~ dplyr::case_when( . >= Cutoffs ~ 1, . < Cutoffs ~ 0, @@ -34,11 +34,10 @@ splnr_apply_cutoffs <- function(features, Cutoffs, inverse = FALSE) { if (inverse == TRUE) { # Need to flip the ones/zeros features <- features %>% - dplyr::mutate(dplyr::across(-dplyr::any_of(c("cellID", "geometry")), ~ 1 - .)) + dplyr::mutate(dplyr::across(-dplyr::any_of("geometry"), ~ 1 - .)) } } else if (length(Cutoffs) == length(names(Cutoffs))) { # Named vector with values for each column - nm <- names(Cutoffs) # Testing - We should only be operating on the columns in the Cutoffs vector for (f in 1:length(nm)) { diff --git a/R/splnr_featureRep.R b/R/splnr_featureRep.R index 39f00898..ce0ea455 100644 --- a/R/splnr_featureRep.R +++ b/R/splnr_featureRep.R @@ -2,7 +2,7 @@ #' #' @param soln The `prioritizr` solution #' @param pDat The `prioritizr` problem -#' @param targetsDF `data.frame`with list of features under "feature" column and their corresponding targets under "target" column +#' @param targets `data.frame`with list of features under "feature" column and their corresponding targets under "target" column #' @param climsmart logical denoting whether spatial planning was done climate-smart (and targets have to be calculated differently) #' @param climsmartApproach either 0,1,2 or 3 depending on the climate-smart approach used (0 = None; 1 = Climate Priority Area; 2 = Feature; 3 = Percentile). #' @param solnCol Name of the column with the solution @@ -29,15 +29,17 @@ #' soln = soln, #' pDat = pDat #' ) -splnr_get_featureRep <- function(soln, pDat, targetsDF = NA, - climsmart = FALSE, climsmartApproach = 0, solnCol = "solution_1") { +splnr_get_featureRep <- function(soln, pDat, targets = NA, + climsmart = FALSE, + climsmartApproach = 0, + solnCol = "solution_1") { s_cols <- pDat$data$features[[1]] # Get data for features not chosen not_selected <- soln %>% dplyr::select( -tidyselect::starts_with(c("Cost", "solution_")), - -tidyselect::any_of(c("metric", "cellID")), + -tidyselect::any_of(c("metric")), -tidyselect::any_of(s_cols) ) %>% sf::st_drop_geometry() @@ -102,13 +104,13 @@ splnr_get_featureRep <- function(soln, pDat, targetsDF = NA, dplyr::ungroup() %>% dplyr::mutate(relative_held = .data$absolute_held / .data$total_amount) %>% # Calculate proportion dplyr::select(-"total_amount", -"absolute_held") %>% # Remove extra columns - dplyr::left_join(targetsDF, by = "feature") #%>% # Add targets to df + dplyr::left_join(targets, by = "feature") #%>% # Add targets to df # dplyr::select(-"type") } else if (climsmart == TRUE & climsmartApproach == 3) { s1 <- s1 %>% - dplyr::left_join(targetsDF, by = "feature") + dplyr::left_join(targets, by = "feature") } else { # Add targets to df @@ -179,11 +181,13 @@ splnr_get_featureRep <- function(soln, pDat, targetsDF = NA, #' #' (splnr_plot_featureRep(df, category = dat_category)) #' -splnr_plot_featureRep <- function(df, category = NA, +splnr_plot_featureRep <- function(df, + category = NA, categoryFeatureCol = NA, renameFeatures = FALSE, namesToReplace = NA, - nr = 1, showTarget = NA, + nr = 1, + showTarget = NA, plotTitle = "", ...) { diff --git a/R/splnr_plot.R b/R/splnr_plot.R index 12e85f2d..ea6116cb 100644 --- a/R/splnr_plot.R +++ b/R/splnr_plot.R @@ -2,15 +2,13 @@ #' #' (For now can replace splnr_plot_cost(), splnr_plot_binFeature(), splnr_plot_MPAs(), splnr_plot_featureNo()) #' -#' Written by Kilian Barreiro +#' Written by Kilian Barreiro and Jason Everett #' Written: February 2024 #' -#' Plot Spatial Data, returns a gg object -#' #' @param df The dataframe containing the data to be plotted. It must include a geometry column to be used with geom_sf. -#' @param col_names A list of column names to include in the plot. If specified, only these columns will be used to color the plot. -#' @param paletteName The name of the color palette to use for filling. Default is "YlGnBu". -#' @param colourVals The color values to use if col_names is specified and the data is binary. +#' @param col_names A list of column names to include in the plot. If specified, only these columns will be used to colour the plot. +#' @param paletteName The name of the colour palette to use for filling. Default is "YlGnBu". +#' @param colourVals The colour values to use if col_names is specified and the data is binary. #' @param plot_title The title of the plot. #' @param legend_title The title of the legend. #' @param legend_labels A vector of strings containing the labels to use for legend values. @@ -158,7 +156,7 @@ splnr_plot <- function(df, gg <- gg + ggplot2::geom_sf(data = df, ggplot2::aes(fill = .data[[col_names]]), colour = "grey80", size = 0.1) + - ggplot2::scale_fill_viridis_c() + + ggplot2::scale_fill_viridis_c(name = legend_title) + ggplot2::guides(fill = ggplot2::guide_colourbar(order = 1)) } else if (is.null(col_names)){ # No column to plot by diff --git a/R/splnr_plotting.R b/R/splnr_plotting.R index e3fc219a..b97fecbd 100644 --- a/R/splnr_plotting.R +++ b/R/splnr_plotting.R @@ -206,7 +206,7 @@ splnr_plot_costOverlay <- function(soln, Cost = NA, Cost_name = "Cost", as.numeric(stats::quantile(dplyr::pull(Cost, Cost_name), 0.99)) ), # direction = 1, - # oob = scales::squish, + oob = scales::squish, # guide = ggplot2::guide_colourbar( # title.position = "bottom", # title.hjust = 0.5, diff --git a/R/splnr_plotting_climate.R b/R/splnr_plotting_climate.R index 4653fa42..f245e820 100644 --- a/R/splnr_plotting_climate.R +++ b/R/splnr_plotting_climate.R @@ -208,7 +208,6 @@ splnr_plot_climKernelDensity_Fancy <- function(solution_list, names, #' #' @examples #' target <- dat_species_bin %>% -#' dplyr::select(-"cellID") %>% #' sf::st_drop_geometry() %>% #' colnames() %>% #' data.frame() %>% @@ -216,21 +215,20 @@ splnr_plot_climKernelDensity_Fancy <- function(solution_list, names, #' dplyr::mutate(target = 0.3) #' #' CPA <- splnr_climate_priorityAreaApproach( -#' featuresDF = dat_species_bin, -#' metricDF = dat_clim, -#' targetsDF = target, +#' features = dat_species_bin, +#' metric = dat_clim, +#' targets = target, #' direction = -1, #' refugiaTarget = 1 #' ) #' #' out_sf <- CPA$Features %>% #' dplyr::mutate(Cost_None = rep(1, 780)) %>% -#' dplyr::left_join(dat_clim %>% -#' sf::st_drop_geometry(), by = "cellID") +#' sf::st_join(dat_clim, join = sf::st_equals) #' #' usedFeatures <- out_sf %>% #' sf::st_drop_geometry() %>% -#' dplyr::select(-tidyselect::starts_with("Cost_"), -"cellID", -"metric") %>% +#' dplyr::select(-tidyselect::starts_with("Cost_"), -"metric") %>% #' names() #' #' p1 <- prioritizr::problem(out_sf, usedFeatures, "Cost_None") %>% diff --git a/R/splnr_targets.R b/R/splnr_targets.R index 0c140864..b6ac769b 100644 --- a/R/splnr_targets.R +++ b/R/splnr_targets.R @@ -19,8 +19,7 @@ splnr_targets_byInverseArea <- function(df, target_min, target_max) { inherits(df, c("sf", "data.frame")), is.numeric(target_min) && target_min >= 0 && target_min <= 1, is.numeric(target_max) && target_max >= 0 && target_max <= 1, - target_min <= target_max, - "cellID" %in% names(df) + target_min <= target_max ) PU_area_km2 <- as.numeric(sf::st_area(df[1, 1]) / 1e+06) # Area of each planning unit @@ -28,7 +27,6 @@ splnr_targets_byInverseArea <- function(df, target_min, target_max) { total_PU_area <- nrow(df) * PU_area_km2 # Total area of the study region dat <- df %>% - dplyr::select(-"cellID") %>% sf::st_drop_geometry() %>% dplyr::mutate(dplyr::across(dplyr::everything(), ~ tidyr::replace_na(.x, 0))) %>% dplyr::summarise(dplyr::across(dplyr::everything(), ~ sum(., is.na(.), 0))) %>% diff --git a/R/utils-climate.R b/R/utils-climate.R index 881ce0ee..dddb0467 100644 --- a/R/utils-climate.R +++ b/R/utils-climate.R @@ -2,9 +2,9 @@ #' Function to split the feature data into climate-smart (CS) and non-climate-smart (NCS) areas depending on the percentile chosen by the user. #' -#' @param featuresDF feature sf object which should have a column for cellID +#' @param features feature sf object +#' @param metric climate metric `sf` object with 'metric' as the column name of the metric values per planning unit. #' @param percentile cut-off threshold for determining whether an area is a climate priority area or not (e.g., lower 35th percentile of warming or upper 65th percentile of acidification). Note that the percentile here is the lower limit of the threshold. -#' @param metricDF climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID #' @param direction If direction = 1, metric values are from low (least climate-smart) to high (most climate-smart). If direction = -1, metric values are from high (least climate-smart) to low (most climate-smart). #' #' @return A new sf dataframe that has cutoffs applied. @@ -14,34 +14,26 @@ #' @importFrom rlang .data #' #' @examples -#' metric_df <- dat_clim -#' -#' dat_species_binDF <- dat_species_bin %>% -#' sf::st_drop_geometry() #' #' out_sf <- splnr_climate_priorityArea_preprocess( -#' featuresDF = dat_species_bin, -#' percentile = 5, metricDF = metric_df, direction = 1 +#' features = dat_species_bin, +#' percentile = 5, +#' metric = dat_clim, +#' direction = 1 #' ) -splnr_climate_priorityArea_preprocess <- function(featuresDF, +splnr_climate_priorityArea_preprocess <- function(features, percentile, - metricDF, + metric, direction) { - spp <- featuresDF %>% - dplyr::select(-"geometry", -"cellID") %>% + spp <- features %>% sf::st_drop_geometry() %>% names() - metric <- metricDF %>% - sf::st_drop_geometry() - imptList <- list() # empty list to fill in with the important features for (i in 1:length(spp)) { - df <- featuresDF %>% - tibble::as_tibble() %>% - dplyr::select(!!rlang::sym(spp[i]), "cellID") %>% # Select 1 species at a time - dplyr::left_join(metricDF, by = "cellID") %>% - dplyr::select(-"cellID") + df <- features %>% + dplyr::select(!!rlang::sym(spp[i])) %>% # Select 1 species at a time + sf::st_join(metric, join = sf::st_equals) if (any((apply(df, 2, is.na))[, 2])) { print("There are some NAs in the metric data. Please check.") @@ -75,37 +67,46 @@ splnr_climate_priorityArea_preprocess <- function(featuresDF, } } + if (i > 1){ + df <- df %>% + sf::st_drop_geometry() # Drop here otherwise we get multiple version below + } + imptList[[i]] <- df %>% dplyr::mutate(!!rlang::sym(paste0(spp[i], "_CS")) := .data$V1 * .data$V2) %>% # CS = climate-smart areas dplyr::select(!!rlang::sym(paste0(spp[i], "_CS"))) } - imptList <- do.call(dplyr::bind_cols, imptList) %>% - dplyr::mutate(cellID = dplyr::row_number()) + imptList <- do.call(dplyr::bind_cols, imptList) repList <- list() for (i in 1:length(spp)) { - df1 <- featuresDF %>% - tibble::as_tibble() %>% - dplyr::select(!!rlang::sym(spp[i]), "cellID") %>% # Select 1 species at a time - dplyr::left_join(metricDF, by = "cellID") + + df1 <- features %>% + dplyr::select(!!rlang::sym(spp[i])) %>% # Select 1 species at a time + sf::st_join(metric, join = sf::st_equals) df2 <- imptList %>% - dplyr::select(!!rlang::sym(paste0(spp[i], "_CS")), "cellID") + dplyr::select(!!rlang::sym(paste0(spp[i], "_CS")),) + + df3 <- sf::st_join(df1, df2, join = sf::st_equals) - repList[[i]] <- dplyr::left_join(df1, df2, by = "cellID") %>% + if (i > 1){ + df3 <- df3 %>% + sf::st_drop_geometry() # Drop here otherwise we get multiple version below + } + + repList[[i]] <- df3 %>% dplyr::mutate(!!rlang::sym(paste0(spp[i], "_NCS")) := dplyr::if_else(!!rlang::sym(paste0(spp[i], "_CS")) == 1, - true = 0, - false = .data[[spp[i]]] - )) %>% + true = 0, + false = .data[[spp[i]]] + )) %>% dplyr::select(tidyselect::matches("_NCS|_CS")) } repList <- do.call(dplyr::bind_cols, repList) %>% - dplyr::bind_cols(featuresDF %>% - dplyr::select("cellID", "geometry")) %>% - dplyr::select("cellID", tidyselect::everything()) %>% + dplyr::select(tidyselect::everything()) %>% sf::st_as_sf(sf_column_name = "geometry") return(repList) @@ -114,7 +115,7 @@ splnr_climate_priorityArea_preprocess <- function(featuresDF, #' Function to assign targets for climate-priority-area approach #' -#' @param targetsDF `data.frame`with list of features under "feature" column and their corresponding targets under "target" column +#' @param targets `data.frame`with list of features under "feature" column and their corresponding targets under "target" column #' @param climateSmartDF `sf` object produced using the function splnr_ClimatePriorityArea_CSapproach() #' @param refugiaTarget target assigned to climate-smart areas #' @@ -125,10 +126,9 @@ splnr_climate_priorityArea_preprocess <- function(featuresDF, #' @importFrom rlang .data #' #' @examples -#' Features <- dat_species_bin %>% -#' dplyr::select(-"cellID") +#' Features <- dat_species_bin #' -#' target <- Features %>% +#' targets <- Features %>% #' sf::st_drop_geometry() %>% #' colnames() %>% #' data.frame() %>% @@ -141,32 +141,31 @@ splnr_climate_priorityArea_preprocess <- function(featuresDF, #' sf::st_drop_geometry() #' #' out_sf <- splnr_climate_priorityArea_preprocess( -#' featuresDF = dat_species_bin, -#' percentile = 5, metricDF = metric_df, direction = 1 +#' features = dat_species_bin, +#' percentile = 5, metric = metric_df, direction = 1 #' ) #' #' targets <- splnr_climate_priorityArea_assignTargets( -#' targetsDF = target, +#' targets = targets, #' climateSmartDF = out_sf, #' refugiaTarget = 1 #' ) -splnr_climate_priorityArea_assignTargets <- function(targetsDF, +splnr_climate_priorityArea_assignTargets <- function(targets, climateSmartDF, refugiaTarget = 1) { - spp <- targetsDF %>% + spp <- targets %>% dplyr::select("feature") %>% dplyr::pull() featDF <- climateSmartDF %>% sf::st_drop_geometry() %>% - dplyr::select(-"cellID") %>% dplyr::mutate(dplyr::across(dplyr::everything(), ~ tidyr::replace_na(.x, 0))) %>% dplyr::summarize(dplyr::across(tidyselect::everything(), sum)) %>% tidyr::pivot_longer(tidyselect::everything(), names_to = "feature", values_to = "planunit") finalList <- list() # empty list for (i in 1:length(spp)) { - filteredTarget <- targetsDF %>% # Get the set target per feature + filteredTarget <- targets %>% # Get the set target per feature dplyr::filter(.data$feature == spp[i]) trgt <- filteredTarget$target # Extracting the target set for each feature @@ -215,9 +214,9 @@ splnr_climate_priorityArea_assignTargets <- function(targetsDF, #' Function to run the climate-priority-area approach #' -#' @param featuresDF feature `sf`object which should have a column for cellID -#' @param targetsDF `data.frame`with list of features under "feature" column and their corresponding targets under "target" column -#' @param metricDF climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID +#' @param features feature `sf`object +#' @param metric climate metric `sf` object with 'metric' as the column name of the metric values per planning unit. +#' @param targets `data.frame`with list of features under "feature" column and their corresponding targets under "target" column #' @param refugiaTarget target assigned to climate-smart areas #' @param direction If direction = 1, metric values are from low (least climate-smart) to high (most climate-smart). If direction = -1, metric values are from high (least climate-smart) to low (most climate-smart). #' @param percentile cut-off threshold for determining whether an area is a climate priority area or not (e.g., lower 35th percentile of warming or upper 65th percentile of acidification). Note that the percentile here is the lower limit of the threshold. @@ -228,39 +227,36 @@ splnr_climate_priorityArea_assignTargets <- function(targetsDF, #' @importFrom rlang .data #' #' @examples -#' Features <- dat_species_bin %>% -#' dplyr::select(-"cellID") #' -#' target <- Features %>% +#' targets <- dat_species_bin %>% #' sf::st_drop_geometry() %>% #' colnames() %>% #' data.frame() %>% #' setNames(c("feature")) %>% #' dplyr::mutate(target = 0.3) #' -#' metric_df <- dat_clim -#' -#' #' CPA_Approach <- splnr_climate_priorityAreaApproach( -#' featuresDF = dat_species_bin, -#' metricDF = metric_df, targetsDF = target, direction = -1 +#' features = dat_species_bin, +#' metric = dat_clim, +#' targets = targets, +#' direction = -1 #' ) #' out_sf <- CPA_Approach$Features #' targets <- CPA_Approach$Targets -splnr_climate_priorityAreaApproach <- function(featuresDF, - metricDF, - targetsDF, +splnr_climate_priorityAreaApproach <- function(features, + metric, + targets, direction, percentile = 5, refugiaTarget = 1) { - assertthat::assert_that(inherits(featuresDF, "sf"), - "cellID" %in% names(featuresDF), - is.data.frame(metricDF), - "cellID" %in% names(metricDF), - is.data.frame(targetsDF), - "feature" %in% names(targetsDF), - "target" %in% names(targetsDF), + #TODO check that geometry of both sf objects are the same. + + assertthat::assert_that(inherits(features, "sf"), + inherits(metric, "sf"), + is.data.frame(targets), + "feature" %in% names(targets), + "target" %in% names(targets), direction %in% c(-1, 1), is.numeric(percentile), percentile >= 0 && percentile <= 100, @@ -268,13 +264,16 @@ splnr_climate_priorityAreaApproach <- function(featuresDF, refugiaTarget >= 0 && refugiaTarget <= 1) CPAFeatures <- splnr_climate_priorityArea_preprocess( - featuresDF = featuresDF, metricDF = metricDF, - direction = direction, percentile = percentile + features = features, + metric = metric, + direction = direction, + percentile = percentile ) CPATargets <- splnr_climate_priorityArea_assignTargets( - targetsDF = targetsDF, - CPAFeatures, refugiaTarget = refugiaTarget + targets = targets, + CPAFeatures, + refugiaTarget = refugiaTarget ) return(list(Features = CPAFeatures, Targets = CPATargets)) } @@ -285,8 +284,8 @@ splnr_climate_priorityAreaApproach <- function(featuresDF, #' #' This function creates a climate layer by selecting the most climate-smart areas in the entire planning region. #' -#' @param featuresDF feature `sf`object which should have a column for cellID -#' @param metricDF climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID +#' @param features feature `sf`object +#' @param metric climate metric `sf` object with 'metric' as the column name of the metric values per planning unit.#' #' @param direction If direction = 1, metric values are from low (least climate-smart) to high (most climate-smart). If direction = -1, metric values are from high (least climate-smart) to low (most climate-smart). #' @param percentile cut-off threshold for determining whether an area is a climate priority area or not. Note that the percentile here is the lower limit of the threshold. #' @@ -298,28 +297,28 @@ splnr_climate_priorityAreaApproach <- function(featuresDF, #' #' @examples #' -#' metric_df <- dat_clim -#' #' featureTest <- splnr_climate_feature_preprocess( -#' featuresDF = dat_species_bin, -#' percentile = 5, metricDF = metric_df, direction = 1 +#' features = dat_species_bin, +#' percentile = 5, +#' metric = dat_clim, +#' direction = 1 #' ) -splnr_climate_feature_preprocess <- function(featuresDF, +splnr_climate_feature_preprocess <- function(features, percentile, - metricDF, + metric, direction) { - if (any(apply(metricDF, 2, is.na)[, "metric"])) { + if (any(apply(metric, 2, is.na)[, "metric"])) { print("There are some NAs in the metric data. Please check.") } prct <- percentile / 100 - qntl <- stats::quantile(metricDF$metric, prct)[[1]] # Get the percentile + qntl <- stats::quantile(metric$metric, prct)[[1]] # Get the percentile if (direction == 1) { print("Higher values mean more climate-smart areas.") - df <- metricDF %>% + df <- metric %>% dplyr::mutate(climate_layer = ifelse(.data$metric >= qntl, yes = 1, no = 0)) # Create the climate layer } else if (direction == -1) { print("Lower values mean more climate-smart areas.") - df <- metricDF %>% + df <- metric %>% dplyr::mutate(climate_layer = ifelse(.data$metric <= qntl, yes = 1, no = 0)) # Create the climate layer } else { if (direction != 1 & direction != -1) { @@ -328,24 +327,21 @@ splnr_climate_feature_preprocess <- function(featuresDF, } } + # Get the most climate-smart areas climateSmartDF <- df %>% - dplyr::select("cellID", "climate_layer") %>% - tibble::as_tibble() + dplyr::select("climate_layer") # Attach "climate_layer" to the features df and have this as the output - featuresDF <- featuresDF %>% - sf::st_drop_geometry() %>% - tibble::as_tibble() %>% - dplyr::left_join(climateSmartDF, by = "cellID") %>% - sf::st_as_sf(geometry = featuresDF$geometry) + features <- features %>% + sf::st_join(climateSmartDF, join = sf::st_equals) - return(featuresDF) + return(features) } #' Function to assign targets for the feature approach #' -#' @param targetsDF `data.frame`with list of features under "feature" column and their corresponding targets under "target" column +#' @param targets `data.frame`with list of features under "feature" column and their corresponding targets under "target" column #' @param climateSmartDF `sf` object produced using the function splnr_ClimatePriorityArea_CSapproach() #' @param refugiaTarget target assigned to climate-smart areas #' @@ -356,34 +352,34 @@ splnr_climate_feature_preprocess <- function(featuresDF, #' @importFrom rlang .data #' #' @examples -#' Features <- dat_species_bin %>% -#' dplyr::select(-"cellID") +#' Features <- dat_species_bin #' -#' target <- Features %>% +#' targets <- Features %>% #' sf::st_drop_geometry() %>% #' colnames() %>% #' data.frame() %>% #' setNames(c("feature")) %>% #' dplyr::mutate(target = 0.3) #' -#' metric_df <- dat_clim -#' #' dat_species_binDF <- dat_species_bin %>% #' sf::st_drop_geometry() #' #' out_sf <- splnr_climate_feature_preprocess( -#' featuresDF = dat_species_bin, -#' percentile = 5, metricDF = metric_df, direction = 1 +#' features = dat_species_bin, +#' percentile = 5, +#' metric = dat_clim, +#' direction = 1 #' ) #' #' targets <- splnr_climate_feature_assignTargets( -#' targetsDF = target, +#' targets = targets, #' climateSmartDF = out_sf, #' refugiaTarget = 0.3 #' ) splnr_climate_feature_assignTargets <- function(climateSmartDF, refugiaTarget, - targetsDF) { + targets) { + # Calculate the target depending on the # of PUs deemed as "climate-smart" trgt <- refugiaTarget / (sum(climateSmartDF$climate_layer) / nrow(climateSmartDF)) @@ -392,7 +388,7 @@ splnr_climate_feature_assignTargets <- function(climateSmartDF, "climate_layer", trgt ) - finalDF <- targetsDF %>% + finalDF <- targets %>% dplyr::bind_rows(climate_layerDF) # %>% # dplyr::mutate(targets = .data$targets / 100) # Convert target to proportions @@ -401,9 +397,9 @@ splnr_climate_feature_assignTargets <- function(climateSmartDF, #' Function to run the feature approach #' -#' @param featuresDF feature `sf`object which should have a column for cellID -#' @param targetsDF `data.frame`with list of features under "feature" column and their corresponding targets under "target" column -#' @param metricDF climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID +#' @param features feature `sf`object +#' @param metric climate metric `sf` object with 'metric' as the column name of the metric values per planning unit. +#' @param targets `data.frame`with list of features under "feature" column and their corresponding targets under "target" column #' @param refugiaTarget target assigned to climate-smart areas #' @param direction If direction = 1, metric values are from low (least climate-smart) to high (most climate-smart). If direction = -1, metric values are from high (least climate-smart) to low (most climate-smart). #' @param percentile cut-off threshold for determining whether an area is a climate priority area or not (e.g., lower 35th percentile of warming or upper 65th percentile of acidification). Note that the percentile here is the lower limit of the threshold. @@ -414,39 +410,37 @@ splnr_climate_feature_assignTargets <- function(climateSmartDF, #' @importFrom rlang .data #' #' @examples -#' Features <- dat_species_bin %>% -#' dplyr::select(-"cellID") +#' Features <- dat_species_bin #' -#' target <- Features %>% +#' targets <- Features %>% #' sf::st_drop_geometry() %>% #' colnames() %>% #' data.frame() %>% #' setNames(c("feature")) %>% #' dplyr::mutate(target = 0.3) #' -#' metric_df <- dat_clim -#' -#' #' Feature_Approach <- splnr_climate_featureApproach( -#' featuresDF = dat_species_bin, -#' metricDF = metric_df, targetsDF = target, direction = 1 +#' features = dat_species_bin, +#' metric = dat_clim, +#' targets = targets, +#' direction = 1 #' ) #' out_sf <- Feature_Approach$Features #' targets <- Feature_Approach$Targets -splnr_climate_featureApproach <- function(featuresDF, - metricDF, - targetsDF, +splnr_climate_featureApproach <- function(features, + metric, + targets, direction, percentile = 35, refugiaTarget = 0.3) { - assertthat::assert_that(inherits(featuresDF, "sf"), - "cellID" %in% names(featuresDF), - is.data.frame(metricDF), - "cellID" %in% names(metricDF), - is.data.frame(targetsDF), - "feature" %in% names(targetsDF), - "target" %in% names(targetsDF), + #TODO Check that geometry is the same in all the asserts + + assertthat::assert_that(inherits(features, "sf"), + inherits(metric, "sf"), + is.data.frame(targets), + "feature" %in% names(targets), + "target" %in% names(targets), direction %in% c(-1, 1), is.numeric(percentile), percentile >= 0 && percentile <= 100, @@ -455,12 +449,14 @@ splnr_climate_featureApproach <- function(featuresDF, featureFeatures <- splnr_climate_feature_preprocess( - featuresDF = featuresDF, metricDF = metricDF, - direction = direction, percentile = percentile + features = features, + metric = metric, + direction = direction, + percentile = percentile ) featureTargets <- splnr_climate_feature_assignTargets( - targetsDF = targetsDF, + targets = targets, featureFeatures, refugiaTarget = refugiaTarget ) return(list(Features = featureFeatures, Targets = featureTargets)) @@ -469,9 +465,9 @@ splnr_climate_featureApproach <- function(featuresDF, ##### Percentile Approach #### #' Preprocessing for the percentile climate-smart approach #' This function filters the species' distributions to their climate-smart areas only. -#' @param featuresDF feature sf object which should have a column for cellID +#' @param features feature sf object +#' @param metric climate metric `sf` object with 'metric' as the column name of the metric values per planning unit. #' @param percentile cut-off threshold for determining whether an area is a climate priority area or not (e.g., lower 35th percentile of warming or upper 65th percentile of acidification). Note that the percentile here is the lower limit of the threshold. -#' @param metricDF climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID #' @param direction If direction = 1, metric values are from low (least climate-smart) to high (most climate-smart). If direction = -1, metric values are from high (least climate-smart) to low (most climate-smart). #' #' @return A new sf dataframe that has cutoffs applied. @@ -481,40 +477,32 @@ splnr_climate_featureApproach <- function(featuresDF, #' @importFrom rlang .data #' #' @examples -#' metric_df <- dat_clim -#' -#' dat_species_binDF <- dat_species_bin %>% -#' sf::st_drop_geometry() #' #' out_sf <- splnr_climate_percentile_preprocess( -#' featuresDF = dat_species_bin, -#' percentile = 5, metricDF = metric_df, direction = 1 +#' features = dat_species_bin, +#' metric = dat_clim, +#' percentile = 5, +#' direction = 1 #' ) -splnr_climate_percentile_preprocess <- function(featuresDF, +splnr_climate_percentile_preprocess <- function(features, + metric, percentile, - metricDF, direction) { - if (any(apply(metricDF, 2, is.na)[, "metric"])) { + if (any(apply(metric, 2, is.na)[, "metric"])) { print("There are some NAs in the metric data. Please check.") } - spp <- featuresDF %>% # Get the list of features - tibble::as_tibble() %>% - dplyr::select(-"geometry", -"cellID") %>% - names() - - metric <- metricDF %>% # Make sure metric df is a data.frame - dplyr::mutate(cellID = dplyr::row_number()) %>% + spp <- features %>% # Get the list of features sf::st_drop_geometry() %>% - tibble::as_tibble() + names() percentileList <- list() for (i in 1:length(spp)) { - df <- featuresDF %>% - tibble::as_tibble() %>% - dplyr::select(!!rlang::sym(spp[i]), "cellID") %>% # Select 1 feature at a time - dplyr::left_join(metric, by = "cellID") %>% # Join with the metric layer - dplyr::select(-"cellID") + + df <- features %>% + dplyr::select(!!rlang::sym(spp[i]),) %>% # Select 1 feature at a time + sf::st_join(metric, join = sf::st_equals) %>% # Join with the metric layer + sf::st_drop_geometry() # Drop here otherwise we get multiple version below filteredDF <- df %>% dplyr::filter(!!rlang::sym(spp[i]) == 1) # Select only areas with presences @@ -550,11 +538,10 @@ splnr_climate_percentile_preprocess <- function(featuresDF, dplyr::select(!!rlang::sym(paste0(spp[i], "_filtered"))) } - resultDF <- do.call(dplyr::bind_cols, percentileList) %>% # Create sf object as output dplyr::rename_all(~ stringr::str_sub(.x, end = -10)) %>% - dplyr::bind_cols(featuresDF %>% dplyr::select("cellID", "geometry")) %>% - dplyr::select("cellID", tidyselect::everything()) %>% + dplyr::bind_cols(features %>% dplyr::select("geometry")) %>% + dplyr::select(tidyselect::everything()) %>% sf::st_as_sf(sf_column_name = "geometry") return(resultDF) @@ -562,8 +549,8 @@ splnr_climate_percentile_preprocess <- function(featuresDF, #' Function to assign targets for the percentile approach #' -#' @param featuresDF feature sf object which should have a column for cellID -#' @param targetsDF `data.frame`with list of features under "feature" column and their corresponding targets under "target" column +#' @param features feature sf object +#' @param targets `data.frame`with list of features under "feature" column and their corresponding targets under "target" column #' @param climateSmartDF `sf` object produced using the function `splnr_climate_percentile_preprocess()` #' #' @return A new sf dataframe that has cutoffs applied. @@ -573,55 +560,51 @@ splnr_climate_percentile_preprocess <- function(featuresDF, #' @importFrom rlang .data #' #' @examples -#' Features <- dat_species_bin %>% -#' dplyr::select(-"cellID") +#' Features <- dat_species_bin #' -#' target <- Features %>% +#' targets <- Features %>% #' sf::st_drop_geometry() %>% #' colnames() %>% #' data.frame() %>% #' setNames(c("feature")) %>% #' dplyr::mutate(target = 0.3) #' -#' metric_df <- dat_clim -#' #' dat_species_binDF <- dat_species_bin %>% #' sf::st_drop_geometry() #' #' out_sf <- splnr_climate_percentile_preprocess( -#' featuresDF = dat_species_bin, -#' percentile = 35, metricDF = metric_df, direction = 1 +#' features = dat_species_bin, +#' metric = dat_clim, +#' percentile = 35, +#' direction = 1 #' ) #' #' targets <- splnr_climate_percentile_assignTargets( -#' featuresDF = dat_species_bin, -#' targetsDF = target, +#' features = dat_species_bin, +#' targets = targets, #' climateSmartDF = out_sf #' ) -splnr_climate_percentile_assignTargets <- function(featuresDF, +splnr_climate_percentile_assignTargets <- function(features, climateSmartDF, - targetsDF) { - spp <- featuresDF %>% # Get the list of features - tibble::as_tibble() %>% - dplyr::select(-"cellID", -"geometry") %>% + targets) { + spp <- features %>% # Get the list of features + sf::st_drop_geometry() %>% names() suppressMessages({ - df <- featuresDF %>% + df <- features %>% sf::st_drop_geometry() %>% dplyr::mutate_all(~ ifelse(is.na(.), 0, .)) %>% tibble::as_tibble() %>% - dplyr::select(-"cellID") %>% dplyr::summarize(dplyr::across(dplyr::everything(), sum)) %>% # Get the # of planning units where feature is present tidyr::pivot_longer(tidyselect::everything(), names_to = "feature", values_to = "original") %>% - dplyr::left_join(targetsDF) # %>% + dplyr::left_join(targets) # %>% # dplyr::mutate(feature = paste0(.data$feature, "_filtered")) # Change names df1 <- climateSmartDF %>% sf::st_drop_geometry() %>% dplyr::mutate_all(~ ifelse(is.na(.), 0, .)) %>% tibble::as_tibble() %>% - dplyr::select(-"cellID") %>% dplyr::summarize(dplyr::across(dplyr::everything(), sum)) %>% # Get the # of planning units selected using the climate-smart approach tidyr::pivot_longer(tidyselect::everything(), names_to = "feature", values_to = "filtered") @@ -639,9 +622,9 @@ splnr_climate_percentile_assignTargets <- function(featuresDF, #' Function to run the percentile approach #' -#' @param featuresDF feature `sf`object which should have a column for cellID -#' @param targetsDF `data.frame`with list of features under "feature" column and their corresponding targets under "target" column -#' @param metricDF climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID +#' @param features feature `sf`object +#' @param metric climate metric `sf` object with 'metric' as the column name of the metric values per planning unit. +#' @param targets `data.frame`with list of features under "feature" column and their corresponding targets under "target" column #' @param direction If direction = 1, metric values are from low (least climate-smart) to high (most climate-smart). If direction = -1, metric values are from high (least climate-smart) to low (most climate-smart). #' @param percentile cut-off threshold for determining whether an area is a climate priority area or not (e.g., lower 35th percentile of warming or upper 65th percentile of acidification). Note that the percentile here is the lower limit of the threshold. #' @@ -651,53 +634,52 @@ splnr_climate_percentile_assignTargets <- function(featuresDF, #' @importFrom rlang .data #' #' @examples -#' Features <- dat_species_bin %>% -#' dplyr::select(-"cellID") #' -#' target <- Features %>% +#' targets <- dat_species_bin %>% #' sf::st_drop_geometry() %>% #' colnames() %>% #' data.frame() %>% #' setNames(c("feature")) %>% #' dplyr::mutate(target = 0.3) #' -#' metric_df <- dat_clim -#' -#' #' Percentile_Approach <- splnr_climate_percentileApproach( -#' featuresDF = dat_species_bin, -#' metricDF = metric_df, targetsDF = target, direction = 1 +#' features = dat_species_bin, +#' metric = dat_clim, +#' targets = targets, +#' direction = 1 #' ) #' out_sf <- Percentile_Approach$Features #' targets <- Percentile_Approach$Targets -splnr_climate_percentileApproach <- function(featuresDF, - metricDF, - targetsDF, +splnr_climate_percentileApproach <- function(features, + metric, + targets, direction, percentile = 35) { - assertthat::assert_that(inherits(featuresDF, "sf"), - "cellID" %in% names(featuresDF), - is.data.frame(metricDF), - "cellID" %in% names(metricDF), - is.data.frame(targetsDF), - "feature" %in% names(targetsDF), - "target" %in% names(targetsDF), + assertthat::assert_that(inherits(features, "sf"), + inherits(metric, "sf"), + is.data.frame(targets), + "feature" %in% names(targets), + "target" %in% names(targets), direction %in% c(-1, 1), is.numeric(percentile), percentile >= 0 && percentile <= 100) percentileFeatures <- splnr_climate_percentile_preprocess( - featuresDF = featuresDF, metricDF = metricDF, - direction = direction, percentile = percentile + features = features, + metric = metric, + direction = direction, + percentile = percentile ) percentileTargets <- splnr_climate_percentile_assignTargets( - featuresDF = featuresDF, - targetsDF = targetsDF, + features = features, + targets = targets, percentileFeatures ) return(list(Features = percentileFeatures, Targets = percentileTargets)) } + + ##### Penalty Approach ##### diff --git a/R/utils.R b/R/utils.R index 4781cf8e..58b4a0da 100644 --- a/R/utils.R +++ b/R/utils.R @@ -34,8 +34,8 @@ splnr_create_polygon <- function(x, cCRS = "EPSG:4326") { #' Remove NAs from spatial data using nearest neighbour #' -#' `splnr_replace_NAs()` allows you to replace NA values in your data with the value of the nearest neighbor. -#' The nearest neighbor is determined using `st_nearest_feature()` from the `sf` package. +#' `splnr_replace_NAs()` allows you to replace NA values in your data with the value of the nearest neighbour. +#' The nearest neighbour is determined using `st_nearest_feature()` from the `sf` package. #' #' @param df An `sf` dataframe #' @param vari Variable to remove NAs from @@ -59,6 +59,7 @@ splnr_replace_NAs <- function(df, vari) { if (sum(is.na(dplyr::pull(df, !!rlang::sym(vari)))) > 0) { # Check if there are NAs gp <- df %>% + tibble::rowid_to_column("cellID") %>% # Add cellID to reorder df later dplyr::mutate(isna = is.na(!!rlang::sym(vari))) gp <- split(gp, f = as.factor(gp$isna)) @@ -70,7 +71,8 @@ splnr_replace_NAs <- function(df, vari) { df <- rbind(gp$`FALSE`, gp$`TRUE`) %>% dplyr::select(-"isna") %>% - dplyr::arrange(.data$cellID) + dplyr::arrange(.data$cellID) %>% + dplyr::select(-"cellID") # Remove added column } return(df) } @@ -91,7 +93,7 @@ splnr_replace_NAs <- function(df, vari) { #' #' @importFrom rlang := #' @examples -#' dat <- dat_region %>% dplyr::select(-cellID) +#' dat <- dat_region #' nam <- c("Region1" = "SE Aust", "Region2" = "Tas", "Region3" = "NE Aust") #' df <- splnr_match_names(dat, nam) splnr_match_names <- function(dat, nam) { @@ -165,7 +167,7 @@ splnr_scale_01 <- function(dat, col_name) { #' #' @examples #' df <- dat_species_prob %>% -#' splnr_featureNames(exclude = c("cellID")) +#' splnr_featureNames() splnr_featureNames <- function(dat, exclude = NA) { assertthat::assert_that( @@ -174,9 +176,9 @@ splnr_featureNames <- function(dat, exclude = NA) { ) if (is.na(exclude)) { - exclude <- c("Cost_", "cellID") + exclude <- c("Cost_") } else { - exclude <- c("Cost_", "cellID", exclude) + exclude <- c("Cost_", exclude) } dat <- dat %>% @@ -195,7 +197,7 @@ splnr_featureNames <- function(dat, exclude = NA) { #' #' @param df An sf object to sort by Lon and Lat #' -#' @return A sorted sf object with the additionl cellID column +#' @return A sorted sf object #' @export #' #' @examples @@ -211,8 +213,6 @@ splnr_arrangeFeatures <- function(df) { ) df <- df[order(xy[, "X"], xy[, "Y"]), ] - df <- df %>% - dplyr::mutate(cellID = dplyr::row_number()) } diff --git a/data-raw/DATASET.R b/data-raw/DATASET.R index f87ccc26..59914c78 100644 --- a/data-raw/DATASET.R +++ b/data-raw/DATASET.R @@ -24,9 +24,7 @@ dat_bndry <- dplyr::tibble(x = 100, y = seq(-50, 0, by = 1)) %>% # Use boundary to create grid dat_PUs <- sf::st_make_grid(dat_bndry, cellsize = 2) %>% - sf::st_sf() %>% - dplyr::mutate(cellID = dplyr::row_number()) # Add a cell ID reference - + sf::st_sf() # Create some regionalisations dat_region <- dat_PUs %>% @@ -54,16 +52,14 @@ col_name <- dat_species_prob %>% colnames() dat_species_bin <- dat_species_prob %>% - dplyr::as_tibble() %>% dplyr::mutate(dplyr::across( - -dplyr::any_of(c("cellID", "geometry")), # Apply to all columns except geometry and cellID + -dplyr::any_of(c("geometry")), # Apply to all columns except geometry and cellID ~ dplyr::case_when( . >= 0.5 ~ 1, . < 0.5 ~ 0, is.na(.data) ~ 0 ) - )) %>% - sf::st_as_sf() + )) # create second species_bin data set with unused species dat_species_bin2 <- dat_species_bin %>% @@ -73,9 +69,12 @@ dat_species_bin2 <- dat_species_bin %>% # Add a random MPA dat_mpas <- dat_PUs %>% sf::st_sf() %>% + tibble::rowid_to_column("cellID") %>% # Add a cell ID reference dplyr::mutate(wdpa = ifelse((cellID > 33 & cellID < 38) | (cellID > 63 & cellID < 68) | - (cellID > 93 & cellID < 98), 1, 0)) + (cellID > 93 & cellID < 98), 1, 0)) %>% + dplyr::select(-"cellID") + # Add a problem object dat_problem <- problem(dat_species_bin %>% dplyr::mutate(Cost = runif(n = dim(.)[[1]])), @@ -127,6 +126,22 @@ dat_bathy <- oceandatr::get_bathymetry(spatial_grid = dat_PUs, classify_bathymetry = FALSE) + +#TODO Need to sort out the datasets that are not created here + +load("data/spDataFiltered.rda") +spDataFiltered <- spDataFiltered %>% + dplyr::select(-"cellID") + +load("data/MPAsCoralSea.rda") +MPAsCoralSea <- MPAsCoralSea %>% + dplyr::select(-"cellID") + +load("data/CoralSeaVelocity.rda") +CoralSeaVelocity <- CoralSeaVelocity %>% + dplyr::select(-"cellID") + + # Save the data usethis::use_data(dat_bndry, dat_PUs, @@ -142,5 +157,8 @@ usethis::use_data(dat_bndry, dat_category2, dat_clim, dat_bathy, + spDataFiltered, + MPAsCoralSea, + CoralSeaVelocity, overwrite = TRUE ) diff --git a/data-raw/testOptimalityGap.R b/data-raw/testOptimalityGap.R index a05a4282..439e0e00 100644 --- a/data-raw/testOptimalityGap.R +++ b/data-raw/testOptimalityGap.R @@ -63,8 +63,7 @@ Bndry <- dplyr::tibble(x = 60, y = seq(-60, 0, by = 1)) %>% # Use boundary to create grid PUs <- sf::st_make_grid(Bndry, cellsize = 0.125) %>% - sf::st_sf() %>% - dplyr::mutate(cellID = dplyr::row_number()) + sf::st_sf() feature_num <- c(25, 50, 100, 500)#, 1000)#, 5000, 10000)#, 50000, 100000) PU_cellsize <- c(2,1,0.5,0.25,0.125) @@ -75,8 +74,7 @@ counter = 1 for (k in 1:length(PU_cellsize)) { PUs <- sf::st_make_grid(Bndry, cellsize = PU_cellsize[k]) %>% - sf::st_sf() %>% - dplyr::mutate(cellID = dplyr::row_number()) + sf::st_sf() for (j in 1:length(feature_num)) { @@ -129,8 +127,7 @@ counter = 1 for (k in 1:length(PU_cellsize)) { PUs <- sf::st_make_grid(Bndry, cellsize = PU_cellsize[k]) %>% - sf::st_sf() %>% - dplyr::mutate(cellID = dplyr::row_number()) + sf::st_sf() for (j in 1:length(feature_num)) { @@ -192,8 +189,7 @@ counter = 1 for (k in 1:length(PU_cellsize)) { PUs <- sf::st_make_grid(Bndry, cellsize = PU_cellsize[k]) %>% - sf::st_sf() %>% - dplyr::mutate(cellID = dplyr::row_number()) + sf::st_sf() for (j in 1:length(feature_num)) { diff --git a/data/CoralSeaVelocity.rda b/data/CoralSeaVelocity.rda index 12dcdb4b..e4f310ab 100644 Binary files a/data/CoralSeaVelocity.rda and b/data/CoralSeaVelocity.rda differ diff --git a/data/MPAsCoralSea.rda b/data/MPAsCoralSea.rda index 6fa5d6d9..047e959d 100644 Binary files a/data/MPAsCoralSea.rda and b/data/MPAsCoralSea.rda differ diff --git a/data/dat_PUs.rda b/data/dat_PUs.rda index 1bdc4fdd..18822c3b 100644 Binary files a/data/dat_PUs.rda and b/data/dat_PUs.rda differ diff --git a/data/dat_bathy.rda b/data/dat_bathy.rda index 390eff9e..b3ad1b46 100644 Binary files a/data/dat_bathy.rda and b/data/dat_bathy.rda differ diff --git a/data/dat_bndry.rda b/data/dat_bndry.rda index 45c6b444..c9303d3e 100644 Binary files a/data/dat_bndry.rda and b/data/dat_bndry.rda differ diff --git a/data/dat_clim.rda b/data/dat_clim.rda index 6f66dab6..3c56ce0c 100644 Binary files a/data/dat_clim.rda and b/data/dat_clim.rda differ diff --git a/data/dat_mpas.rda b/data/dat_mpas.rda index 17c892b6..05d9a5b4 100644 Binary files a/data/dat_mpas.rda and b/data/dat_mpas.rda differ diff --git a/data/dat_region.rda b/data/dat_region.rda index dca2ff02..cf59a238 100644 Binary files a/data/dat_region.rda and b/data/dat_region.rda differ diff --git a/data/dat_species_bin.rda b/data/dat_species_bin.rda index 3f614418..8ec626ac 100644 Binary files a/data/dat_species_bin.rda and b/data/dat_species_bin.rda differ diff --git a/data/dat_species_bin2.rda b/data/dat_species_bin2.rda index b0c9c8bc..1ab31954 100644 Binary files a/data/dat_species_bin2.rda and b/data/dat_species_bin2.rda differ diff --git a/data/dat_species_prob.rda b/data/dat_species_prob.rda index 3c8d5bd5..3486705d 100644 Binary files a/data/dat_species_prob.rda and b/data/dat_species_prob.rda differ diff --git a/data/spDataFiltered.rda b/data/spDataFiltered.rda index 326e17da..d9172f1d 100644 Binary files a/data/spDataFiltered.rda and b/data/spDataFiltered.rda differ diff --git a/docs/404.html b/docs/404.html index 580b1688..cc8d7112 100644 --- a/docs/404.html +++ b/docs/404.html @@ -75,7 +75,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index c3f4aa48..1add8f31 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -49,7 +49,7 @@ diff --git a/docs/LICENSE.html b/docs/LICENSE.html index d3fd61da..ed33049e 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -53,7 +53,7 @@ diff --git a/docs/articles/ClimateSmart.html b/docs/articles/ClimateSmart.html index d8d9fcab..70b88183 100644 --- a/docs/articles/ClimateSmart.html +++ b/docs/articles/ClimateSmart.html @@ -117,7 +117,7 @@
Bndry <- splnr_get_boundary(Limits = Region, Type = Type, cCRS = cCRS)
#> Reading layer `ne_10m_geography_marine_polys' from data source
-#> `/private/var/folders/_r/mcmw_qtn0m7cd23cbdqfszl40000gp/T/RtmpQilTyY/ne_10m_geography_marine_polys.shp'
+#> `/private/var/folders/_r/mcmw_qtn0m7cd23cbdqfszl40000gp/T/RtmpMuMJpx/ne_10m_geography_marine_polys.shp'
#> using driver `ESRI Shapefile'
#> Simple feature collection with 306 features and 37 fields
#> Geometry type: MULTIPOLYGON
@@ -179,7 +179,7 @@ Convert the probabilities to b
datEx_species_bin <- spDataFiltered %>%
dplyr::as_tibble() %>%
dplyr::mutate(dplyr::across(
- -dplyr::any_of(c("cellID", "geometry")), # Don't apply to geometry/cellID
+ -dplyr::any_of(c("geometry")), # Don't apply to geometry
~ dplyr::case_when(
. >= 0.5 ~ 1,
. < 0.5 ~ 0,
@@ -190,7 +190,6 @@ Convert the probabilities to b
col_name <- spDataFiltered %>%
sf::st_drop_geometry() %>%
- dplyr::select(-"cellID") %>%
colnames()
target <- datEx_species_bin %>%
sf::st_drop_geometry() %>%
- dplyr::select(-"cellID") %>%
colnames() %>%
data.frame() %>%
setNames(c("feature")) %>%
@@ -266,21 +264,19 @@ Climate-smart spatial planningCPA_Approach <- splnr_climate_priorityAreaApproach(
featuresDF = datEx_species_bin,
- metricDF = metric_df, targetsDF = target, direction = -1, refugiaTarget = 1
+ metricDF = metric_df,
+ targetsDF = target,
+ direction = -1, refugiaTarget = 1
)
out_sf <- CPA_Approach$Features %>%
- dplyr::left_join(
+ sf::st_join(
datEx_species_bin %>%
- sf::st_drop_geometry() %>%
dplyr::select(
- "cellID",
tidyselect::starts_with("Cost_")
),
- by = "cellID"
- ) %>%
- dplyr::left_join(metric_df %>%
- sf::st_drop_geometry(), by = "cellID")
+ join = sf::st_equals) %>%
+ sf::st_join(metric_df, join = sf::st_equals)
targets <- CPA_Approach$Targets
We now add other information required to perform the spatial @@ -293,7 +289,6 @@

However, we are also interested how climate-smart the selected planning units in the solution actually are. For this, we can use a -kernel density plot
+kernel density plot.
(ggClimDens <- splnr_plot_climKernelDensity(
soln = list(dat_solnClim),
@@ -342,7 +337,6 @@ Percentile Approach
target <- datEx_species_bin %>%
sf::st_drop_geometry() %>%
- dplyr::select(-"cellID") %>%
colnames() %>%
data.frame() %>%
setNames(c("feature")) %>%
@@ -355,17 +349,14 @@ Percentile Approach#> [1] "Lower values mean more climate-smart areas."
out_sf <- Percentile_Approach$Features %>%
- dplyr::left_join(
+ sf::st_join(
datEx_species_bin %>%
- sf::st_drop_geometry() %>%
dplyr::select(
- "cellID",
tidyselect::starts_with("Cost_")
),
- by = "cellID"
+ join = sf::st_equals
) %>%
- dplyr::left_join(metric_df %>%
- sf::st_drop_geometry(), by = "cellID")
+ sf::st_join(metric_df, join = sf::st_equals)
targets <- Percentile_Approach$Targets
We now add other information required to perform the spatial @@ -378,7 +369,6 @@
target <- datEx_species_bin %>%
sf::st_drop_geometry() %>%
- dplyr::select(-"cellID") %>%
colnames() %>%
data.frame() %>%
setNames(c("feature")) %>%
@@ -427,22 +416,20 @@ Feature Approach
Feature_Approach <- splnr_climate_featureApproach(
featuresDF = datEx_species_bin,
- metricDF = metric_df, targetsDF = target, direction = 1
+ metricDF = metric_df,
+ targetsDF = target,
+ direction = 1
)
#> [1] "Higher values mean more climate-smart areas."
out_sf <- Feature_Approach$Features %>%
- dplyr::left_join(
+ sf::st_join(
datEx_species_bin %>%
- sf::st_drop_geometry() %>%
dplyr::select(
- "cellID",
tidyselect::starts_with("Cost_")
),
- by = "cellID"
- ) %>%
- dplyr::left_join(metric_df %>%
- sf::st_drop_geometry(), by = "cellID")
+ join = sf::st_equals) %>%
+ sf::st_join(metric_df, join = sf::st_equals)
targets <- Feature_Approach$Targets
We now add other information required to perform the spatial @@ -455,7 +442,6 @@
Bndry <- splnr_get_boundary(Limits = Region, Type = Type, cCRS = cCRS)
#> Reading layer `ne_10m_geography_marine_polys' from data source
-#> `/private/var/folders/_r/mcmw_qtn0m7cd23cbdqfszl40000gp/T/RtmpBoWWk8/ne_10m_geography_marine_polys.shp'
+#> `/private/var/folders/_r/mcmw_qtn0m7cd23cbdqfszl40000gp/T/Rtmp0tUE3F/ne_10m_geography_marine_polys.shp'
#> using driver `ESRI Shapefile'
#> Simple feature collection with 306 features and 37 fields
#> Geometry type: MULTIPOLYGON
@@ -190,7 +190,6 @@ Convert the
col_name <- spDataFiltered %>%
sf::st_drop_geometry() %>%
- dplyr::select(-"cellID") %>%
colnames()
mpas <- MPAsCoralSea %>%
dplyr::mutate(zone = "zone 1") %>%
- dplyr::rename(
- pu = cellID,
- status = wdpa
- ) %>%
+ dplyr::rename(status = wdpa) %>%
+ tibble::rowid_to_column("pu") %>%
sf::st_drop_geometry() %>%
tibble::tibble() %>%
dplyr::filter(status == 1)
datSpecZone1 <- datEx_species_bin %>%
- sf::st_drop_geometry() %>%
- dplyr::rename_at(dplyr::vars(-cellID), ~ paste0(.x, "_zone1"))
+ dplyr::rename_at(dplyr::vars(-geometry), ~ paste0(.x, "_zone1"))
featuresZone1 <- datSpecZone1 %>%
- dplyr::select(-"cellID") %>%
+ sf::st_drop_geometry() %>%
colnames()
datSpecZone2 <- datEx_species_bin %>%
- sf::st_drop_geometry() %>%
- dplyr::rename_at(dplyr::vars(-cellID), ~ paste0(.x, "_zone2"))
+ dplyr::rename_at(dplyr::vars(-geometry), ~ paste0(.x, "_zone2"))
featuresZone2 <- datSpecZone2 %>%
- dplyr::select(-"cellID") %>%
+ sf::st_drop_geometry() %>%
colnames()
We also extract the new feature names and then create the
zones object, before joining the two newly created data
@@ -781,9 +776,7 @@
We then create a zones object for three different zones:
datSpecZone1 <- datEx_species_bin %>%
- sf::st_drop_geometry() %>%
- dplyr::rename_at(dplyr::vars(-cellID), ~ paste0(.x, "_zone1"))
+ dplyr::rename_at(dplyr::vars(-geometry), ~ paste0(.x, "_zone1"))
featuresZone1 <- datSpecZone1 %>%
- dplyr::select(-"cellID") %>%
+ sf::st_drop_geometry() %>%
colnames()
datSpecZone2 <- datEx_species_bin %>%
- sf::st_drop_geometry() %>%
- dplyr::rename_at(dplyr::vars(-cellID), ~ paste0(.x, "_zone2"))
+ dplyr::rename_at(dplyr::vars(-geometry), ~ paste0(.x, "_zone2"))
featuresZone2 <- datSpecZone2 %>%
- dplyr::select(-"cellID") %>%
+ sf::st_drop_geometry() %>%
colnames()
datSpecZone3 <- datEx_species_bin %>%
- sf::st_drop_geometry() %>%
- dplyr::rename_at(dplyr::vars(-cellID), ~ paste0(.x, "_zone3"))
+ dplyr::rename_at(dplyr::vars(-geometry), ~ paste0(.x, "_zone3"))
featuresZone3 <- datSpecZone3 %>%
- dplyr::select(-"cellID") %>%
+ sf::st_drop_geometry() %>%
colnames()
z12 <- prioritizr::zones(
@@ -989,8 +979,8 @@ Targets across some (but not all)
# NOTE: When using sf input, we need as many cost columns as we have zones
out_sf <- datSpecZone1 %>%
- dplyr::left_join(datSpecZone2, by = "cellID") %>%
- dplyr::left_join(datSpecZone3, by = "cellID") %>%
+ sf::st_join(datSpecZone2, join = sf::st_equals) %>%
+ sf::st_join(datSpecZone3, join = sf::st_equals) %>%
dplyr::mutate(geometry = datEx_species_bin$geometry) %>%
sf::st_as_sf() %>%
dplyr::mutate(
@@ -1108,7 +1098,7 @@ Longer-term
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/articles/index.html b/docs/articles/index.html
index 534d8232..fae856d2 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -57,7 +57,7 @@ All vignettes
Bndry <- splnr_get_boundary(Limits = Region, Type = Type, cCRS = cCRS)
#> Reading layer `ne_10m_geography_marine_polys' from data source
-#> `/private/var/folders/_r/mcmw_qtn0m7cd23cbdqfszl40000gp/T/RtmpFXGTcW/ne_10m_geography_marine_polys.shp'
+#> `/private/var/folders/_r/mcmw_qtn0m7cd23cbdqfszl40000gp/T/RtmpYDUd6r/ne_10m_geography_marine_polys.shp'
#> using driver `ESRI Shapefile'
#> Simple feature collection with 306 features and 37 fields
#> Geometry type: MULTIPOLYGON
@@ -253,8 +253,7 @@ Convert the probabilities to b
(ggFeatNo <- splnr_plot(df = datEx_species_bin,
col_names = colnames(datEx_species_bin %>%
- sf::st_drop_geometry() %>%
- dplyr::select(-"cellID")),
+ sf::st_drop_geometry()),
plot_title = "",
legend_title = "Number of features") +
splnr_gg_add(
@@ -263,9 +262,10 @@ Convert the probabilities to b
))

-
+
+Prepare Data for prioritisation
+
For the spatial prioritization we also need to extract the names of
our features to pass into prioritizr.
-
+
+Set Targets
+
As shown previously, we assigned the conservation features a class
reflecting their importance in the planning region. Conservation targets
are then assigned a target based on their class, in our case 30% of
@@ -346,10 +347,9 @@
Set Targets
-Set up conservation problem
-
+
+Set up conservation problem
+
datEx_problem <- prioritizr::problem(out_sf, feature_names, "Cost_None") %>%
prioritizr::add_min_set_objective() %>%
@@ -357,23 +357,23 @@ Set up conservation problemprioritizr::add_binary_decisions() %>%
prioritizr::add_default_solver(verbose = FALSE)
-
-Solve the conservation problem
-
+
+Solve the conservation problem
+
datEx_soln <- datEx_problem %>%
prioritizr::solve.ConservationProblem()
-
-Visualize Output
-
+
+Visualize Output
+
There are different ways to visualize the output of the
prioritization that can be loosely grouped into three categories:
+ Visualization of the solution + Visualization of
targets + Visualization of importance scores
-
-Visualization of the solution
-
+
+Visualization of the solution
+
(ggSoln <- splnr_plot(datEx_soln,
col_names = "solution_1",
@@ -405,9 +405,9 @@ Visualization of the solution
-Visualization of targets
-
+
+Visualization of targets
+
To visualize how well the targets are met, we first need to extract
how much suitable habitat of each feature are selected in the spatial
plan. This also includes potential incidental coverage of feature that
@@ -431,21 +431,21 @@
Visualization of targetsFor a circular bar plot, one additional step of data preparation
needs to be done.
-# dfTargetCirc <- dfTarget %>%
-# dplyr::select("feature", "value", "group") %>%
-# na.omit()
+dfTargetCirc <- dfTarget %>%
+dplyr::select("feature", "value", "group") %>%
+na.omit()
-# colors <- c(
-# "important" = "darkgreen",
-# "representative" = "darkred"
-# )
-# legends <- c("Important", "Representative")
+colors <- c(
+ "important" = "darkgreen",
+ "representative" = "darkred"
+)
+legends <- c("Important", "Representative")
-# (ggCircTarg <- splnr_plot_circBplot(df = dfTargetCirc, legend_list = legends, legend_color = colors, impTarget = 30, repTarget = 10))
+(ggCircTarg <- splnr_plot_circBplot(df = dfTargetCirc, legend_list = legends, legend_color = colors, impTarget = 30, repTarget = 10))
-
-Visualization of importance scores
-
+
+Visualization of importance scores
+
Importance scores can help to assess the relative importance of an
individual selected planning unit in the spatial plan (for more
information, see https://prioritizr.net/reference/importance.html)
@@ -484,9 +484,9 @@ Visualization of importance scores
-
-Comparing Spatial Plans
-
+
+Comparing Spatial Plans
+
Sometimes it can be useful to have a direct comparison of two spatial
plans. To show how to achieve this with this package, we first need a
second conservation problem and resulting solution.
@@ -546,9 +546,9 @@ Comparing Spatial PlansSys.setenv(IUCN_REDLIST_KEY = "[Your Token]"). You can
start by running rredlist::rl_use_iucn().
-
-Set up second conservation problem
-
+
+Set up second conservation problem
+
datEx_problem2 <- prioritizr::problem(out_sf, feature_names, "Cost_None") %>%
prioritizr::add_min_set_objective() %>%
@@ -593,9 +593,9 @@ Set up second conservation problem ))

-
-Visualize comparison
-
+
+Visualize comparison
+
(ggComp <- splnr_plot_comparison(datEx_soln, datEx_soln2) +
splnr_gg_add(
@@ -620,12 +620,11 @@ Visualize comparison
Plotting selection frequency
Sometimes when multiple spatial plans are generated, we are
-interesting in how many times a planning unit is selected across the
+interested in how many times a planning unit is selected across the
array of solutions. To demonstrate how this can be done using this
package, we first create an array (= portfolio) of solutions. One
example of this is by using the portfolio
@@ -662,7 +661,7 @@ Plotting selection frequency
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/authors.html b/docs/authors.html
index 664edbe1..1a6983d2 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -75,7 +75,7 @@ Citation
diff --git a/docs/index.html b/docs/index.html
index 203eb28c..30594fef 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -136,7 +136,7 @@ Dev status
diff --git a/docs/pkgdown.js b/docs/pkgdown.js
index 9757bf9e..1a99c65f 100644
--- a/docs/pkgdown.js
+++ b/docs/pkgdown.js
@@ -152,3 +152,11 @@ async function searchFuse(query, callback) {
});
});
})(window.jQuery || window.$)
+
+document.addEventListener('keydown', function(event) {
+ // Check if the pressed key is '/'
+ if (event.key === '/') {
+ event.preventDefault(); // Prevent any default action associated with the '/' key
+ document.getElementById('search-input').focus(); // Set focus to the search input
+ }
+});
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml
index 32c1be4c..06fb05a1 100644
--- a/docs/pkgdown.yml
+++ b/docs/pkgdown.yml
@@ -1,12 +1,12 @@
-pandoc: 3.1.11
-pkgdown: 2.1.0
+pandoc: '3.2'
+pkgdown: 2.1.1
pkgdown_sha: ~
articles:
ClimateSmart: ClimateSmart.html
GlobalFishingWatch: GlobalFishingWatch.html
MultipleUse: MultipleUse.html
spatialplanr: spatialplanr.html
-last_built: 2024-09-10T21:15Z
+last_built: 2024-10-31T03:47Z
urls:
reference: https://mathmarecol.github.io/spatialplanr/reference
article: https://mathmarecol.github.io/spatialplanr/articles
diff --git a/docs/reference/CoralSeaVelocity.html b/docs/reference/CoralSeaVelocity.html
index a7a1756f..65a8832a 100644
--- a/docs/reference/CoralSeaVelocity.html
+++ b/docs/reference/CoralSeaVelocity.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/IUCN_IA_Targets.html b/docs/reference/IUCN_IA_Targets.html
index 7034c5a0..5e3e4c4a 100644
--- a/docs/reference/IUCN_IA_Targets.html
+++ b/docs/reference/IUCN_IA_Targets.html
@@ -79,7 +79,7 @@ Source<
diff --git a/docs/reference/MPAsCoralSea.html b/docs/reference/MPAsCoralSea.html
index 6c5fdd63..cc8c627c 100644
--- a/docs/reference/MPAsCoralSea.html
+++ b/docs/reference/MPAsCoralSea.html
@@ -53,9 +53,6 @@ Format<
A data frame with 397 rows and 17 columns:- wdpa
binary vector denoting presence or absence of a current marine protected area
-- cellID
-cell ID of planning units
-
...
@@ -73,7 +70,7 @@ Source<
diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png
deleted file mode 100644
index 17a35806..00000000
Binary files a/docs/reference/Rplot001.png and /dev/null differ
diff --git a/docs/reference/Rplot002.png b/docs/reference/Rplot002.png
deleted file mode 100644
index c23677dc..00000000
Binary files a/docs/reference/Rplot002.png and /dev/null differ
diff --git a/docs/reference/Rplot003.png b/docs/reference/Rplot003.png
deleted file mode 100644
index a8e75125..00000000
Binary files a/docs/reference/Rplot003.png and /dev/null differ
diff --git a/docs/reference/Rplot004.png b/docs/reference/Rplot004.png
deleted file mode 100644
index 59cd958c..00000000
Binary files a/docs/reference/Rplot004.png and /dev/null differ
diff --git a/docs/reference/Rplot005.png b/docs/reference/Rplot005.png
deleted file mode 100644
index cfa29e01..00000000
Binary files a/docs/reference/Rplot005.png and /dev/null differ
diff --git a/docs/reference/dat_PUs.html b/docs/reference/dat_PUs.html
index 098398e5..7881a68e 100644
--- a/docs/reference/dat_PUs.html
+++ b/docs/reference/dat_PUs.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/dat_bathy.html b/docs/reference/dat_bathy.html
index 3a7fb744..f530c1f5 100644
--- a/docs/reference/dat_bathy.html
+++ b/docs/reference/dat_bathy.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/dat_bndry.html b/docs/reference/dat_bndry.html
index 68edcb04..8d7297f9 100644
--- a/docs/reference/dat_bndry.html
+++ b/docs/reference/dat_bndry.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/dat_category.html b/docs/reference/dat_category.html
index cb76a841..2d47bdac 100644
--- a/docs/reference/dat_category.html
+++ b/docs/reference/dat_category.html
@@ -73,7 +73,7 @@ Source<
diff --git a/docs/reference/dat_category2.html b/docs/reference/dat_category2.html
index 0485e0fe..5a4def95 100644
--- a/docs/reference/dat_category2.html
+++ b/docs/reference/dat_category2.html
@@ -73,7 +73,7 @@ Source<
diff --git a/docs/reference/dat_clim.html b/docs/reference/dat_clim.html
index eb3e05ec..3e5d5e50 100644
--- a/docs/reference/dat_clim.html
+++ b/docs/reference/dat_clim.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/dat_mpas.html b/docs/reference/dat_mpas.html
index 91aa85c6..d0d049f8 100644
--- a/docs/reference/dat_mpas.html
+++ b/docs/reference/dat_mpas.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/dat_region.html b/docs/reference/dat_region.html
index fe3defca..fa7ff803 100644
--- a/docs/reference/dat_region.html
+++ b/docs/reference/dat_region.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/dat_species_bin.html b/docs/reference/dat_species_bin.html
index 4d07d01f..4ad65384 100644
--- a/docs/reference/dat_species_bin.html
+++ b/docs/reference/dat_species_bin.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/dat_species_bin2.html b/docs/reference/dat_species_bin2.html
index fe0d6cad..6244bc26 100644
--- a/docs/reference/dat_species_bin2.html
+++ b/docs/reference/dat_species_bin2.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/dat_species_prob.html b/docs/reference/dat_species_prob.html
index 0cbbfda2..e2195ed6 100644
--- a/docs/reference/dat_species_prob.html
+++ b/docs/reference/dat_species_prob.html
@@ -50,10 +50,7 @@ Usage
diff --git a/docs/reference/index.html b/docs/reference/index.html
index 87a4630a..ef3a71e2 100644
--- a/docs/reference/index.html
+++ b/docs/reference/index.html
@@ -436,7 +436,7 @@ Built in datasets
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/reference/pipe.html b/docs/reference/pipe.html
index 5f0bf241..d4d6ac27 100644
--- a/docs/reference/pipe.html
+++ b/docs/reference/pipe.html
@@ -56,7 +56,7 @@ Usage
diff --git a/docs/reference/spDataFiltered.html b/docs/reference/spDataFiltered.html
index ad84b62f..c4bd52bf 100644
--- a/docs/reference/spDataFiltered.html
+++ b/docs/reference/spDataFiltered.html
@@ -69,7 +69,7 @@ Source<
diff --git a/docs/reference/spatialplanr-package.html b/docs/reference/spatialplanr-package.html
index bc3d656e..bf90e9bd 100644
--- a/docs/reference/spatialplanr-package.html
+++ b/docs/reference/spatialplanr-package.html
@@ -67,7 +67,7 @@ Author<
diff --git a/docs/reference/splnr_apply_cutoffs.html b/docs/reference/splnr_apply_cutoffs.html
index a42f1e0f..630ce178 100644
--- a/docs/reference/splnr_apply_cutoffs.html
+++ b/docs/reference/splnr_apply_cutoffs.html
@@ -82,7 +82,7 @@ Examples
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/reference/splnr_arrangeFeatures.html b/docs/reference/splnr_arrangeFeatures.html
index 74a8fe8e..485218c1 100644
--- a/docs/reference/splnr_arrangeFeatures.html
+++ b/docs/reference/splnr_arrangeFeatures.html
@@ -57,7 +57,7 @@ Arguments
Value
- A sorted sf object with the additionl cellID column
+ A sorted sf object
diff --git a/docs/reference/splnr_climate_featureApproach.html b/docs/reference/splnr_climate_featureApproach.html
index fd75d951..bc11832b 100644
--- a/docs/reference/splnr_climate_featureApproach.html
+++ b/docs/reference/splnr_climate_featureApproach.html
@@ -59,11 +59,11 @@ ArgumentsfeaturesDF
-feature sfobject which should have a column for cellID
+feature sfobject
metricDF
-climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID
+climate metric data.frame with 'metric' as the column name of the metric values per planning unit.
targetsDF
@@ -89,8 +89,7 @@ Value
Examples
- Features <- dat_species_bin %>%
- dplyr::select(-"cellID")
+ Features <- dat_species_bin
target <- Features %>%
sf::st_drop_geometry() %>%
@@ -120,7 +119,7 @@ Examples
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/reference/splnr_climate_percentileApproach.html b/docs/reference/splnr_climate_percentileApproach.html
index e42a568c..4006d93a 100644
--- a/docs/reference/splnr_climate_percentileApproach.html
+++ b/docs/reference/splnr_climate_percentileApproach.html
@@ -58,11 +58,11 @@ ArgumentsfeaturesDF
-feature sfobject which should have a column for cellID
+feature sfobject
metricDF
-climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID
+climate metric data.frame with 'metric' as the column name of the metric values per planning unit.
targetsDF
@@ -84,8 +84,7 @@ Value
Examples
- Features <- dat_species_bin %>%
- dplyr::select(-"cellID")
+ Features <- dat_species_bin
target <- Features %>%
sf::st_drop_geometry() %>%
@@ -115,7 +114,7 @@ Examples
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/reference/splnr_climate_priorityAreaApproach.html b/docs/reference/splnr_climate_priorityAreaApproach.html
index c9cc4244..07d5e735 100644
--- a/docs/reference/splnr_climate_priorityAreaApproach.html
+++ b/docs/reference/splnr_climate_priorityAreaApproach.html
@@ -59,11 +59,11 @@ ArgumentsfeaturesDF
-feature sfobject which should have a column for cellID
+feature sfobject
metricDF
-climate metric data.frame with 'metric' as the column name of the metric values per planning unit. This should also have a column for the cellID
+climate metric data.frame with 'metric' as the column name of the metric values per planning unit.
targetsDF
@@ -89,8 +89,7 @@ Value
Examples
- Features <- dat_species_bin %>%
- dplyr::select(-"cellID")
+ Features <- dat_species_bin
target <- Features %>%
sf::st_drop_geometry() %>%
@@ -101,7 +100,6 @@ Examples
metric_df <- dat_clim
-
CPA_Approach <- splnr_climate_priorityAreaApproach(
featuresDF = dat_species_bin,
metricDF = metric_df, targetsDF = target, direction = -1
@@ -119,7 +117,7 @@ Examples
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/reference/splnr_convert_regionalisation.html b/docs/reference/splnr_convert_regionalisation.html
index bcb13e19..6ca24cf2 100644
--- a/docs/reference/splnr_convert_regionalisation.html
+++ b/docs/reference/splnr_convert_regionalisation.html
@@ -95,7 +95,7 @@ Examples
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/reference/splnr_convert_toPUs.html b/docs/reference/splnr_convert_toPUs.html
index 7e5c7510..1ceb2ccb 100644
--- a/docs/reference/splnr_convert_toPUs.html
+++ b/docs/reference/splnr_convert_toPUs.html
@@ -86,7 +86,7 @@ Examples
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/reference/splnr_create_polygon.html b/docs/reference/splnr_create_polygon.html
index 5a4c5bd6..2477302c 100644
--- a/docs/reference/splnr_create_polygon.html
+++ b/docs/reference/splnr_create_polygon.html
@@ -81,7 +81,7 @@ Examples
- Site built with pkgdown 2.1.0.
+ Site built with pkgdown 2.1.1.
diff --git a/docs/reference/splnr_featureNames.html b/docs/reference/splnr_featureNames.html
index bfe708bb..dd62f04b 100644
--- a/docs/reference/splnr_featureNames.html
+++ b/docs/reference/splnr_featureNames.html
@@ -70,7 +70,7 @@ Value
Examples