Commit 5efa4528 authored by David Douard's avatar David Douard
Browse files

[doc] improve a bit the README file to give query examples

parent fce7c575bde9
......@@ -23,12 +23,17 @@ It introduces one new type when defining attributes in the data model schema:
* ``coord_dimension``. The number of dimensions used by geometries. Defaults
to 2.
* a ``Geography`` type (see the description_).
.. _description: https://postgis.net/docs/using_postgis_dbmanagement.html#PostGIS_Geography
Then you can also use geometric functions like ``ST_INTERSECTS``, ``ST_WITHIN``
or ``ST_UNION`` to work with this new type.
See `Postgis manual`_ for reference documentation about Postgis.
.. _Postgis manual: http://postgis.net/docs/manual-2.0/
.. _Postgis manual: http://postgis.net/docs/
Example
......@@ -41,3 +46,21 @@ In ``schema.py``, one can declare a ``City`` entity like the following.
class City(EntityType):
name = String(required=True)
geometry = Geometry(geom_type='POLYGON', srid=4326)
You may then make queries like:
.. code-block:: python
# get all cities in a given bounding box
rql('City C WHERE C geometry G HAVING(ST_WITHIN(G, ST_MAKEENVELOPE('
'%(left)s, %(bottom)s, %(right)s, %(top)s, 4326)) = TRUE)',
{'left': 2.2,
'right': 2.6,
'top': 49,
'bottom': 48})
# get all cities at a given distance from a point, sorted by distance
rql('Any C, ST_DISTANCE(G, ST_SETSRID(ST_MAKEPOINT(2.2, 48.4), 4326)) '
'ORDERBY 5 WHERE '
'C geometry G HAVING ('
' ST_DWITHIN(G, ST_SETSRID(ST_MAKEPOINT(2.2, 48.4), 4326), 0.1) = TRUE)')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment