Skip to content

Commit

Permalink
Add get_naip_data() (#44)
Browse files Browse the repository at this point in the history
Fixes #43
  • Loading branch information
mikemahoney218 authored Feb 26, 2024
1 parent d08d73f commit bcb2a6a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(filter_bands)
export(filter_platforms)
export(get_dem)
export(get_landsat_imagery)
export(get_naip_imagery)
export(get_sentinel1_imagery)
export(get_sentinel2_imagery)
export(get_stac_data)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# rsi (development version)

* Added `get_naip_data()`, a function for getting National Agricultural Imagery
Program data from (by default) Planetary Computer. Data covers the continental
United States.

* `stack_rasters()` will only rename bands if `band_names` is the same length as
the number of bands in the output raster (or missing, or defined by a
function). It will now warn you if these lengths are different. Previously, if
Expand Down
42 changes: 42 additions & 0 deletions R/get_stac_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,48 @@ get_landsat_imagery <- function(aoi,
do.call(get_stac_data, args)
}

#' @rdname get_stac_data
#' @export
get_naip_imagery <- function(aoi,
start_date,
end_date,
...,
pixel_x_size = 1,
pixel_y_size = 1,
asset_names = "image",
stac_source = "https://planetarycomputer.microsoft.com/api/stac/v1",
collection = "naip",
query_function = default_query_function,
sign_function = sign_planetary_computer,
rescale_bands = FALSE,
output_filename = paste0(proceduralnames::make_english_names(1), ".tif"),
composite_function = "merge",
limit = 999,
gdalwarp_options = c(
"-r", "bilinear",
"-multi",
"-overwrite",
"-co", "COMPRESS=DEFLATE",
"-co", "PREDICTOR=2",
"-co", "NUM_THREADS=ALL_CPUS"
),
gdal_config_options = c(
VSI_CACHE = "TRUE",
GDAL_CACHEMAX = "30%",
VSI_CACHE_SIZE = "10000000",
GDAL_HTTP_MULTIPLEX = "YES",
GDAL_INGESTED_BYTES_AT_OPEN = "32000",
GDAL_DISABLE_READDIR_ON_OPEN = "EMPTY_DIR",
GDAL_HTTP_VERSION = "2",
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES = "YES",
GDAL_NUM_THREADS = "ALL_CPUS"
)) {
args <- mget(names(formals()))
args$`...` <- NULL
args <- c(args, rlang::list2(...))
do.call(get_stac_data, args)
}

#' @rdname get_stac_data
#' @export
get_dem <- function(aoi,
Expand Down
25 changes: 25 additions & 0 deletions man/get_stac_data.Rd

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

18 changes: 18 additions & 0 deletions tests/testthat/test-get_stac_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,21 @@ test_that("no-composites return the same data", {
setdiff(rsi::landsat_band_mapping$planetary_computer_v1, "T")
)
})

test_that("get_naip_imagery() is stable", {
skip_on_cran()
skip_if_offline()
aoi <- sf::st_point(c(-74.912131, 44.080410))
aoi <- sf::st_set_crs(sf::st_sfc(aoi), 4326)
aoi <- sf::st_buffer(sf::st_transform(aoi, 3857), 100)

expect_no_error(
out <- get_naip_imagery(
aoi,
"2018-01-01",
"2020-01-31",
output_filename = tempfile(fileext = ".tif")
)
)
expect_no_error(terra::rast(out))
})

0 comments on commit bcb2a6a

Please sign in to comment.