Search code examples
openstreetmapoverpass-api

Use polygon as search area overpass api / overpass turbo


I'm fairly new at using overpass API, I finally managed to generate a query to retrieve all nodes within an area by using overpass-turbo wizard.

Using highway=* in "Paulino Navarro" in the wizard generates me the following query.

/*
This has been generated by the overpass-turbo wizard.
The original search was:
“highway=* in "Paulino Navarro"”
*/
[out:json][timeout:25];
// fetch area “Paulino Navarro” to search in
{{geocodeArea:Paulino Navarro}}->.searchArea;
// gather results
(
  // query part for: “highway=*”
  node["highway"](area.searchArea);
  way["highway"](area.searchArea);
  relation["highway"](area.searchArea);
);
// print results
out body;
>;
out skel qt;

However, how could I use a polygon as a search area? maybe something like highway=* in poly([lat,lon],[lat,lon],...,[lat,lon]) or how can I do that on the query itself.

I don't quite understand the documentation in overpass wiki nor overpass-turbo wizard.


Solution

  • The polygon filter is explained in the Overpass QL documentation.

    Example:

    [out:xml][timeout:30];
    way[highway=primary](poly:"50.7 7.1 50.7 7.2 50.75 7.15");
    (._;>;);
    out;