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

Is it possible to get all cities of a country from OSM using a web service? I need this in order to use in a combo box (fill the combo box with city names when user selects a country) Thanks in advance.

asked 05 May '12, 10:02

sewdil's gravatar image

sewdil
6113
accept rate: 0%


No. OpenStreetMap has the raw data from which you could extract such a list yourself, but there's no ready-made web service that does that for you.

It is possible to go a little way in your direction with the Overpass API; this allows you to ask for "all objects tagged place=city within the boundary described by the OpenStreetMap relation with the ID x". This requires that you first find out which relation you are interested in.

Say you wanted to find all cities in Moldova. Google can be used to find out that the relation id you are looking for is 58974. Add 3600000000 to that number and use the following Overpass query:

<query type="node">
  <has-kv k="place" v="city"/>
  <area-query ref="3600058974"/>
</query>
<print mode="body"/>

This returns the OSM XML for all city nodes in Moldova.

However, requesting such information live from the database every time you need it is a terrible waste of time; you really want to compute such a list ahead of time and then use that.

permanent link

answered 05 May '12, 11:17

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

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:

×26

question asked: 05 May '12, 10:02

question was seen: 8,036 times

last updated: 05 May '12, 11:17

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