C++ R Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


Build Status Build status codecov CRAN_Status_Badge status CRAN Downloads Project Status: Active

osmdata is an R package for accessing the raw vector data underlying OpenStreetMap (OSM) via the Overpass API. (Other packages such as OpenStreetMap can be used to download raster tiles based on OSM data.) The Overpass API (or OSM3S) is a read-only API that serves up custom selected parts of the OSM map data. Map data can be returned either as Simple Features (sf) or Spatial (sp) objects.


#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
#> [1] '0.0.7'


Overpass API queries can be built from a base query constructed with opq followed by add_osm_feature. The corresponding OSM objects are then downloaded and converted to R Simple Features (sf) objects with osmdata_sf() or to R Spatial (sp) objects with osmdata_sp(). For example,

q0 <- opq(bbox = c(-0.27, 51.47, -0.20, 51.50)) # Chiswick Eyot in London, U.K.
q1 <- add_osm_feature(q0, key = 'name', value = "Thames", value_exact = FALSE)
x <- osmdata_sf(q1)
#>  Object of class 'osmdata' with:
#>                   $bbox : 51.47,-0.27,51.5,-0.2
#>          $overpass_call : The call submitted to the overpass API
#>              $timestamp : [ Wed 4 May 2017 09:33:52 ]
#>             $osm_points : 'sf' Simple Features Collection with 21459 points
#>              $osm_lines : 'sf' Simple Features Collection with 1916 linestrings
#>           $osm_polygons : 'sf' Simple Features Collection with 23 polygons
#>         $osm_multilines : 'sf' Simple Features Collection with 5 multilinestrings
#>      $osm_multipolygons : 'sf' Simple Features Collection with 3 multipolygons

OSM data can also be downloaded in OSM XML format with osmdata_xml() and saved for use with other software.

osmdata_xml(q1, "data.xml")

The XML document is returned silently and may be passed directly to osmdata_sp() or osmdata_sf()

doc <- osmdata_xml(q1, "data.xml")
x <- osmdata_sf(q1, doc)

Or data can be read from a previously downloaded file:

x <- osmdata_sf(q1, "data.xml")

For more details, see the website

Style guide

We appreciate any contributions; those that comply with our general coding style even more. In four short points:

  1. <- not =
  2. Indent with four spaces
  3. Be generous with other white spaces - you've got plenty of real estate on that big screen of yours.
  4. Code is much easier to read when braces are vertically aligned, so please put { in the same vertical position as }.


citation ("osmdata")
#> To cite osmdata in publications use:
#>   Mark Padgham, Bob Rudis, Robin Lovelace, Maëlle Salmon (2017).
#>   osmdata Journal of Open Source Software, 2(14). URL
#>   https://doi.org/10.21105/joss.00305
#> A BibTeX entry for LaTeX users is
#>   @Article{,
#>     title = {osmdata},
#>     author = {Mark Padgham and Bob Rudis and Robin Lovelace and Maëlle Salmon},
#>     journal = {The Journal of Open Source Software},
#>     year = {2017},
#>     volume = {2},
#>     number = {14},
#>     month = {jun},
#>     publisher = {The Open Journal},
#>     url = {https://doi.org/10.21105/joss.00305},
#>     doi = {10.21105/joss.00305},
#>   }

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.