knitr::opts_chunk$set( collapse = TRUE, warning = FALSE, message = FALSE, width = 120, comment = "#>", fig.retina = 2, fig.path = "README-" )
overpass is a packge with tools to work with the OpenStreetMap (OSM) Overpass API. To explore simple Overpass queries interactively, try overpass turbo.
Here's an RPub for overpass
that I'll continually update as this goes (that will eventually be a vignette).
The Overpass API (or OSM3S) is a read-only API that serves up custom selected parts of the OSM map data. It acts as a database over the web: the client sends a query to the API and gets back the data set that corresponds to the query.
Unlike the main API, which is optimized for editing, Overpass API is optimized for data consumers that need a few elements within a glimpse or up to roughly 100 million elements in some minutes, both selected by search criteria like e.g. location, type of objects, tag properties, proximity, or combinations of them. It acts as a database backend for various services.
Overpass API has a powerful query language (language guide, language reference, an IDE) beyond XAPI, but also has a compatibility layer to allow a smooth transition from XAPI.
This package pairs nicely with nominatim.
The following functions are implemented:
add_feature
: Add a feature to an Overpass queryavailable_features
: List recognized features in OSM Overpassavailable_tags
: List tags associated with a featurebbox_to_string
: Convert a named matrix or a named vector (or an unnamed vector) return a stringissue_query
: Finalize and issue an Overpass queryopq
: Begin building an Overpass queryoverpass_query
: Issue OSM Overpass Queryoverpass_status
: Retrieve status of the Overpass APIread_osm
: Read an XML OSM Overpass response from pathdevtools::install_github("hrbrmstr/overpass")
library(overpass) library(sp) library(ggmap) # current verison packageVersion("overpass")
# CSV example osmcsv <- '[out:csv(::id,::type,"name")]; area[name="Bonn"]->.a; ( node(area.a)[railway=station]; way(area.a)[railway=station]; rel(area.a)[railway=station]; ); out;' opq <- overpass_query(osmcsv) read.table(text = opq, sep="\t", header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
# just nodes only_nodes <- '[out:xml]; node ["highway"="bus_stop"] ["shelter"] ["shelter"!~"no"] (50.7,7.1,50.8,7.25); out body;' pts <- overpass_query(only_nodes) plot(pts)
# ways & nodes nodes_and_ways <- '[out:xml]; (node["amenity"="fire_station"] (50.6,7.0,50.8,7.3); way["amenity"="fire_station"] (50.6,7.0,50.8,7.3); rel["amenity"="fire_station"] (50.6,7.0,50.8,7.3);); (._;>;); out;' wys <- overpass_query(nodes_and_ways) plot(wys)
# xml version of the query actual_ways <- '<osm-script output="xml"> <query type="way"> <bbox-query e="7.157" n="50.748" s="50.746" w="7.154"/> </query> <union> <item/> <recurse type="down"/> </union> <print/> </osm-script>' awy <- overpass_query(actual_ways) plot(awy)
# more complex example from Robin: motorways surrounding London # warning: may take a few minutes to run from_robin <- '[out:xml][timeout:100]; ( node["highway"="motorway"](51.24,-0.61,51.73,0.41); way["highway"="motorway"](51.24,-0.61,51.73,0.41); relation["highway"="motorway"](51.24,-0.61,51.73,0.41); ); out body; >; out skel qt;' frb <- overpass_query(from_robin) gg <- ggplot() gg <- gg + geom_path(data=fortify(frb), aes(x=long, y=lat, group=group), color="black", size=0.25) gg <- gg + coord_quickmap() gg <- gg + ggthemes::theme_map() gg ggsave("README-from_robin-1.png")
library(overpass) library(testthat) date() test_dir("tests/")
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.