We can formulate the answer in different ways:
Option 1:
Basically, you want to remove those amenity=embassy
from your current result list, which have a diplomatic
value that is not embassy (assuming they have a diplomatic
tag at all).
For this purpose, I used the -
(difference) operator to reduce the current result set for each node, way and relation:
[out:json];
(
( node[amenity=embassy]; - node[amenity=embassy][diplomatic][diplomatic!=embassy]; );
( way[amenity=embassy]; - way[amenity=embassy][diplomatic][diplomatic!=embassy]; );
( rel[amenity=embassy]; - rel[amenity=embassy][diplomatic][diplomatic!=embassy]; );
);
out tags;
overpass turbo link: http://overpass-turbo.eu/s/mXx
Option 2:
This alternative approach effectively returns the same result, but may be a bit easier to understand. In the following query, we create a union of
- all elements with
amenity=embassy
, but no diplomatic
tag, and
- all elements with
amenity=embassy
and diplomatic=embassy
[out:json];
(
node[amenity=embassy][!diplomatic];
node[amenity=embassy][diplomatic=embassy];
way[amenity=embassy][!diplomatic];
way[amenity=embassy][diplomatic=embassy];
rel[amenity=embassy][!diplomatic];
rel[amenity=embassy][diplomatic=embassy];
);
out tags;
overpass turbo link: http://overpass-turbo.eu/s/mY8
Option 3:
Since version 0.7.54 (released March 2017), there's a new option to specify an (if: ...)
filter, which finally supports boolean expressions. The query above can be written in the following way:
is_tag
checks, if a specific tag exists
t["diplomatic"]
returns the value of a diplomatic
tag.
[out:json];
(
node[amenity=embassy]
(if:!is_tag("diplomatic") ||
(is_tag("diplomatic") && t["diplomatic"] == "embassy"));
way[amenity=embassy]
(if:!is_tag("diplomatic") ||
(is_tag("diplomatic") && t["diplomatic"] == "embassy"));
rel[amenity=embassy]
(if:!is_tag("diplomatic") ||
(is_tag("diplomatic") && t["diplomatic"] == "embassy"));
);
out tags;
overpass turbo link: http://overpass-turbo.eu/s/nr6
Option 4:
You can also try the overpass turbo wizard, if you don't want to fiddle around with those details.
In overpass turbo wizard, you can easily create the query mentioned in Option 2 above using the following expression:
(amenity=embassy and diplomatic!=*) or (amenity=embassy and diplomatic=embassy) global
Now, that's something easily digestible at last.