Read a .pbf or .gpkg object from file or url
This function is used to read a .pbf
or .gpkg
object from file or URL. It
is a wrapper around oe_download()
, oe_vectortranslate()
, and
sf::st_read()
, creating an easy way to download, convert, and read a .pbf
or .gpkg
file. Check the introductory vignette and the help pages of the
wrapped function for more details.
oe_read( file_path, layer = "lines", ..., provider = NULL, download_directory = oe_download_directory(), file_size = NULL, force_download = FALSE, max_file_size = 5e+08, download_only = FALSE, skip_vectortranslate = FALSE, vectortranslate_options = NULL, osmconf_ini = NULL, extra_tags = NULL, force_vectortranslate = FALSE, never_skip_vectortranslate = FALSE, quiet = FALSE )
file_path |
A URL or the path of a |
layer |
Which |
... |
Arguments that will be passed to |
provider |
Which provider should be used to download the data? Available
providers can be found with the following command: |
download_directory |
Where to download the file containing the OSM data?
By default this is equal to |
file_size |
How big is the file? Optional. |
force_download |
Should the |
max_file_size |
The maximum file size to download without asking in
interactive mode. Default: |
download_only |
Boolean. If |
skip_vectortranslate |
Boolean. If |
vectortranslate_options |
Options passed to the |
osmconf_ini |
The configuration file. See documentation at
gdal.org. Check details in the
introductory vignette and the help page of |
extra_tags |
Which additional columns, corresponding to OSM tags, should
be in the resulting dataset? |
force_vectortranslate |
Boolean. Force the original |
never_skip_vectortranslate |
Boolean. This is used in case the user
passed its own |
quiet |
Boolean. If |
The arguments provider
, download_directory
, file_size
,
force_download
, and max_file_size
are ignored if file_path
points to
an existing .pbf
or .gpkg
file.
You cannot add any field or layer to an existing .gpkg
file (unless you
have the .pbf
file and you convert it again with a different
configuration), but you can extract some of the tags in other_tags
field.
Check examples and oe_get_keys()
for more details.
An sf
object.
# Read an existing .pbf file. First we need to copy a .pbf file into a # temporary directory file.copy( from = system.file("its-example.osm.pbf", package = "osmextract"), to = file.path(tempdir(), "its-example.osm.pbf") ) my_pbf = file.path(tempdir(), "its-example.osm.pbf") oe_read(my_pbf) oe_read(my_pbf, layer = "points") # Read a new layer # The following example shows how to add new tags names(oe_read(my_pbf, extra_tags = c("oneway", "ref"), quiet = FALSE)) # Read an existing .gpkg file. This file was created by oe_read my_gpkg = file.path(tempdir(), "its-example.gpkg") oe_read(my_gpkg) # You cannot add any layer to an existing .gpkg file but you can extract some # of the tags in other_tags. Check oe_get_keys() for more details. names(oe_read(my_gpkg, extra_tags = c("maxspeed"))) # doesn't work # Instead, use the query argument names(oe_read( my_gpkg, quiet = TRUE, query = "SELECT *, hstore_get_value(other_tags, 'maxspeed') AS maxspeed FROM lines " )) # Read from a URL my_url = "https://github.com/ropensci/osmextract/raw/master/inst/its-example.osm.pbf" # Please note that if you read from a URL which is not linked to one of the # supported providers, you need to specify the provider parameter: ## Not run: oe_read(my_url, provider = "test", quiet = FALSE) ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.