fb152de add overpy git-subtree-dir: pyextra git-subtree-split: fb152de1e9e54247d933400be1dbf580f4dd0f43pull/438/head
parent
ea6c19638c
commit
efa97f23a5
10 changed files with 1974 additions and 0 deletions
@ -0,0 +1,123 @@ |
|||||||
|
Metadata-Version: 1.1 |
||||||
|
Name: overpy |
||||||
|
Version: 0.4 |
||||||
|
Summary: Python Wrapper to access the OpenStreepMap Overpass API |
||||||
|
Home-page: https://github.com/DinoTools/python-overpy |
||||||
|
Author: PhiBo (DinoTools) |
||||||
|
Author-email: UNKNOWN |
||||||
|
License: MIT |
||||||
|
Description: Python Overpass Wrapper |
||||||
|
======================= |
||||||
|
|
||||||
|
A Python Wrapper to access the Overpass API. |
||||||
|
|
||||||
|
Have a look at the `documentation`_ to find additional information. |
||||||
|
|
||||||
|
.. image:: https://pypip.in/version/overpy/badge.svg |
||||||
|
:target: https://pypi.python.org/pypi/overpy/ |
||||||
|
:alt: Latest Version |
||||||
|
|
||||||
|
.. image:: https://pypip.in/license/overpy/badge.svg |
||||||
|
:target: https://pypi.python.org/pypi/overpy/ |
||||||
|
:alt: License |
||||||
|
|
||||||
|
.. image:: https://travis-ci.org/DinoTools/python-overpy.svg?branch=master |
||||||
|
:target: https://travis-ci.org/DinoTools/python-overpy |
||||||
|
|
||||||
|
.. image:: https://coveralls.io/repos/DinoTools/python-overpy/badge.png?branch=master |
||||||
|
:target: https://coveralls.io/r/DinoTools/python-overpy?branch=master |
||||||
|
|
||||||
|
Features |
||||||
|
-------- |
||||||
|
|
||||||
|
* Query Overpass API |
||||||
|
* Parse JSON and XML response data |
||||||
|
* Additional helper functions |
||||||
|
|
||||||
|
Install |
||||||
|
------- |
||||||
|
|
||||||
|
**Requirements:** |
||||||
|
|
||||||
|
Supported Python versions: |
||||||
|
|
||||||
|
* Python 2.7 |
||||||
|
* Python >= 3.2 |
||||||
|
* PyPy and PyPy3 |
||||||
|
|
||||||
|
**Install:** |
||||||
|
|
||||||
|
.. code-block:: console |
||||||
|
|
||||||
|
$ pip install overpy |
||||||
|
|
||||||
|
Examples |
||||||
|
-------- |
||||||
|
|
||||||
|
Additional examples can be found in the `documentation`_ and in the *examples* directory. |
||||||
|
|
||||||
|
.. code-block:: python |
||||||
|
|
||||||
|
import overpy |
||||||
|
|
||||||
|
api = overpy.Overpass() |
||||||
|
|
||||||
|
# fetch all ways and nodes |
||||||
|
result = api.query(""" |
||||||
|
way(50.746,7.154,50.748,7.157) ["highway"]; |
||||||
|
(._;>;); |
||||||
|
out body; |
||||||
|
""") |
||||||
|
|
||||||
|
for way in result.ways: |
||||||
|
print("Name: %s" % way.tags.get("name", "n/a")) |
||||||
|
print(" Highway: %s" % way.tags.get("highway", "n/a")) |
||||||
|
print(" Nodes:") |
||||||
|
for node in way.nodes: |
||||||
|
print(" Lat: %f, Lon: %f" % (node.lat, node.lon)) |
||||||
|
|
||||||
|
|
||||||
|
Helper |
||||||
|
~~~~~~ |
||||||
|
|
||||||
|
Helper methods are available to provide easy access to often used requests. |
||||||
|
|
||||||
|
.. code-block:: python |
||||||
|
|
||||||
|
import overpy.helper |
||||||
|
|
||||||
|
# 3600062594 is the OSM id of Chemnitz and is the bounding box for the request |
||||||
|
street = overpy.helper.get_street( |
||||||
|
"Straße der Nationen", |
||||||
|
"3600062594" |
||||||
|
) |
||||||
|
|
||||||
|
# this finds an intersection between Straße der Nationen and Carolastraße in Chemnitz |
||||||
|
intersection = overpy.helper.get_intersection( |
||||||
|
"Straße der Nationen", |
||||||
|
"Carolastraße", |
||||||
|
"3600062594" |
||||||
|
) |
||||||
|
|
||||||
|
|
||||||
|
License |
||||||
|
------- |
||||||
|
|
||||||
|
Published under the MIT (see LICENSE for more information) |
||||||
|
|
||||||
|
.. _`documentation`: http://python-overpy.readthedocs.org/ |
||||||
|
|
||||||
|
Keywords: OverPy Overpass OSM OpenStreetMap |
||||||
|
Platform: UNKNOWN |
||||||
|
Classifier: Development Status :: 4 - Beta |
||||||
|
Classifier: License :: OSI Approved :: MIT License |
||||||
|
Classifier: Operating System :: OS Independent |
||||||
|
Classifier: Programming Language :: Python |
||||||
|
Classifier: Programming Language :: Python :: 2.7 |
||||||
|
Classifier: Programming Language :: Python :: 3 |
||||||
|
Classifier: Programming Language :: Python :: 3.2 |
||||||
|
Classifier: Programming Language :: Python :: 3.3 |
||||||
|
Classifier: Programming Language :: Python :: 3.4 |
||||||
|
Classifier: Programming Language :: Python :: 3.5 |
||||||
|
Classifier: Programming Language :: Python :: Implementation :: CPython |
||||||
|
Classifier: Programming Language :: Python :: Implementation :: PyPy |
@ -0,0 +1,61 @@ |
|||||||
|
CHANGELOG.rst |
||||||
|
LICENSE |
||||||
|
MANIFEST.in |
||||||
|
README.rst |
||||||
|
setup.cfg |
||||||
|
setup.py |
||||||
|
docs/make.bat |
||||||
|
docs/source/api.rst |
||||||
|
docs/source/changelog.rst |
||||||
|
docs/source/conf.py |
||||||
|
docs/source/contributing.rst |
||||||
|
docs/source/example.rst |
||||||
|
docs/source/index.rst |
||||||
|
docs/source/introduction.rst |
||||||
|
examples/get_areas.py |
||||||
|
examples/get_nodes.py |
||||||
|
examples/get_ways.py |
||||||
|
overpy/__about__.py |
||||||
|
overpy/__init__.py |
||||||
|
overpy/exception.py |
||||||
|
overpy/helper.py |
||||||
|
overpy.egg-info/PKG-INFO |
||||||
|
overpy.egg-info/SOURCES.txt |
||||||
|
overpy.egg-info/dependency_links.txt |
||||||
|
overpy.egg-info/not-zip-safe |
||||||
|
overpy.egg-info/top_level.txt |
||||||
|
tests/__init__.py |
||||||
|
tests/base_class.py |
||||||
|
tests/test_exception.py |
||||||
|
tests/test_json.py |
||||||
|
tests/test_request.py |
||||||
|
tests/test_result.py |
||||||
|
tests/test_result_way.py |
||||||
|
tests/test_xml.py |
||||||
|
tests/json/area-01.json |
||||||
|
tests/json/node-01.json |
||||||
|
tests/json/relation-01.json |
||||||
|
tests/json/relation-02.json |
||||||
|
tests/json/relation-03.json |
||||||
|
tests/json/relation-04.json |
||||||
|
tests/json/result-expand-01.json |
||||||
|
tests/json/result-expand-02.json |
||||||
|
tests/json/result-way-01.json |
||||||
|
tests/json/result-way-02.json |
||||||
|
tests/json/result-way-03.json |
||||||
|
tests/json/way-01.json |
||||||
|
tests/json/way-02.json |
||||||
|
tests/json/way-03.json |
||||||
|
tests/json/way-04.json |
||||||
|
tests/response/bad-request-encoding.html |
||||||
|
tests/response/bad-request.html |
||||||
|
tests/xml/area-01.xml |
||||||
|
tests/xml/node-01.xml |
||||||
|
tests/xml/relation-01.xml |
||||||
|
tests/xml/relation-02.xml |
||||||
|
tests/xml/relation-03.xml |
||||||
|
tests/xml/relation-04.xml |
||||||
|
tests/xml/way-01.xml |
||||||
|
tests/xml/way-02.xml |
||||||
|
tests/xml/way-03.xml |
||||||
|
tests/xml/way-04.xml |
@ -0,0 +1 @@ |
|||||||
|
|
@ -0,0 +1,56 @@ |
|||||||
|
../overpy/__about__.py |
||||||
|
../overpy/__about__.pyc |
||||||
|
../overpy/__init__.py |
||||||
|
../overpy/__init__.pyc |
||||||
|
../overpy/exception.py |
||||||
|
../overpy/exception.pyc |
||||||
|
../overpy/helper.py |
||||||
|
../overpy/helper.pyc |
||||||
|
../tests/__init__.py |
||||||
|
../tests/__init__.pyc |
||||||
|
../tests/base_class.py |
||||||
|
../tests/base_class.pyc |
||||||
|
../tests/json/area-01.json |
||||||
|
../tests/json/node-01.json |
||||||
|
../tests/json/relation-01.json |
||||||
|
../tests/json/relation-02.json |
||||||
|
../tests/json/relation-03.json |
||||||
|
../tests/json/relation-04.json |
||||||
|
../tests/json/result-expand-01.json |
||||||
|
../tests/json/result-expand-02.json |
||||||
|
../tests/json/result-way-01.json |
||||||
|
../tests/json/result-way-02.json |
||||||
|
../tests/json/result-way-03.json |
||||||
|
../tests/json/way-01.json |
||||||
|
../tests/json/way-02.json |
||||||
|
../tests/json/way-03.json |
||||||
|
../tests/json/way-04.json |
||||||
|
../tests/response/bad-request-encoding.html |
||||||
|
../tests/response/bad-request.html |
||||||
|
../tests/test_exception.py |
||||||
|
../tests/test_exception.pyc |
||||||
|
../tests/test_json.py |
||||||
|
../tests/test_json.pyc |
||||||
|
../tests/test_request.py |
||||||
|
../tests/test_request.pyc |
||||||
|
../tests/test_result.py |
||||||
|
../tests/test_result.pyc |
||||||
|
../tests/test_result_way.py |
||||||
|
../tests/test_result_way.pyc |
||||||
|
../tests/test_xml.py |
||||||
|
../tests/test_xml.pyc |
||||||
|
../tests/xml/area-01.xml |
||||||
|
../tests/xml/node-01.xml |
||||||
|
../tests/xml/relation-01.xml |
||||||
|
../tests/xml/relation-02.xml |
||||||
|
../tests/xml/relation-03.xml |
||||||
|
../tests/xml/relation-04.xml |
||||||
|
../tests/xml/way-01.xml |
||||||
|
../tests/xml/way-02.xml |
||||||
|
../tests/xml/way-03.xml |
||||||
|
../tests/xml/way-04.xml |
||||||
|
PKG-INFO |
||||||
|
SOURCES.txt |
||||||
|
dependency_links.txt |
||||||
|
not-zip-safe |
||||||
|
top_level.txt |
@ -0,0 +1 @@ |
|||||||
|
|
@ -0,0 +1,2 @@ |
|||||||
|
overpy |
||||||
|
tests |
@ -0,0 +1,22 @@ |
|||||||
|
__all__ = [ |
||||||
|
"__author__", |
||||||
|
"__copyright__", |
||||||
|
"__email__", |
||||||
|
"__license__", |
||||||
|
"__summary__", |
||||||
|
"__title__", |
||||||
|
"__uri__", |
||||||
|
"__version__", |
||||||
|
] |
||||||
|
|
||||||
|
__title__ = "overpy" |
||||||
|
__summary__ = "Python Wrapper to access the OpenStreepMap Overpass API" |
||||||
|
__uri__ = "https://github.com/DinoTools/python-overpy" |
||||||
|
|
||||||
|
__version__ = "0.4" |
||||||
|
|
||||||
|
__author__ = "PhiBo (DinoTools)" |
||||||
|
__email__ = "" |
||||||
|
|
||||||
|
__license__ = "MIT" |
||||||
|
__copyright__ = "Copyright 2014-2016 %s" % __author__ |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,108 @@ |
|||||||
|
class OverPyException(BaseException): |
||||||
|
"""OverPy base exception""" |
||||||
|
pass |
||||||
|
|
||||||
|
|
||||||
|
class DataIncomplete(OverPyException): |
||||||
|
""" |
||||||
|
Raised if the requested data isn't available in the result. |
||||||
|
Try to improve the query or to resolve the missing data. |
||||||
|
""" |
||||||
|
def __init__(self, *args, **kwargs): |
||||||
|
OverPyException.__init__( |
||||||
|
self, |
||||||
|
"Data incomplete try to improve the query to resolve the missing data", |
||||||
|
*args, |
||||||
|
**kwargs |
||||||
|
) |
||||||
|
|
||||||
|
|
||||||
|
class ElementDataWrongType(OverPyException): |
||||||
|
""" |
||||||
|
Raised if the provided element does not match the expected type. |
||||||
|
|
||||||
|
:param type_expected: The expected element type |
||||||
|
:type type_expected: String |
||||||
|
:param type_provided: The provided element type |
||||||
|
:type type_provided: String|None |
||||||
|
""" |
||||||
|
def __init__(self, type_expected, type_provided=None): |
||||||
|
self.type_expected = type_expected |
||||||
|
self.type_provided = type_provided |
||||||
|
|
||||||
|
def __str__(self): |
||||||
|
return "Type expected '%s' but '%s' provided" % ( |
||||||
|
self.type_expected, |
||||||
|
str(self.type_provided) |
||||||
|
) |
||||||
|
|
||||||
|
|
||||||
|
class OverpassBadRequest(OverPyException): |
||||||
|
""" |
||||||
|
Raised if the Overpass API service returns a syntax error. |
||||||
|
|
||||||
|
:param query: The encoded query how it was send to the server |
||||||
|
:type query: Bytes |
||||||
|
:param msgs: List of error messages |
||||||
|
:type msgs: List |
||||||
|
""" |
||||||
|
def __init__(self, query, msgs=None): |
||||||
|
self.query = query |
||||||
|
if msgs is None: |
||||||
|
msgs = [] |
||||||
|
self.msgs = msgs |
||||||
|
|
||||||
|
def __str__(self): |
||||||
|
tmp_msgs = [] |
||||||
|
for tmp_msg in self.msgs: |
||||||
|
if not isinstance(tmp_msg, str): |
||||||
|
tmp_msg = str(tmp_msg) |
||||||
|
tmp_msgs.append(tmp_msg) |
||||||
|
|
||||||
|
return "\n".join(tmp_msgs) |
||||||
|
|
||||||
|
|
||||||
|
class OverpassGatewayTimeout(OverPyException): |
||||||
|
""" |
||||||
|
Raised if load of the Overpass API service is too high and it can't handle the request. |
||||||
|
""" |
||||||
|
def __init__(self): |
||||||
|
OverPyException.__init__(self, "Server load too high") |
||||||
|
|
||||||
|
|
||||||
|
class OverpassTooManyRequests(OverPyException): |
||||||
|
""" |
||||||
|
Raised if the Overpass API service returns a 429 status code. |
||||||
|
""" |
||||||
|
def __init__(self): |
||||||
|
OverPyException.__init__(self, "Too many requests") |
||||||
|
|
||||||
|
|
||||||
|
class OverpassUnknownContentType(OverPyException): |
||||||
|
""" |
||||||
|
Raised if the reported content type isn't handled by OverPy. |
||||||
|
|
||||||
|
:param content_type: The reported content type |
||||||
|
:type content_type: None or String |
||||||
|
""" |
||||||
|
def __init__(self, content_type): |
||||||
|
self.content_type = content_type |
||||||
|
|
||||||
|
def __str__(self): |
||||||
|
if self.content_type is None: |
||||||
|
return "No content type returned" |
||||||
|
return "Unknown content type: %s" % self.content_type |
||||||
|
|
||||||
|
|
||||||
|
class OverpassUnknownHTTPStatusCode(OverPyException): |
||||||
|
""" |
||||||
|
Raised if the returned HTTP status code isn't handled by OverPy. |
||||||
|
|
||||||
|
:param code: The HTTP status code |
||||||
|
:type code: Integer |
||||||
|
""" |
||||||
|
def __init__(self, code): |
||||||
|
self.code = code |
||||||
|
|
||||||
|
def __str__(self): |
||||||
|
return "Unknown/Unhandled status code: %d" % self.code |
@ -0,0 +1,64 @@ |
|||||||
|
__author__ = 'mjob' |
||||||
|
|
||||||
|
import overpy |
||||||
|
|
||||||
|
|
||||||
|
def get_street(street, areacode, api=None): |
||||||
|
""" |
||||||
|
Retrieve streets in a given bounding area |
||||||
|
|
||||||
|
:param overpy.Overpass api: First street of intersection |
||||||
|
:param String street: Name of street |
||||||
|
:param String areacode: The OSM id of the bounding area |
||||||
|
:return: Parsed result |
||||||
|
:raises overpy.exception.OverPyException: If something bad happens. |
||||||
|
""" |
||||||
|
if api is None: |
||||||
|
api = overpy.Overpass() |
||||||
|
|
||||||
|
query = """ |
||||||
|
area(%s)->.location; |
||||||
|
( |
||||||
|
way[highway][name="%s"](area.location); |
||||||
|
- ( |
||||||
|
way[highway=service](area.location); |
||||||
|
way[highway=track](area.location); |
||||||
|
); |
||||||
|
); |
||||||
|
out body; |
||||||
|
>; |
||||||
|
out skel qt; |
||||||
|
""" |
||||||
|
|
||||||
|
data = api.query(query % (areacode, street)) |
||||||
|
|
||||||
|
return data |
||||||
|
|
||||||
|
|
||||||
|
def get_intersection(street1, street2, areacode, api=None): |
||||||
|
""" |
||||||
|
Retrieve intersection of two streets in a given bounding area |
||||||
|
|
||||||
|
:param overpy.Overpass api: First street of intersection |
||||||
|
:param String street1: Name of first street of intersection |
||||||
|
:param String street2: Name of second street of intersection |
||||||
|
:param String areacode: The OSM id of the bounding area |
||||||
|
:return: List of intersections |
||||||
|
:raises overpy.exception.OverPyException: If something bad happens. |
||||||
|
""" |
||||||
|
if api is None: |
||||||
|
api = overpy.Overpass() |
||||||
|
|
||||||
|
query = """ |
||||||
|
area(%s)->.location; |
||||||
|
( |
||||||
|
way[highway][name="%s"](area.location); node(w)->.n1; |
||||||
|
way[highway][name="%s"](area.location); node(w)->.n2; |
||||||
|
); |
||||||
|
node.n1.n2; |
||||||
|
out meta; |
||||||
|
""" |
||||||
|
|
||||||
|
data = api.query(query % (areacode, street1, street2)) |
||||||
|
|
||||||
|
return data.get_nodes() |
Loading…
Reference in new issue