What I'm trying to achieve

I want to enter a US city/state or zip code value. Then enter a radius (ex: 30 - would stand for 30 miles). Then I enter a minimum population (ex: 100000 - would tell the program logic to only look for cities with populations greater than or equal to 100000). The program returns the names of cities within the radius that has populations greater than or equal to the minimum population.

I don't care about super-precise numbers. For example, if a major city barely touches the outside radius, it still counts so I want to include that city's entire population (even though it's only perhaps a small sliver of the actual population) in the output.

My Question

Is there an open-source Python software or solution out there that would allow me to achieve this? If yes, what do you recommend?

What I'm considering

  • Google geolocation but don't know if it's possible to do what I'm trying to do
  • Some Python radius software package I don't know about
  • Utilizing a giant database lookup table or an API but don't know which route is best from a strategic standpoint?
  • 4
    Do you have access to the data, like where cities are located, population? If so easiest would be Postgis and one SQL Query
    – Benjamin
    Nov 30, 2014 at 16:27

1 Answer 1


There may have commercial api for achieving this, but it will be very hard to find similar open-source software; it requires a database to support the software. If you'd like to make in-house, you may consider:

  1. download Gazetteer file from census - https://www.census.gov/geo/maps-data/data/gazetteer2010.html note that you just need the "Place" file. This file has all data (city name, population, city center lat/lon position, etc.) you need to make your own implementation. Also note that this file include city, town, village, etc. you may want to filter out city if that is the only place you are looking for.

  2. load the file into mysql, or sql server. the databases have built in function to query geo object by distance, the query looks like:

select all cities from table where Distance (a lat/lon point, city's center lat/lon) < given number and population > a given number.

  1. there will have a question on how to do the mapping between mile and lat/lon, which may be a bit tricky. You can reference this page: http://en.wikipedia.org/wiki/Latitude.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.