For use as predict boundary for a taxa, but also see
make_predict_boundary()
Usage
make_mcp(
presence,
out_file,
force_new = FALSE,
pres_x = "long",
pres_y = "lat",
in_crs = 4326,
out_crs = in_crs,
buf = 0,
clip = NULL
)
Arguments
- presence
Cleaned and filtered dataframe of presences
- out_file
Character. Path for the mcp to be saved. Will be saved by
sfarrow::st_write_parquet()
. Currently will not work very well with any full stop in the path. Other file types are changed to .parquet- force_new
Logical. If
out_file
exists, recreate it?- pres_x, pres_y
Character. Name of the columns in
presence
that have the x and y coordinates- in_crs
epsg code for coordinates in
presence
- out_crs
epsg code for coordinates in output mcp. Usually the same as predictors
- buf
Distance to buffer the mcp. Passed to the
dist
argument ofsf:st_buffer()
so units should follow that guidance.- clip
sf to clip the mcp
Examples
out_dir <- file.path(system.file(package = "envSDM"), "examples")
data <- file.path(system.file(package = "predicts"), "ex") |>
fs::dir_ls(regexp = "\\.csv$") |>
tibble::enframe(name = NULL, value = "path") |>
dplyr::mutate(taxa = gsub("\\.csv", "", basename(path))
, presence = purrr::map(path, rio::import, setclass = "tibble")
, presence = purrr::map(presence
, \(x) x |>
dplyr::filter(!is.na(lat)
, !is.na(lon)
)
)
, out_dir = fs::path(out_dir, taxa)
, out_mcp = fs::path(out_dir, "mcp.parquet")
)
# mcps --------
purrr::pwalk(list(data$presence
, data$out_mcp
)
, \(x, y) make_mcp(x, y, pres_x = "lon")
)