How to order result by distance from the point in Overpass?

1.8k Views Asked by At

I using query which returns nearby streets. Is it possible to order this streets by distance from the point?

<query type="way">
    <around lat="51.15178610143037" lon="9.931640625" radius="1000"/>
    <has-kv k="highway" regv="primary|secondary|tertiary|residential"/>
</query>
<union>
    <item/>
    <recurse type="down"/>
</union>
<print/>
2

There are 2 best solutions below

0
On

Not directly within the Overpass API. You'd have to sort the streets yourself in a post-processing step.

0
On

According to documentation on OSM wiki you can use:

out qt

or in your case

<print order="quadtile"/>

described as sort by quadtile index; this is roughly geographical and significantly faster than order by ids. It's not exactly you want, but still better than sort by ids.