NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I am looking district names of India with state names as CSV format. I tried to write an overpass query but it is not working. Please let me know what I am doing wrong. Is there any other simple query also. I am looking only from Overpass API not from any other data provider.

[out:csv(::type,::id,admin_level,name,"name:en","country","admin_level_4_name")];

rel["name:en"="India"]->.rel;
map_to_area->.a;

(
    rel[admin_level=4](area.a)->.admin_level_4;
    rel[admin_level=5](area.a)->.admin_level_5;
    foreach.admin_level_5(
        out center ->.ctr;
        .ctr is_in->.admin_level_4_relation;
        .admin_level_5 set admin_level_4_name = .admin_level_4_relation["name"];
        out;
    );
);

out;

Update 1:

I am adding here the overpass-turbo error:

An error occurred during the execution of the overpass query! This is what overpass API returned:

Error: line 10: parse error: Invalid parameter for print: "->"
Error: line 10: parse error: Invalid parameter for print: "."
Error: line 10: parse error: Invalid parameter for print: "ctr"
Error: line 12: parse error: ';' expected - 'set' found.

Link to overpass-turbo for this routine.

Update 2:

As per DaveF suggestions here is the modified the query. Now not able to make out how to set admin_level 4 names to admin_level 5.

[out:csv(::type,::id,admin_level,name,"name:en","country","admin_level_4_name")];
rel["name:en"="India"];
map_to_area->.a;
(
    rel[admin_level=4](area.a)->.admin_level_4;
    rel[admin_level=5](area.a)->.admin_level_5;
    foreach.admin_level_5(
        out center;
        is_in->.admin_level_4_relation;
        // not able to make out how to set level 4 name to level 5 relation
        convert rel ::=::; 
        out;
    );
 );

Overpass turbo link for above query

asked 25 Oct '23, 08:32

Gagan's gravatar image

Gagan
3053515
accept rate: 14%

edited 26 Oct '23, 17:59

It seems inconceivable you got to this stage by building the routine step by step. Start with the basics. Tip: you don't need to put every output into a named set. Try passing level 5 to the foreach

(25 Oct '23, 16:07) DaveF

@Davef I have added the overpass-turbo error also. I suppose I am looping through the admin_level_5 only or is this not the correct way to loop?

(26 Oct '23, 11:32) Gagan

Could you provide urls to an example of what your searching for? Both the district & state.

(26 Oct '23, 14:48) DaveF

Here are URLs for India's states admin_level 4 and districts admin_level 5.

(26 Oct '23, 18:02) Gagan

I think this query would help me. This is based on this example

(26 Oct '23, 18:26) Gagan

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:

×483

question asked: 25 Oct '23, 08:32

question was seen: 721 times

last updated: 26 Oct '23, 18:26

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum