Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

oe_download

Download a file given a url


Description

This function is used to download a file given a URL. It focuses on OSM extracts with .osm.pbf format stored by one of the providers implemented in the package. The URL is specified through the parameter file_url.

Usage

oe_download(
  file_url,
  provider = NULL,
  file_basename = basename(file_url),
  download_directory = oe_download_directory(),
  file_size = NA,
  force_download = FALSE,
  max_file_size = 5e+08,
  quiet = FALSE
)

Arguments

file_url

A URL pointing to a .osm.pbf file that should be downloaded.

provider

Which provider stores the file? If NULL (the default), it may be inferred from the URL, but it must be specified for non-standard cases. See details and examples.

file_basename

The basename of the file. The default behaviour is to auto-generate it from the URL using basename().

download_directory

Where to download the file containing the OSM data? By default this is equal to oe_download_directory(), which is equal to tempdir() and it changes each time you restart R. You can set a persistent download_directory by adding the following to your .Renviron file (e.g. with edit_r_environ function in usethis package): OSMEXT_DOWNLOAD_DIRECTORY=/path/to/osm/data.

file_size

How big is the file? Optional. NA by default. If it's bigger than max_file_size and the function is run in interactive mode, then an interactive menu is displayed, asking for permission for downloading the file.

force_download

Should the .osm.pbf file be updated if it has already been downloaded? FALSE by default. This parameter is used to update old .osm.pbf files.

max_file_size

The maximum file size to download without asking in interactive mode. Default: 5e+8, half a gigabyte.

quiet

Boolean. If FALSE, the function prints informative messages. Starting from sf version 0.9.6, if quiet is equal to FALSE, then vectortranslate operations will display a progress bar.

Details

This function runs several checks before actually downloading a new file to avoid overloading the OSM providers. The first step is the definition of the file's path associated to the input file_url. The path is created by pasting together the download_directory, the name of chosen provider (which may be inferred from the URL) and the basename() of the URL. For example, if file_url is equal to "https://download.geofabrik.de/europe/italy-latest.osm.pbf", and download_directory = "/tmp", then the path is built as "/tmp/geofabrik_italy-latest.osm.pbf". Thereafter, the function checks the existence of that file and, if it founds it, then it returns the path. The parameter force_download is used to modify this behaviour. If there is no file associated with the new path, then the function downloads a new file using download.file() with mode = "wb", and, again, it returns the path.

Value

A character string representing the file's path.

Examples

its_match = oe_match("ITS Leeds", provider = "test", quiet = TRUE)
# ITS Leeds data are stored on github, which is not a standard provider.
# So we need to specify the provider parameter.
oe_download(
  file_url = its_match$url,
  file_size = its_match$file_size,
  provider = "test"
)
## Not run: 
iow_details = oe_match("Isle of Wight")
oe_download(
  file_url = iow_details$url,
  file_size = iow_details$file_size
)
Sucre_details = oe_match("Sucre", provider = "bbbike")
oe_download(
  file_url = Sucre_details$url,
  file_size = Sucre_details$file_size,
  download_directory = tempdir()
)
## End(Not run)

osmextract

Download and Read OpenStreetMap Data Extracts

v0.2.1
GPL-3
Authors
Andrea Gilardi [aut, cre] (<https://orcid.org/0000-0002-9424-7439>), Robin Lovelace [aut] (<https://orcid.org/0000-0001-5679-6536>), Barry Rowlingson [ctb] (<https://orcid.org/0000-0002-8586-6625>), Salva Fernández [rev] (Salva reviewed the package (v. 0.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/395>), Nicholas Potter [rev] (Nicholas reviewed the package (v. 0.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/395>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.