Search code examples
matlabcoordinateselementoverpass-api

How can I search for elements within a polygon with Overpass?


I am new to Overpass API and GIS in general.

Is there an easy way to export all buildings in a specific region using coordinates to specify the polygon? I couldn't find a solution using the wiki and google so far.

I have large sets of coordinates which are determining some medium-voltage grids.

Or is there another tool I could use? I want to use the polygon- coordinates of the exported buildings in matlab.

Thanks for your help!


Solution

  • Overpass API provides the (poly: ) filter to query objects inside a given polygon. See the documentation in the wiki for details.

    Buildings in a given polygon can be queried as follows:

    way[building](poly:"50.7 7.1 50.7 7.12 50.71 7.11");
    (._;>;);
    out meta;
    

    Due to a recent memory limitation, you might have to either add a [maxsize: xxx] setting:

    [maxsize:2073741824];
    way[building](poly:"50.7 7.1 50.7 7.12 50.71 7.11");
    (._;>;);
    out;
    

    or resort to the following workaround to force another evaluation sequence:

    way(poly: "50.7 7.1 50.7 7.12 50.71 7.11");
    way._[building];
    (._;>;);
    out meta;