# Copy ITS file to tempdir so that the examples do not require internet
# connection. You can skip the next 4 lines 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
)
# Match, download (not really) and convert OSM extracts associated to a simple test.
its = oe_get("ITS Leeds", download_directory = tempdir())
class(its)
unique(sf::st_geometry_type(its))
# Get another layer from ITS Leeds extract
its_points = oe_get("ITS Leeds", layer = "points", download_directory = tempdir())
unique(sf::st_geometry_type(its_points))
# Get the .osm.pbf and .gpkg files paths
oe_get(
"ITS Leeds", download_only = TRUE, quiet = TRUE,
download_directory = tempdir()
)
oe_get(
"ITS Leeds", download_only = TRUE, skip_vectortranslate = TRUE,
quiet = TRUE, download_directory = tempdir()
)
# See also ?oe_find()
# Add additional tags
its_with_oneway = oe_get(
"ITS Leeds", extra_tags = "oneway",
download_directory = tempdir()
)
names(its_with_oneway)
table(its_with_oneway$oneway, useNA = "ifany")
# Use the query argument to get only oneway streets:
q = "SELECT * FROM 'lines' WHERE oneway == 'yes'"
its_oneway = oe_get("ITS Leeds", query = q, download_directory = tempdir())
its_oneway[, c(1, 3, 9)]
# Apply a spatial filter during the vectortranslate operations
its_poly = sf::st_sfc(
sf::st_polygon(
list(rbind(
c(-1.55577, 53.80850),
c(-1.55787, 53.80926),
c(-1.56096, 53.80891),
c(-1.56096, 53.80736),
c(-1.55675, 53.80658),
c(-1.55495, 53.80749),
c(-1.55577, 53.80850)
))
),
crs = 4326
)
its_spat = oe_get("ITS Leeds", boundary = its_poly, download_directory = tempdir())
its_clipped = oe_get(
"ITS Leeds", boundary = its_poly, boundary_type = "clipsrc",
quiet = TRUE, download_directory = tempdir()
)
plot(sf::st_geometry(its), reset = FALSE, col = "lightgrey")
plot(sf::st_boundary(its_poly), col = "black", add = TRUE)
plot(sf::st_boundary(sf::st_as_sfc(sf::st_bbox(its_poly))), col = "black", add = TRUE)
plot(sf::st_geometry(its_spat), add = TRUE, col = "darkred")
plot(sf::st_geometry(its_clipped), add = TRUE, col = "orange")
# More complex examples
if (FALSE) {
west_yorkshire = oe_get("West Yorkshire")
# If you run it again, the function will not download the file
# or convert it again
west_yorkshire = oe_get("West Yorkshire")
# Match with place name
oe_get("Milan") # Warning: the .pbf file is 400MB
oe_get("Vatican City") # Check all providers
oe_get("Zurich") # Use Nominatim API for geolocating places
# Match with coordinates (any EPSG)
milan_duomo = sf::st_sfc(sf::st_point(c(1514924, 5034552)), crs = 3003)
oe_get(milan_duomo, quiet = FALSE) # Warning: the .pbf file is 400MB
# Match with numeric coordinates (EPSG = 4326)
oe_match(c(9.1916, 45.4650), quiet = FALSE)
# Check also alternative providers
baku = oe_get(place = "Baku")
# Other examples:
oe_get("RU", match_by = "iso3166_1_alpha2", quiet = FALSE)
# The following example mimics read_sf
oe_get("Andora", stringsAsFactors = FALSE, quiet = TRUE, as_tibble = TRUE)}
# Remove .pbf and .gpkg files in tempdir
oe_clean(tempdir())
Run the code above in your browser using DataLab