0

For example one may wish to search for roads under construction, with known opening date that is in past (in other words - one of many possible indicators that OSM data is outdated).

[timeout:180]; ( way[highway=construction][opening_date](if:date(t[opening_date])<date("2018-2-6"))({{bbox}}); ); out body geom qt;

query is doing it (for query on overpass see http://overpass-turbo.eu/s/vUH ), but one needs to keep date updated.

How one may use current date directly?

2

One may use {{date}} documented at https://wiki.openstreetmap.org/wiki/Overpass_turbo/Extended_Overpass_Turbo_Queries#Available_Shortcuts

Query would be

[timeout:180][bbox:{{bbox}}];
way[highway=construction][opening_date]
    (if:is_date(t["opening_date"]) && 
        date(t["opening_date"])<date("{{date:0 days}}"));
out geom;

overpass link: http://overpass-turbo.eu/s/w03

Note that it allows to use also other units to specify date in past: {{date:1 day}} is replaced with the timestamp 24 hours ago. Allowed time units are: second(s), minute(s), hour(s), day(s), week(s), month(s) and year(s).

  • Note: once github.com/tyrasd/overpass-turbo/commit/… will be released in that case one will be able to use just {{date}} instead of {{date:0 days}} – Mateusz Konieczny Feb 6 '18 at 20:45
  • Corrections: Next version 0.7.55 requires t["opening_date"] instead of t[opening_date] to avoid a syntax error. Also added sanity check, if t["opening_date"] is really a valid date. – mmd Feb 7 '18 at 16:12
  • @mmd How behavior is changed with sanity check? I expected that date will return NaN for invalid dates and comparison with NaN will always be false. – Mateusz Konieczny Feb 8 '18 at 12:18
  • Overpass QL is not Javascript, date comparisons are internally based on string comparisons, an invalid date is translated to a string "NaD". If you change your query a bit to check for future dates, your previous approach would hurt you badly: overpass-turbo.eu/s/w09 – mmd Feb 8 '18 at 12:48
  • 1
    Even though it doesn't make a difference right now, you're effectively relying on (undocumented) implementation details, which could change in the future. – mmd Feb 8 '18 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.