Get elements with same value on other tags

Hi,

I have a question related to using Overpass.

With which query I can get elements where a value of a specific tag (e.g. name) appears on other tags of the same element?

Overpass API/Overpass API by Example - OpenStreetMap Wiki (Change != to == )

1 Like

Also one thing in addition. How this can be combined with area queries (using {{geocodeArea}} and area.*)?

{{geocodeArea:Dublin}}->.ar;
nwr(area.ar)[name]["name:ga"](if: t["name"] == t["name:ga"]);

I couldn’t get this to work somehow…
I think I’ll tell what I’m trying to do. Probably should have told about this at first hand :smile:

I’m trying to find relations in a specific area that are of type destination_sign or destinationsign, and have tags (in this case keys label, note and name) with values matching the value of the destination tag.

Here’s my code:

[out:xml][timeout:90];
{{geocodeArea:Pääkaupunkiseutu}}->.searchArea;
(
  relation(area.searchArea)["type"="destination_sign"](if: (t["destination"] == t["label"]) || (t["destination"] == t["name"]) || (t["destination"] == t["note"]));
  relation(area.searchArea)["type"="destinationsign"](if: (t["destination"] == t["label"]) || (t["destination"] == t["name"]) || (t["destination"] == t["note"]));
);
(._;>;);
out meta;

I don’t know what steps you took before this point, but it looks like you may be trying to achieve everything at once rather than build up from a simpler query.

For example, if I focus only on relations of a single type where the name tag matches the destination tag, I think this works:

[out:xml][timeout:90];
{{geocodeArea:Pääkaupunkiseutu}}->.searchArea;
(
  relation(area.searchArea)["type"="destination_sign"]["destination"]["name"](if: (t["destination"] == t["name"]));
);
out geom;

This returns a small number of relations like this one, which I think matches what you are looking for. If you can confirm this is a correct subset of the results you want, you can expand the query to cover other combinations.

(I’m not an expert with this type of code, but I suspect an issue with your query is that it is not reliable when not all the fields you are comparing are present. Note that my example first checks if the name field exists).

In what way?
I ran it. It returned over 11000 objects which appear at a glance to be the desired relations (and nodes as your using (._;>;);)

1 Like

I tried doing this first. Didn’t get anything for some reason (I used JOSM). Data is output on overpass turbo though. I then imported it to JOSM. I’m still also getting relations that don’t meet what I’m expecting (when keys destination = label, for instance).

Can you give an example of a relation you are getting that you shouldn’t be getting, along with the exact query you are currently using?

1 Like

I don’t remember what I was doing then, but now I don’t get anything on overpass turbo. I used this snippet:

[out:xml][timeout:90];
{{geocodeArea:Pääkaupunkiseutu}}->.searchArea;
(
  relation(area.searchArea)["type"="destination_sign"]["destination"]["note"](if: (t["destination"] == t["note"]));
);
out meta;

I remember there is also relations with keys destination = note.

I can only find two relations in the search area with both destination and note fields populated:

As you can see, neither of these has destination exactly the same as note.

So maybe it is correct that nothing is returned for this combination?

1 Like

That’s odd. Have to look more at some point again.

Yep, it seems like it. There’s differing combinations of tags on the relations in general.

Thanks everyone for your help!