[GIS] query school elements using Overpass Turbo

openstreetmapoverpass-api

I'm looking for the correct way to query point/polygon elements that are

  1. name=* but neither tagged as amenity=school and building=school tags; and
  2. elements tagged as building=school but without a parent polygon that are tagged as amenity=school (to mark the school grounds)

I expect to see a list of nodes or ways that are tagged as building=school, but are not inside a closed way tagged as amenity=school. The purpose of the query is for Q&A of school-related elements in our region.

The following is the code I use to get the initial elements I'm interested in:

[out:json]
[timeout:25];
(
  node
    [name ~ "^.school.*$",i]["building"="school"]["amenity"!~"."]({{bbox}});
  way
[name ~ "^.school.*$",i]["building"="school"]["amenity"!~"."]({{bbox}});
);
//
// how to get parent poly for each resulting element?
//
// print results:
out body; 
>; 
out skel qt;

Best Answer

At the moment the closest possible approach is the following. It will return a number of false positives, because Overpass API doesn't have any area for ways with amenity=school, lacking a name=* tag.

[out:json]
[timeout:25];

// Retrieve (surrounding) ways with amenity=school
way({{bbox}})[amenity=school];

// convert ways to area for later area query
map_to_area ->.area;

(
  // Determine difference of all school buildings in bbox
  // minus those inside the closed way with an amenity=school tag

  // All nodes+ways with building=school and no amenity=* tag in bbox
  (
    node ["building"="school"]["amenity"!~"."]({{bbox}});
    way  ["building"="school"]["amenity"!~"."]({{bbox}});
  );
- // except for
  (
    // All nodes+ways with building=school and no amenity=* tag in area
    node ["building"="school"]["amenity"!~"."](area.area);
    way  ["building"="school"]["amenity"!~"."](area.area);    
  );
);

out geom;

Try it in overpass turbo: http://overpass-turbo.eu/s/der