Dear All,

This is with reference to the explanation of foreach loop in Overpass QL on the following page: query about foreach loop

Query 1:

Inside foreach loop, does ._ refer to one item in the set _ in the global namespace?

For example in this snippet:

way[name="Foo"];
  foreach(
    (
      ._;
      >;
    );
    out;
  );

Here way[name="Foo"]; will put every way with the name ="Foo" in the default set _ . Then foreach will loop over each way in _ ( the global default set) and at each iteration of the foreach loop ._ (inside the foreach loop) refers to ONE way with the name ="Foo" ie ONE way in the global default set.It is taking the union of that ONE way with the nodes constituting that particular way.

Whereas in the following code:

way[name="Foo"];
(._;>;);
out;

Out here ._ is the set containing ALL the ways with name="Foo".

Do I understand correctly? The meaning of ._ is different when it is within the foreach loop and when it is outside the foreach loop. Is that correct? Its something like a global vs a local variable.

Query 2: In this snippet :

way[name="Foo"];
  foreach(
    (
      ._;
      >;
    );
    out;
  );

The foreach will loop over the global _ and put each way in the global _ in _ (which is local to the foreach) and place the result of (union of local _ and it's nodes ) (._ ;>;); in _ which is local to the foreach and is NOT the global default set. The out will refer to this local _ and print out the contents of the local _ . Is this correct?

Query 3:

It says that the following snippet of code (from here, once again link:query about foreach loop):-

way[name="Foo"];
  foreach(
    (
      ._;
      >;
    );
    out;
  );

will do the following:

For each way that has a name tag with value "Foo", this prints the nodes that belong to this way immediately followed by the way itself.

I think the order is the other way round. It seems to me that it will first print each way with the name tag with value Foo and then print the nodes that belong to this way. Reason : inside the union in foreach loop we have (._;>;); which FIRST has the way and THEN the nodes and not the other way round. Have I misunderstood how this works?

asked 08 Feb, 10:43

ashimkapoor's gravatar image

ashimkapoor
21112
accept rate: 0%

edited 08 Feb, 10:48

scai's gravatar image

scai ♦
30.3k17271423

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×39
×2

question asked: 08 Feb, 10:43

question was seen: 360 times

last updated: 08 Feb, 10:48

powered by OSQA