# 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.
its_pbf = file.path(tempdir(), "test_its-example.osm.pbf")
file.copy(
from = system.file("its-example.osm.pbf", package = "osmextract"),
to = its_pbf,
overwrite = TRUE
)
# Get keys
oe_get_keys("ITS Leeds", download_directory = tempdir())
# Get keys and values
oe_get_keys("ITS Leeds", values = TRUE, download_directory = tempdir())
# Subset some keys
oe_get_keys(
"ITS Leeds", values = TRUE, which_keys = c("surface", "lanes"),
download_directory = tempdir()
)
# Print all (non-NA) values for a given set of keys
res = oe_get_keys("ITS Leeds", values = TRUE, download_directory = tempdir())
res["surface"]
# Get keys from an existing sf object
its = oe_get("ITS Leeds", download_directory = tempdir())
oe_get_keys(its, values = TRUE)
# Get keys from a character vector pointing to a file (might be faster than
# reading the complete file and then filter it)
its_path = oe_get(
"ITS Leeds", download_only = TRUE,
download_directory = tempdir(), quiet = TRUE
)
oe_get_keys(its_path, values = TRUE)
# Add a key to an existing .gpkg file without repeating the
# vectortranslate operations
its = oe_get("ITS Leeds", download_directory = tempdir())
colnames(its)
its_extra = oe_read(
its_path,
query = "SELECT *, hstore_get_value(other_tags, 'oneway') AS oneway FROM lines",
quiet = TRUE
)
colnames(its_extra)
# The following fails since there is no points layer in the .gpkg file
if (FALSE) {
oe_get_keys(its_path, layer = "points")}
# Add layer and read keys
its_path = oe_get(
"ITS Leeds", layer = "points", download_only = TRUE,
download_directory = tempdir(), quiet = TRUE
)
oe_get_keys(its_path, layer = "points")
# Remove .pbf and .gpkg files in tempdir
rm(its_pbf, res, its_path, its, its_extra)
oe_clean(tempdir())
Run the code above in your browser using DataLab