Extracting cities list from a bounding polygon

Hello. I’m new to OSM. I need a multi-lingual world cities dataset with countries and regions. I searched on the Internet and found nothing suitable. However OSM seem to contain enough data.

I downloaded full OSM data from here in pbf format. Then I used osmium-tool to estract cities ($ osmium tags-filter -O -o test.xml planet-230206.osm.pbf n/place=city). It worked but the output seem to contain around 11000 nodes. Is that normal? Also the accepted answer to this question tells that cities may be modelled not only as nodes. Does that meen that I missed some cities with my method of extracting them?

Another question that I have is how to get the country and the region of a city? Some cities contain tag “is_in:country” or “is_in:country_code”, but some don’t. It seems that the only way to actually check the country and the region of any level of any city is to first extract bounding polygon and then check if the city is in that polygon or not. I found this program that extracts polygons pretty well. Then I have 2 options - to extract the map contained in each polygon from the map and then extract cities from it or to first extract all the cities and then for each city find the polygon that containt that city. First option seems to be very slow for a large amount of polygons. So I need to check if a polygon contains a city. What is the easiest way to do that? I can even make my own script that performs that check. But I need to know some details about bounding polygons. How does the connection of 2 nodes work? Is it a straight line on the globe as a sphere, or is it a straight line in flat 2d lat-lon coorginates? If the second case it true, then how are the connections from <180 to >-180 lon modelled?

4 posts - 3 participants

Read full topic


Ce sujet de discussion accompagne la publication sur https://community.openstreetmap.org/t/extracting-cities-list-from-a-bounding-polygon/9180