[Python-modules-commits] [osmalchemy] 01/05: New upstream version 0.1a0

Dominik George natureshadow-guest at moszumanska.debian.org
Sun Sep 11 10:58:14 UTC 2016


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

natureshadow-guest pushed a commit to branch master
in repository osmalchemy.

commit 6bdeefd1ea20703fe73e03feb8baab0b26162ad5
Author: Dominik George <nik at naturalnet.de>
Date:   Sun Sep 11 12:52:45 2016 +0200

    New upstream version 0.1a0
---
 OSMAlchemy.egg-info/PKG-INFO             | 244 ++++++++++++++++++
 OSMAlchemy.egg-info/SOURCES.txt          |  20 ++
 OSMAlchemy.egg-info/dependency_links.txt |   1 +
 OSMAlchemy.egg-info/requires.txt         |   7 +
 OSMAlchemy.egg-info/top_level.txt        |   1 +
 OSMAlchemy.egg-info/zip-safe             |   1 +
 PKG-INFO                                 | 244 ++++++++++++++++++
 README.rst                               | 225 ++++++++++++++++
 osmalchemy/__init__.py                   |   8 +
 osmalchemy/model.py                      | 320 +++++++++++++++++++++++
 osmalchemy/osmalchemy.py                 | 204 +++++++++++++++
 osmalchemy/triggers.py                   | 171 +++++++++++++
 osmalchemy/util/__init__.py              |   0
 osmalchemy/util/db.py                    | 212 +++++++++++++++
 osmalchemy/util/online.py                | 425 +++++++++++++++++++++++++++++++
 osmalchemy/util/patch.py                 |  84 ++++++
 setup.cfg                                |   5 +
 setup.py                                 |  85 +++++++
 test/test_api.py                         |  85 +++++++
 test/test_model.py                       | 389 ++++++++++++++++++++++++++++
 test/test_util_db.py                     | 208 +++++++++++++++
 test/test_util_online.py                 | 234 +++++++++++++++++
 22 files changed, 3173 insertions(+)

