Skip to content
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: SELECTRdata
Title: Download and Format Spatially Explicit Load Enrichment Calculation
Tool ('SELECT') Data
Version: 0.1.2
Version: 0.1.3
Authors@R:
person("Michael", "Schramm", , "mpschramm@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1876-6592"))
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# SELECTRdata 0.1.3 (2025-11-04)

## New Features

* template arguments accept SpatVector or SpatRaster objects.

# SELECTRdata 0.1.2 (2025-10-22)

## New Features
Expand Down
6 changes: 3 additions & 3 deletions R/download_NPDES_permits.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Downloads NPDES permits from EPA ECHO API services within the bounds of the
#' SpatRast template.
#'
#' @param template A SpatRaster object.
#' @param template A SpatRaster or SpatVector object. The extent of the returned object will match `template`.
#' @param permit_component A character vector with one or more of the following: `PRE` (pretreatment), `CAF` (CAFO), `CSO` (CSO), `POT` (Publicly Owned Treatment Works, the default), `BIO` (Biosolids), `SWS` (Stormwater Small MS4), `SWM` (Stormwater Medium/Large MS4), `SWI` (Stormwater Industrial), `SWC` (Stormwater Construction).
#' @param permit_status A character vector with one or more of the following: `EFF` (effective, the default), `EXP` (expired), `PND` (pending), `TRM` (terminated), `RET` (retired), `NON` (not needed), `ADC` (administratively continued).
#' @param output A character file path specifying where the raster file should be stored. Defaults to a temporary file.
Expand All @@ -21,8 +21,8 @@ download_NPDES_permits <- function(template,
permit_status = "EFF",
output = tempfile(fileext = ".gpkg")) {

## check that DEM is SpatRaster
check_spat_ras(template)
## check that DEM is SpatRaster or is SpatVector
check_terra_spat_obj(template)

## get bbox of the template. need lat, lons in decimal degrees
## create a bbox object from DEM
Expand Down
6 changes: 3 additions & 3 deletions R/download_buildings.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Downloads building footprints and attribute data from FEMA's
#' USA Structures dataset (https://fema.maps.arcgis.com/home/item.html?id=0ec8512ad21e4bb987d7e848d14e7e24#overview).
#'
#' @param template A SpatRaster object. The extent of the returned object will match `template`.
#' @param template A SpatRaster or SpatVector object. The extent of the returned object will match `template`.
#' @param return A character object, either `SpatVector` or `sf`. Defaults to `SpatVector`.
#' @param output A character file path specifying where the `SpatVector` file should be written. Defaults to a temporary file.
#'
Expand All @@ -28,8 +28,8 @@ download_buildings <- function(template,
return(invisible(NULL))
}

## check that DEM is SpatRaster
check_spat_ras(template)
## check that DEM is SpatRaster or is SpatVector
check_terra_spat_obj(template)

## check that return is one of "SpatVector" or "sf"
check_string(return)
Expand Down
6 changes: 3 additions & 3 deletions R/download_census_blocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Downloads U.S. Census block boundaries and associated information for
#' blocks within the spatial extent of the template SpatRaster.
#'
#' @param template A SpatRaster object.
#' @param template A SpatRaster or SpatVector object.
#' @param year A character value. Any of the following values should work: `c("2000","2010","2020")`.
#' @param page_size a numeric value passed to `arcgislayers::arcselect()`. Defaults to NULL. Useful when the requests returns a 500 error code.
#' @param output A character file path specifying where the raster file should be stored. Defaults to a temporary file.
Expand All @@ -30,8 +30,8 @@ download_census_blocks <- function(template,
if (!isTRUE(check_connectivity("services.arcgis.com"))) {
return(invisible(NULL))
}
## check template if a spatraster
check_spat_ras(template)
## check that DEM is SpatRaster or is SpatVector
check_terra_spat_obj(template)

## check years
year <- rlang::arg_match(year,
Expand Down
6 changes: 3 additions & 3 deletions R/download_counties.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Shortcut function that downloads and extracts TIGER U.S. County boundaries
#' and returns them as a terra SpatVector object.
#'
#' @param template A SpatRaster object.
#' @param template A SpatRaster or SpatVector object. The extent of the returned object will match `template`.
#' @param output A character file path specifying where the raster file should be stored. Defaults to a temporary file.
#'
#' @return A terra SpatVector object. If API resources are not available an invisible `NULL` is returned.
Expand All @@ -28,8 +28,8 @@ download_counties <- function(template,
return(invisible(NULL))
}

## check template if a spatraster
check_spat_ras(template)
## check that DEM is SpatRaster or is SpatVector
check_terra_spat_obj(template)

furl <- "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Census_Counties/FeatureServer"

Expand Down
8 changes: 4 additions & 4 deletions R/download_nlcd.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' Downloads and writes an NLCD SpatRaster to file with extents defined by `template`. This function downloads the annualized NLCD data products. See [https://www.mrlc.gov/data/project/annual-nlcd](https://www.mrlc.gov/data/project/annual-nlcd) for more information.
#'
#' @param template A SpatRaster object defining the spatial extent of the returned NLCD raster.
#' @param template A SpatRaster or SpatVector object. The extent of the returned object will match `template`.
#' @param year character, expects a value between `1986:2024`.
#' @param dataset Character. Expects `c("LndCov","LndChg","LndCnf","FctImp","ImpDsc","SpcChg")`. Only `"LndCov"` is supported at this time.
#' @param landmass Depreciated. Character, one of: `c("CU", "AK", "HI")`.
Expand Down Expand Up @@ -39,8 +39,8 @@ download_nlcd <- function(template,
return(invisible(NULL))
}

## check template if a spatraster
check_spat_ras(template)
## check that DEM is SpatRaster or is SpatVector
check_terra_spat_obj(template)

## need to check year, dataset, and landmass are valid values
## check landmass
Expand Down Expand Up @@ -121,7 +121,7 @@ download_nlcd <- function(template,
wrap = TRUE)
template_ext <- terra::project(template_ext,
from = template_srs,
to = nlcd_epsg)
to = paste0("epsg:",nlcd_epsg))

}

Expand Down
6 changes: 3 additions & 3 deletions R/download_urban_areas.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Downloads a U.S. Census designated urban areas intersecting the spatial extent of the template SpatRaster.
#'
#' @param template A SpatRaster object.
#' @param template A SpatRaster or SpatVector object.
#' @param page_size a numeric value passed to `arcgislayers::arcselect()`. Defaults to NULL. Useful when the requests returns a 500 error code.
#' @param output A character file path specifying where the `SpatVector` output object should be written. Defaults to a temporary file.
#'
Expand All @@ -29,8 +29,8 @@ download_urban_areas <- function(template,
if (!isTRUE(check_connectivity("services.arcgis.com"))) {
return(invisible(NULL))
}
## check template if a spatraster
check_spat_ras(template)
## check that DEM is SpatRaster or is SpatVector
check_terra_spat_obj(template)

furl <- "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Census_Urban_Areas/FeatureServer"

Expand Down
10 changes: 10 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ check_spat_ras <- function(x,
}
}


check_terra_spat_obj <- function(x,
arg = rlang::caller_arg(x),
call = rlang::caller_env()) {
if(!inherits(x, c("SpatRaster", "SpatRasterCollection", "SpatVector"))) {
cli::cli_abort("The object supplied to {.arg {arg}} must be a {.cls SpatRaster}, {.cls SpatRasterCollection}, or {.cls SpatVector} object. Try loading the raster with {.code terra::rast()} or {.code terra::vect()}.",
call = call)
}
}

check_string <- function(x,
arg = rlang::caller_arg(x),
call = rlang::caller_env()) {
Expand Down
30 changes: 27 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,38 @@ You can install the development version of SELECTRdata like so:
install.packages("SELECTRdata", repos = c("https://txwri.r-universe.dev", "https://cloud.r-project.org"))
```

## Example
## Examples

## MRLC National Land Cover Dataset
### USGS DEM

```{r example}
```{r dem}
library(SELECTRdata)
library(terra)

## our location of interest
location_of_interest <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata")
location_of_interest <- terra::rast(location_of_interest)
## grab the extent
extent <- ext(location_of_interest)
## create a extent or object that an extent and srs
## can be grabbed
extent <- vect(extent, crs = crs(location_of_interest))
## project the extent to something used by USGS Seamless data
extent <- project(extent, "EPSG:6579")
## grab the epsg code from our extent
auth <- crs(extent, describe = TRUE)
auth <- paste0(auth$authority, ":", auth$code)
extent <- ext(extent)

## download DEM
example_dem <- download_dem(x = extent, srs = auth)
plot(example_dem)
```


### MRLC National Land Cover Dataset

```{r example}
## we need a template file, this is the thomsoncreek watershed in Texas
dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata")
dem <- terra::rast(dem)
Expand Down
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,41 @@ You can install the development version of SELECTRdata like so:
install.packages("SELECTRdata", repos = c("https://txwri.r-universe.dev", "https://cloud.r-project.org"))
```

## Example
## Examples

## MRLC National Land Cover Dataset
### USGS DEM

``` r
library(SELECTRdata)
library(terra)
#> Warning: package 'terra' was built under R version 4.3.3
#> terra 1.8.10
#> terra 1.8.29

## our location of interest
location_of_interest <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata")
location_of_interest <- terra::rast(location_of_interest)
## grab the extent
extent <- ext(location_of_interest)
## create a extent or object that an extent and srs
## can be grabbed
extent <- vect(extent, crs = crs(location_of_interest))
## project the extent to something used by USGS Seamless data
extent <- project(extent, "EPSG:6579")
## grab the epsg code from our extent
auth <- crs(extent, describe = TRUE)
auth <- paste0(auth$authority, ":", auth$code)
extent <- ext(extent)

## download DEM
example_dem <- download_dem(x = extent, srs = auth)
plot(example_dem)
```

<img src="man/figures/README-dem-1.png" width="100%" />

### MRLC National Land Cover Dataset

``` r
## we need a template file, this is the thomsoncreek watershed in Texas
dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata")
dem <- terra::rast(dem)
Expand Down Expand Up @@ -81,9 +106,9 @@ buildings <- download_buildings(template = dem)
#> Registered S3 method overwritten by 'jsonify':
#> method from
#> print.json jsonlite
#> Iterating ■■■■■ 12% | ETA: 19sIterating ■■■■■■■■■ 25% | ETA: 11sIterating
#> ■■■■■■■■■■■■■■■■ 50% | ETA: 4sIterating ■■■■■■■■■■■■■■■■■■■■■■■ 75% | ETA:
#> 2sIterating ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 88% | ETA: 1s
#> Iterating ■■■■■ 12% | ETA: 8sIterating ■■■■■■■■■ 25% | ETA: 6sIterating
#> ■■■■■■■■■■■■ 38% | ETA: 4sIterating ■■■■■■■■■■■■■■■■■■■■ 62% | ETA: 2sIterating
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 88% | ETA: 0s
plot(buildings)
plot(wbd, add = TRUE)
```
Expand Down
2 changes: 1 addition & 1 deletion man/download_NPDES_permits.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/download_buildings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/download_census_blocks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/download_counties.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/download_nlcd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/download_urban_areas.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added man/figures/README-dem-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.