rlandfire
Provides access to a diverse suite of spatial data layers via the LANDFIRE Product Services (LFPS) API.
https://github.com/bcknr/rlandfire
Category: Biosphere
Sub Category: Wildfire
Last synced: about 19 hours ago
JSON representation
Repository metadata
Tools for Accessing and Working with LANDFIRE in R
- Host: GitHub
- URL: https://github.com/bcknr/rlandfire
- Owner: bcknr
- License: gpl-3.0
- Created: 2023-02-22T23:21:02.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-19T22:17:40.000Z (11 days ago)
- Last Synced: 2026-03-22T07:02:50.760Z (8 days ago)
- Language: R
- Homepage:
- Size: 4.36 MB
- Stars: 21
- Watchers: 2
- Forks: 1
- Open Issues: 0
- Releases: 10
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE.md
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
## rlandfire: Interface to 'LANDFIRE Product Service' API
 [](https://github.com/bcknr/rlandfire/actions/workflows/R-CMD-check.yaml)
`rlandfire` provides access to a diverse suite of spatial data layers via the LANDFIRE Product Services ([LFPS](https://lfps.usgs.gov/arcgis/rest/services/LandfireProductService/GPServer)) API. [LANDFIRE](https://landfire.gov) is a joint program of the USFS, DOI, and other major partners, which provides data layers for wildfire management, fuel modeling, ecology, natural resource management, climate, conservation, etc. The complete list of available layers and additional resources can be found on the LANDFIRE webpage.
## Installation
Install `rlandfire` from CRAN:
``` r
install.packages("rlandfire")
```
The development version of `rlandfire` can be installed from GitHub with:
``` r
# install.packages("devtools")
devtools::install_github("bcknr/rlandfire")
```
Set `build_vignettes = TRUE` to access this vignette in R:
``` r
devtools::install_github("bcknr/rlandfire", build_vignettes = TRUE)
```
This package being maintained in my free time and users may encounter bugs or unexpected behavior. Please report any issues, feature requests, or suggestions in the package's [GitHub repo](https://github.com/bcknr/rlandfire/issues).
## Using `rlandfire`
To demonstrate `rlandfire`, we will explore how ponderosa pine forest canopy cover changed after the 2020 Calwood fire near Boulder, Colorado.
```{r setup, message = FALSE, warning = FALSE}
library(rlandfire)
library(sf)
library(terra)
library(foreign)
```
```{r include=FALSE}
devtools::load_all()
```
First, we will load the Calwood Fire perimeter data which was downloaded from Boulder County's [geospatial data hub](https://opendata-bouldercounty.hub.arcgis.com/).
```{r, fig.align = "center", fig.height = 5, fig.width = 7}
boundary_file <- file.path(tempdir(), "wildfire")
utils::unzip(system.file("extdata/wildfire.zip", package = "rlandfire"),
exdir = tempdir())
boundary <- st_read(file.path(boundary_file, "wildfire.shp")) |>
sf::st_transform(crs = st_crs(32613))
plot(boundary$geometry, main = "Calwood Fire Boundary (2020)",
border = "red", lwd = 1.5)
```
### AOI
We can use the function `rlandfire::getAOI()` to create an area of interest (AOI) vector with the correct format for `landfireAPIv2()`. `getAOI()` handles several steps for us, it ensures that the AOI is returned in the correct order (`xmin`, `ymin`, `xmax`, `ymax`) and converts the AOI to latitude and longitude coordinates (as required by the API) if needed.
Using the `extend` argument, we will increase the AOI by 1 km in all directions to provide additional context surrounding the burned area. This argument takes an optional numeric vector of 1, 2, or 4 elements.
```{r}
aoi <- getAOI(boundary, extend = 1000)
aoi
```
Alternatively, you can supply a LANDFIRE map zone number in place of the AOI vector. The function `getZone()` returns the zone number containing an `sf` object or which corresponds to the supplied zone name. See `help("getZone")` for more information and an example.
### Products
For this example, we are interested in canopy cover data for two years, 2016 (`LF2016_CC`) and 2022 (`LF2022_CC`), and existing vegetation type (`LF2016_EVT`). All available data products, and their abbreviated names, can be found in the [products table](https://lfps.usgs.gov/products) which can be opened by calling `viewProducts()`.
```{r}
products <- c("LF2016_CC", "LF2022_CC", "LF2016_EVT")
```
### Email
As part of the LANDFIRE program's update to LFPSv2 an email is now required with each request. See the [LFPS Guide](https://lfps.usgs.gov/LFProductsServiceUserGuide.pdf) for more information.
```{r}
email <- "rlandfire@markabuckner.com"
```
### Projection and resolution
We can ask the API to project the data to the same CRS as our fire perimeter data by providing the `WKID` for our CRS of interest and a resolution of our choosing, in meters.
```{r}
projection <- 32613 # WGS 84 / UTM zone 13N
resolution <- 90
```
### Edit rule
We will use the `edit_rule` argument to filter out canopy cover data that does not correspond to Ponderosa Pine Woodland. The `edit_rule` statement should tell the API that when existing vegetation cover is anything other than Ponderosa Pine Woodland (`7054`), the value of the canopy cover layers should be set to (`st`) a specified value.
To do so, we specify that when `LF2016_EVT` is not equal (`ne`) to `7054`, the "condition," the canopy cover layers should be set equal (`st`) to `1`, the "change." The edit rule syntax is explained in more depth in the [LFPS guide](https://lfps.usgs.gov/LFProductsServiceUserGuide.pdf).
*(How the API applies edit rules can be unintuitive. For example, if we used 'clear value' [`cv`] or set the value outside of 0-100 the edits we want would not work. To work around this behavior, we set the values to `1` since it is not found in the original data set.*)
```{r}
edit_rule <- list(
c("condition", "LF2016_EVT", "ne", 7054),
c("change", "LF2016_CC", "st", 1),
c("change", "LF2022_CC", "st", 1)
)
```
Note: Edits are performed in the order that they are listed and are limited to fuel theme products (i.e., Fire Behavior Fuel Model 13, Fire Behavior Fuel Model 40, Forest Canopy Base Height, Forest Canopy Bulk Density, Forest Canopy Cover, and Forest Canopy Height). The more advanced functionality of the LFPS edit rules are available and implemented in this package, but not covered here.
If we wanted to restrict these edits to a certain area we could pass the path to a zip archive (`.zip`) containing a shapefile to `edit_mask`:
```{r, eval=FALSE}
edit_mask <- "path/to/wildfire.zip"
```
If an `edit_mask` is provided `landfireAPIv2` will automatically post the raster to the LFPS and integrate it into your call.
(*Note: The file must follow ESRI shapefile naming standards (e.g., no special characters) and be less than 1MB in size.*)
### Path
Finally, we will provide a path to a temporary zip file. Setting the path as a temp file is not strictly necessary because if `path` is left blank `landfireAPIv2()` will save the data to a temporary folder by default. The path can be set to any writable directory.
```{r}
path <- tempfile(fileext = ".zip")
```
### Call `landfireAPIv2()`
Now we are able to submit a request to the LANDFIRE Product Services API with the `landfireAPIv2()` function.
```{r,eval=FALSE}
resp <- landfireAPIv2(products = products,
aoi = aoi,
email = email,
projection = projection,
resolution = resolution,
edit_rule = edit_rule,
path = path,
verbose = TRUE)
```
`landfireAPIv2()` will download your requested data into the folder provided in the path argument. If you did not provide one, you can find the path to your data in the `$path` element of the `landfire_api` object.
```{r,include=FALSE}
# Build example without calling API
resp <- landfireAPIv2(products = products,
aoi = aoi,
email = email,
projection = projection,
resolution = resolution,
edit_rule = edit_rule,
path = path,
execute = FALSE,
verbose = FALSE)
```
```{r,eval=FALSE}
resp$path
```
```{r,include=FALSE}
# Modify path to extdata
resp$path <- system.file("extdata/LFPS_Return_new.zip", package = "rlandfire")
```
### Load and process LF data
The files returned by the LFPS API are compressed `.zip` files containing a single multiband `GeoTIFF` and the metadata files. We have two options for programmatically accessing the files:
1. Manually unzip the directory before reading the `.tif` file using `terra`, or
```{r, eval=FALSE}
lf_dir <- file.path(tempdir(), "lf")
utils::unzip(path, exdir = lf_dir)
lf <- terra::rast(list.files(lf_dir, pattern = ".tif$",
full.names = TRUE,
recursive = TRUE))
```
2. Read the `GeoTIFF` file in directly using GDAL's Virtual File system in a single line.
```{r}
lf <- landfireVSI(resp)
lf
```
Note: `landfireVSI()` can also be used to read data directly from the LFPS server into R when using `method = "none"` in `landfireAPIv2()`.
Now we can reclassify the canopy cover layers to remove any values which are not classified as Ponderosa Pine, calculate the change, and plot our results.
```{r, fig.align = "center", fig.height = 5, fig.width = 7}
lf$LF2016_CC_CONUS[lf$LF2016_CC_CONUS == 1] <- NA
lf$LF2022_CC_CONUS[lf$LF2022_CC_CONUS == 1] <- NA
change <- lf$LF2022_CC_CONUS - lf$LF2016_CC_CONUS
plot(change, col = rev(terrain.colors(250)),
main = "Canopy Cover Loss - Calwood Fire (2020)",
xlab = "Easting",
ylab = "Northing")
plot(boundary$geometry, add = TRUE, col = NA,
border = "black", lwd = 2)
```
### Working with Categorical Products
The LFPS REST API now embeds attributes in the GeoTIFF files for some variables
and returns a database file (`.dbf`) containing the full attribute table.
To demonstrate, we will download the Existing Vegetation Cover product from LF 2.4.0
(`LF2023_EVC`). Unlike in the example above we will submit a minimal request with
the default projection and resolution. We will also allow `rlandfire` to
save the files to a temporary directory automatically. As mentioned above, we
can find the path to the temporary directory in the `$path` element of the
`landfire_api` object returned by `landfireAPIv2()`.
```{r,eval=FALSE}
resp <- landfireAPIv2(products = "LF2023_EVC",
aoi = aoi,
email = email,
verbose = FALSE)
```
```{r,include=FALSE}
resp <- landfireAPIv2(products = "LF2023_EVC",
aoi = aoi,
email = email,
execute = FALSE,
verbose = FALSE)
resp$path <- system.file("extdata/LFPS_Return_cat_new.zip", package = "rlandfire")
```
When we read in and plot the EVC layer the legend will now list the `classnames`
for each vegetation type.
```{r}
evc <- landfireVSI(resp)
plot(evc)
```
To access the values each `classname` is assigned to we can uses the `levels()`
function. This returns a simple two column data frame containing both the index
and active category, in our case the vegetation cover classes.
```{r}
head(levels(evc)[[1]])
```
Alternatively, we can access the full attribute table using two methods.
We can use the function `cats()` which works similarly to `levels()` but
returns the full attribute table as a data frame. Alternatively, we can read the
database file using `foreign::read.dbf()` which requires us to unzip the
directory first. Both methods return similar results, although in this case, we
see that the `.dbf` file includes an additional `Count` column not included in
the data frame returned from `cats()`.
```{r}
# cats
attr_tbl <- cats(evc)
# Find path to database file
lf_cat <- file.path(tempdir(), "lf_cat")
utils::unzip(resp$path, exdir = lf_cat)
dbf <- list.files(lf_cat, pattern = ".dbf$",
full.names = TRUE,
recursive = TRUE)
# Read file
dbf_tbl <- foreign::read.dbf(dbf)
head(attr_tbl[[1]])
head(dbf_tbl)
```
### Citation
Visit the [LANDFIRE webpage](https://landfire.gov/data/citation) for information
on citing LANDFIRE data layers. The package citation information can be viewed
with `citation("rlandfire")`.
Owner metadata
- Name: Mark Buckner
- Login: bcknr
- Email:
- Kind: user
- Description: Predictive Community Ecology | Global Change | Conservation
- Website: markabuckner.com
- Location: Ithaca, NY
- Twitter: bucknermarka
- Company: Cornell University
- Icon url: https://avatars.githubusercontent.com/u/70759701?u=96034f7aa8d5c55fa64e1dc6ad7ff8b97bcb3a68&v=4
- Repositories: 1
- Last ynced at: 2023-03-02T01:20:17.137Z
- Profile URL: https://github.com/bcknr
GitHub Events
Total
- Release event: 1
- Delete event: 5
- Pull request event: 9
- Issues event: 13
- Watch event: 9
- Issue comment event: 4
- Push event: 36
- Create event: 5
Last Year
- Release event: 1
- Delete event: 3
- Pull request event: 5
- Issues event: 9
- Watch event: 7
- Issue comment event: 2
- Push event: 29
- Create event: 1
Committers metadata
Last synced: 3 days ago
Total Commits: 191
Total Committers: 2
Avg Commits per committer: 95.5
Development Distribution Score (DDS): 0.005
Commits in past year: 65
Committers in past year: 1
Avg Commits per committer in past year: 65.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| Mark Buckner | m****7@c****u | 190 |
| JoshOBrien | j****n@g****m | 1 |
Committer domains:
- cornell.edu: 1
Issue and Pull Request metadata
Last synced: 9 days ago
Total issues: 17
Total pull requests: 28
Average time to close issues: 3 months
Average time to close pull requests: about 10 hours
Total issue authors: 4
Total pull request authors: 2
Average comments per issue: 0.76
Average comments per pull request: 0.07
Merged pull request: 24
Bot issues: 0
Bot pull requests: 0
Past year issues: 5
Past year pull requests: 4
Past year average time to close issues: about 2 months
Past year average time to close pull requests: about 3 hours
Past year issue authors: 3
Past year pull request authors: 1
Past year average comments per issue: 0.4
Past year average comments per pull request: 0.25
Past year merged pull request: 2
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- bcknr (14)
- mikoontz (1)
- TylerLMcIntosh (1)
- CCheCastaldo (1)
Top Pull Request Authors
- bcknr (26)
- JoshOBrien (2)
Top Issue Labels
- enhancement (5)
- bug (5)
- awaiting release (2)
- documentation (1)
- todo (1)
Top Pull Request Labels
Package metadata
- Total packages: 2
-
Total downloads:
- cran: 303 last-month
- Total dependent packages: 0 (may contain duplicates)
- Total dependent repositories: 0 (may contain duplicates)
- Total versions: 15
- Total maintainers: 1
proxy.golang.org: github.com/bcknr/rlandfire
- Homepage:
- Documentation: https://pkg.go.dev/github.com/bcknr/rlandfire#section-documentation
- Licenses: gpl-3.0
- Latest release: v2.0.2+incompatible (published 11 days ago)
- Last Synced: 2026-03-27T22:00:48.080Z (3 days ago)
- Versions: 11
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 5.401%
- Average: 5.583%
- Dependent repos count: 5.764%
cran.r-project.org: rlandfire
Interface to 'LANDFIRE Product Service' API
- Homepage: https://github.com/bcknr/rlandfire
- Documentation: http://cran.r-project.org/web/packages/rlandfire/rlandfire.pdf
- Licenses: GPL (≥ 3)
- Latest release: 2.0.2 (published 13 days ago)
- Last Synced: 2026-03-27T22:00:48.476Z (3 days ago)
- Versions: 4
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 303 Last month
-
Rankings:
- Dependent packages count: 28.086%
- Average: 32.083%
- Dependent repos count: 36.08%
- Maintainers (1)
Dependencies
- httr * imports
- sf * imports
- stringr * imports
- terra * imports
- utils * imports
- knitr * suggests
- raster * suggests
- rmarkdown * suggests
- stars * suggests
- testthat >= 3.0.0 suggests
- actions/checkout v4 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- r-hub/actions/checkout v1 composite
- r-hub/actions/platform-info v1 composite
- r-hub/actions/run-check v1 composite
- r-hub/actions/setup v1 composite
- r-hub/actions/setup-deps v1 composite
- r-hub/actions/setup-r v1 composite
Score: 9.45469731968959