knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
devtools::install_github("ITSleeds/OSMtools") library(OSMtools)
osmt_geofabrik_dl(region = "europe/great-britain/england/isle-of-wight", destfile = "iow.pbf")
You can also use the geofabrik package
osmt_convert(file = "iow.pbf", format_out = "o5m")
Formats supported are:
Note on file format choice
The native format of OSm is the the .osm. But .pbf is the prefered format for transfering data as it is the most compact. It is also acceptable and an input for many pieces of sofotware e.g. sf
package and opentripplanner
. But it is not supported by osmt_filter
.
You could convert your files from pbf to osm and then use osmt_filter
and finally read them into R. But osmt_filter
also accepts .o5m files and will process them faster. So a typical workflow for large files is:
You can keep or remove (drop) objects based on their tags. For example if you only wanted to keep the roads you could use
keep = "highway="
this would only keep objects that had any value for the highway tag.
osmt_filter(file = "iow.o5m", path_out = "cycling.o5m", keep = "highway=")
You can keep or remove (drop) tags from objects. This example removed the cycleway tag from all objects
osmt_filter(file = "cycling.o5m", path_out = "driving.o5m", drop_tags = "cycleway")
To modify tags use the form "key=tag1 to =tag2" you can do multiple modifications at once. This example changes all the objects with the tags highway = primary or highway = secondary to highway = tertiary.
osmt_filter(file = "cycling.o5m", path_out = "smallstreets.o5m", modify_tags = "highway=primary to =tertiary highway=secondary to =tertiary")
The SF package supports reading .osm and .pbf files but not .o5m files.
lines <- sf::st_read("iow.pbf", layer = "lines") # Works lines2 <- sf::st_read("cycling.o5m", layer = "lines") # Fails osmt_convert(file = "cycling.o5m", format_out = "pbf") lines3 <- sf::st_read("cycling.pbf", layer = "lines") # Works
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.