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.

Usage

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)
x
#>  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 }.

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.

ropensci_footer