[Home] [Puzzles & Projects] [Delphi Techniques] [Math Topics] [Library] [Utilities]
I recently updated our Traveling Salesman Program to replace pixel city locations with more useful latitude/longitude coordinates. In the process I found myself in need of a "master" file of cities and their locations to simplify extracting a subset for map display of a subset for a particular TSP problem. (There are on the order of 50,000 US cities making it impractical to display them all.)
Searching the web for a master file did not yield any usable results, but I did find a master "zip code" file at http://federalgovernmentzipcodes.us/. One minor problem with using this file, is that the mapping is not unique. In fact the same city name may map to multiple zip codes and a single zip code can have multiple "city" names associated with it. For example, 72 different zip codes all can be referred to as Pittsburgh, many of them have alternate names. Zip code 15235 for example officially refers to Pleasant Hills and West Mifflin as well as Pittsburgh and several abbreviations of these names. My solution was to average the coordinates for all records which could officially refer to each city name and retain that one averaged record for my output file.
The program itself should be easy to use, my master file, 'free-zipcode-database-abbreviated.csv' contains only the first few fields we need from the master zip code file downloaded from the site referenced above. This is simple a space saving measure (2.5mb for the abbreviated file compared to 12.5mb for the full file). The abbreviated file is read and summarized by city at startup time. The results are listed in the a list box on the left side of the form. A city list to save may be built by clicking on city records from this list. Selected records are added to the right side list box. You may also load your own list (or a list previously built by this program). Only first two fields (Cityname and State Id) separated by commas are used from this input file. Records have latitudes and longitudes in decimal degrees added from the right side list box if a match is found. These are saved as 3rd and 4th comma separated fields if the left side list is saved.
Clicking on the right side list entry will add that entry to the left side list if it is not already there. Clicking an entry in the left side list will remove it.
Input file names are save in a an "init" file, makeCityLocation.ini and become the default names for future runs. The initial file names reflect the files included in the downloads below: 'free-zipcode-database-abbreviated.csv' and 'CityList.txt'.
Running/Exploring the Program
Copyright © 2000-2013, Gary Darby
All rights reserved.