Giter VIP home page Giter VIP logo

overpass's Introduction

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 query
  • available_features: List recognized features in OSM Overpass
  • available_tags: List tags associated with a feature
  • bbox_to_string: Convert a named matrix or a named vector (or an unnamed vector) return a string
  • issue_query: Finalize and issue an Overpass query
  • opq: Begin building an Overpass query
  • overpass_query: Issue OSM Overpass Query
  • overpass_status: Retrieve status of the Overpass API
  • read_osm: Read an XML OSM Overpass response from path

Installation

devtools::install_github("hrbrmstr/overpass")

Usage

library(overpass)
library(sp)
library(ggmap)

# current verison
packageVersion("overpass")
#> [1] '0.2.0.9000'
# 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)
#>          @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
ggsave("README-from_robin-1.png")

london

Test Results

library(overpass)
library(testthat)

date()
#> [1] "Thu Oct  6 13:47:56 2016"

test_dir("tests/")
#> testthat results ===========================================================
#> OK: 4 SKIPPED: 0 FAILED: 0
#> 
#> DONE ======================================================================

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.

overpass's People

Contributors

hrbrmstr avatar maelle avatar patperu avatar robinlovelace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

overpass's Issues

Merge `osmdatar` with `overpass`

So thanks to the work of @Robinlovelace, we both know there is a great deal of compatibility between overpass and osmdatar. So much in fact that i'd suggest the two be merged. The good news as far as I can discern it is:

  1. overpass seems to be primarily focussed on enabling a very precise tool for constructing and passing overpass queries within R, while ...
  2. osmdatar has the crudest of all possible ways of constructing queries, and focusses instead on the fastest possible processing of OSM objects within an R call.

The two thus seem to be to be entirely complementary, and merging could and would only help both enormously (from your side as shown by the speed comparisons of @Robinlovelace). osmdatar effectively just Rcpp-ifies all of your internal dplyr-type manipulation of the overpass XML data. I did have an explicit timing comparison with your approach here. Although both our packages have developed since then, the general pattern remains.

The division of labour of a potential merge would seem pretty obvious: The interface end would remain almost unchanged from overpass, while the processing currently done in way_utils and node_utils could simply be replaced by the osmdatar code. (Also note that polygon processing in osmdatar is almost complete.)

If you're interested, we could at least start by discussing the direction of the merge ... for which my only concern from an osmdatar perspective would be that I'm attempting to merely use overpass to access data, with the package primarily serving those data in a usable format. (This will ultimately also include returning street networks in igraph form for routing queries.) Thus the name overpass doesn't really reflect the breadth of what I envision the package achieving. But that's a very minor concern, and other than that I look forward to your insights

overpass_buildings()

Can we create such wrappers to auto-download certain common osm features for a given bbox?

Discussion/TODOs

  • Should there be a message (perhaps using a verbose parameter) displayed when the query is issued and complete?
  • Do we want to return a list by default with all the nodes, ways and relations and let the user sort it out and/or provide higher-level functions to work on those return types?
  • ways can be lines or polygons ref. It doesn't make sense to only return a SpatialLinesDataFrame if so. Therefore it might be prudent to return a list of individual way objects (whether they be SpatialLines or SpatialPolygons) but we'd also need to keep the metadata with them.
  • relations can hold pretty much anything and there's a concept of inner & outer things, so the return here might need to be a list of various Spatial objects

And I def need some collaboration on next steps since we can clearly get data out of this API :-)

Borrow some osmar code

Went through osmar and there's salvageable code.

Also went through sp a bit and I think I've got an idea for how to make a new Spatial class to hold composite geometries.

osmdata submission to ropensci

@hrbrmstr,
i've opened this issue on overpass because we now officially need your explicit consent on this one. osmdata has been submitted to ropensci with intended simultaneous JOSS consideration. The latter is effected by this paper.md file - your name really ought to appear in this list, but for that we really do need your explicit consent. Please!

It'd be best if you could state your consent within this osmdata issue. I'll also take this opportunity to thank you again for your code which has helped make osmdata much better than what it would have been without. I'm mighty pleased with the 'end' result of this project!
cheers!
mark

Error following mamoth request

Experimenting, I tried to get all proposed new national cycle paths in the UK:

from_robin <- '[out:xml][timeout:25];
(
  node["ncn"="proposed"](49.16,-13.4,60.85,1.76);
  way["ncn"="proposed"](49.16,-13.4,60.85,1.76);
  relation["ncn"="proposed"](49.16,-13.4,60.85,1.76);
);
out body;
>;
out skel qt;'

frb <- overpass_query(from_robin)
Error in `row.names<-.data.frame`(`*tmp*`, value = value) : 
  duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique value when setting 'row.names': ‘299893104’ 

Can anyone reproduce this?

overpass is slow compared with osmdatarr

Reproducible example:

# Requirements:
# devtools::install_github ('osmdatar/osmdatar')
library(osmdatar)
# devtools::install_github("hrbrmstr/overpass")
library(overpass)

b = structure(c(-1.80036221446736, 53.6990006231171, -1.29035539895422,
                53.9458885889733), .Dim = c(2L, 2L), .Dimnames = list(c("x",
                                                                        "y"), c("min", "max")))
# download road network
system.time({ # 8s
  r = get_lines(bbox = b, key = "highway", value = "primary") # slow
})

system.time({ # nearly 70 s
  from_robin <- '[out:xml][timeout:100];
(
  node["highway"="primary"](53.6990006231171,-1.80036221446736,53.9458885889733,-1.29035539895422);
  way["highway"="primary"](53.6990006231171,-1.80036221446736,53.9458885889733,-1.29035539895422);
  relation["highway"="primary"](53.6990006231171,-1.80036221446736,53.9458885889733,-1.29035539895422);
);
out body;
>;
out skel qt;'

  frb <- overpass_query(from_robin)
})

cc @mpadge - how is it so much faster? Even more weirdly

> object.size(frb) / 1000000
3.908632 bytes
> object.size(r) / 1000000
4.145232 bytes

overpass query pipes?

Posit (alpha minimum working in 0.1.0.9000):

opq(bbox="43.0135509,-70.8229993,43.0996118,-70.7280563") %>% 
  add_feature("amenity", "pub", ) %>% 
  add_feature("amenity", "restaurant") %>% 
  add_feature("amenity", "library") %>% 
  issue_query() -> reading_noms

plot(reading_noms)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.