knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
osmxml is an R package useful to download, read, prepare and (rudimentarily) visualise OpenStreetMap (OSM) XML files like the map.osm
file you would get from the OSM website's "Export" page.
This package might not be what you're after: please see below the section "Other OSM-related R packages" to find more powerful tools.
You can install the development version of osmexport from GitHub with:
# install.packages("devtools") devtools::install_github("stragu/osmxml")
ox_download()
: download an OSM export by defining its bounding box, save it to file.ox_read()
: read a .osm
file as an object of class osm
ox_separate_tags()
: separate the tags contained in the other_tags
column. This is done by default when importing the data with ox_read()
osm
classThe osm
S3 class – very much subject to changing in name and properties – has print()
and plot()
methods. It is made of sf
("simple features") spatial objects.
The functions available are designed to be pipeable. For example, to download and read the area around Te Kura Tatauranga, Waipapa Taumata Rau:
library(osmxml) TKT <- c(174.76598, -36.85440, 174.77019, -36.85129) |> ox_download() |> ox_read() # see what the object contains TKT
We can now use the default plot method to have a glimpse at the data:
plot(TKT)
Because the parts of the object are of class sf
, they can be processed with sf and well as dplyr functions:
library(dplyr) library(sf) # most common "building" values in polygons TKT$multipolygons |> st_drop_geometry() |> # remove geometry column filter(!is.na(building)) |> # only keep buildings count(building, sort = TRUE) # most commons values at the top
Contributions are welcome and appreciated. You can contribute to this package by:
Note that all contributions to the codebase will be released under the GPL, and submitting your contribution to this repository is an implicit agreement.
We expect contributors to respect UQRUG's Code of Conduct.
If a conversation or comment does not belong in a public issue report, please contact the maintainer listed in the package description.
OSM data included in this package (in the ./inst
directory) and downloaded with the ox_download()
function is © OpenStreetMap contributors, and the conditions of its reuse are defined by the ODbL licence. You likely need to include this information on anything derived from it. Find out more on the OSM website.
There are many other OSM-related R packages that might be more suitable for what you are hoping to achieve. Notable packages available on CRAN are:
Transport-specific packages:
To acquire basemaps:
Other interactive visualisation packages automatically fetch rendered OSM data as basemaps, like leaflet and tmap.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.