-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kba #349
Merged
Add kba #349
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#' Calculate Key Biodiversity Areas | ||
#' | ||
#' This function calculates the total area of key biodiversity areas for a given | ||
#' input polygon. | ||
#' | ||
#' The required resources for this indicator are: | ||
#' - [key_biodiversity_areas] | ||
#' | ||
#' @name key_biodiversity_areas | ||
#' @docType data | ||
#' @keywords indicator | ||
#' @format A function returning an indicator tibble with `key_biodiversity_area` | ||
#' as variable and the total overlap area (in ha) as value. | ||
#' @include register.R | ||
#' @export | ||
#' @examples | ||
#' \dontshow{ | ||
#' mapme.biodiversity:::.copy_resource_dir(file.path(tempdir(), "mapme-data")) | ||
#' } | ||
#' \dontrun{ | ||
#' library(sf) | ||
#' library(mapme.biodiversity) | ||
#' | ||
#' outdir <- file.path(tempdir(), "mapme-data") | ||
#' dir.create(outdir, showWarnings = FALSE) | ||
#' | ||
#' mapme_options( | ||
#' outdir = outdir, | ||
#' verbose = FALSE | ||
#' ) | ||
#' | ||
#' kbas <- system.file("resources", "key_biodiversity_areas", "kbas.gpkg", | ||
#' package = "mapme.biodiversity") | ||
#' | ||
#' aoi <- system.file("extdata", "shell_beach_protected_area_41057_B.gpkg", | ||
#' package = "mapme.biodiversity" | ||
#' ) %>% | ||
#' read_sf() %>% | ||
#' get_resources(get_key_biodiversity_area(kbas)) %>% | ||
#' calc_indicators(calc_key_biodiversity_area()) %>% | ||
#' portfolio_long() | ||
#' | ||
#' aoi | ||
#' } | ||
calc_key_biodiversity_area <- function() { | ||
function(x = NULL, | ||
key_biodiversity_areas, | ||
name = "key_biodiversity_areas", | ||
mode = "asset", | ||
aggregation = "mean", | ||
verbose = mapme_options()[["verbose"]]) { | ||
|
||
key_biodiversity_areas <- key_biodiversity_areas[[1]] | ||
if (is.null(key_biodiversity_areas) | nrow(key_biodiversity_areas) == 0) { | ||
return(NULL) | ||
} | ||
|
||
int_area <- suppressWarnings(st_intersection(x, key_biodiversity_areas)) | ||
if (nrow(int_area) == 0) return(NULL) | ||
int_area_ha <- as.numeric(sum(st_area(int_area), na.rm = TRUE) / 10000) | ||
|
||
results <- tibble::tibble( | ||
datetime = as.POSIXct("2024-01-01T00:00:00Z"), | ||
variable = "key_biodiversity_area", | ||
unit = "ha", | ||
value = int_area_ha | ||
) | ||
|
||
return(results) | ||
} | ||
} | ||
|
||
register_indicator( | ||
name = "key_biodiversity_areas", | ||
description = "Area estimation of intersection with key biodiversity areas.", | ||
resources = "key_biodiversity_areas" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' Key Biodiversity Areas | ||
#' | ||
#' This resource contains outlines of key biodiversity areas, which are areas | ||
#' representing sites with specific importance for nature conservation. | ||
#' | ||
#' To use this data in mapme workflows, you will have to manually download the | ||
#' global data set and point towards its file path on your local machine. | ||
#' Please find the available data under the source link given below. | ||
#' | ||
#' @name key_biodiversity_areas | ||
#' @keywords resource | ||
#' @param path A character vector to the key biodiversity areas GPKG file. | ||
#' Note, that the file has to be downloaded manually. | ||
#' @returns A function that returns an `sf` footprints object. | ||
#' @references BirdLife International (2024). The World Database of | ||
#' Key Biodiversity Areas. Developed by the KBA Partnership: BirdLife | ||
#' International, International Union for the Conservation of Nature, | ||
#' Amphibian Survival Alliance, Conservation International, Critical Ecosystem | ||
#' Partnership Fund, Global Environment Facility, Re:wild, NatureServe, | ||
#' Rainforest Trust, Royal Society for the Protection of Birds, Wildlife | ||
#' Conservation Society and World Wildlife Fund. Available at | ||
#' www.keybiodiversityareas.org. | ||
#' @source \url{https://www.keybiodiversityareas.org/kba-data} | ||
#' @include register.R | ||
#' @export | ||
get_key_biodiversity_areas <- function(path = NULL) { | ||
|
||
if(is.null(path) || !file.exists(path)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you include a line in the test script that triggers this line? |
||
stop("Expecting path to point towards an existing file.") | ||
} | ||
|
||
function( | ||
x, | ||
name = "key_biodiversity_areas", | ||
type = "vector", | ||
outdir = mapme_options()[["outdir"]], | ||
verbose = mapme_options()[["verbose"]]) { | ||
|
||
bbox <- c(xmin = -180.0, ymin = -90.0, xmax = 180.0, ymax = 90.0) | ||
tile <- st_as_sf(st_as_sfc(st_bbox(bbox, crs = "EPSG:4326"))) | ||
tile[["source"]] <- path | ||
make_footprints(tile, what = "vector") | ||
} | ||
} | ||
|
||
register_resource( | ||
name = "key_biodiversity_areas", | ||
description = "Key Biodiversity Areas", | ||
licence = "https://www.keybiodiversityareas.org/termsofservice", | ||
source = "https://www.keybiodiversityareas.org/kba-data", | ||
type = "vector" | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you are at it, maybe also test this line?