Skip to content
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

Cleaning pipeline #91

Merged
merged 3 commits into from
Dec 11, 2023
Merged
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
Empty file removed R/map_covariates.R
Empty file.
46 changes: 18 additions & 28 deletions R/process_spatial_covariates.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
#' Project and save imperviousness data to a new crs
#' (used for projection to EPSG:5070 previously to prediction grid creation
#' Aggregate raster and store it in a new file (useful for dem)
#'
#' @param crs_dest A character with the crs of destination
#' @param crs_name A character for the crs without weird characters
#' to concat to file name
project_imp <- function(crs_dest, crs_name) {
# imperviousness is by default in wgs84 (epsg:4326)
imp <- terra::rast("../input/NC_imperviousness_2019.tif")
if (!terra::same.crs(terra::crs(imp), crs_dest)) {
imp_proj <- terra::project(imp, crs_dest)
terra::writeRaster(imp_proj,
filename = paste0(
"../input/",
"NC_imperviousness_2019_",
crs_name,
".tif"
),
#' @param in_filepath A character path to data file with high resolution
#' @param out_filepath A character path to the folder where the aggregate file
#' will be stored
agg_rast <- function(in_filepath, out_filepath, agg_fact = 30) {
raw <- terra::rast(in_filepath)
agg <- terra::aggregate(raw, fact = agg_fact, fun = "median") %>%
terra::writeRaster(
filename = paste0(out_filepath),
overwrite = TRUE
)
}
return(agg)
}

#' Aggregate digital elevation model (~1m to ~30m)

#' Subset a polygon area from a SpatRaster or a SpatVector
#'
#' @param dem_path A path to dem file with high resolution
agg_dem <- function(dem_path = "../input/NC-DEM.tif") {
dem <- terra::rast(dem_path)
dem_agg <- terra::aggregate(dem, fact = 30, fun = "median")
terra::writeRaster(dem_agg,
filename = "../input/NC-DEM-agg.tif",
overwrite = TRUE
)
return(dem_agg)
#' @param sp a SpatRaster or a SpatVector
#' @param poly a SpatVector with polygon geometry
subset_area <- function(sp, poly) {
poly_proj <- terra::project(poly, terra::crs(sp))
crop_sp <- terra::crop(sp, poly_proj)
return(crop_sp)
}
File renamed without changes.
Empty file.
Empty file.
Empty file.
272 changes: 0 additions & 272 deletions vignettes/add_covariates_to_prediction_grid.Rmd

This file was deleted.

Loading
Loading