oe_read | R Documentation |
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,
boundary = NULL,
boundary_type = c("spat", "clipsrc"),
quiet = FALSE
)
file_path |
A URL or the path to a |
layer |
Which |
... |
(Named) 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 |
boundary |
An |
boundary_type |
A character vector of length 1 specifying the type of
spatial filter. The |
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.
Please note that you cannot add any field to an existing .gpkg
file using
the argument extra_tags
without rerunning the vectortranslate process on
the corresponding .pbf
file. On the other hand, you can extract some of
the tags in other_tags
field as new columns. See examples and
oe_get_keys()
for more details.
An sf
object or, when download_only
argument equals TRUE
, a
character vector.
# Read an existing .pbf file. First we need to copy a .pbf file into a
# temporary directory
its_pbf = file.path(tempdir(), "test_its-example.osm.pbf")
file.copy(
from = system.file("its-example.osm.pbf", package = "osmextract"),
to = its_pbf
)
oe_read(its_pbf)
# Read a new layer
oe_read(its_pbf, layer = "points")
# The following example shows how to add new tags
names(oe_read(its_pbf, extra_tags = c("oneway", "ref"), quiet = TRUE))
# Read an existing .gpkg file. This file was created internally by oe_read().
its_gpkg = file.path(tempdir(), "test_its-example.gpkg")
oe_read(its_gpkg)
# You cannot add any new 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(its_gpkg, extra_tags = c("maxspeed"))) # doesn't work
# Instead, use the query argument
names(oe_read(
its_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)
# Remove .pbf and .gpkg files in tempdir
oe_clean(tempdir())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.