Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bcknr authored and cran-robot committed Mar 16, 2024
0 parents commit a06e547
Show file tree
Hide file tree
Showing 32 changed files with 2,213 additions and 0 deletions.
27 changes: 27 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,27 @@
Package: rlandfire
Type: Package
Title: Interface to 'LANDFIRE Product Service' API
Version: 1.0.0
Authors@R:
c(person(given = "Mark",
family = "Buckner",
role = c("aut", "cre", "cph"),
email = "mab677@cornell.edu",
comment = c(ORCID = "0000-0002-9692-7454")))
Maintainer: Mark Buckner <mab677@cornell.edu>
Description: Provides access to a suite of geospatial data layers for wildfire management, fuel modeling, ecology, natural resource management, climate, conservation, etc., via the 'LANDFIRE' (<https://www.landfire.gov/index.php>) Product Service ('LFPS') API.
License: MIT + file LICENSE
Encoding: UTF-8
URL: https://github.com/bcknr/rlandfire
BugReports: https://github.com/bcknr/rlandfire/issues
RoxygenNote: 7.2.3
Imports: httr, sf, utils
Suggests: knitr, raster, rmarkdown, stars, terra, testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
Depends: R (>= 2.10)
NeedsCompilation: no
Packaged: 2024-03-14 20:56:57 UTC; mark
Author: Mark Buckner [aut, cre, cph] (<https://orcid.org/0000-0002-9692-7454>)
Repository: CRAN
Date/Publication: 2024-03-15 11:20:02 UTC
2 changes: 2 additions & 0 deletions LICENSE
@@ -0,0 +1,2 @@
YEAR: 2024
COPYRIGHT HOLDER: Mark A. Buckner
31 changes: 31 additions & 0 deletions MD5
@@ -0,0 +1,31 @@
d9881ac702635497ee617f841f283329 *DESCRIPTION
b3bb376d7424a07eb2421a707d578818 *LICENSE
97c8c59d909d05ee59ae869000b8a0f8 *NAMESPACE
68e7e26e61b128322d8f6e63f5c04d1b *NEWS.md
422d01d6c48cd16a05cf9b32318d8c56 *R/getAOI.R
c871ff48a9580b84e36611910c385832 *R/landfireAPI.R
97d108ef8077d6e92038e030379bab3e *R/rlandfire-package.R
a37cabea6f85182d33018d4c4b6bc193 *R/sysdata.rda
74b72ca32494d55f2df93897f25a41ec *R/utils.R
2f058d565f66c54e4f3c5edd04c7d48c *README.md
da71fe049ba9efb516a35203c461539c *build/vignette.rds
fc7af20dc16b3b230eceea75c4421ef6 *inst/CITATION
cc68a0b18f8b6602beab957e8092dbe2 *inst/doc/rlandfire.R
ee96a4a0a168b9a8e1666a99ba50fa89 *inst/doc/rlandfire.Rmd
da1b7cc426aad0ea54342496d14c30c9 *inst/doc/rlandfire.html
84596338665dcdbbede9448668e9a736 *inst/extdata/LFPS_Return.zip
4f7112828bff6b996c326e503a3bd943 *inst/extdata/Wildfire_History.zip
945d9c6c673d923408df4500196cd500 *man/figures/README-unnamed-chunk-11-1.png
945d9c6c673d923408df4500196cd500 *man/figures/README-unnamed-chunk-12-1.png
8621e5d869ff2d11fbea5882204efac8 *man/figures/README-unnamed-chunk-2-1.png
911edcd0ac8f06a0dbef6afc9ee510b6 *man/figures/lfps.png
be4395ee810cfeb7197bbf003d31062b *man/figures/rlandfire.png
5e61c1416ff3220bd4890641d5ba4b24 *man/getAOI.Rd
7e7fb85ed00746208b47427fe76597da *man/getZone.Rd
7854f62cd0cd61a125cc5c985606935d *man/landfireAPI.Rd
8552134d37a66b342acee956cf85aa29 *man/rlandfire-package.Rd
ca3a2869b6ab602c9c7bee1184b98cd2 *man/viewProducts.Rd
85de70eb5ee24273ad03a07042aae1c3 *tests/testthat.R
024f6f89f69c13bdcc779c233ba35ef2 *tests/testthat/test-getAOI.R
62ae145efda8cda622ef951fc415e84f *tests/testthat/test-landfireAPI.R
ee96a4a0a168b9a8e1666a99ba50fa89 *vignettes/rlandfire.Rmd
7 changes: 7 additions & 0 deletions NAMESPACE
@@ -0,0 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(getAOI)
export(getZone)
export(landfireAPI)
export(viewProducts)
importFrom(utils,browseURL)
44 changes: 44 additions & 0 deletions NEWS.md
@@ -0,0 +1,44 @@
# rlandfire 1.0.0
- CRAN submission
- Modified `CITATION` and `DESCRIPTION` files
- Minor edits to vignette and documentation
- Improved error reporting in `landfireAPI()` if multiple map zones are supplied

# rlandfire 0.4.1
- Fixed issue with license badge in README

# rlandfire 0.4.0
- Added new function (`getZone()`) which returns the LANDFIRE map zone based on a spatial object or zone name
- Removed dependencies on `terra` and `stringr`
- Updated to MIT + file LICENSE
- Added argument to specify order of values in the `extend` argument of `getAOI()`
- Added additional tests for `getAOI()`, `getZone()`, and `landfireAPI()`
- Improved portability of examples

# rlandfire 0.3.0

- Added new function (`viewProducts()`) to open the LFPS products table in your web browser
- Fixed bug causing early timeout well before `max_time` was reached

# rlandfire 0.2.2

- Added a `NEWS.md` file to track changes to the package.
- Improved getAOI() example
- Added additional checks to landfireAPI
- Created a vignette

# rlandfire 0.2.1

- Corrected issue with `getAOI()` returning values in wrong order
- Added checks to prevent API error when resolution is set to 30 by user
- Fixed documentation formatting
- Updated package tests

# rlandfire 0.2.0

- Added edit rule functionality in `landfireAPI()`
- Improved error/warning reporting
- Return useful object w/ class `landfire_api`
- Added tests for `landfireAPI()` and `.fmt_editrules` (internal)
- Improved and updated documentation
- Fixed minor errors and bugs
117 changes: 117 additions & 0 deletions R/getAOI.R
@@ -0,0 +1,117 @@
#' Create extent vector for `landfireAPI()`
#'
#' @description
#' `getAOI` creates an extent vector in WGS84 from spatial data
#'
#' @param data A SpatRaster, SpatVector, sf, stars, or RasterLayer (raster) object
#' @param extend Optional. A numeric vector of 1, 2, or 4 elements to
#' increase the extent by.
#' @param sf_order If `extend` != NULL, logical indicating that the order of the
#' `extend` vector follows [sf::st_bbox()] (`xmin`, `ymin`, `xmax`, `ymax`) when TRUE or
#' [terra::extend()] (`xmin`, `xmax`, `ymin`, `ymax`) when FALSE. This
#' is `FALSE` by default to ensure backwards compatibility with previous versions.
#'
#' @return Returns an extent vector ordered `xmin`, `ymin`, `xmax`, `ymax`
#' with a lat/lon projection.
#'
#' @md
#' @export
#'
#' @examples
#' r <- terra::rast(nrows = 50, ncols = 50,
#' xmin = -123.7835, xmax = -123.6352,
#' ymin = 41.7534, ymax = 41.8042,
#' crs = terra::crs("epsg:4326"),
#' vals = rnorm(2500))
#' ext <- getAOI(r, c(10, 15))
#'
getAOI <- function(data, extend = NULL, sf_order = FALSE) {
# Check object class and extract extent as SpatExtent
if(inherits(data, c("SpatRaster", "SpatVector", "sf", "RasterLayer", "stars"))) {
ext <- sf::st_bbox(data)
} else {
stop("`data` must be SpatRaster, SpatVector, sf, stars, or RasterLayer (raster) object")
}

stopifnot("argument `sf_order` must be logical" = inherits(sf_order, c("logical")))

if(!is.null(extend)) {
stopifnot("argument `extend` must be numeric vector" = inherits(extend, c("numeric")))
stopifnot("argument `extend` must be a numeric vector with a length of 1, 2, or 4 elements" = length(extend) %in% c(1,2,4))
}

# if extend !null extend the SpatExtent Object
if(!is.null(extend)){

# Change order, for back compatibility
if(sf_order == FALSE & length(extend) == 4) {
extend <- extend[c(1,3,2,4)]
}

if(length(extend) < 4) {
extend <- rep_len(extend, 4)
}
# Extend
ext <- ext + extend * c(-1,-1,1,1)
}

# Check object projection and project to lat/lon if need
if(sf::st_crs(data) != sf::st_crs(4326)) {
ext <- sf::st_bbox(sf::st_transform(sf::st_as_sfc(ext), 4326))
}
as.vector(c(ext$xmin, ext$ymin, ext$xmax, ext$ymax))
}



#' Find LANDFIRE map zone for use with `landfireAPI()`
#'
#' @description
#' `getZone` returns the LANDFIRE Map Zone(s) a spatial object intersects or the
#' zone number from the zone name. Currently, only map zones within CONUS are
#' supported.
#'
#' @param data An sf object or character string with the map zone name.
#'
#' @return Returns a numeric vector containing the map zone(s)
#'
#' @md
#' @export
#'
#' @examples
#' \dontrun{
#'v <- sf::st_bbox(sf::st_as_sf(data.frame(x = c(-123.7835,-123.6352),
#' y = c(41.7534,41.8042)),
#' coords = c("x", "y"),
#' crs = 4326)) |>
#' sf::st_as_sfc()
#' zone <- getZone(v)
#'}
#'
getZone <- function(data) {

if(inherits(data, c("sf", "sfc"))) {
# Extract mz
if(sf::st_crs(data) != sf::st_crs(mapzones)) {
data <- sf::st_transform(data, sf::st_crs(mapzones))
}

mz <- sf::st_intersects(data, mapzones)

} else if(inherits(data, "character")) {
mz <- which(sf::st_drop_geometry(mapzones[,"ZONE_NAME"]) == data)

} else {
stop("argument `data` must be sf object, or character string")
}

mz <- unique(unlist(mz))

stopifnot("argument `data` must be sf object or zone name within CONUS" = length(mz) != 0)
if(length(mz) > 1) {
warning("Spatial object intersects more than one map zone. `landfireAPI` only accepts one zone at a time!\nConsider using `getAOI()` instead")
}

mapzones$ZONE_NUM[mz]

}

0 comments on commit a06e547

Please sign in to comment.