R/read_asc_gz_file.R

Defines functions read_asc_gz_file

Documented in read_asc_gz_file

# read_asc_gz_file -------------------------------------------------------------

#' Read Zipped ESRI-Ascii-Grid File (from URL)
#'
#' @param file path to zipped file in ESRI-ascii-grid format (.asc.gz)
#' @param url optional. URL to zipped file in ESRI-ascii-grid format (.asc.gz)
#' @return object of class "RasterLayer"
#' @export
#' @importFrom kwb.utils callWith removeExtension tempSubdirectory
#' @importFrom raster raster
read_asc_gz_file <- function(file, url = NULL)
{
  target_dir <- if (is.null(url)) {
    dirname(file)
  } else {
    temp_dir(template. = kwb.utils::removeExtension(url))
  }

  # Call the unzip function setting either "url" or "file" argument
  grid_file <- unzip_asc_gz_file(
    file = if (is.null(url)) file else url,
    target_dir = target_dir
  )

  #dir(target_dir)

  # Provide a copy of the projection file in the download folder
  provide_projection_file(grid_file)

  raster::raster(grid_file)
}
KWB-R/kwb.dwd documentation built on Sept. 28, 2022, 6:03 p.m.