This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Get center point from Overpass via overpy

0

I'm trying to get the center point with Python and overpy:

api = overpy.Overpass()
result = api.query("""way(381501602);out center;""")

but unlike to Overpass Turbo, where I get the center point 49.2559306 / 8.4525152 overpy just returns all nodes:

result.nodes is empty and result.ways contains

< overpy.Way id=381501602 nodes=[2338081031, ...]>

asked 07 Oct '17, 17:19

Druzhba's gravatar image

Druzhba
150111118
accept rate: 0%


One Answer:

0

Overpass appends a center element to the way:

<?xml version="1.0" encoding="UTF-8"?> <osm version="0.6" generator="Overpass API"> <note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note> <meta osm_base="2017-10-07T18:59:02Z"/> <way id="381501602"> <center lat="49.2559306" lon="8.4525152"/> <nd ref="2338081031"/> <nd ref="2338081030"/>

You'll have to see if overpy supports this element or not. It seems to: https://python-overpy.readthedocs.io/en/latest/api.html#elements

answered 07 Oct '17, 20:08

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

edited 07 Oct '17, 20:09

Source code available on GitHub .