status

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.

Installation

To install (note that the CRAN version does not currently work with the Overpass API):

To load the package and check the version:

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,

x <- opq(bbox = c(-0.27, 51.47, -0.20, 51.50)) %>% # Chiswick Eyot in London, U.K.
    add_osm_feature(key = 'name', value = "Thames", value_exact = FALSE) %>%
    osmdata_sf()
x
#> Object of class 'osmdata' with:
#>                  $bbox : 51.47,-0.27,51.5,-0.2
#>         $overpass_call : The call submitted to the overpass API
#>                  $meta : metadata including timestamp and version numbers
#>            $osm_points : 'sf' Simple Features Collection with 24548 points
#>             $osm_lines : 'sf' Simple Features Collection with 2219 linestrings
#>          $osm_polygons : 'sf' Simple Features Collection with 33 polygons
#>        $osm_multilines : 'sf' Simple Features Collection with 6 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