Get the municipality (admin_level=8) for a list of nodes (place=village)

Hello!

I have the following query which returns every place=village in South Tyrol:

[out:csv(name,"name:de","name:it","municipality","municipality:it",::lat,::lon;true;";")]; {{geocodeArea:"South Tyrol"}}; node[place~"village"](area); out body;

How can i get the name of the municipality the nodes are in?
For example: the village “Lengstein” (Node: ‪Lengstein - Longostagno‬ (‪1435595862‬) | OpenStreetMap) is in the municipality “Ritten” (Relation: ‪Ritten - Renon‬ (‪47233‬) | OpenStreetMap) which is admin_level 8.

I would like to get the name of the municipality where the node (place=village) is in.

Is this possible?

Thank you for your time and responses.
Have a great day!
Lorenz

I’m not an expert, I’m playing with something like this, it seems to work but it’s better to wait for more opinions from those who really know about it :sweat_smile:

[out:csv(municipality_name,village_name; true; ";")];
area["ISO3166-2"="IT-BZ"];
node[place=village](area)->.villages;
foreach .villages -> .village (
  .village;
  is_in;
  area._[admin_level=8]->.municipality;
  make name_info
    village_name = village.set(t["name"]),
    municipality_name = municipality.set(t["name"]);
  out;
);

Well that worked quite well, thanks!
However, I am not able to retrieve latitude and longitude information. This is what I tried:

[out:csv(municipality_name,village_name,village_lat,vlilage_lon; true; ";")];
area["ISO3166-2"="IT-BZ"];
node[place=village](area)->.villages;
foreach .villages -> .village (
  .village;
  is_in;
  area._[admin_level=8]->.municipality;
  make name_info
    village_name = village.set(t["name"]),
    village_lat = village.set(t["lat"]),
    village_lon = village.set(t["lon"]),
    municipality_name = municipality.set(t["name"]);
  out;

and this is the result

municipality_name;village_name;village_lat;vlilage_lon
Stilfs - Stelvio;Trafoi;;
Stilfs - Stelvio;Sulden - Solda;;
Martell - Martello;Thal;;

Thanks a lot!

:thinking: Test this

[out:csv(municipality_name,village_name,village_lat,village_lon; true; ";")];
area["ISO3166-2"="IT-BZ"];
node[place=village](area)->.villages;
foreach .villages -> .village (
  .village;
  is_in;
  area._[admin_level=8]->.municipality;
  make name_info
    village_name = village.set(t["name"]),
    village_lat = village.set(lat()),
    village_lon = village.set(lon()),
    municipality_name = municipality.set(t["name"]);
  out;

That worked how i wanted it to! Thanks a lot!!