This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Overpass: count size of set

0

Hi I'm selecting railway=station then searching 20m around them for any building that are not train_station. If there are none then I output the railway=station entity.

How do I check if the .build set to see if it has no members? Is there even a simpler way to achieve this?

In this example:

  • Tottenham Court Road shouldn't display as it has no adjacent building=train_station.
  • Russell Square should display as it does.
  • Goodge Street should as it's both building=train_station and railway=station.

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

[bbox:{{bbox}}];
nwr[railway=station]->.TStats;
foreach .TStats
(
 way(around:20)[building];
 way._[building!=train_station]->.build;
 if (.build.count(ways) == 0) 
  (.TStats out geom;)
);

Edit: I spotted an error I my code, now rectified, but it doesn't help with the solution.

asked 26 Jun '18, 17:17

DaveF's gravatar image

DaveF
3.3k8498133
accept rate: 16%

edited 26 Jun '18, 17:49

(.TStats out geom;) will output all members of the .TStats set, so the script will currently output the whole set for each one that matches the test.

(27 Jun '18, 02:29) maxerickson

I see. So is there a way to get the individual element of .TStats being processed by the foreach loop?

(27 Jun '18, 11:33) DaveF

Yep, take a look at https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#For-each_loop_.28foreach.29 it shows how to name the loop variable.

I experimented a bit, the current test doesn't work with the variable fixed.

(27 Jun '18, 12:20) maxerickson

Note I've updated the OP routine To test, I simplified the routine a bit: http://overpass-turbo.eu/s/zSZ I've made it more verbose than it needs to be, to hopefully make it clearer. if you look on the data tab Tottenham shouldn't be displaying as the way count is 0. It seems to me the if:count(ways) line isn't filtering, but I'm unsure why. I took it from : https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_API_by_Example#Isolated_Buildings. ----- Sorry, which variable shouldn't be fixed?

(27 Jun '18, 16:54) DaveF

By variable fixed I meant I experimented with the initial script after correcting the issue with the looping variable.

(27 Jun '18, 17:14) maxerickson

Source code available on GitHub .