diff --git a/OSMAlchemy.egg-info/PKG-INFO b/OSMAlchemy.egg-info/PKG-INFO
new file mode 100644
index 0000000..9136415
--- /dev/null
+++ b/OSMAlchemy.egg-info/PKG-INFO
@@ -0,0 +1,244 @@
+Metadata-Version: 1.1
+Name: OSMAlchemy
+Version: 0.1a0
+Summary: OpenStreetMap to SQLAlchemy bridge
+Home-page: https://github.com/Natureshadow/OSMAlchemy
+Author: Dominik George, Eike Tim Jesinghaus
+Author-email: osmalchemy at veripeditus.org
+License: UNKNOWN
+Description: OSMAlchemy
+        ==========
+        
+        OSMAlchemy is a bridge between SQLAlchemy and the OpenStreetMap API.
+        
+        Goals
+        -----
+        
+        OSMAlchemy's goal is to provide completely transparent integration of
+        the real-world OpenStreetMap data within projects using SQLAlchemy. It
+        provides two things:
+        
+        1. Model declaratives resembling the structure of the main OpenStreetMap
+           database, with some limitations, usable wherever SQLAlchemy is used,
+           and
+        2. Transparent proxying and data-fetching from OpenStreetMap data.
+        
+        The idea is that the model can be queried using SQLAlchemy, and
+        OSMAlchemy will either satisfy the query from the database directly or
+        fetch data from OpenStreetMap. That way, projects already using
+        SQLAlchemy do not need another database framework to use OpenStreetMap
+        data, and the necessity to keep a local copy of planet.osm is relaxed.
+        
+        If, for example, a node with a certain id is queried, OSMAlchemy will…
+        
+        -  …try to get the node from the database/ORM directly, then…
+        -  …if it is available, check its caching age, and…
+        
+           -  …if it is too old, refresh it from OSM, or…
+           -  …else, fetch it from OSM, and…
+        
+        -  …finally create a real, ORM-mapped database object.
+        
+        That's the rough idea, and it counts for all kinds of OSM elements and
+        queries.
+        
+        OSMAlchemy uses Overpass to satisfy complex queries.
+        
+        Non-goals
+        ~~~~~~~~~
+        
+        OSMAlchemy does not aim to replace large-scale OSM data frameworks like
+        PostGIS, Osmosis or whatever. In fact, in terms of performance and
+        otherwise, it cannot keep up with them.
+        
+        If you are running a huge project that handles massive amounts of map
+        data, has millions of requests or users, then OSMAlchemy is not for you
+        (YMMV).
+        
+        OSMAlchemy fills a niche for projects that have limited resources and
+        cannot handle a full copy of planet.osm and an own API backend and
+        expect to handle limited amounts of map data.
+        
+        It might, however, be cool to use OSMAlchemy as ORM proxy with an own
+        API backend. Who knows?
+        
+        It might, as well, turn out that OSMAlchemy is an incredibly silly idea
+        under all circumstances.
+        
+        Usage
+        -----
+        
+        Here are a few tiny examples of how to basically use OSMAlchemy:
+        
+        Installation
+        ~~~~~~~~~~~~
+        
+        OSMAlchemy can be installed just like any other standard Python package
+        by one of…
+        
+        .. code-block:: console
+        
+            # pip3 install OSMAlchemy
+            # python3 setup.py install
+        
+        …or what ever kind of distribution and install system you prefer.
+        
+        Using plain SQLAlchemy
+        ~~~~~~~~~~~~~~~~~~~~~~
+        
+        Make sure to get at least an engine from SQLAlchemy. Even better, get a
+        declarative base and a scoped session:
+        
+        .. code-block:: python
+        
+            from sqlalchemy import create_engine
+            from sqlalchemy.ext.declarative import declarative_base
+            from sqlalchemy.orm import sessionmaker, scoped_session
+        
+            engine = create_engine("sqlite:////tmp/foo.db")
+            base = declarative_base(bind=engine)
+            session = scoped_session(sessionmaker(bind=engine))
+        
+        You can then initialise OSMAlchemy like so:
+        
+        .. code-block:: python
+        
+            osmalchemy = OSMAlchemy((engine, base, session), overpass=True)
+        
+        And probably install the databases:
+        
+        .. code-block:: python
+        
+            base.metadata.create_all()
+        
+        Using Flask-SQLAlchemy and Flask-Restless
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        Imagine you have an SQLAlchemy object from Flask-SQLAlchemy bound to
+        your Flask application. called db, and a Flask-Restless API manager as
+        manager:
+        
+        .. code-block:: python
+        
+            from osmalchemy import OSMAlchemy
+            osm = OSMAlchemy(db, overpass=True)
+            db.create_all()
+            osm.create_api(manager)
+        
+        You should now magically be able to query OSM via the REST API. Keep in
+        mind that, with no filter provided, OSMAlchemy refuses to do automatic
+        updates from Overpass. However, providing a query in the default JSON
+        query way in Flask-Restless will give you live data and cache it in the
+        database.
+        
+        Limitations
+        ~~~~~~~~~~~
+        
+        Only some basic SQL queries are supported by the online update code.
+        This is because compiling SQLAlchemy's queries to OverpassQL is very
+        complex. If you are very good at algorithms and building compilers, feel
+        free to help us out!
+        
+        The following kinds of queries are fully supported:
+        
+        .. code-block:: python
+        
+            # A node with a specific id
+            session.query(osmalchemy.node).filter_by(id=12345).one()
+        
+            # All nodes within a bounding box
+            session.query(osmalchemy.node).filter(
+                and_(latitude>51.0, latitude<51.1, longitude>7.0, longitude<7.1)
+            ).all()
+        
+            # All nodes having a specific tag
+            session.query(osmalchemy.node).filter(
+                osmalchemy.node.tags.any(key="name", value="Schwarzrheindorf Kirche")
+            ).all()
+        
+        You can go mad combining the two with and\_() and or\_(). You can also
+        query for tags of ways and relations and for ways and relations by id.
+        
+        Not supported (yet) are queries for ways or relations by coordinates.
+        You also cannot query for nodes related to a way or anything related to
+        a relation - having a way or a relation, accessing it will, however,
+        magically pull and update the nodes and members and add them to the
+        database:
+        
+        .. code-block:: python
+        
+            # Get all nodes that are members of a (unique) named way
+            session.query(osmalchemy.way).filter(
+                osmalchemy.way.tags.any(key="name", value="My Unique Way")
+            ).one().nodes
+        
+        This should, in reality, cover most use cases. If you encounter a use
+        case that is not supported, please open an issue asking whether it can
+        be supported (if you have an idea how it can be, please add it or even
+        implement it and open a pull request).
+        
+        Projects using OSMAlchemy
+        ~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        OSMAlchemy was designed for use in the Veripeditus Augmented Reality
+        framework.
+        
+        Development and standards
+        -------------------------
+        
+        Albeit taking the above into account, OSMAlchemy is developed with
+        quality and good support in mind. That means code shall be well-tested
+        and well-documented.
+        
+        OSMAlchemy is tested against the following SQLAlchemy backends:
+        
+        -  SQLite
+        -  PostgreSQL
+        -  MySQL
+        
+        However, we recommend PostgreSQL. MySQL acts strangely with some data
+        and is incredibly slow, and SQLite just doesn't scale too well (however,
+        it is incredibly fast, in comparison).
+        
+        Code status
+        ~~~~~~~~~~~
+        
+        |PyPI package| |Build Status| |Code Coverage| |Scrutinizer Code Quality|
+        
+        Authors and credits
+        -------------------
+        
+        :Authors:
+            Dominik George,
+            Eike Tim Jesinghaus
+        
+        :Credits:
+            Special thanks to Mike Bayer from SQLAlchemy for his help with
+            some SQLAlchemy bugs and pitfalls, and also some heads-up.
+        
+        License
+        -------
+        
+        OSMAlchemy is licensed under the MIT license. Alternatively, you are
+        free to use OSMAlchemy under Simplified BSD, The MirOS Licence, GPL-2+,
+        LGPL-2.1+, AGPL-3+ or the same terms as Python itself.
+        
+        .. |PyPI package| image:: https://badge.fury.io/py/OSMAlchemy.svg
+           :target: https://badge.fury.io/py/OSMAlchemy
+        .. |Build Status| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/build.png?b=master
+           :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/build-status/master
+        .. |Code Coverage| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/coverage.png?b=master
+           :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/?branch=master
+        .. |Scrutinizer Code Quality| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/quality-score.png?b=master
+           :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/?branch=master
+        
+Keywords: osm,openstreetmap,proxy,caching,orm
+Platform: UNKNOWN
+Classifier: Development Status :: 3 - Alpha
+Classifier: Environment :: Plugins
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Programming Language :: Python :: 3 :: Only
+Classifier: Topic :: Database
+Classifier: Topic :: Scientific/Engineering :: GIS
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/OSMAlchemy.egg-info/SOURCES.txt b/OSMAlchemy.egg-info/SOURCES.txt
new file mode 100644
index 0000000..11d7526
--- /dev/null
+++ b/OSMAlchemy.egg-info/SOURCES.txt
@@ -0,0 +1,20 @@
+README.rst
+setup.py
+OSMAlchemy.egg-info/PKG-INFO
+OSMAlchemy.egg-info/SOURCES.txt
+OSMAlchemy.egg-info/dependency_links.txt
+OSMAlchemy.egg-info/requires.txt
+OSMAlchemy.egg-info/top_level.txt
+OSMAlchemy.egg-info/zip-safe
+osmalchemy/__init__.py
+osmalchemy/model.py
+osmalchemy/osmalchemy.py
+osmalchemy/triggers.py
+osmalchemy/util/__init__.py
+osmalchemy/util/db.py
+osmalchemy/util/online.py
+osmalchemy/util/patch.py
+test/test_api.py
+test/test_model.py
+test/test_util_db.py
+test/test_util_online.py
\ No newline at end of file
diff --git a/OSMAlchemy.egg-info/dependency_links.txt b/OSMAlchemy.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/OSMAlchemy.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/OSMAlchemy.egg-info/requires.txt b/OSMAlchemy.egg-info/requires.txt
new file mode 100644
index 0000000..e960f80
--- /dev/null
+++ b/OSMAlchemy.egg-info/requires.txt
@@ -0,0 +1,7 @@
+SQLAlchemy>=1.0.0
+python-dateutil
+overpass
+
+[Flask]
+Flask>=0.10
+Flask-SQLAlchemy
diff --git a/OSMAlchemy.egg-info/top_level.txt b/OSMAlchemy.egg-info/top_level.txt
new file mode 100644
index 0000000..cdec5f3
--- /dev/null
+++ b/OSMAlchemy.egg-info/top_level.txt
@@ -0,0 +1 @@
+osmalchemy
diff --git a/OSMAlchemy.egg-info/zip-safe b/OSMAlchemy.egg-info/zip-safe
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/OSMAlchemy.egg-info/zip-safe
@@ -0,0 +1 @@
+
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..9136415
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,244 @@
+Metadata-Version: 1.1
+Name: OSMAlchemy
+Version: 0.1a0
+Summary: OpenStreetMap to SQLAlchemy bridge
+Home-page: https://github.com/Natureshadow/OSMAlchemy
+Author: Dominik George, Eike Tim Jesinghaus
+Author-email: osmalchemy at veripeditus.org
+License: UNKNOWN
+Description: OSMAlchemy
+        ==========
+        
+        OSMAlchemy is a bridge between SQLAlchemy and the OpenStreetMap API.
+        
+        Goals
+        -----
+        
+        OSMAlchemy's goal is to provide completely transparent integration of
+        the real-world OpenStreetMap data within projects using SQLAlchemy. It
+        provides two things:
+        
+        1. Model declaratives resembling the structure of the main OpenStreetMap
+           database, with some limitations, usable wherever SQLAlchemy is used,
+           and
+        2. Transparent proxying and data-fetching from OpenStreetMap data.
+        
+        The idea is that the model can be queried using SQLAlchemy, and
+        OSMAlchemy will either satisfy the query from the database directly or
+        fetch data from OpenStreetMap. That way, projects already using
+        SQLAlchemy do not need another database framework to use OpenStreetMap
+        data, and the necessity to keep a local copy of planet.osm is relaxed.
+        
+        If, for example, a node with a certain id is queried, OSMAlchemy will…
+        
+        -  …try to get the node from the database/ORM directly, then…
+        -  …if it is available, check its caching age, and…
+        
+           -  …if it is too old, refresh it from OSM, or…
+           -  …else, fetch it from OSM, and…
+        
+        -  …finally create a real, ORM-mapped database object.
+        
+        That's the rough idea, and it counts for all kinds of OSM elements and
+        queries.
+        
+        OSMAlchemy uses Overpass to satisfy complex queries.
+        
+        Non-goals
+        ~~~~~~~~~
+        
+        OSMAlchemy does not aim to replace large-scale OSM data frameworks like
+        PostGIS, Osmosis or whatever. In fact, in terms of performance and
+        otherwise, it cannot keep up with them.
+        
+        If you are running a huge project that handles massive amounts of map
+        data, has millions of requests or users, then OSMAlchemy is not for you
+        (YMMV).
+        
+        OSMAlchemy fills a niche for projects that have limited resources and
+        cannot handle a full copy of planet.osm and an own API backend and
+        expect to handle limited amounts of map data.
+        
+        It might, however, be cool to use OSMAlchemy as ORM proxy with an own
+        API backend. Who knows?
+        
+        It might, as well, turn out that OSMAlchemy is an incredibly silly idea
+        under all circumstances.
+        
+        Usage
+        -----
+        
+        Here are a few tiny examples of how to basically use OSMAlchemy:
+        
+        Installation
+        ~~~~~~~~~~~~
+        
+        OSMAlchemy can be installed just like any other standard Python package
+        by one of…
+        
+        .. code-block:: console
+        
+            # pip3 install OSMAlchemy
+            # python3 setup.py install
+        
+        …or what ever kind of distribution and install system you prefer.
+        
+        Using plain SQLAlchemy
+        ~~~~~~~~~~~~~~~~~~~~~~
+        
+        Make sure to get at least an engine from SQLAlchemy. Even better, get a
+        declarative base and a scoped session:
+        
+        .. code-block:: python
+        
+            from sqlalchemy import create_engine
+            from sqlalchemy.ext.declarative import declarative_base
+            from sqlalchemy.orm import sessionmaker, scoped_session
+        
+            engine = create_engine("sqlite:////tmp/foo.db")
+            base = declarative_base(bind=engine)
+            session = scoped_session(sessionmaker(bind=engine))
+        
+        You can then initialise OSMAlchemy like so:
+        
+        .. code-block:: python
+        
+            osmalchemy = OSMAlchemy((engine, base, session), overpass=True)
+        
+        And probably install the databases:
+        
+        .. code-block:: python
+        
+            base.metadata.create_all()
+        
+        Using Flask-SQLAlchemy and Flask-Restless
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        Imagine you have an SQLAlchemy object from Flask-SQLAlchemy bound to
+        your Flask application. called db, and a Flask-Restless API manager as
+        manager:
+        
+        .. code-block:: python
+        
+            from osmalchemy import OSMAlchemy
+            osm = OSMAlchemy(db, overpass=True)
+            db.create_all()
+            osm.create_api(manager)
+        
+        You should now magically be able to query OSM via the REST API. Keep in
+        mind that, with no filter provided, OSMAlchemy refuses to do automatic
+        updates from Overpass. However, providing a query in the default JSON
+        query way in Flask-Restless will give you live data and cache it in the
+        database.
+        
+        Limitations
+        ~~~~~~~~~~~
+        
+        Only some basic SQL queries are supported by the online update code.
+        This is because compiling SQLAlchemy's queries to OverpassQL is very
+        complex. If you are very good at algorithms and building compilers, feel
+        free to help us out!
+        
+        The following kinds of queries are fully supported:
+        
+        .. code-block:: python
+        
+            # A node with a specific id
+            session.query(osmalchemy.node).filter_by(id=12345).one()
+        
+            # All nodes within a bounding box
+            session.query(osmalchemy.node).filter(
+                and_(latitude>51.0, latitude<51.1, longitude>7.0, longitude<7.1)
+            ).all()
+        
+            # All nodes having a specific tag
+            session.query(osmalchemy.node).filter(
+                osmalchemy.node.tags.any(key="name", value="Schwarzrheindorf Kirche")
+            ).all()
+        
+        You can go mad combining the two with and\_() and or\_(). You can also
+        query for tags of ways and relations and for ways and relations by id.
+        
+        Not supported (yet) are queries for ways or relations by coordinates.
+        You also cannot query for nodes related to a way or anything related to
+        a relation - having a way or a relation, accessing it will, however,
+        magically pull and update the nodes and members and add them to the
+        database:
+        
+        .. code-block:: python
+        
+            # Get all nodes that are members of a (unique) named way
+            session.query(osmalchemy.way).filter(
+                osmalchemy.way.tags.any(key="name", value="My Unique Way")
+            ).one().nodes
+        
+        This should, in reality, cover most use cases. If you encounter a use
+        case that is not supported, please open an issue asking whether it can
+        be supported (if you have an idea how it can be, please add it or even
+        implement it and open a pull request).
+        
+        Projects using OSMAlchemy
+        ~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        OSMAlchemy was designed for use in the Veripeditus Augmented Reality
+        framework.
+        
+        Development and standards
+        -------------------------
+        
+        Albeit taking the above into account, OSMAlchemy is developed with
+        quality and good support in mind. That means code shall be well-tested
+        and well-documented.
+        
+        OSMAlchemy is tested against the following SQLAlchemy backends:
+        
+        -  SQLite
+        -  PostgreSQL
+        -  MySQL
+        
+        However, we recommend PostgreSQL. MySQL acts strangely with some data
+        and is incredibly slow, and SQLite just doesn't scale too well (however,
+        it is incredibly fast, in comparison).
+        
+        Code status
+        ~~~~~~~~~~~
+        
+        |PyPI package| |Build Status| |Code Coverage| |Scrutinizer Code Quality|
+        
+        Authors and credits
+        -------------------
+        
+        :Authors:
+            Dominik George,
+            Eike Tim Jesinghaus
+        
+        :Credits:
+            Special thanks to Mike Bayer from SQLAlchemy for his help with
+            some SQLAlchemy bugs and pitfalls, and also some heads-up.
+        
+        License
+        -------
+        
+        OSMAlchemy is licensed under the MIT license. Alternatively, you are
+        free to use OSMAlchemy under Simplified BSD, The MirOS Licence, GPL-2+,
+        LGPL-2.1+, AGPL-3+ or the same terms as Python itself.
+        
+        .. |PyPI package| image:: https://badge.fury.io/py/OSMAlchemy.svg
+           :target: https://badge.fury.io/py/OSMAlchemy
+        .. |Build Status| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/build.png?b=master
+           :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/build-status/master
+        .. |Code Coverage| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/coverage.png?b=master
+           :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/?branch=master
+        .. |Scrutinizer Code Quality| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/quality-score.png?b=master
+           :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/?branch=master
+        
+Keywords: osm,openstreetmap,proxy,caching,orm
+Platform: UNKNOWN
+Classifier: Development Status :: 3 - Alpha
+Classifier: Environment :: Plugins
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Programming Language :: Python :: 3 :: Only
+Classifier: Topic :: Database
+Classifier: Topic :: Scientific/Engineering :: GIS
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..3048000
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,225 @@
+OSMAlchemy
+==========
+
+OSMAlchemy is a bridge between SQLAlchemy and the OpenStreetMap API.
+
+Goals
+-----
+
+OSMAlchemy's goal is to provide completely transparent integration of
+the real-world OpenStreetMap data within projects using SQLAlchemy. It
+provides two things:
+
+1. Model declaratives resembling the structure of the main OpenStreetMap
+   database, with some limitations, usable wherever SQLAlchemy is used,
+   and
+2. Transparent proxying and data-fetching from OpenStreetMap data.
+
+The idea is that the model can be queried using SQLAlchemy, and
+OSMAlchemy will either satisfy the query from the database directly or
+fetch data from OpenStreetMap. That way, projects already using
+SQLAlchemy do not need another database framework to use OpenStreetMap
+data, and the necessity to keep a local copy of planet.osm is relaxed.
+
+If, for example, a node with a certain id is queried, OSMAlchemy will…
+
+-  …try to get the node from the database/ORM directly, then…
+-  …if it is available, check its caching age, and…
+
+   -  …if it is too old, refresh it from OSM, or…
+   -  …else, fetch it from OSM, and…
+
+-  …finally create a real, ORM-mapped database object.
+
+That's the rough idea, and it counts for all kinds of OSM elements and
+queries.
+
+OSMAlchemy uses Overpass to satisfy complex queries.
+
+Non-goals
+~~~~~~~~~
+
+OSMAlchemy does not aim to replace large-scale OSM data frameworks like
+PostGIS, Osmosis or whatever. In fact, in terms of performance and
+otherwise, it cannot keep up with them.
+
+If you are running a huge project that handles massive amounts of map
+data, has millions of requests or users, then OSMAlchemy is not for you
+(YMMV).
+
+OSMAlchemy fills a niche for projects that have limited resources and
+cannot handle a full copy of planet.osm and an own API backend and
+expect to handle limited amounts of map data.
+
+It might, however, be cool to use OSMAlchemy as ORM proxy with an own
+API backend. Who knows?
+
+It might, as well, turn out that OSMAlchemy is an incredibly silly idea
+under all circumstances.
+
+Usage
+-----
+
+Here are a few tiny examples of how to basically use OSMAlchemy:
+
+Installation
+~~~~~~~~~~~~
+
+OSMAlchemy can be installed just like any other standard Python package
+by one of…
+
+.. code-block:: console
+
+    # pip3 install OSMAlchemy
+    # python3 setup.py install
+
+…or what ever kind of distribution and install system you prefer.
+
+Using plain SQLAlchemy
+~~~~~~~~~~~~~~~~~~~~~~
+
+Make sure to get at least an engine from SQLAlchemy. Even better, get a
+declarative base and a scoped session:
+
+.. code-block:: python
+
+    from sqlalchemy import create_engine
+    from sqlalchemy.ext.declarative import declarative_base
+    from sqlalchemy.orm import sessionmaker, scoped_session
+
+    engine = create_engine("sqlite:////tmp/foo.db")
+    base = declarative_base(bind=engine)
+    session = scoped_session(sessionmaker(bind=engine))
+
+You can then initialise OSMAlchemy like so:
+
+.. code-block:: python
+
+    osmalchemy = OSMAlchemy((engine, base, session), overpass=True)
+
+And probably install the databases:
+
+.. code-block:: python
+
+    base.metadata.create_all()
+
+Using Flask-SQLAlchemy and Flask-Restless
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Imagine you have an SQLAlchemy object from Flask-SQLAlchemy bound to
+your Flask application. called db, and a Flask-Restless API manager as
+manager:
+
+.. code-block:: python
+
+    from osmalchemy import OSMAlchemy
+    osm = OSMAlchemy(db, overpass=True)
+    db.create_all()
+    osm.create_api(manager)
+
+You should now magically be able to query OSM via the REST API. Keep in
+mind that, with no filter provided, OSMAlchemy refuses to do automatic
+updates from Overpass. However, providing a query in the default JSON
+query way in Flask-Restless will give you live data and cache it in the
+database.
+
+Limitations
+~~~~~~~~~~~
+
+Only some basic SQL queries are supported by the online update code.
+This is because compiling SQLAlchemy's queries to OverpassQL is very
+complex. If you are very good at algorithms and building compilers, feel
+free to help us out!
+
+The following kinds of queries are fully supported:
+
+.. code-block:: python
+
+    # A node with a specific id
+    session.query(osmalchemy.node).filter_by(id=12345).one()
+
+    # All nodes within a bounding box
+    session.query(osmalchemy.node).filter(
+        and_(latitude>51.0, latitude<51.1, longitude>7.0, longitude<7.1)
+    ).all()
+
+    # All nodes having a specific tag
+    session.query(osmalchemy.node).filter(
+        osmalchemy.node.tags.any(key="name", value="Schwarzrheindorf Kirche")
+    ).all()
+
+You can go mad combining the two with and\_() and or\_(). You can also
+query for tags of ways and relations and for ways and relations by id.
+
+Not supported (yet) are queries for ways or relations by coordinates.
+You also cannot query for nodes related to a way or anything related to
+a relation - having a way or a relation, accessing it will, however,
+magically pull and update the nodes and members and add them to the
+database:
+
+.. code-block:: python
+
+    # Get all nodes that are members of a (unique) named way
+    session.query(osmalchemy.way).filter(
+        osmalchemy.way.tags.any(key="name", value="My Unique Way")
+    ).one().nodes
+
+This should, in reality, cover most use cases. If you encounter a use
+case that is not supported, please open an issue asking whether it can
+be supported (if you have an idea how it can be, please add it or even
+implement it and open a pull request).
+
+Projects using OSMAlchemy
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+OSMAlchemy was designed for use in the Veripeditus Augmented Reality
+framework.
+
+Development and standards
+-------------------------
+
+Albeit taking the above into account, OSMAlchemy is developed with
+quality and good support in mind. That means code shall be well-tested
+and well-documented.
+
+OSMAlchemy is tested against the following SQLAlchemy backends:
+
+-  SQLite
+-  PostgreSQL
+-  MySQL
+
+However, we recommend PostgreSQL. MySQL acts strangely with some data
+and is incredibly slow, and SQLite just doesn't scale too well (however,
+it is incredibly fast, in comparison).
+
+Code status
+~~~~~~~~~~~
+
+|PyPI package| |Build Status| |Code Coverage| |Scrutinizer Code Quality|
+
+Authors and credits
+-------------------
+
+:Authors:
+    Dominik George,
+    Eike Tim Jesinghaus
+
+:Credits:
+    Special thanks to Mike Bayer from SQLAlchemy for his help with
+    some SQLAlchemy bugs and pitfalls, and also some heads-up.
+
+License
+-------
+
+OSMAlchemy is licensed under the MIT license. Alternatively, you are
+free to use OSMAlchemy under Simplified BSD, The MirOS Licence, GPL-2+,
+LGPL-2.1+, AGPL-3+ or the same terms as Python itself.
+
+.. |PyPI package| image:: https://badge.fury.io/py/OSMAlchemy.svg
+   :target: https://badge.fury.io/py/OSMAlchemy
+.. |Build Status| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/build.png?b=master
+   :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/build-status/master
+.. |Code Coverage| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/coverage.png?b=master
+   :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/?branch=master
+.. |Scrutinizer Code Quality| image:: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/badges/quality-score.png?b=master
+   :target: https://scrutinizer-ci.com/g/Natureshadow/OSMAlchemy/?branch=master
diff --git a/osmalchemy/__init__.py b/osmalchemy/__init__.py
new file mode 100644
index 0000000..6e94665
--- /dev/null
+++ b/osmalchemy/__init__.py
@@ -0,0 +1,8 @@
+# ~*~~ coding: utf-8 ~*~
+
+# Monkey patch SQLAlchemy to support some query constructs
+from .util.patch import monkey_patch_sqlalchemy, monkey_patch_flask_restless
+monkey_patch_sqlalchemy()
+monkey_patch_flask_restless()
+
+from .osmalchemy import OSMAlchemy
diff --git a/osmalchemy/model.py b/osmalchemy/model.py
new file mode 100644
index 0000000..6b6e97e
--- /dev/null
+++ b/osmalchemy/model.py
@@ -0,0 +1,320 @@
+# ~*~ coding: utf-8 ~*~
+#-
+# OSMAlchemy - OpenStreetMap to SQLAlchemy bridge
+# Copyright (c) 2016 Dominik George <nik at naturalnet.de>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+# Alternatively, you are free to use OSMAlchemy under Simplified BSD, The
+# MirOS Licence, GPL-2+, LGPL-2.1+, AGPL-3+ or the same terms as Python
+# itself.
+
+""" Simple representation of OpenStreetMap's conceptual data model.
+(cf. http://wiki.openstreetmap.org/wiki/Elements)
+
+This implementation of the model assumes that only current data is used,
+not historic data.
+"""
+
+import datetime
+from sqlalchemy import (Column, ForeignKey, Integer, BigInteger, Numeric, String, Unicode,
+                        DateTime, Boolean, UniqueConstraint)
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.ext.associationproxy import association_proxy
+from sqlalchemy.ext.orderinglist import ordering_list
+from sqlalchemy.orm import relationship, backref
+from sqlalchemy.orm.collections import attribute_mapped_collection
+
+def _generate_model(oa):
+    """ Generates the data model.
+
+    The model classes are generated dynamically to allow passing in a
+    declarative base and a prefix.
+    """
+
+    class OSMTag(oa.base):
+        """ An OSM tag element.
+
+        Simple key/value pair.
+        """
+
+        # Name of the table in the database, prefix provided by user
+        __tablename__ = oa.prefix + "tags"
+
+        # The internal ID of the element, only for structural use
+        tag_id = Column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True)
+
+        # Key/value pair
+        key = Column(Unicode(256))
+        value = Column(Unicode(256))
+
+        def __init__(self, key="", value="", **kwargs):
+            """ Initialisation with two main positional arguments.
+
+            Shorthand for OSMTag(key, value)
+            """
+
+            self.key = key
+            self.value = value
+
+            # Pass rest on to default constructor
+            oa.base.__init__(self, **kwargs)
+
+    class OSMElement(oa.base):
+        """ Base class for all the conceptual OSM elements. """
+
+        # Name of the table in the database, prefix provided by user
+        __tablename__ = oa.prefix + "elements"
+
+        # The internal ID of the element, only for structural use
+        element_id = Column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True)
+
+        # Track element modification for OSMAlchemy caching
+        osmalchemy_updated = Column(DateTime, default=datetime.datetime.now,
+                                    onupdate=datetime.datetime.now)
+
+        # The type of the element, used by SQLAlchemy for polymorphism
+        type = Column(String(256))
+
+        # ID of the element in OSM, not to be confused with the primary key element_id
+        id = Column(BigInteger)
+
+        # Tags belonging to the element
+        # Accessed as a dictionary like {'name': 'value', 'name2': 'value2',…}
+        # Uses proxying across several tables to OSMTag
+        tags = association_proxy(oa.prefix+"elements_tags", "tag_value",
+                                 creator=lambda k, v: OSMElementsTags(tag=OSMTag(key=k, value=v)))
+
+        # Metadata shared by all element types
+        version = Column(Integer)
+        changeset = Column(BigInteger)
+        user = Column(Unicode(256))
+        uid = Column(BigInteger)
+        visible = Column(Boolean)
+        timestamp = Column(DateTime)
+
+        # OSM ids are unique per type
+        _u_type_id = UniqueConstraint("type", "id")
+
+        # Configure polymorphism
+        __mapper_args__ = {
+            'polymorphic_identity': 'element',
+            'polymorphic_on': type,
+            'with_polymorphic': '*'
+        }
+
+    class OSMElementsTags(oa.base):
+        """ Secondary mapping table for elements and tags """
+
+        # Name of the table in the database, prefix provided by user
+        __tablename__ = oa.prefix + "elements_tags"
+
+        # Internal ID of the mapping, only for structural use
+        map_id = Column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True)
+
+        # Foreign key columns for the element and tag of the mapping
+        element_id = Column(BigInteger().with_variant(Integer, "sqlite"),
+                            ForeignKey(oa.prefix + 'elements.element_id'))
+        tag_id = Column(BigInteger().with_variant(Integer, "sqlite"),
+                        ForeignKey(oa.prefix + 'tags.tag_id'))
+
+        # Relationship with all the tags mapped to the element
+        # The backref is the counter-part to the tags association proxy
+        # in OSMElement to form the dictionary
+        element = relationship(OSMElement, foreign_keys=[element_id],
+                               backref=backref(oa.prefix+"elements_tags",
+                                               collection_class=attribute_mapped_collection(
+                                                   "tag_key"
+                                               ), cascade="all, delete-orphan"))
+
+        # Relationship to the tag object and short-hand for its key and value
+        # for use in the association proxy
+        tag = relationship(OSMTag, foreign_keys=[tag_id])
+        tag_key = association_proxy("tag", "key")
+        tag_value = association_proxy("tag", "value")
+
+    class OSMNode(OSMElement):
+        """ An OSM node element.
+
+        A node hast a latitude and longitude, which are non-optional,
+        and a list of zero or more tags.
+        """
+
... 2333 lines suppressed ...

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



More information about the Python-modules-commits mailing list