Search code examples
overpass-api

overpass-api: regex on keys


According to http://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL queries can use regular expressions on both the values and the keys. While I have no trouble using regex on the values, I'm having a problem with the keys.

The example on the wiki referenced above says (among other examples):

/* finds addr:* tags with value exactly "Foo" */
node[~"^addr:.*$"~"^Foo$"];    

So, that's an example of using regex on the keys and the values.

What I am interested in is the name key. Specifically the name:en key. There are a couple problems with searching by name. Not all names are in English, and for those nodes/way/relations whose names are not in English, there is no guarantee there will be a name:en tag with an English version of the name.

In general, there is no way to know in advance if the name will be in English or that there is a name:en tag. If you only ask for name or name:en, you run the risk of finding no hit. (Of course, searching for both is no guarantee of success, either.)

I have a case where I know name fails, but name:en succeeds. That is my test case. I can query the overpass-api.de/api/interpreter using this:

[out:json][timeout:25][bbox:33.465530,36.156006,33.608615,36.574516];

(
  node[name~"duma",i][place];
  way[name~"duma",i][place];
  >;
  relation[name~"duma",i][place];
  node["name:en"~"duma",i][place];
  way["name:en"~"duma",i][place];
  >;relation["name:en"~"duma",i][place];
);

out center;

see it on overpass and it works fine ("duma" is not found through name, but it is found with name:en), but I find it lengthy and somewhat repetitive.

I would like to use a regular expression involving the name and name:en tags, but either the server does not understand the query or I simply am using an incorrect regex.

Using the example shown in the wiki: node[~"^addr:.*$"~"^Foo$"] I have tried:

[~"name|name:en"~"duma",i]  
[~"name.*"~"duma",i]  
[~"^name.*$"~"duma",i]  

and several others. I even mimicked the example with [~"^name:.*"~"duma",i] just to see if anything would be returned.

Does overpass-api.de recognize regular expressions on the keys or do I just have the regex wrong? I don't get an error from overpass-api.de, just the coordinates of the bbox and an empty result. It's usually very strict about reacting to a poortly formatted query. Thanks in advance.


Solution

  • That's really a bug in the Overpass API implementation concerning case-insensitive key regex matching, see this Github ticket for details.

    For the time being, you can already test the patch on the development box:

    http://overpass-turbo.eu/s/b1l

    BTW: If you don't need case-insensitive regexp matching, this should already work on overpass-api.de as of today.