Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Cleaned up documentation
  • Loading branch information
jeffreyevans committed Nov 16, 2023
1 parent 71a7dae commit 66e8ef6
Show file tree
Hide file tree
Showing 283 changed files with 2,000 additions and 2,384 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: spatialEco
Type: Package
Title: Spatial Analysis and Modelling Utilities
Version: 2.0-2
Date: 2023-11-10
Date: 2023-11-15
Authors@R: c(
person(family="Evans", given="Jeffrey S.", email = "jeffrey_evans@tnc.org",
role = c("aut", "cre"), comment = c(ORCID = "0000-0002-5533-7044")),
Expand Down Expand Up @@ -44,7 +44,8 @@ Suggests:
units,
sp,
stringr,
lwgeom
lwgeom,
geodata
Maintainer: Jeffrey S. Evans <jeffrey_evans@tnc.org>
License: GPL-3
URL: https://github.com/jeffreyevans/spatialEco, https://jeffreyevans.github.io/spatialEco/
Expand Down
17 changes: 1 addition & 16 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export(breeding.density)
export(built.index)
export(cgls_urls)
export(chae)
export(class.comparison)
export(classBreaks)
export(collinear)
export(combine)
Expand All @@ -38,14 +37,9 @@ export(daymet.tiles)
export(dispersion)
export(dissection)
export(divergence)
export(download.daymet)
export(download.hansen)
export(download.prism)
export(effect.size)
export(erase.point)
export(explode)
export(extract.vertices)
export(focal.lmetrics)
export(fuzzySum)
export(gaussian.kernel)
export(geo.buffer)
Expand All @@ -60,12 +54,10 @@ export(impute.loess)
export(insert)
export(insert.values)
export(is.empty)
export(kde.2D)
export(kendall)
export(kl.divergence)
export(knn)
export(lai)
export(land.metrics)
export(local.min.max)
export(loess.boot)
export(loess.ci)
Expand All @@ -74,7 +66,6 @@ export(max_extent)
export(mean_angle)
export(moments)
export(morans.plot)
export(mwCorr)
export(nni)
export(nth.values)
export(o.ring)
Expand All @@ -86,11 +77,9 @@ export(overlap)
export(parea.sample)
export(parse.bits)
export(partial.cor)
export(point.in.poly)
export(poly.regression)
export(polyPerimeter)
export(poly_trend)
export(polygon_extract)
export(pp.subsample)
export(proximity.index)
export(pseudo.absence)
Expand All @@ -117,11 +106,8 @@ export(rm.ext)
export(rotate.polygon)
export(sa.trans)
export(sample.annulus)
export(sample.line)
export(sample.poly)
export(sampleTransect)
export(sar)
export(se.news)
export(separability)
export(sf.kde)
export(sf_dissolve)
Expand All @@ -133,8 +119,8 @@ export(similarity)
export(smooth.time.series)
export(sobal)
export(sp.kde)
export(sp.na.omit)
export(spatial.select)
export(spatialEcoNews)
export(spectral.separability)
export(spherical.sd)
export(squareBuffer)
Expand All @@ -151,5 +137,4 @@ export(tri)
export(vrm)
export(winsorize)
export(wt.centroid)
export(zonal.stats)
import(terra)
9 changes: 5 additions & 4 deletions R/all_pairwise.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#' @description Creates all pairwise combinations list for iteration
#'
#' @param x A numeric or character vector
#'
#' @return A list object with increasing all combination objects,
#' the first list element are the pairwise comparisons
#'
#' @note This returns a list of vector combinations starting with
#' @details
#' This returns a list of vector combinations starting with
#' pairwise, as the first nested list element, then in groups of
#' threes, fours, to length of the vector.
#'
#' @return A list object with increasing all combination objects,
#' the first list element are the pairwise comparisons
#'
#' @author Jeffrey S. Evans <jeffrey_evans<at>tnc.org>
#'
#' @examples
Expand Down
6 changes: 3 additions & 3 deletions R/annulus.matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
#' @param outer.scale Number of outer rings to set to null.value
#' @param null.value Value to set inner and outer scale(s) to
#'
#' @return A matrix object with defined null.value and 1, representing retained rings
#'
#' @note
#' @details
#' This function will return a matrix of 1 and defined null.value based on a specification
#' of the scale, inner scale and outer scale. The scale defines how many rings will be
#' represented in the matrix based on (2 * scale - 1). So, a scale of 3 will result in a
#' 5x5 matrix. The inner.scale and outer.scale arguments represent the > and < rings that
#' will be set to the defined null.value (see examples). The resulting matrix can be used
#' as the specified window in a focal function.
#'
#' @return A matrix object with defined null.value and 1, representing retained rings
#'
#' @author Jeffrey S. Evans <jeffrey_evans@@tnc.org>
#'
#' @examples
Expand Down
37 changes: 21 additions & 16 deletions R/aspline.downscale.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
#' @param plot (FALSE/TRUE) Plot results
#' @param ... Additional arguments passed to earth
#'
#' @details
#' This function uses Multivariate Adaptive Regression Splines, to downscale a raster based
#' on higher-resolution or more detailed raster data specified as covariate(s). This is similar
#' to the raster.downsample function which uses a robust regression and is a frequentest model for
#' fitting linear asymptotic relationships whereas, this approach is for fitting nonparametric
#' functions and should be used when the distributional relationship are complex/nonlinear.
#' Using add.coords adds spatial coordinates to the model, including creating the associated
#' rasters for prediction.
#'
#' @return A list object containing:
#' * downscale Downscaled terra SpatRaster object
#' * GCV Generalized Cross Validation (GCV)
Expand All @@ -19,32 +28,24 @@
#' * model earth MARS model object (if keep.model = TRUE)
#' @md
#'
#' @note
#' This function uses Multivariate Adaptive Regression Splines, to downscale a raster based
#' on higher-resolution or more detailed raster data specified as covariate(s). This is similar
#' to the raster.downsample function which uses a robust regression and is a frequentest model for
#' fitting linear asymptotic relationships whereas, this approach is for fitting nonparametric
#' functions and should be used when the distributional relationship are complex/nonlinear.
#' Using add.coords adds spatial coordinates to the model, including creating the associated
#' rasters for prediction.
#'
#' @references
#' Friedman (1991) Multivariate Adaptive Regression Splines (with discussion)
#' Annals of Statistics 19(1):1–141
#'
#' @author Jeffrey S. Evans <jeffrey_evans@@tnc.org>
#'
#' @examples
#' \dontrun{
#' library(geodata)
#' \donttest{
#' if (require(geodata, quietly = TRUE)) {
#' library(terra)
#' library(geodata)
#'
#' # Download example data (requires geodata package)
#' elev <- geodata::elevation_30s(country="SWZ", path=tempdir())
#' elev <- elevation_30s(country="SWZ", path=tempdir())
#' slp <- terrain(elev, v="slope")
#' x <- c(elev,slp)
#' names(x) <- c("elev","slope")
#' tmax <- geodata::worldclim_country(country="SWZ", var="tmax",
#' tmax <- worldclim_country(country="SWZ", var="tmax",
#' path=tempdir())
#' tmax <- crop(tmax[[1]], ext(elev))
#' names(tmax) <- "tmax"
Expand All @@ -60,8 +61,12 @@
#' plot(x[[2]], main="slope")
#' plot(tmax.ds$downscale, main="Downscaled Temp max")
#' par(opar)
#'
#'
#' } else {
#' cat("Please install geodata package to run example", "\n")
#' }
#' }
#'
#' @export
aspline.downscale <- function(x, y, add.coords = TRUE, keep.model = FALSE,
grid.search = FALSE, plot = FALSE, ...) {
Expand All @@ -75,7 +80,7 @@ aspline.downscale <- function(x, y, add.coords = TRUE, keep.model = FALSE,
y <- y[[1]]
}
if(grid.search) {
if(!any(which(utils::installed.packages()[,1] %in% "caret")))
if(length(find.package("caret", quiet = TRUE)) == 0)
stop("please install caret package to implement grid search")
}
sub.samp.sp <- terra::as.points(x, na.rm=TRUE)
Expand All @@ -101,7 +106,7 @@ aspline.downscale <- function(x, y, add.coords = TRUE, keep.model = FALSE,
names(x)[(nlyr(x)-1):nlyr(x)] <- c("xcoord", "ycoord")
}
if(grid.search) {
if(!any(which(utils::installed.packages()[,1] %in% "caret")))
if(length(find.package("caret", quiet = TRUE)) == 0)
stop("please install caret package to implement grid search")
hyper_grid <- expand.grid(
degree = 1:3,
Expand Down
8 changes: 4 additions & 4 deletions R/background.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
#' @param d Threshold distance for known proximity
#' @param type Type of sample c("systematic", "random", "hexagon", "nonaligned")
#'
#' @return A sf POINT feature class or data.frame with x,y coordinates
#'
#' @note
#' @details
#' This function creates a background point sample based on an extent
#' or polygon sampling region. The known argument can be used with d
#' to remove sample points based on distance-based proximity to existing
#' locations (eg., known species locations). The size (p) of the resulting
#' sample will be dependent on the known locations and the influence of
#' the distance threshold (d). As such, if the know and d arguments are
#' provided the exact value provided in p will not be returned.
#'
#' @return A sf POINT feature class or data.frame with x,y coordinates
#'
#' @author Jeffrey S. Evans <jeffrey_evans@@tnc.org>
#'
Expand Down Expand Up @@ -66,7 +66,7 @@ background <- function(x, p=1000, known=NULL, d=NULL,
if(as.character(unique(sf::st_geometry_type(x))) != "POLYGON")
stop(deparse(substitute(x)), " x must be an sf POLYGON object")
}
if(!any(which(utils::installed.packages()[,1] %in% "lwgeom")))
if(length(find.package("lwgeom", quiet = TRUE)) == 0)
stop("please install lwgeom package before running this function")
if(!is.null(known)){
if(!inherits(known, c("sf", "sfc")))
Expand Down
45 changes: 22 additions & 23 deletions R/bbox_poly.R
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
#' @title Bounding box polygon
#'
#' @description Creates a polygon from a vector or raster extent
#'
#' @param x An sf or terra object or vector of bounding coordinates
#'
#' @return A single feature sf class polygon object
#'
#' @note
#' @details
#' If not a spatial object, expected order of input for x is: xmin, ymin,
#' xmax, ymax. Where; xmin, ymin and the coordinates of top left corner of the
#' bounding box and xmax, ymax represent the bottom right corner. The maximum
#' value of xmax is width of the extent while maximum value of ymax is the height
#' of the extent.
#'
#' @return A single feature sf class polygon object
#'
#' @author Jeffrey S. Evans <jeffrey_evans@@tnc.org>
#'
#' @examples
#' p = c("sf", "sp", "terra")
#' if(any(!unlist(lapply(p, requireNamespace, quietly=TRUE)))) {
#' m = which(!unlist(lapply(p, requireNamespace, quietly=TRUE)))
#' message("Can't run examples, please install ", paste(p[m], collapse = " "))
#' } else {
#' invisible(lapply(p, require, character.only=TRUE))
#'
#' if(require(sp, quietly = TRUE)) {
#' library(terra)
#' library(sf)
#' data(meuse, package = "sp")
#' meuse <- st_as_sf(meuse, coords = c("x", "y"), crs = 28992,
#' agr = "constant")
#'
#' # raster (terra)
#' r <- rast(ext(meuse))
#' r[] <- runif(ncell(r))
#' crs(r) <- "epsg:28992"
#' e <- bbox_poly(r)
#'
#' plot(r)
#' plot(st_geometry(e), border="red", add=TRUE)
#'
#' # extent vector
#' e <- bbox_poly(c(178605, 329714, 181390, 333611))
#' plot(e)
#'
#' # vector bounding box
#' e <- bbox_poly(meuse)
#'
#' plot(st_geometry(meuse), pch=20)
#' plot(st_geometry(e), add=TRUE)
#'
#' # raster (terra)
#' r <- rast(ext(meuse))
#' r[] <- runif(ncell(r))
#' crs(r) <- "epsg:28992"
#' e <- bbox_poly(r)
#'
#' plot(r)
#' plot(st_geometry(e), border="red", add=TRUE)
#'
#' # extent vector
#' e <- bbox_poly(c(178605, 329714, 181390, 333611))
#' plot(e)
#'
#' } else {
#' cat("Please install sp package to run this example", "\n")
#' }
#'
#' @export bbox_poly
Expand Down
4 changes: 2 additions & 2 deletions R/bearing.distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#' @param azimuth Azimuth to new point
#' @param EastOfNorth Specified surveying convention
#'
#' @return a new point representing location of baring and distance
#' @details East of north is a surveying convention and defaults to true.
#'
#' @note East of north is a surveying convention and defaults to true.
#' @return a new point representing location of baring and distance
#'
#' @author Jeffrey S. Evans <jeffrey_evans@@tnc.org>
#'
Expand Down
18 changes: 8 additions & 10 deletions R/breeding.density.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
#' @param self (TRUE/FALSE) Should source observations be included in
#' density (default TRUE)
#'
#' @details
#' The breeding density areas model identifies the Nth-percent population exhibiting
#' the highest spatial density and counts/frequency. It then buffers these points by
#' a specified distance to produce breeding area polygons. If you would like to recreate
#' the results in Doherty et al., (2010), then define bw = 6400m and b[if p < 0.75
#' b = 6400m, | p >= 0.75 b = 8500m]
#'
#' @return A list object with:
#' \itemize{
#' \item pop.pts sf POINT object with points identified within the specified p
Expand All @@ -19,13 +26,6 @@
#' \item p Specified population percent
#' }
#'
#' @note
#' The breeding density areas model identifies the Nth-percent population exhibiting
#' the highest spatial density and counts/frequency. It then buffers these points by
#' a specified distance to produce breeding area polygons. If you would like to recreate
#' the results in Doherty et al., (2010), then define bw = 6400m and b[if p < 0.75
#' b = 6400m, | p >= 0.75 b = 8500m]
#'
#' @author Jeffrey S. Evans <jeffrey_evans@@tnc.org>
#'
#' @references
Expand All @@ -34,7 +34,7 @@
#' Bureau of Land Management. Number L10PG00911
#'
#' @examples
#' if(require(sf, quietly = TRUE)) {
#' library(sf)
#'
#' n=1500
#' bb <- rbind(c(-1281299,-761876.5),c(1915337,2566433.5))
Expand All @@ -53,8 +53,6 @@
#' plot(st_geometry(bd75$pop.pts), pch=20, col='red', add=TRUE)
#' legend("bottomright", legend=c("selected areas","selected sites", "all sites"),
#' bg="white", fill=c("grey","red", "black"), pt.cex = 2)
#'
#' }
#'
#' @export
breeding.density <- function(x, pop, p = 0.75, bw = 6400,
Expand Down
Loading

0 comments on commit 66e8ef6

Please sign in to comment.