(I edited my answer for your follow-up questions)
You have to use the order in which the node IDs are referenced by the corresponding <way>
element in the XML file. In contrast, the order in which the <nodes>
elements appear in the XML file is completely irrelevant.
Furthermore, as you already discovered, a relation can contain multiple separate ways forming a single polygon. Here, the relation doesn't necessarily has to reference the ways in the correct order. Consequently the correct order of the ways has to be determined by looking at the first and last node of the way. Consecutive ways will share the same last and first node.
For a neat sorting algorithm you can take a look at the source code of JOSM.
Alternatively you might take a look at overpass turbo which provides a GeoJSON output which Leaflet should be able to handle.
A little more digging found me the answer. Executing e.g.
vars(result.get_way(4755884))
gives the internal structure of the way object:
{'_attribute_modifiers': {'changeset': int,
'timestamp': <function overpy.Element.__init__.<locals>.<lambda>>,
'uid': int,
'version': int,
'visible': <function overpy.Element.__init__.<locals>.<lambda>>},
'_node_ids': [26229733,
291529159,
246189513,
2682629060,
291529223,
3723657411,
3723657424,
2018716449,
291530424,
2018716450,
291530803,
26229737,
1741942073,
4100724928,
4100724934],
'_result': <overpy.Result at 0x221fc5b17f0>,
'attributes': {},
'center_lat': None,
'center_lon': None,
'id': 4755884,
'tags': {'bicycle': 'yes',
'highway': 'residential',
'maxspeed': '20 mph',
'name': 'Reedley Road',
'postal_code': 'BS9',
'sidewalk': 'both'}}
I can therefore access the list of raw node IDs using e.g. result.get_way(4755884)._node_ids
.
Best Answer
Maybe you can find the solution via the is_in parameter of overpass-api?
see these postings:
http://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Query_for_areas_.28is_in.29]2
https://help.openstreetmap.org/questions/48088/what-makes-a-closed-way-show-up-as-an-enclosing-feature-with-query-features