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

I'm in a process of making a game based on OSM data. I will have the player starting in a random city.

I have something that is kinda working. It is not producing a result every time, it is slow, and possibly stressful for the server:

node["place"~"village|town|city"] (around: 100000, -32.950,23.325); out 1;

I am generating a random coordinates and search for any node with place=village|town|city tag within 100 km. The problem is that some of the random coordinates appear in the ocean or in deserts where there are no cities in that radius. I tried increasing it, but the query is getting even slower (expected) and I'm not sure if it is not bad for the Overpass server.

Can you see any way to improve this query? Can you suggest entirely different method of finding a random city?

asked 02 Feb '16, 07:30

ivanatora's gravatar image

ivanatora
2.7k355568
accept rate: 7%

edited 02 Feb '16, 07:50


How about retrieving all cities of the world once, storing them in a list and choosing a random list element every time you need it? This seems to be a better approach since there isn't a new city appearing every 5 minutes.

permanent link

answered 03 Feb '16, 08:14

scai's gravatar image

scai ♦
33.3k21309459
accept rate: 23%

1

This might be getting me to some place. I managed to filter world cities based on population between 100000 - 399999 and it seems there are only 800 cities matching this criteria. I did not mean to use the pop filter in the game, but it is okay way to reduce the size of the list that will be kept locally. http://overpass-turbo.eu/s/e8c

(02 Feb '16, 08:32) ivanatora

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
×7
×4

question asked: 02 Feb '16, 07:30

question was seen: 3,474 times

last updated: 03 Feb '16, 09:35

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