0

I'm trying to combine 2 features of the OSM overpass flavor : if statement + regular expression.
Example :

[out:json][timeout:50];

area["name"="Paris"][admin_level=8]->.searchArea;;

(
  node(area.searchArea)
    ["addr:housenumber"]["addr:postcode"]
    [!"contact:email"]
    [!"contact:phone"]
    [!"phone"]
    [!"email"]
    [!"ref:FR:SIRET"]
    [!"landuse"]
    [!"amenity"]
    [!"leisure"]
    [!"website"]
    [!"shop"]
    [!"brand"]
    [!"office"]
    [!"tourism"]
    [!"operator"]
// Below is the problem I struggle with
    ((if: t["building"] && t["building"]~"dormitory|apartments|yes|residential|house");
)->.filtered;

(
  .filtered;
  >;  
);
out body;

The idea is : If the key building existe it should has the value dormitory or apartments or yes or residential or house. If the key doesn't existe we add the node to the result.

If any one can tell me if 1st it's possible, and if possible tell me how to do it / correct my example. thx :)

I tried to find examples in the official doc but not that much result. https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_API_by_Example https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Value_matches_regular_expression_(~,_!~)

Tried some auto correct with AI but not much result too.

1 Answer 1

1

You cannot use (if:...) in this case, since it does not support regular expression. Instead, create an intermediate result .step1 without checking the building tag, then use this intermediate result to further filter for nodes without building or only the given list of building tags. Combine both results to the final result.

[out:json][timeout:50];

area["name"="Paris"][admin_level=8]->.searchArea;


node(area.searchArea)
    ["addr:housenumber"]
    ["addr:postcode"]
    [!"contact:email"]
    [!"contact:phone"]
    [!"phone"]
    [!"email"]
    [!"ref:FR:SIRET"]
    [!"landuse"]
    [!"amenity"]
    [!"leisure"]
    [!"website"]
    [!"shop"]
    [!"brand"]
    [!"office"]
    [!"tourism"]
    [!"operator"]->.step1;

(
 node.step1[!building];   // previous result without building
 node.step1["building"~"^(dormitory|apartments|yes|residential|house)$"];  // previous result matching given list of building=... tags
);

out body;

By the way, you need to fine tune area["name"="Paris"][admin_level=8] a bit, since it finds some places in the US. I have left that as an exercise for the reader.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.