The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
rosmium is a package that allows one to use Osmium Tool from R. Osmium is a multipurpose command line tool that enables one to manipulate and analyze OpenStreetMap (OSM) files through several different commands. Currently, the package does not aim to cover the entirety of Osmium’s API, instead making available functions that wrap only a very limited set of Osmium’s features. This vignette briefly overviews the package with a few reproducible examples.
Before using rosmium please make sure that you have it installed in your computer. You can download either the most stable version from CRAN…
install.packages("rosmium")
…or the development version from GitHub.
# install.packages("remotes")
::install_github("ipeaGIT/rosmium") remotes
Please note that rosmium requires Osmium to be installed and added to the PATH environment variable of your local system. For instructions on how to install Osmium, please check its official website.
The package currently includes only three entrypoints to Osmium’s API. To demonstrate them, we will use some sample data bundled with the package.
library(rosmium)
library(ggplot2)
system.file("extdata/cur.osm.pbf", package = "rosmium")
cur_pbf <-
sf::st_read(cur_pbf, layer = "lines", quiet = TRUE)
cur_pbf_lines <-
ggplot(cur_pbf_lines) + geom_sf()
extract()
extract()
creates geographical extracts from OSM files. In its most basic form, the function takes the path to the OSM file whose geographical extent should be extracted from, the extent, either as a bounding box or as a (multi)polygon, and the path to the file where the output should be written to. Additionally, the function can also take the strategy to be used when creating the extract, which defaults to "complete_ways"
. Please check the function documentation for details on the available strategies and their behavior.
# buffering the pbf bounding box 4000 meters inward and using the result
# extent to extract the osm data inside it. transforming the crs because
# inward buffers only work with projected crs
sf::st_bbox(cur_pbf_lines)
bbox <- sf::st_as_sf(sf::st_as_sfc(bbox))
bbox_polygon <- sf::st_buffer(sf::st_transform(bbox_polygon, 5880), -4000)
smaller_bbox_poly <- sf::st_transform(smaller_bbox_poly, 4326)
smaller_bbox_poly <-
extract(
output_path <-
cur_pbf,
smaller_bbox_poly,tempfile(fileext = ".osm.pbf"),
spinner = FALSE
)
sf::st_read(output_path, layer = "lines", quiet = TRUE)
extracted_pbf_lines <-
ggplot() +
geom_sf(data = extracted_pbf_lines) +
geom_sf(data = smaller_bbox_poly, color = "red", fill = NA)
show_content()
Finally, show_content()
displays the content of an OSM file either in .html
, .xml
or .opl
format. The function takes as input the path to the OSM file whose content should be shown, the output format in which the content should be displayed (defaulting to .html
, the most human readable format, although also the slowest to open and inspect, depending on the size of the input file) and the type of objects that should be included in the output (defaulting to all existing objects in the input). The function returns the path to the temporary file in which the OSM file content was saved and opens the content in the web browser or the most appropriate application, depending on the output format.
# displays the content of the previous tags_filter() output in html format
show_content(output, spinner = FALSE)
#> [1] "/tmp/RtmpKOEIV5/osm_content35ad5d2fd5a3.html"
rosmium is developed by a team at the Institute for Applied Economic Research (Ipea), Brazil. We would like to thank the authors and contributors of Osmium for the development of Osmium Tool.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.