The Blog of Travis Gneiting
  • Home
KEEP IN TOUCH

SQL Server Import of Country, State, Zip, From GeoNames.Org

Feb12
2010
2 Comments Written by admin

A few post have been made with complex solutions for importing information from GeoNames.org into SQL Server.  These involved downloading converters to change the file from UTF-8 encoding and downloading additional software (EditPad Pro) to complete the conversion to UTF-16.

A much simpler way is to open the txt file in Microsoft Excel. Let Excel perform it’s magic on the tab delimited file.

Add the headers to the top row:

The main 'geoname' table has the following fields :
---------------------------------------------------
geonameid         : integer id of record in geonames database
name              : name of geographical point (utf8) varchar(200)
asciiname         : name of geographical point in plain ascii characters, varchar(200)
alternatenames    : alternatenames, comma separated varchar(5000)
latitude          : latitude in decimal degrees (wgs84)
longitude         : longitude in decimal degrees (wgs84)
feature class     : see http://www.geonames.org/export/codes.html, char(1)
feature code      : see http://www.geonames.org/export/codes.html, varchar(10)
country code      : ISO-3166 2-letter country code, 2 characters
cc2               : alternate country codes, comma separated, ISO-3166 2-letter country code, 60 characters
admin1 code       : fipscode (subject to change to iso code), see exceptions below, see file admin1Codes.txt for display names of this code; varchar(20)
admin2 code       : code for the second administrative division, a county in the US, see file admin2Codes.txt; varchar(80)
admin3 code       : code for third level administrative division, varchar(20)
admin4 code       : code for fourth level administrative division, varchar(20)
population        : bigint (4 byte int)
elevation         : in meters, integer
gtopo30           : average elevation of 30'x30' (ca 900mx900m) area in meters, integer
timezone          : the timezone id (see file timeZone.txt)
modification date : date of last modification in yyyy-MM-dd format

Then save the Excel file. Use SQL Server import to import the Excel file and your done.
Posted in SQL Server
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Microsoft Certified Technology Specialist (MCTS)
» Entity Framwork Query Examples

2 Comments

  1. Dirco's Gravatar Dirco
    August 13, 2010 at 2:15 pm | Permalink

    That was the first thing I tried, but Excel only loads the first ~1 million rows.
    allCountries.txt has ~7.5 million entries, so you will need those other tools/scripts (unless you want to import the individual country files).

  2. admin's Gravatar admin
    August 30, 2010 at 6:44 am | Permalink

    Yes, unfortunatly I did end up importing the countries that I needed. I too ran into the limitations you are talking about. It still a good solution if you are only importing one country.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Programming

  • ASP.NET
  • MSDN
  • Visual Studio Offical Website
  • www.w3.org

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Welcome to My Programming Blog

This is my brain dump. I use it to post thing I may use again, interesting things I have run into and programming helps.

Tags

.net Agile Software Development Engineering ASP.NET attack Beginner Blueprint CSS Database Deployment DevExpress Framework Functional hacked Hotmail How to test software HTTP IIS Javascript JQuery MIME New Website Checklist PHP querystring Software Testing Specification spoof Status Codes Testing Trace Debug ASP.NET Tutorial Velocity webmethod Website Testing Zend

Blog Archive

  • January 2012
  • November 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • February 2011
  • January 2011
  • November 2010
  • October 2010
  • August 2010
  • July 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • February 2009
  • January 2009
  • November 2008
  • September 2008
  • August 2008
  • July 2008
  • April 2008

EvoLve theme by Theme4Press  •  Powered by WordPress The Blog of Travis Gneiting