oe_find {osmextract}R Documentation

Get the path of .pbf and .gpkg files associated with an input OSM extract

Description

This function takes a place name and returns the path of .pbf/.gpkg files associated with it.

Usage

oe_find(
  place,
  provider = "geofabrik",
  download_directory = oe_download_directory(),
  download_if_missing = FALSE,
  return_pbf = TRUE,
  return_gpkg = TRUE,
  quiet = FALSE,
  ...
)

Arguments

place

Description of the geographical area that should be matched with a .osm.pbf file. Can be either a length-1 character vector, an sf/sfc/bbox object, or a numeric vector of coordinates with length 2. In the last case, it is assumed that the EPSG code is 4326 specified as c(LON, LAT), while you can use any CRS with sf/sfc/bbox objects. See Details and Examples in oe_match().

provider

Which provider should be used to download the data? Available providers can be found with the following command: oe_providers(). For oe_get() and oe_match(), if place is equal to ⁠ITS Leeds⁠, then provider is set equal to test. This is just for simple examples and internal tests.

download_directory

Directory where the files downloaded by osmextract are stored. By default it is equal to oe_download_directory().

download_if_missing

Attempt to download the file if it cannot be found? FALSE by default.

return_pbf

Logical of length 1. If TRUE, the function returns the path of the pbf file that matches the input place.

return_gpkg

Logical of length 1. If TRUE, the function returns the path of the gpkg file that matches the input place.

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.

...

Extra arguments that are passed to oe_match() and oe_get(). Please note that you cannot modify the argument download_only.

Details

The matching between the existing files (saved in the directory specified by download_directory parameter) and the input place is performed using list.files(), setting the pattern argument equal to the basename of the URL associated to the input place. For example, if you specify place = "Isle of Wight", then the input is matched (via oe_match()) with the URL of Isle of Wight's .osm.pbf file, and the files are selected using a pattern equal to the basename of that URL.

If there is no file in the download_directory that can be matched with the basename of the URL and download_if_missing parameter is equal to TRUE, then the function tries to download and read a new file from the chosen provider (geofabrik is the default provider). If download_if_missing parameter is equal to FALSE (default value), then the function stops with an error.

By default, this function returns the path of .pbf and .gpkg files associated with the input place (if any). You can exclude one of the two formats setting the arguments return_pbf or return_gpkg to FALSE.

Value

A character vector of length one (or two) representing the path(s) of the .pbf/.gpkg files associated with the input place. The files are sorted in alphabetical order which implies that if both formats are present in the download_directory, then the .gpkg file is returned first.

Examples

# Copy the ITS file to tempdir() to make sure that the examples do not
# require internet connection. You can skip the next 4 lines (and start
# directly with oe_get_keys) when running the examples locally.

res = file.copy(
  from = system.file("its-example.osm.pbf", package = "osmextract"),
  to = file.path(tempdir(), "test_its-example.osm.pbf"),
  overwrite = TRUE
)
res = oe_get("ITS Leeds", quiet = TRUE, download_directory = tempdir())
oe_find("ITS Leeds", provider = "test", download_directory = tempdir())
oe_find(
  "ITS Leeds", provider = "test",
  download_directory = tempdir(), return_gpkg = FALSE
)

## Not run: 
oe_find("Isle of Wight", download_directory = tempdir())
oe_find("Malta", download_if_missing = TRUE, download_directory = tempdir())
oe_find(
  "Leeds",
  provider = "bbbike",
  download_if_missing = TRUE,
  download_directory = tempdir(),
  return_pbf = FALSE
)
## End(Not run)

# Remove .pbf and .gpkg files in tempdir
oe_clean(tempdir())

[Package osmextract version 0.5.1 Index]