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 following functions are implemented:
overpass_query
: Issue OSM Overpass Queryread_osm
: Read OSM Overpass Response
- Version 0.0.0.9000 released
devtools::install_github("hrbrmstr/overpass")
library(overpass)
library(sp)
library(ggplot2)
# current verison
packageVersion("overpass")
#> [1] '0.0.0.9001'
# 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;'
read.table(text=overpass_query(osmcsv), sep="\t", header=TRUE,
check.names=FALSE, stringsAsFactors=FALSE)
#> @id @type name
#> 1 26945519 node Bonn-Oberkassel
#> 2 1271017705 node Bonn-Beuel
#> 3 2428355974 node Bonn-Bad Godesberg
#> 4 2713060210 node Bonn Hauptbahnhof
#> 5 3400717493 node Bonn-Mehlem
# 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
library(overpass)
library(testthat)
date()
#> [1] "Tue Aug 11 01:17:31 2015"
test_dir("tests/")
#> testthat results ===========================================================
#> OK: 0 SKIPPED: 0 FAILED: 0
#>
#> DONE
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.