header_tag.html

Skip to contents

Download STAC files based on filter parameters.

Usage

download_stac(
  features,
  file_directory = tempdir(),
  output_returned = c("partition_folder"),
  showWarnings = TRUE
)

Arguments

features

Output from search_stac

file_directory

Folder to store parquet files.

output_returned

Output of this function is either a vector of file paths that point to each individual file ("targets"), or the subfolder of partitioned parquet files ("partition_folder")

showWarnings

Logical, whether to show a warning or not if the file_directory already has subdirectory of the requested collection.

Value

vector of file paths to downloaded data

Details

Downloaded files are structured as partitioned parquet files. The partitioning is defined by the feature id, which in most cases is monitoring_location_id. Each collection is stored in a subfolder of the file_directory, and within those subfolders are partitioned parquet files.

Examples


# \donttest{

monitoring_location_id <- c("USGS-01435000", "USGS-05406360")
file_out_dir <- tempdir()

features_2_sites <- search_stac(
    monitoring_location_id = monitoring_location_id,
    collections = c("daily", "continuous"))
#> Requesting:
#> https://api.waterdata.usgs.gov/stac/v0/search?collections=daily%2Ccontinuous&filter=monitoring_location_id%20IN%20%28%27USGS-01435000%27%2C%20%27USGS-05406360%27%29%20OR%20&filter-lang=cql2-text&limit=50000&f=json&lang=en-US
#> Remaining requests this hour:661 
files_out <- download_stac(
    features = features_2_sites,
    file_directory = file_out_dir)
#> Downloading USGS-05406360: continuous
#> Downloading USGS-05406360: daily
#> Downloading USGS-01435000: continuous
#> Downloading USGS-01435000: continuous
#> Downloading USGS-01435000: daily
files_out
#> [1] "/tmp/RtmpFyCwwh/continuous" "/tmp/RtmpFyCwwh/daily"     

file_out_dane <- tempdir()
dane_county_features <- search_stac(
    county_name = "Dane County",
    state_name = "Wisconsin",
    site_type = "Stream",
    collections = "daily",
    end_datetime = c("2026-10-01", NA)
)
#> Requesting:
#> https://api.waterdata.usgs.gov/stac/v0/search?collections=daily&end_datetime=2026-10-01T00%3A00%3A00Z%2F..&filter=county_name%20%3D%20%27Dane%20County%27%20AND%20state_name%20%3D%20%27Wisconsin%27%20AND%20site_type%20%3D%20%27Stream%27%20OR%20&filter-lang=cql2-text&limit=50000&f=json&lang=en-US
#> Remaining requests this hour:657 

files_out_county <- download_stac(
  features = dane_county_features,
  file_directory = file_out_dane)
#> Warning: Files already existed within: /tmp/RtmpFyCwwh/daily
#> Downloading USGS-430639089185701: daily
#> Downloading USGS-05429510: daily
#> Downloading USGS-05427905: daily
#> Downloading USGS-05429369: daily
#> Downloading USGS-05428600: daily
#> Downloading USGS-05427910: daily
#> Downloading USGS-05427930: daily
#> Downloading USGS-05427927: daily
#> Downloading USGS-05427880: daily
#> Downloading USGS-05406479: daily
#> Downloading USGS-05428668: daily
#> Downloading USGS-05406457: daily
#> Downloading USGS-054279465: daily
#> Downloading USGS-05435950: daily
#> Downloading USGS-05432927: daily
#> Downloading USGS-430310089225401: daily
#> Downloading USGS-05435935: daily
#> Downloading USGS-054065295: daily
#> Downloading USGS-05406524: daily
#> Downloading USGS-05406540: daily
#> Downloading USGS-05406465: daily
#> Downloading USGS-054065145: daily
#> Downloading USGS-054064915: daily
#> Downloading USGS-054064895: daily
#> Downloading USGS-054064509: daily
#> Downloading USGS-05406450: daily
#> Downloading USGS-05429700: daily
#> Downloading USGS-05428500: daily
#> Downloading USGS-05427850: daily
#> Downloading USGS-054279509: daily
#> Downloading USGS-05406469: daily
#> Downloading USGS-054064785: daily
#> Downloading USGS-05435934: daily
#> Downloading USGS-054359315: daily
#> Downloading USGS-05435943: daily
#> Downloading USGS-05406520: daily
#> Downloading USGS-054065199: daily
#> Downloading USGS-05406360: daily
#> Downloading USGS-431655089393801: daily
#> Downloading USGS-05406497: daily
#> Downloading USGS-05406476: daily
#> Downloading USGS-05406483: daily
#> Downloading USGS-05430095: daily
#> Downloading USGS-05406491: daily
#> Downloading USGS-05406470: daily
#> Downloading USGS-05406460: daily
#> Downloading USGS-05430030: daily
#> Downloading USGS-05435980: daily
#> Downloading USGS-05427952: daily
#> Downloading USGS-05427945: daily
#> Downloading USGS-05427943: daily
#> Downloading USGS-05427950: daily
#> Downloading USGS-05427507: daily
#> Downloading USGS-05427900: daily
#> Downloading USGS-05427718: daily
#> Downloading USGS-05429580: daily
#> Downloading USGS-05427948: daily
#> Downloading USGS-05427970: daily
#> Downloading USGS-05429080: daily
#> Downloading USGS-05429150: daily
#> Downloading USGS-05429120: daily
#> Downloading USGS-05427800: daily
#> Downloading USGS-05430100: daily
#> Downloading USGS-05406500: daily
#> Downloading USGS-05436000: daily
#> Downloading USGS-05406000: daily
#> Downloading USGS-05429500: daily

# }