Overpass API – Retrieve Buildings in Areas with Specific Landuse using Overpass API

overpass-apioverpass-turbo

I get regions with landuse=industrial with this query

[out:json];
area["name"="my_area"]->.searchArea;
(
  way["landuse"="industrial"](area.searchArea);
  relation["landuse"="industrial"](area.searchArea);
);
out body;
>;
out skel qt;

now i am trying to get the building in that area. (all buildings no matter the tags)

[out:json];
area["name"="my_area"]->.searchArea;
(
  way["landuse"="industrial"](area.searchArea)["building"];
  relation["landuse"="industrial"](area.searchArea)["building"];
);
out body;
>;
out skel qt;

but this does only return buildings that have the tag "landuse"="industrial"?
I want all buildings with the general area has "landuse"="industrial".
(buildings can have any tags)

Best Answer

The correct solution is a bit more involved, because you need to convert relations explicitly into an internal representation called area (this happens implicitly for ways).

// fetch both ways and relations with landuse=industrial in your current bbox
wr["landuse"="industrial"]({{bbox}});

// visualize landuse=industrial ways and relations for debugging purposes
out geom;

// explicitly convert relation to area, also include ways in search area
map_to_area -> .searchArea;

// query for buildings inside search area
nwr["building"](area.searchArea);

// and print results
out body;
>;
out skel qt;

Note: the query uses the shorter version "wr" for ways & relations, as well as "nwr" for nodes, ways & relations to avoid some extra typing.

Check out this overpass turbo link for an example: https://overpass-turbo.eu/s/1tzE

Sample screenshot highlighting buildings both inside landuse=industrial ways and relations:

enter image description here

Related Question