views:

861

answers:

8

I find that I always find it useful to have a list of all Countries and their country codes. If someone provided it in multiple formats (eg: SQL, DDL, Xml, CSV, JSON, YAML...).

I've found sites that attempt to sell a list of countries but that seems crazy to me. Is there an open source project that I'm overlooking? If there isn't does anyone else see any usefulness of starting a project that maintains a list of coutries and even something that attempts a region hierarchy?

There have been times where I have been wanting to retrieve the top 50 largest cities in a province located in Canada for example.

Ooh, maybe this could be a handy "cloud" computing service.

Thanks, I just want to make sure that I'm not over analyzing an issue that's had a trivial solution for ages.

[Edit]

Just realized that a community based regional allocation strategy might be a bit tricky. How would you deal with regions in conflict?

+11  A: 

HTML, XML, TXT and Access

http://www.iso.ch/iso/country_codes/iso_3166_code_lists.htm

Jason
Seems like the best source so far. What would be nifty is a Localized version of this list. I may want that list in English, French, Spanish, and German...
Scott Muc
anybody got a downloadable version of this with lowercase country names (that take up less width in a dropdown)?
Simon_Weaver
Either lcase if on the fly, or run it through a text tool (even Excel will do it) to lcase it all at once.
Jason
+1  A: 

I assume what you want are the ISO 3166-1 2-alpha or 3-alpha codes, which are defined by ISO 3166-1. You can get various text and XML versions straight from ISO.org. This doesn't include any province, State, or city data, however.

EDIT: The UN/LOCODE site has a list of sublocations that sync up with ISO 3166-2 (ISO codes for provinces/States): http://www.unece.org/cefact/locode/service/sublocat.htm.

Also, UN/LOCODE has a location code list, which is a list of cities/towns by country: http://www.unece.org/cefact/locode/service/location.htm.

Finally, regarding the comment on regional differences/conflicts, ISO 3166-3 sort of approaches that, maintaining a list of prior names for locations.

nezroy
A: 

In Java, you can call java.util.Locale.getISOCountries(), which may help, depending on what you need.

A region hierarchy is more complex; I expect it cost Yahoo a lot to build that aspect of FireEagle.

There is a lot of information in the GNS country files at http://earth-info.nga.mil/gns/html/namefiles.htm - names, locations and other data for a very large number of places internationally.

Peter Hilton
I wonder if community effort would help complete regional stuff.
Scott Muc
A: 

Wikipedia has a list all country codes and their corresponding countries. I found it through a google search for "wikipedia country code".

rmeador
+1  A: 

Also: http://www.ics.uci.edu/pub/websoft/wwwstat/country-codes.txt

Brian Clapper
this one has the advantage over http://www.iso.ch/iso/country_codes/iso_3166_code_lists.htm of having lowercase letters for countryname ie. France instead of FRANCE
Simon_Weaver
aha BUT be warned - this appears to be a TLD list. UK for instance has two entries (UK and GB) instead of GB which is the ISO 3166 code. it also includes BIZ, COM, EDU, GOV etc. if you're needing a true country code list it looks like this isnt what you should be using
Simon_Weaver
+3  A: 

I occasionally find the Apendix of the CIA - World Fact Book useful.

Chris Nava
+2  A: 

I have a list on my website in sql and tab delimited at http://www.john.geek.nz/index.php/2009/01/sql-tips-list-of-countries/

John
There seems to be a php stackoverflow error when accessing this particular page on your blog.
JSmyth
NB: these are 3 digit country codes (no error anymore)
Simon_Weaver
+1  A: 

I created a rerunnable sql script to handle this. See my blog post: ISO 3166-1 Country Data SQL Script. And you can get the sql script here.

Jeff Widmer