header_tag.html Skip to contents

Create a lazy-tibble from STAC parquet files

Usage

open_stac_parquet(con, features)

Arguments

con

Connection

features

return from search_stac

Examples


# \donttest{

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

features <- search_stac(
    monitoring_location_id = monitoring_location_id,
    collections = c("continuous"))
#> Requesting:
#> https://api.waterdata.usgs.gov/stac/v0/search?collections=continuous&filter=monitoring_location_id%20IN%20%28%27USGS-01435000%27%2C%20%27USGS-05406360%27%29&filter-lang=cql2-text&limit=50000&f=json&lang=en-US
#> Remaining requests this hour:824 

###################################################
# No download, no load: Returns lazy table
# con_1 <- initial_connection()
# data_tbl <- open_stac_parquet(features = features,
#                       con = con_1)
# head(data_tbl)
# dplyr::count(data_tbl)

# summarize_data <- data_tbl |>
#    dplyr::mutate(value = as.numeric(value)) |>
#    dplyr::summarize(count = dplyr::n(),
#                     start = min(time, na.rm = TRUE),
#                     end = max(time, na.rm = TRUE),
#                     max_val = max(value, na.rm = TRUE),
#                     .by = c(time_series_id,
#                             monitoring_location_id,
#                             parameter_code)) |>
#    dplyr::collect()
#
# summarize_data
# log_stac_limit()
# DBI::dbDisconnect(con_1)

#########################################################
# Download data locally, no load: Returns lazy table
raw_data_store <- file.path(tempdir(), "test_1")
dir.create(raw_data_store, showWarnings = FALSE)

local_path <- download_stac(
  features = features,
  file_directory = raw_data_store)
#> Downloading USGS-05406360: continuous
#> Downloading USGS-01435000: continuous
#> Downloading USGS-01435000: continuous

# con_2 <- initial_connection()
#
# data_tbl <- open_stac(features = local_path,
#                       con = con_2)
# head(data_tbl)
# log_stac_limit()
#
# DBI::dbDisconnect(con_2)

# }