0

I would like to be able to click on a building on a map and get the polygon that comprises the building at the clicked coordinate.

I looked into overpass api and tried the following:

<query type="way">
  <around lat="51.0566036" lon="13.7181033" radius="30"/>
  <has-kv k="building"/>
</query>
<union>
  <item/>
  <recurse type="down"/>
</union>
<print/>

If I choose a large radius I get too many buildings. If the radius is too small I don't get any buildings. Using bbox-query did not help.

I also tried coord-query, but I was not able to construct a meaningful query. The necessary query syntax seems to be different.

Is there a better approach at hand? Even withouth overpass, I have just to look into it.

Amelse Etomer
  • 1,253
  • 10
  • 28

3 Answers3

3

A similar requirement was discussed in this GitHub ticket. At this time, Overpass API doesn't calculate area information for buildings, which would be required for is_into work. However, you could set up your own Overpass API instance and adjust the area creation rules to also include buildings. For a small area this should be even feasible on your local machine.

Please also check all links in the GitHub ticket I mentioned. It includes a number of additional pointers which may be relevant to your problem.

Caveat: The performance and space implications of calculating areas for buildings on a world wide scale are unknown, respectively not fully tested yet.

mmd
  • 3,423
  • 1
  • 16
  • 23
  • Thanks for elucidating! At the start I don't want to set up my own instance. I've described what I'll do first in my comment to MaM's answer. – Amelse Etomer Jul 21 '14 at 10:58
3

There is a Python solution using gis_geometrics [1] and overpy. This Python program finds the building at LAT,LON. Put it in the same directory as gis_geometrics.py:

import overpy
from gis_geometrics import OSM_Polygon, Overpass

api = overpy.Overpass()
building = OSM_Polygon.getPolygonByCoords(api, LAT, LON)
if building is None: print("No building found.")
else: print(building.wayId)

With the way id you can make an overpass request to find the polygon coordinates.

[1] https://github.com/timojuez/home/blob/master/mylib/gis_geometrics.py

Timo Richter
  • 165
  • 1
  • 3
2

What you try to realize is a 'reverse geocoding'. To avoid the mentioned problems (AFAIK) usual implementations use an arbitary radius and then test the resulting shapes once more if they contain the desired position.

MaM
  • 2,043
  • 10
  • 20
  • Thanks! I'll try the following: Testing with a small radius (50m) and if it fails using a large one (500m). After a few queries I'll reassess and see if I could optimise by using a different radius to find a good ratio between number of api calls to transfered data. – Amelse Etomer Jul 21 '14 at 10:56