Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example.rst #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/source/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,52 @@ Line 20-21:

Line 22-25:
The resolved nodes have been added to the result set and are available to be used again later.


Relations
---------

Get all ways of a relation
~~~~~~~~~~~~~~~~~~~~~~~~~~
In this example we query a relation with the id 2686919 and get its constituting ways. Then we resolve its nodes.

.. code-block:: text
:linenos:

rel(id:2686919);
out;

**Use OverPy:**

.. code-block:: pycon
:linenos:

>>> import overpy
>>> api = overpy.Overpass()
>>> result = api.query("""rel(id:2686919;out;""")
>>> result.relations
[<overpy.Relation id=2686919>]
>>> relation = result.relations[0]
>>> relation.tags
{'name': 'Fardumeträsk', 'natural': 'water', 'source:lake': 'Review by So9q using LM Topographic Map', 'type': 'multipolygon', 'water': 'lake'}
>>> relation.members
[<overpy.RelationWay ref=199775464 role=outer>, <overpy.RelationWay ref=199775467 role=inner>]
>>> relation.members[0]
<overpy.RelationWay ref=199775464 role=outer>
>>> way = relation.members[0].resolve(True)
>>> nodes = way.get_nodes(True)

Line 3:
We query the Overpass using the id of the relation.

Line 7:
It turns out to be a Lake. It is a multipolygon relation.

Line 9:
The members constituting this relation are 2 ways. One is the outer border, the other the inner (there is a island on this lake).

Line 13:
The object is of type RelationWay. To get a way object we need to resolve it. The parameter True tells the api to download the missing data.

Line 14:
We download the ways nodes, like in the example above.