suppressPackageStartupMessages({
library(terra)
library(ggplot2)
library(spatialsample)
library(rsample)
library(sf)
library(dplyr)
})
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
library(reticulate) | |
py_require(c("dask", "distributed", "rioxarray")) | |
dask.distributed <- reticulate::import("dask.distributed") | |
rioxarray <- reticulate::import("rioxarray") | |
Sys.setenv(GDAL_VRT_ENABLE_PYTHON = "YES") | |
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
#' Download geospatial embeddings for Major-TOM datsets | |
#' @param bbox numeric vector of length 4 representing the bounding box in | |
#' longitude and latitude coordinates (WGS84). Ordered as c(xmin, xmax, ymin, | |
#' ymax). | |
#' @param embed character vector of length 1 representing the embedding to | |
#' download. | |
#' @param limit integer vector of length 1 representing the maximum number of | |
#' rows to return. Useful for testing, if NULL then all rows within the bbox | |
#' are returned. |
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
#' Create a composite raster with a VRT pixel function | |
#' @param src_files a character vector with the paths to the source rasters. | |
#' @param outfile a character path to the output raster. | |
#' @param fun a character with the pixel function to apply. | |
#' @param t_srs a character with the target SRS. If empty string "", the spatial | |
#' reference of src_files[1] will be used. | |
#' @param vrt_options a character vector with additional options to pass to the | |
#' gdalbuildVRT command. | |
#' @param warp_options a character vector with additional options to pass to the | |
#' gdalwarp command. |
library(terra)
#> terra 1.8.0
# create example landcover raster
r <- rast(
extent = c(0, 15000, 0, 15000),
resolution = 30,
crs = "+proj=laea"
)
as_the_crow_flies <- function(city1, city2,
country1 = NULL, country2 = NULL,
units = "km", quiet = FALSE) {
gcl <- tidygeocoder::geo(
city = c(city1, city2), country = c(country1, country2),
method = "osm", quiet = TRUE, progress_bar = FALSE, verbose = FALSE
)
l1 <- gcl[1, ]
l2 <- gcl[2, ]
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
#' Project an sf/sfc object to a generic projected coordinate system | |
#' @param x an sf or sfc object | |
#' @param proj a character vector. The projection to use. One of "laea", "aeqd", | |
#' "utm", "pconic", or "eqdc". | |
#' @param ellps a character vector. The ellipsoid to use. Select from | |
#' `sf_proj_info(type = "ellps")`. | |
#' @param opts a character vector. Additional proj options to pass to the | |
#' proj string. see details for more information. | |
#' @return an sf or sfc object | |
#' @details For further info about the available "generic" projects see: |
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
# Description: This script is used to download HLS data from NASA's Earthdata | |
# STAC API and build a cloud-free composite image. | |
# ----- Functions ----- | |
# band mapping for HLS SL data | |
#' @return a named character vector of band mappings for HLS SL data | |
hlssl_band_mapping <- function() { | |
c( | |
B01 = "A", B02 = "B", B03 = "G", B04 = "R", |
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
#' @title Get administritive outlines for a country | |
#' @description using the geoBoundaires API, get the administritive polygon(s) | |
#' for a country | |
#' @param country character vector: a country name | |
#' @param admin_level character vector: the admin level to download | |
#' @param quiet logical, should st_read be quiet? | |
#' @return sf object of the outlines | |
#' @details check out the documentation for the geoboundaries API at: | |
#' geoBoundaries.org | |
#' |
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
#' Buffer a point along a terrain surface. | |
#' | |
#' @param dtm A SpatRaster Digital Terrain Model | |
#' @param pnts A SpatVector of points | |
#' @param .dist Numeric - the buffer distance. | |
#' @param .res Numeric - approximate resampling resolution of the (internally | |
#' calculated) cost raster. | |
#' @param .smooth Logical default FALSE. Should the output buffer be smoothed using `smoothr::smooth`? | |
#' @param .method The smoothing method to use - see `smoothr::smooth` for details. | |
#' @param ... Passed to `smoothr::smooth` for eg. to control smoothness. |
NewerOlder