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.6k355267
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 ♦
31.6k19287440
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
Your answer
toggle preview

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:

×355
×6
×2

question asked: 02 Feb '16, 07:30

question was seen: 1,692 times

last updated: 03 Feb '16, 09:35

powered by OSQA