[Python-modules-commits] [overpass] 01/03: import overpass_0.4.0.orig.tar.gz

Sandro Tosi morph at moszumanska.debian.org
Sat Apr 23 12:04:27 UTC 2016


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository overpass.

commit 38277e0e7ece68d912fb2d1109c2077819bc8dbb
Author: Sandro Tosi <morph at debian.org>
Date:   Sat Apr 23 13:02:16 2016 +0100

    import overpass_0.4.0.orig.tar.gz
---
 PKG-INFO                               | 199 +++++++++++++++++++++++++++++++++
 README.rst                             | 180 +++++++++++++++++++++++++++++
 overpass.egg-info/PKG-INFO             | 199 +++++++++++++++++++++++++++++++++
 overpass.egg-info/SOURCES.txt          |  14 +++
 overpass.egg-info/dependency_links.txt |   1 +
 overpass.egg-info/entry_points.txt     |   3 +
 overpass.egg-info/requires.txt         |   6 +
 overpass.egg-info/top_level.txt        |   1 +
 overpass/__init__.py                   |  13 +++
 overpass/api.py                        | 143 +++++++++++++++++++++++
 overpass/cli.py                        |  25 +++++
 overpass/errors.py                     |  45 ++++++++
 overpass/queries.py                    |  44 ++++++++
 setup.cfg                              |   8 ++
 setup.py                               |  37 ++++++
 15 files changed, 918 insertions(+)

diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..69b7b45
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,199 @@
+Metadata-Version: 1.1
+Name: overpass
+Version: 0.4.0
+Summary: Python wrapper for the OpenStreetMap Overpass API
+Home-page: https://github.com/mvexel/overpass-api-python-wrapper
+Author: Martijn van Exel
+Author-email: m at rtijn.org
+License: Apache
+Description: Overpass API python wrapper
+        ===========================
+        
+        This is a thin wrapper around the OpenStreetMap `Overpass
+        API <http://wiki.openstreetmap.org/wiki/Overpass_API>`__.
+        
+        .. image:: https://travis-ci.org/mvexel/overpass-api-python-wrapper.svg
+           :target: https://travis-ci.org/mvexel/overpass-api-python-wrapper
+        
+        
+        Install it
+        ==========
+        
+        .. code:: bash
+        
+            $ pip install overpass
+        
+        If you get an error similar to
+        
+        ::
+        
+            OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']
+        
+        you can install the required libraries on linux with
+        
+        .. code:: bash
+        
+            $ sudo apt-get install libgeos-c1 libgeos-3.4.2
+        
+        Use it
+        ======
+        
+        You can use the overpass command line interface or use it as a Python
+        library.
+        
+        Command line interface
+        ---------------------
+        
+        You can use the CLI to execute queries and save the result in a GeoJSON
+        file.
+        
+        ::
+        
+            Usage: overpass [OPTIONS] QUERY OUTPUT_FILE
+        
+            Run query and save the result in output_file
+        
+            Options:
+            --timeout INTEGER  Timeout in seconds
+            --endpoint TEXT    URL of your prefered API
+            --format TEXT      Format to save the data. Options are 'geojson', 'json', 'xml'. Default format is geojson.
+            --help             Show this message and exit.
+        
+        For example:
+        
+        To make a query and save the result as GeoJSON:
+        
+        .. code:: bash
+        
+            overpass --timeout 50 'node(area:3602758138)[amenity=cafe]' brasilia-cafe.geojson
+        
+        Or to get the result as an OSM XML file:
+        
+        .. code:: bash
+        
+            overpass --timeout 50 --format xml 'node(area:3602758138)[amenity=cafe]' brasilia-cafe.osm
+        
+        Python Library
+        -------------
+        
+        .. code:: python
+        
+            >>> import overpass
+            >>> api = overpass.API()
+            >>> response = api.Get('node["name"="Salt Lake City"]')
+        
+        Note that you don't have to include any of the output meta statements.
+        The wrapper will, well, wrap those.
+        
+        You will get your result as a dictionary, which (for now) represents the
+        JSON output you would get `from the Overpass API
+        directly <http://overpass-api.de/output_formats.html#json>`__. So you
+        could do this for example:
+        
+        .. code:: python
+        
+            >>> print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
+            [(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]
+        
+        You can specify the format of the response. By default, you will get GeoJSON using the `responseformat` parameter. Alternatives are plain JSON (`json`) and OSM XML (`xml`), as ouput directly by the Overpass API.
+        
+        .. code:: python
+        
+            >>> import overpass
+            >>> api = overpass.API()
+            >>> response = api.Get('node["name"="Salt Lake City"]', responseformat="xml")
+        
+        Parameters
+        ~~~~~~~~~~
+        
+        The API takes a few parameters:
+        
+        ``endpoint``
+        ^^^^^^^^^^
+        
+        The default endpoint is ``http://overpass-api.de/api/interpreter`` but
+        you can pass in the rambler instance
+        (``http://overpass.osm.rambler.ru/cgi/interpreter``) or your own:
+        
+        .. code:: python
+        
+            api = overpass.API(endpoint=http://overpass.myserver/interpreter)
+        
+        ``timeout``
+        ^^^^^^^^^^
+        
+        The default timeout is 25 seconds, but you can set it to whatever you
+        want.
+        
+        .. code:: python
+        
+            api = overpass.API(timeout=600)
+        
+        ``debug``
+        ^^^^^^^^^^
+        
+        Setting this to ``True`` will get you debug output.
+        
+        Simple queries
+        ~~~~~~~~~~~
+        
+        In addition to just send your query and parse the result, the wrapper
+        provides shortcuts for often used map queries. To use them, just pass
+        them like to normal query to the API.
+        
+        MapQuery
+        ^^^^^^^^
+        
+        This is a shorthand for a `complete ways and
+        relations <http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Completed_ways_and_relations>`__
+        query in a bounding box (the 'map call'). You just pass the bounding box
+        to the constructor:
+        
+        .. code:: python
+        
+            >>> map_query = overpass.MapQuery(50.746,7.154,50.748,7.157)
+            >>> response = api.Get(map_query)
+        
+        WayQuery
+        ^^^^^^^^
+        
+        This is shorthand for getting a set of ways and their child nodes that
+        satisfy certain criteria. Pass the criteria as a Overpass QL stub to the
+        constructor:
+        
+        .. code:: python
+        
+            >>> way_query = overpass.WayQuery('[name="Highway 51"]')
+            >>> response = api.Get(way_query)
+        
+        Need help? Want feature?
+        =======================
+        
+        Create a `new
+        issue <https://github.com/mvexel/overpass-api-python-wrapper/issues>`__.
+        
+        Test it
+        -------
+        
+        ::
+        
+            py.test
+        
+        Fork it
+        -------
+        
+        `Yes
+        please <https://github.com/mvexel/overpass-api-python-wrapper/fork>`__.
+        `Help
+        wanted <https://github.com/mvexel/overpass-api-python-wrapper/labels/help%20wanted>`__.
+        
+Keywords: openstreetmap,overpass,wrapper
+Platform: UNKNOWN
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Topic :: Scientific/Engineering :: GIS
+Classifier: Topic :: Utilities
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..7402c32
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,180 @@
+Overpass API python wrapper
+===========================
+
+This is a thin wrapper around the OpenStreetMap `Overpass
+API <http://wiki.openstreetmap.org/wiki/Overpass_API>`__.
+
+.. image:: https://travis-ci.org/mvexel/overpass-api-python-wrapper.svg
+   :target: https://travis-ci.org/mvexel/overpass-api-python-wrapper
+
+
+Install it
+==========
+
+.. code:: bash
+
+    $ pip install overpass
+
+If you get an error similar to
+
+::
+
+    OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']
+
+you can install the required libraries on linux with
+
+.. code:: bash
+
+    $ sudo apt-get install libgeos-c1 libgeos-3.4.2
+
+Use it
+======
+
+You can use the overpass command line interface or use it as a Python
+library.
+
+Command line interface
+---------------------
+
+You can use the CLI to execute queries and save the result in a GeoJSON
+file.
+
+::
+
+    Usage: overpass [OPTIONS] QUERY OUTPUT_FILE
+
+    Run query and save the result in output_file
+
+    Options:
+    --timeout INTEGER  Timeout in seconds
+    --endpoint TEXT    URL of your prefered API
+    --format TEXT      Format to save the data. Options are 'geojson', 'json', 'xml'. Default format is geojson.
+    --help             Show this message and exit.
+
+For example:
+
+To make a query and save the result as GeoJSON:
+
+.. code:: bash
+
+    overpass --timeout 50 'node(area:3602758138)[amenity=cafe]' brasilia-cafe.geojson
+
+Or to get the result as an OSM XML file:
+
+.. code:: bash
+
+    overpass --timeout 50 --format xml 'node(area:3602758138)[amenity=cafe]' brasilia-cafe.osm
+
+Python Library
+-------------
+
+.. code:: python
+
+    >>> import overpass
+    >>> api = overpass.API()
+    >>> response = api.Get('node["name"="Salt Lake City"]')
+
+Note that you don't have to include any of the output meta statements.
+The wrapper will, well, wrap those.
+
+You will get your result as a dictionary, which (for now) represents the
+JSON output you would get `from the Overpass API
+directly <http://overpass-api.de/output_formats.html#json>`__. So you
+could do this for example:
+
+.. code:: python
+
+    >>> print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
+    [(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]
+
+You can specify the format of the response. By default, you will get GeoJSON using the `responseformat` parameter. Alternatives are plain JSON (`json`) and OSM XML (`xml`), as ouput directly by the Overpass API.
+
+.. code:: python
+
+    >>> import overpass
+    >>> api = overpass.API()
+    >>> response = api.Get('node["name"="Salt Lake City"]', responseformat="xml")
+
+Parameters
+~~~~~~~~~~
+
+The API takes a few parameters:
+
+``endpoint``
+^^^^^^^^^^
+
+The default endpoint is ``http://overpass-api.de/api/interpreter`` but
+you can pass in the rambler instance
+(``http://overpass.osm.rambler.ru/cgi/interpreter``) or your own:
+
+.. code:: python
+
+    api = overpass.API(endpoint=http://overpass.myserver/interpreter)
+
+``timeout``
+^^^^^^^^^^
+
+The default timeout is 25 seconds, but you can set it to whatever you
+want.
+
+.. code:: python
+
+    api = overpass.API(timeout=600)
+
+``debug``
+^^^^^^^^^^
+
+Setting this to ``True`` will get you debug output.
+
+Simple queries
+~~~~~~~~~~~
+
+In addition to just send your query and parse the result, the wrapper
+provides shortcuts for often used map queries. To use them, just pass
+them like to normal query to the API.
+
+MapQuery
+^^^^^^^^
+
+This is a shorthand for a `complete ways and
+relations <http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Completed_ways_and_relations>`__
+query in a bounding box (the 'map call'). You just pass the bounding box
+to the constructor:
+
+.. code:: python
+
+    >>> map_query = overpass.MapQuery(50.746,7.154,50.748,7.157)
+    >>> response = api.Get(map_query)
+
+WayQuery
+^^^^^^^^
+
+This is shorthand for getting a set of ways and their child nodes that
+satisfy certain criteria. Pass the criteria as a Overpass QL stub to the
+constructor:
+
+.. code:: python
+
+    >>> way_query = overpass.WayQuery('[name="Highway 51"]')
+    >>> response = api.Get(way_query)
+
+Need help? Want feature?
+=======================
+
+Create a `new
+issue <https://github.com/mvexel/overpass-api-python-wrapper/issues>`__.
+
+Test it
+-------
+
+::
+
+    py.test
+
+Fork it
+-------
+
+`Yes
+please <https://github.com/mvexel/overpass-api-python-wrapper/fork>`__.
+`Help
+wanted <https://github.com/mvexel/overpass-api-python-wrapper/labels/help%20wanted>`__.
diff --git a/overpass.egg-info/PKG-INFO b/overpass.egg-info/PKG-INFO
new file mode 100644
index 0000000..69b7b45
--- /dev/null
+++ b/overpass.egg-info/PKG-INFO
@@ -0,0 +1,199 @@
+Metadata-Version: 1.1
+Name: overpass
+Version: 0.4.0
+Summary: Python wrapper for the OpenStreetMap Overpass API
+Home-page: https://github.com/mvexel/overpass-api-python-wrapper
+Author: Martijn van Exel
+Author-email: m at rtijn.org
+License: Apache
+Description: Overpass API python wrapper
+        ===========================
+        
+        This is a thin wrapper around the OpenStreetMap `Overpass
+        API <http://wiki.openstreetmap.org/wiki/Overpass_API>`__.
+        
+        .. image:: https://travis-ci.org/mvexel/overpass-api-python-wrapper.svg
+           :target: https://travis-ci.org/mvexel/overpass-api-python-wrapper
+        
+        
+        Install it
+        ==========
+        
+        .. code:: bash
+        
+            $ pip install overpass
+        
+        If you get an error similar to
+        
+        ::
+        
+            OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']
+        
+        you can install the required libraries on linux with
+        
+        .. code:: bash
+        
+            $ sudo apt-get install libgeos-c1 libgeos-3.4.2
+        
+        Use it
+        ======
+        
+        You can use the overpass command line interface or use it as a Python
+        library.
+        
+        Command line interface
+        ---------------------
+        
+        You can use the CLI to execute queries and save the result in a GeoJSON
+        file.
+        
+        ::
+        
+            Usage: overpass [OPTIONS] QUERY OUTPUT_FILE
+        
+            Run query and save the result in output_file
+        
+            Options:
+            --timeout INTEGER  Timeout in seconds
+            --endpoint TEXT    URL of your prefered API
+            --format TEXT      Format to save the data. Options are 'geojson', 'json', 'xml'. Default format is geojson.
+            --help             Show this message and exit.
+        
+        For example:
+        
+        To make a query and save the result as GeoJSON:
+        
+        .. code:: bash
+        
+            overpass --timeout 50 'node(area:3602758138)[amenity=cafe]' brasilia-cafe.geojson
+        
+        Or to get the result as an OSM XML file:
+        
+        .. code:: bash
+        
+            overpass --timeout 50 --format xml 'node(area:3602758138)[amenity=cafe]' brasilia-cafe.osm
+        
+        Python Library
+        -------------
+        
+        .. code:: python
+        
+            >>> import overpass
+            >>> api = overpass.API()
+            >>> response = api.Get('node["name"="Salt Lake City"]')
+        
+        Note that you don't have to include any of the output meta statements.
+        The wrapper will, well, wrap those.
+        
+        You will get your result as a dictionary, which (for now) represents the
+        JSON output you would get `from the Overpass API
+        directly <http://overpass-api.de/output_formats.html#json>`__. So you
+        could do this for example:
+        
+        .. code:: python
+        
+            >>> print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
+            [(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]
+        
+        You can specify the format of the response. By default, you will get GeoJSON using the `responseformat` parameter. Alternatives are plain JSON (`json`) and OSM XML (`xml`), as ouput directly by the Overpass API.
+        
+        .. code:: python
+        
+            >>> import overpass
+            >>> api = overpass.API()
+            >>> response = api.Get('node["name"="Salt Lake City"]', responseformat="xml")
+        
+        Parameters
+        ~~~~~~~~~~
+        
+        The API takes a few parameters:
+        
+        ``endpoint``
+        ^^^^^^^^^^
+        
+        The default endpoint is ``http://overpass-api.de/api/interpreter`` but
+        you can pass in the rambler instance
+        (``http://overpass.osm.rambler.ru/cgi/interpreter``) or your own:
+        
+        .. code:: python
+        
+            api = overpass.API(endpoint=http://overpass.myserver/interpreter)
+        
+        ``timeout``
+        ^^^^^^^^^^
+        
+        The default timeout is 25 seconds, but you can set it to whatever you
+        want.
+        
+        .. code:: python
+        
+            api = overpass.API(timeout=600)
+        
+        ``debug``
+        ^^^^^^^^^^
+        
+        Setting this to ``True`` will get you debug output.
+        
+        Simple queries
+        ~~~~~~~~~~~
+        
+        In addition to just send your query and parse the result, the wrapper
+        provides shortcuts for often used map queries. To use them, just pass
+        them like to normal query to the API.
+        
+        MapQuery
+        ^^^^^^^^
+        
+        This is a shorthand for a `complete ways and
+        relations <http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Completed_ways_and_relations>`__
+        query in a bounding box (the 'map call'). You just pass the bounding box
+        to the constructor:
+        
+        .. code:: python
+        
+            >>> map_query = overpass.MapQuery(50.746,7.154,50.748,7.157)
+            >>> response = api.Get(map_query)
+        
+        WayQuery
+        ^^^^^^^^
+        
+        This is shorthand for getting a set of ways and their child nodes that
+        satisfy certain criteria. Pass the criteria as a Overpass QL stub to the
+        constructor:
+        
+        .. code:: python
+        
+            >>> way_query = overpass.WayQuery('[name="Highway 51"]')
+            >>> response = api.Get(way_query)
+        
+        Need help? Want feature?
+        =======================
+        
+        Create a `new
+        issue <https://github.com/mvexel/overpass-api-python-wrapper/issues>`__.
+        
+        Test it
+        -------
+        
+        ::
+        
+            py.test
+        
+        Fork it
+        -------
+        
+        `Yes
+        please <https://github.com/mvexel/overpass-api-python-wrapper/fork>`__.
+        `Help
+        wanted <https://github.com/mvexel/overpass-api-python-wrapper/labels/help%20wanted>`__.
+        
+Keywords: openstreetmap,overpass,wrapper
+Platform: UNKNOWN
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Topic :: Scientific/Engineering :: GIS
+Classifier: Topic :: Utilities
diff --git a/overpass.egg-info/SOURCES.txt b/overpass.egg-info/SOURCES.txt
new file mode 100644
index 0000000..fa42566
--- /dev/null
+++ b/overpass.egg-info/SOURCES.txt
@@ -0,0 +1,14 @@
+README.rst
+setup.cfg
+setup.py
+overpass/__init__.py
+overpass/api.py
+overpass/cli.py
+overpass/errors.py
+overpass/queries.py
+overpass.egg-info/PKG-INFO
+overpass.egg-info/SOURCES.txt
+overpass.egg-info/dependency_links.txt
+overpass.egg-info/entry_points.txt
+overpass.egg-info/requires.txt
+overpass.egg-info/top_level.txt
\ No newline at end of file
diff --git a/overpass.egg-info/dependency_links.txt b/overpass.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/overpass.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/overpass.egg-info/entry_points.txt b/overpass.egg-info/entry_points.txt
new file mode 100644
index 0000000..b6e7982
--- /dev/null
+++ b/overpass.egg-info/entry_points.txt
@@ -0,0 +1,3 @@
+
+        [console_scripts]
+        overpass=overpass.cli:cli
diff --git a/overpass.egg-info/requires.txt b/overpass.egg-info/requires.txt
new file mode 100644
index 0000000..5a3478d
--- /dev/null
+++ b/overpass.egg-info/requires.txt
@@ -0,0 +1,6 @@
+click
+requests>=2.3.0
+geojson>=1.0.9
+
+[test]
+pytest
diff --git a/overpass.egg-info/top_level.txt b/overpass.egg-info/top_level.txt
new file mode 100644
index 0000000..aab78dd
--- /dev/null
+++ b/overpass.egg-info/top_level.txt
@@ -0,0 +1 @@
+overpass
diff --git a/overpass/__init__.py b/overpass/__init__.py
new file mode 100644
index 0000000..267865a
--- /dev/null
+++ b/overpass/__init__.py
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+
+"""Thin wrapper around the OpenStreetMap Overpass API."""
+
+__title__ = 'overpass'
+__version__ = '0.1.0'
+__license__ = 'Apache 2.0'
+
+from .api import API
+from .queries import MapQuery, WayQuery
+from .errors import (
+    OverpassError, OverpassSyntaxError, TimeoutError, MultipleRequestsError, ServerLoadError, UnknownOverpassError
+)
diff --git a/overpass/api.py b/overpass/api.py
new file mode 100644
index 0000000..a19209a
--- /dev/null
+++ b/overpass/api.py
@@ -0,0 +1,143 @@
+import requests
+import json
+import geojson
+
+from .errors import (OverpassSyntaxError, TimeoutError, MultipleRequestsError,
+                     ServerLoadError, UnknownOverpassError, ServerRuntimeError)
+
+class API(object):
+    """A simple Python wrapper for the OpenStreetMap Overpass API"""
+
+    SUPPORTED_FORMATS = ["geojson", "json", "xml"]
+
+    # defaults for the API class
+    _timeout = 25  # seconds
+    _endpoint = "http://overpass-api.de/api/interpreter"
+    _debug = False
+
+    _QUERY_TEMPLATE = "[out:{out}];{query}out {verbosity};"
+    _GEOJSON_QUERY_TEMPLATE = "[out:json];{query}out body geom;"
+
+    def __init__(self, *args, **kwargs):
+        self.endpoint = kwargs.get("endpoint", self._endpoint)
+        self.timeout = kwargs.get("timeout", self._timeout)
+        self.debug = kwargs.get("debug", self._debug)
+        self._status = None
+
+        if self.debug:
+            import httplib
+            import logging
+            httplib.HTTPConnection.debuglevel = 1
+
+            logging.basicConfig()
+            logging.getLogger().setLevel(logging.DEBUG)
+            requests_log = logging.getLogger("requests.packages.urllib3")
+            requests_log.setLevel(logging.DEBUG)
+            requests_log.propagate = True
+
+    def Get(self, query, responseformat="geojson", verbosity="body"):
+        """Pass in an Overpass query in Overpass QL"""
+
+        # Construct full Overpass query
+        full_query = self._ConstructQLQuery(query, responseformat=responseformat, verbosity=verbosity)
+        
+        # Get the response from Overpass
+        raw_response = self._GetFromOverpass(full_query)
+
+        if responseformat == "xml":
+            return raw_response
+            
+        response = json.loads(raw_response)
+
+        # Check for valid answer from Overpass. A valid answer contains an 'elements' key at the root level.
+        if "elements" not in response:
+            raise UnknownOverpassError("Received an invalid answer from Overpass.")
+
+        # If there is a 'remark' key, it spells trouble.
+        overpass_remark = response.get('remark', None)
+        if overpass_remark and overpass_remark.startswith('runtime error'):
+            raise ServerRuntimeError(overpass_remark)
+
+        if responseformat is not "geojson":
+            return response
+
+        # construct geojson
+        return self._asGeoJSON(response["elements"])
+
+    def Search(self, feature_type, regex=False):
+        """Search for something."""
+        raise NotImplementedError()
+
+    def _ConstructQLQuery(self, userquery, responseformat, verbosity):
+        raw_query = str(userquery)
+        if not raw_query.endswith(";"):
+            raw_query += ";"
+
+        if responseformat == "geojson":
+            template = self._GEOJSON_QUERY_TEMPLATE
+            complete_query = template.format(query=raw_query, verbosity=verbosity)
+        else:
+            template = self._QUERY_TEMPLATE
+            complete_query = template.format(query=raw_query, out=responseformat, verbosity=verbosity)
+
+        if self.debug:
+            print(complete_query)
+        return complete_query
+
+    def _GetFromOverpass(self, query):
+        """This sends the API request to the Overpass instance and
+        returns the raw result, or an error."""
+
+        payload = {"data": query}
+
+        try:
+            r = requests.post(
+                self.endpoint,
+                data=payload,
+                timeout=self.timeout,
+                headers={'Accept-Charset': 'utf-8;q=0.7,*;q=0.7'}
+            )
+            
+        except requests.exceptions.Timeout:
+            raise TimeoutError(self._timeout)
+
+        self._status = r.status_code
+
+        if self._status != 200:
+            if self._status == 400:
+                raise OverpassSyntaxError(query)
+            elif self._status == 429:
+                raise MultipleRequestsError()
+            elif self._status == 504:
+                raise ServerLoadError(self._timeout)
+            raise UnknownOverpassError(
+                "The request returned status code {code}".format(
+                    code=self._status
+                    )
+                )
+        else:
+            r.encoding = 'utf-8'
+            return r.text
+
+    def _asGeoJSON(self, elements):
+
+        features = []
+        for elem in elements:
+            elem_type = elem["type"]
+            if elem_type == "node":
+                geometry = geojson.Point((elem["lon"], elem["lat"]))
+            elif elem_type == "way":
+                points = []
+                for coords in elem["geometry"]:
+                    points.append((coords["lon"], coords["lat"]))
+                geometry = geojson.LineString(points)
+            else:
+                continue
+
+            feature = geojson.Feature(
+                id=elem["id"],
+                geometry=geometry,
+                properties=elem.get("tags"))
+            features.append(feature)
+
+        return geojson.FeatureCollection(features)
diff --git a/overpass/cli.py b/overpass/cli.py
new file mode 100644
index 0000000..28bb026
--- /dev/null
+++ b/overpass/cli.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+from __future__ import print_function
+import click
+import geojson
+import sys
+import overpass
+
+
+ at click.command()
+ at click.option('--timeout', default=25, help='Timeout in seconds.')
+ at click.option('--endpoint', default='http://overpass-api.de/api/interpreter',
+    help='URL of your prefered API.')
+ at click.option('--responseformat', default='geojson', help="""Format to save the data.
+    Options are 'geojson' and 'osm'. Default format is geojson.""")
+ at click.argument('query', type=str)
+def cli(timeout, endpoint, responseformat, query):
+    """Run query"""
+    api = overpass.API(timeout=timeout, endpoint=endpoint)
+    if responseformat not in api.SUPPORTED_FORMATS:
+        print("format {} not supported. Supported formats: {}".format(
+            responseformat,
+            ", ".join(api.SUPPORTED_FORMATS)))
+        sys.exit(1)
+    result = api.Get(query, responseformat=responseformat)
+    click.echo(result)
\ No newline at end of file
diff --git a/overpass/errors.py b/overpass/errors.py
new file mode 100644
index 0000000..f7a95e2
--- /dev/null
+++ b/overpass/errors.py
@@ -0,0 +1,45 @@
+class OverpassError(Exception):
+    """An error during your request occurred.
+    Super class for all Overpass api errors."""
+    pass
+
+
+class OverpassSyntaxError(OverpassError, ValueError):
+    """The request contains a syntax error."""
+
+    def __init__(self, request):
+        self.request = request
+
+
+class TimeoutError(OverpassError):
+    """A request timeout occurred."""
+
+    def __init__(self, timeout):
+        self.timeout = timeout
+
+
+class MultipleRequestsError(OverpassError):
+    """You are trying to run multiple requests at the same time."""
+    pass
+
+
+class ServerLoadError(OverpassError):
+    """The Overpass server is currently under load and declined the request.
+    Try again later or retry with reduced timeout value."""
+
+    def __init__(self, timeout):
+        self.timeout = timeout
+
+
+class UnknownOverpassError(OverpassError):
+    """An unknown kind of error happened during the request."""
+
+    def __init__(self, message):
+        self.message = message
+
+
+class ServerRuntimeError(OverpassError):
+    """The Overpass server returned a runtime error"""
+
+    def __init__(self, message):
+        self.message = message
diff --git a/overpass/queries.py b/overpass/queries.py
new file mode 100644
index 0000000..58d71fc
--- /dev/null
+++ b/overpass/queries.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+
+
+class MapQuery(object):
+    """Query to retrieve complete ways and relations in an area."""
+
+    _QUERY_TEMPLATE = "(node({south},{west},{north},{east});<;);"
+
+    def __init__(self, south, west, north, east):
+        """
+        Initialize query with given bounding box.
+        :param bbox Bounding box with limit values in format west, south,
+        east, north.
+        """
+        self.west = west
+        self.south = south
+        self.east = east
+        self.north = north
+
+    def __str__(self):
+        return self._QUERY_TEMPLATE.format(
+            west=self.west,
+            south=self.south,
+            east=self.east,
+            north=self.north
+        )
+
+
+class WayQuery(object):
+    """Query to retrieve a set of ways and their dependent nodes satisfying
+    the input parameters"""
+
+    _QUERY_TEMPLATE = "(way{query_parameters});(._;>;);"
+
+    def __init__(self, query_parameters):
+        """Initialize a query for a set of ways satisfying the given parameters.
+        :param query_parameters Overpass QL query parameters"""
+
+        self.query_parameters = query_parameters
+
+    def __str__(self):
+        return self._QUERY_TEMPLATE.format(
+            query_parameters=self.query_parameters
+        )
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..df0d51e
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,8 @@
+[metadata]
+description-file = README.md
+
+[egg_info]
+tag_date = 0
+tag_build = 
+tag_svn_revision = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..f890b32
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,37 @@
+from codecs import open as codecs_open
+from setuptools import setup, find_packages
+
+# Get the long description from the relevant file
... 33 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/overpass.git



More information about the Python-modules-commits mailing list