1

I need help understanding the correct use of foreach and sum(length()) in an Overpass query. I've written a query for extracting all relations and ways of a given type within a bounding box, and then, if it finds any, filtering out the ones that don't have ways with highway=footway tags within them (it also extracts parks, but maybe not relevant to the question, apart from explaining why I've named all the sets).

way(8.97266,-79.58028,9.01195,-79.53501)[leisure=park][natural!=wood]->.parks;
(
  rel(8.97266,-79.58028,9.01195,-79.53501)[natural=wood];
  way(8.97266,-79.58028,9.01195,-79.53501)[natural=wood];
)->.tempOther;
if (tempOther.count(ways) != 0)
{
  .tempOther map_to_area->.aOther;
  way(area.aOther)[highway=footway]->.fOther;
  foreach {
    (.fOther; .fOther >;);
    is_in;
    (
      rel(pivot)[natural=wood]->.rOther;
      way(pivot)[natural=wood]->.wOther;
    )->.other;
  }
}
(
  .parks;
  .other;
 );
out geom;

I would further like to exclude relations and ways that only contain short footways, for example, less than 1000 m. I've tried using if (sum(length()) > 1000) {...} (and tried fOther.sum(length())) within the foreach loop, but these fail to do what I think they should do... calculate the length of each individual way (as far as I can tell, it's calculating the total length of all the ways in the set).

Having read the Overpass Language reference and guide, I'm probably still misunderstanding how foreach and/or sum(length()) work.

How do I use them correctly in this situation?

1

I think I found the solution thanks to the answer to another question here: https://help.openstreetmap.org/questions/62730/overpass-query-to-find-multipolygon-relations-with-just-one-member

In my case, I added an if filter and length() evaluator to the line of code above my foreach loop. So way(area.aOther)[highway=footway]->.fOther; becomes

way(area.aOther)[highway=footway](if: length() > 1000 )->.fOther;

and I get what I needed (i.e. relations and ways containing footways longer than x meters).

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.