<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Messages posted by "bwakkie"]]></title>
		<link>http://forum.geonames.org/gforum/posts/listByUser/1289.page</link>
		<description><![CDATA[Messages posted by "bwakkie"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>link RFC 3066 from countryinfo with languages table?</title>
				<description><![CDATA[ What would be the best way?

Add an extra RFC 3066 column in the languages table?
Or use the iso_639_3 code in countryinfo instead?

how about adding the native namings per language like in the wikipedia?
(http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes)

thx,
Bastiaan]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/preList/1302/5505.page#5505</guid>
				<link>http://forum.geonames.org/gforum/posts/preList/1302/5505.page#5505</link>
				<pubDate><![CDATA[Wed, 4 Mar 2009 01:53:31]]> GMT</pubDate>
				<author><![CDATA[ bwakkie]]></author>
			</item>
			<item>
				<title>Re:import countyInfo.txt postgresql</title>
				<description><![CDATA[ nice, fixed it in my script too:
http://forum.geonames.org/gforum/posts/list/926.page#5449

cheers,
Bastiaan
]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/preList/1208/5450.page#5450</guid>
				<link>http://forum.geonames.org/gforum/posts/preList/1208/5450.page#5450</link>
				<pubDate><![CDATA[Wed, 18 Feb 2009 22:23:18]]> GMT</pubDate>
				<author><![CDATA[ bwakkie]]></author>
			</item>
			<item>
				<title>modified script</title>
				<description><![CDATA[ <p></p>

		<cite>bwakkie wrote:</cite><br>
		<blockquote>Hi, 

I loved the script so I started working on it. This is the working end result.
<b>done</b>:
<li> It will create a working path if it is not there
<li> It will create the db
<li> It wil check if you are already using the latest files from the net and therefore not downloading it again
<li> Added the command CASCADE to DROP TABLE geoname due to the constrains
<li> I do not thing you need to change DROP TABLE to DROP TABLE IF EXIST, it is sort of pointless
<b>todo</b>:
<li> perhaps only update/insert/delete changes in the future by removing duplicate lines from the txt files?
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
#!/bin/bash
#===============================================================================
#
#          FILE:  getgeo.sh
# 
#         USAGE:  ./getgeo.sh 
# 
#   DESCRIPTION:  run the script so that the geodata will be downloaded and inserted into your
#		  database
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Andreas &#40;aka Harpagophyt &#41;
#       COMPANY:  http://forum.geonames.org/gforum/posts/list/926.page
#       VERSION:  1.3
#       CREATED:  07/06/2008
#      REVISION:  1.1 2008-06-07 replace COPY continentCodes through INSERT statements.
#                 1.2 2008-11-25 Adjusted by Bastiaan Wakkie in order to not unnessisarily 
#                                download.
#===============================================================================
#!/bin/bash

WORKPATH="~/geodata"
TMPPATH="tmp"
PCPATH="pc"
PREFIX="_"
DBUSER="$USER"
FILES="allCountries.zip alternateNames.zip userTags.zip admin1Codes.txt admin1CodesASCII.txt admin2Codes.txt countryInfo.txt featureCodes.txt iso-languagecodes.txt timeZones.txt"
createdb -O $DBUSER geonames
psql -U $DBUSER geonames &lt;&lt;EOT
DROP TABLE geoname CASCADE;
CREATE TABLE geoname &#40;
	geonameid int,
	name varchar&#40;200&#41;,
	asciiname varchar&#40;200&#41;,
	alternatenames varchar&#40;4000&#41;,
	latitude float,
	longitude float,
	fclass char&#40;1&#41;,
	fcode varchar&#40;10&#41;,
	country varchar&#40;2&#41;,
	cc2 varchar&#40;60&#41;,
	admin1 varchar&#40;20&#41;,
	admin2 varchar&#40;80&#41;,
	admin3 varchar&#40;20&#41;,
	admin4 varchar&#40;20&#41;,
	population bigint,
	elevation int,
	gtopo30 int,
	timezone varchar&#40;40&#41;,
	moddate date
&#41;;

DROP TABLE alternatename;
CREATE TABLE alternatename &#40;
	alternatenameId int,
	geonameid int,
	isoLanguage varchar&#40;7&#41;,
	alternateName varchar&#40;200&#41;,
	isPreferredName boolean,
	isShortName boolean,
	isColloquial boolean,
	isHistoric boolean
&#41;;

DROP TABLE countryinfo;
CREATE TABLE "countryinfo" &#40;
       iso_alpha2 char&#40;2&#41;,
       iso_alpha3 char&#40;3&#41;,
       iso_numeric integer,
       fips_code character varying&#40;3&#41;,
       country character varying&#40;200&#41;,
       capital character varying&#40;200&#41;,
       areainsqkm double precision,
       population integer,
       continent char&#40;2&#41;,
       tld CHAR&#40;10&#41;,
       currency_code char&#40;3&#41;,
       currency_name CHAR&#40;15&#41;,
       phone character varying&#40;20&#41;,
       languages character varying&#40;200&#41;,
       geonameId int,
       neighbours character varying&#40;50&#41;,
       equivalent_fips_code character varying&#40;3&#41;
&#41;;



DROP TABLE iso_languagecodes;
CREATE TABLE iso_languagecodes&#40;
	iso_639_3 CHAR&#40;4&#41;,
	iso_639_2 VARCHAR&#40;50&#41;,
	iso_639_1 VARCHAR&#40;50&#41;,
	language_name VARCHAR&#40;200&#41;
&#41;;

DROP TABLE admin1Codes;
CREATE TABLE admin1Codes &#40;
	code CHAR&#40;6&#41;,
	name TEXT
&#41;;

DROP TABLE admin1CodesAscii;
CREATE TABLE admin1CodesAscii &#40;
	code CHAR&#40;6&#41;,
	name TEXT,
	nameAscii TEXT,
	geonameid int
&#41;;

DROP TABLE featureCodes;
CREATE TABLE featureCodes &#40;
	code CHAR&#40;7&#41;,
	name VARCHAR&#40;200&#41;,
	description TEXT
&#41;;

DROP TABLE timeZones;
CREATE TABLE timeZones &#40;
	timeZoneId VARCHAR&#40;200&#41;,
	GMT_offset numeric&#40;3,1&#41;,
	DST_offset numeric&#40;3,1&#41;
&#41;;

DROP TABLE continentCodes;
CREATE TABLE continentCodes &#40;
	code CHAR&#40;2&#41;,
	name VARCHAR&#40;20&#41;,
	geonameid INT
&#41;;

DROP TABLE postalcodes;
CREATE TABLE postalcodes &#40;
	countrycode char&#40;2&#41;,
	postalcode varchar&#40;10&#41;,
	placename varchar&#40;180&#41;,
	admin1name varchar&#40;100&#41;,
	admin1code varchar&#40;20&#41;,
	admin2name varchar&#40;100&#41;,
	admin2code varchar&#40;20&#41;,
	admin3name varchar&#40;100&#41;,
	latitude float,
	longitude float,
	accuracy smallint
&#41;;

ALTER TABLE ONLY alternatename
      ADD CONSTRAINT pk_alternatenameid PRIMARY KEY &#40;alternatenameid&#41;;
ALTER TABLE ONLY geoname
      ADD CONSTRAINT pk_geonameid PRIMARY KEY &#40;geonameid&#41;;
ALTER TABLE ONLY countryinfo
      ADD CONSTRAINT pk_iso_alpha2 PRIMARY KEY &#40;iso_alpha2&#41;;
ALTER TABLE ONLY countryinfo
      ADD CONSTRAINT fk_geonameid FOREIGN KEY &#40;geonameid&#41; REFERENCES geoname&#40;geonameid&#41;;
ALTER TABLE ONLY alternatename
      ADD CONSTRAINT fk_geonameid FOREIGN KEY &#40;geonameid&#41; REFERENCES geoname&#40;geonameid&#41;;
EOT

# check if needed directories do already exsist
if &#91; -d "$WORKPATH" &#93;; then
	sleep 0
else
	mkdir $WORKPATH
	mkdir $WORKPATH/$TMPPATH
	mkdir $WORKPATH/$PCPATH
	echo "created $WORKPATH"
fi
echo
echo ",---- STARTING &#40;downloading, unpacking and preparing&#41;"
cd $WORKPATH/$TMPPATH
for i in $FILES
do
	wget -N -q "http://download.geonames.org/export/dump/$i" # get newer files
	if  &#91; $i -nt $PREFIX$i &#93; || &#91; ! -e $PREFIX$i &#93; ; then
		cp -p $i $PREFIX$i
		unzip -u -q $i
		case "$i" in
		iso-languagecodes.txt&#41;
			tail -n +2 iso-languagecodes.txt &gt; iso-languagecodes.txt.tmp;
		;;
		countryInfo.txt&#41;
			grep -v '^#' countryInfo.txt | tail -n +2  &gt; countryInfo.txt.tmp;
		;;
		timeZones.txt&#41;
			tail -n +2 timeZones.txt &gt; timeZones.txt.tmp;
		;;
		esac
		echo "| $1 has been downloaded";
	else
		echo "| $i is already the latest version" 

	fi
done
# download the postalcodes. You must know yourself the url
cd $WORKPATH/$PCPATH
wget -q -N "http://.../....zip"
if &#91; $WORKPATH/$PCPATH/....zip -nt $WORKPATH/$PCPATH/allCountries$PREFIX.zip &#93; || &#91; ! -e $WORKPATH/$PCPATH/....zip &#93;; then
	unzip -u -q $WORKPATH/$PCPATH/....zip
	cp -p $WORKPATH/$PCPATH/....zip $WORKPATH/$PCPATH/allCountries$PREFIX.zip
	echo "| ....zip has been downloaded"
else
	echo "| ....zip is already the latest version" 
fi

echo "+---- FILL DATABASE &#40; this takes 2 days on my machine :&#41;"

psql -e -U $DBUSER geonames &lt;&lt;EOT
copy geoname &#40;geonameid,name,asciiname,alternatenames,latitude,longitude,fclass,fcode,country,cc2,admin1,admin2,admin3,admin4,population,elevation,gtopo30,timezone,moddate&#41; from '${WORKPATH}/${TMPPATH}/allCountries.txt' null as '';
copy postalcodes &#40;countrycode,postalcode,placename,admin1name,admin1code,admin2name,admin2code,admin3name,latitude,longitude,accuracy&#41; from '${WORKPATH}/${PCPATH}/allCountries.txt' null as '';
copy timeZones &#40;timeZoneId,GMT_offset,DST_offset&#41; from '${WORKPATH}/${TMPPATH}/timeZones.txt.tmp' null as '';
copy featureCodes &#40;code,name,description&#41; from '${WORKPATH}/${TMPPATH}/featureCodes.txt' null as '';
copy admin1CodesAscii &#40;code,name,nameAscii,geonameid&#41; from '${WORKPATH}/${TMPPATH}/admin1CodesASCII.txt' null as '';
copy admin1Codes &#40;code,name&#41; from '${WORKPATH}/${TMPPATH}/admin1Codes.txt' null as '';
copy iso_languagecodes &#40;iso_639_3,iso_639_2,iso_639_1,language_name&#41; from '${WORKPATH}/${TMPPATH}/iso-languagecodes.txt.tmp' null as '';
copy countryInfo &#40;iso_alpha2,iso_alpha3,iso_numeric,fips_code,country,capital,areainsqkm,population,continent,tld,currency_code,currency_name,phone,postal,postalRegex,languages,geonameid,neighbours,equivalent_fips_code&#41; from '${WORKPATH}/${TMPPATH}/countryInfo.txt.tmp' null as '';
copy alternatename  &#40;alternatenameid,geonameid,isoLanguage,alternateName,isPreferredName,isShortName,isColloquial,isHistoric&#41; from '${WORKPATH}/${TMPPATH}/alternateNames.txt' null as '';
INSERT INTO continentCodes VALUES &#40;'AF', 'Africa', 6255146&#41;;
INSERT INTO continentCodes VALUES &#40;'AS', 'Asia', 6255147&#41;;
INSERT INTO continentCodes VALUES &#40;'EU', 'Europe', 6255148&#41;;
INSERT INTO continentCodes VALUES &#40;'NA', 'North America', 6255149&#41;;
INSERT INTO continentCodes VALUES &#40;'OC', 'Oceania', 6255150&#41;;
INSERT INTO continentCodes VALUES &#40;'SA', 'South America', 6255151&#41;;
INSERT INTO continentCodes VALUES &#40;'AN', 'Antarctica', 6255152&#41;;
CREATE INDEX index_countryinfo_geonameid ON countryinfo USING hash &#40;geonameid&#41;;
CREATE INDEX index_alternatename_geonameid ON alternatename USING hash &#40;geonameid&#41;;
EOT
echo "'----- DONE &#40; have fun... &#41;"
</pre>
		</div>&nbsp;
		</blockquote>]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/preList/926/5449.page#5449</guid>
				<link>http://forum.geonames.org/gforum/posts/preList/926/5449.page#5449</link>
				<pubDate><![CDATA[Wed, 18 Feb 2009 22:20:42]]> GMT</pubDate>
				<author><![CDATA[ bwakkie]]></author>
			</item>
			<item>
				<title>Re:Errors in countryInfo.txt</title>
				<description><![CDATA[ First the countryInfo table has changed.

in PostgreSQL I do the following:
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
CREATE TABLE countryinfo &#40;
	iso_alpha2 char&#40;2&#41;,
	iso_alpha3 char&#40;3&#41;,
	iso_numeric integer,
	fips_code character varying&#40;3&#41;,
	name character varying&#40;200&#41;,
	capital character varying&#40;200&#41;,
	areainsqkm double precision,
	population integer,
	continent char&#40;2&#41;,
	tld character varying&#40;200&#41;,
	currency char&#40;3&#41;,
	curranceName char&#40;10&#41;,
	phone char&#40;10&#41;,
	postal char&#40;60&#41;,
	postalRegex char&#40;250&#41;,
	languages char&#40;130&#41;,
	equivalentFipsCode integer,
	neighbours char&#40;50&#41;
&#41;;
</pre>
		</div>
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
grep -v '^#' countryInfo.txt |sed 's/\t$//g'| tail -n +2 &gt; countryInfo.txt.tmp;
</pre>
		</div>

...before populating the countryinfo table in psql ...
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
copy countryinfo &#40;iso_alpha2,iso_alpha3,iso_numeric,fips_code,name,capital,areaInSqKm,population,continent,tld,currency,curranceName,phone,postal,postalRegex,languages,equivalentFipsCode,neighbours&#41; from '${WORKPATH}/${TMPPATH}/countryInfo.txt.tmp' null as '';
</pre>
		</div>

grep removes all comments
sed removes the tab at the end of each line
and tail removes the column names

see also my importing script here (that will be updates shortly ;-)):
http://forum.geonames.org/gforum/posts/list/926.page

Cheers,
Bastiaan

]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/preList/1145/5023.page#5023</guid>
				<link>http://forum.geonames.org/gforum/posts/preList/1145/5023.page#5023</link>
				<pubDate><![CDATA[Wed, 26 Nov 2008 15:00:51]]> GMT</pubDate>
				<author><![CDATA[ bwakkie]]></author>
			</item>
			<item>
				<title>neighbours and EquivalentFipsCode columns are switched in countryInfo.txt file</title>
				<description><![CDATA[ The countryInfo.txt has wrong table field names:
example:
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>#ISO	ISO3	ISO-Numeric	fips	Country	Capital	Area&#40;in sq km&#41;	Population	Continent	tld	CurrencyCode	CurrencyName	Phone	Postal Code Format	Postal Code Regex	Languages	geonameid	neighbours	EquivalentFipsCode
AD	AND	20	AN	Andorra	Andorra la Vella	468	72000	EU	.ad	EUR	Euro	376	AD###	^&#40;?:AD&#41;*&#40;\d{3}&#41;$	ca,fr-AD,pt	3041565	ES,FR</pre>
		</div>
neighbours	EquivalentFipsCode are switched!
also the geonameid does not exist anymore
so new postgresql sql will be something like this:
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
I adjusted the code above as the length values of phone and currance name where changed too. There was a weird typo with one tab too much .. this is handled now too.
</pre>
		</div>]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/preList/926/5022.page#5022</guid>
				<link>http://forum.geonames.org/gforum/posts/preList/926/5022.page#5022</link>
				<pubDate><![CDATA[Wed, 26 Nov 2008 12:50:58]]> GMT</pubDate>
				<author><![CDATA[ bwakkie]]></author>
			</item>
			<item>
				<title>modified script</title>
				<description><![CDATA[ Hi, 

I loved the script so I started working on it. This is the working end result.
<b>done</b>:
<li> It will create a working path if it is not there
<li> It will create the db
<li> It wil check if you are already using the latest files from the net and therefore not downloading it again
<li> Added the command CASCADE to DROP TABLE geoname due to the constrains
<li> I do not thing you need to change DROP TABLE to DROP TABLE IF EXIST, it is sort of pointless
<b>todo</b>:
<li> perhaps only update/insert/delete changes in the future by removing duplicate lines from the txt files?
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
#!/bin/bash
#===============================================================================
#
#          FILE:  getgeo.sh
# 
#         USAGE:  ./getgeo.sh 
# 
#   DESCRIPTION:  run the script so that the geodata will be downloaded and inserted into your
#		  database
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Andreas &#40;aka Harpagophyt &#41;
#       COMPANY:  http://forum.geonames.org/gforum/posts/list/926.page
#       VERSION:  1.3
#       CREATED:  07/06/2008
#      REVISION:  1.1 2008-06-07 replace COPY continentCodes through INSERT statements.
#                 1.2 2008-11-25 Adjusted by Bastiaan Wakkie in order to not unnessisarily 
#                 1.3 2009-02-18 Fixed countryInfo bug in Aland Islands as there was one tab too many at te end and sone field lengths needed to be larger
#                                download.
#===============================================================================
#!/bin/bash

WORKPATH="~/geodata"
TMPPATH="tmp"
PCPATH="pc"
PREFIX="_"
DBUSER="$USER"
FILES="allCountries.zip alternateNames.zip userTags.zip admin1Codes.txt admin1CodesASCII.txt admin2Codes.txt countryInfo.txt featureCodes.txt iso-languagecodes.txt timeZones.txt"
createdb -O $DBUSER geonames
psql -U $DBUSER geonames &lt;&lt;EOT
DROP TABLE geoname CASCADE;
CREATE TABLE geoname &#40;
	geonameid int,
	name varchar&#40;200&#41;,
	asciiname varchar&#40;200&#41;,
	alternatenames varchar&#40;4000&#41;,
	latitude float,
	longitude float,
	fclass char&#40;1&#41;,
	fcode varchar&#40;10&#41;,
	country varchar&#40;2&#41;,
	cc2 varchar&#40;60&#41;,
	admin1 varchar&#40;20&#41;,
	admin2 varchar&#40;80&#41;,
	admin3 varchar&#40;20&#41;,
	admin4 varchar&#40;20&#41;,
	population bigint,
	elevation int,
	gtopo30 int,
	timezone varchar&#40;40&#41;,
	moddate date
&#41;;

DROP TABLE alternatename;
CREATE TABLE alternatename &#40;
	alternatenameId int,
	geonameid int,
	isoLanguage varchar&#40;7&#41;,
	alternateName varchar&#40;200&#41;,
	isPreferredName boolean,
	isShortName boolean
	isColloquial boolean,
 	isHistoric boolean
&#41;;

DROP TABLE countryinfo;
 CREATE TABLE countryinfo &#40;
 	iso_alpha2 char&#40;2&#41;,
 	iso_alpha3 char&#40;3&#41;,
 	iso_numeric integer,
 	fips_code character varying&#40;3&#41;,
 	name character varying&#40;200&#41;,
 	capital character varying&#40;200&#41;,
 	areainsqkm double precision,
 	population integer,
 	continent char&#40;2&#41;,
 	tld character varying&#40;200&#41;,
 	currency char&#40;3&#41;,
 	curranceName char&#40;15&#41;,
 	phone char&#40;20&#41;,
 	postal char&#40;60&#41;,
 	postalRegex char&#40;250&#41;,
 	languages char&#40;130&#41;,
 	geonameid integer,
 	neighbours char&#40;50&#41;
 &#41;;


DROP TABLE iso_languagecodes;
CREATE TABLE iso_languagecodes&#40;
	iso_639_3 CHAR&#40;4&#41;,
	iso_639_2 VARCHAR&#40;50&#41;,
	iso_639_1 VARCHAR&#40;50&#41;,
	language_name VARCHAR&#40;200&#41;
&#41;;

DROP TABLE admin1Codes;
CREATE TABLE admin1Codes &#40;
	code CHAR&#40;6&#41;,
	name TEXT
&#41;;

DROP TABLE admin1CodesAscii;
CREATE TABLE admin1CodesAscii &#40;
	code CHAR&#40;6&#41;,
	name TEXT,
	nameAscii TEXT,
	geonameid int
&#41;;

DROP TABLE featureCodes;
CREATE TABLE featureCodes &#40;
	code CHAR&#40;7&#41;,
	name VARCHAR&#40;200&#41;,
	description TEXT
&#41;;

DROP TABLE timeZones;
CREATE TABLE timeZones &#40;
	timeZoneId VARCHAR&#40;200&#41;,
	GMT_offset numeric&#40;3,1&#41;,
	DST_offset numeric&#40;3,1&#41;
&#41;;

DROP TABLE continentCodes;
CREATE TABLE continentCodes &#40;
	code CHAR&#40;2&#41;,
	name VARCHAR&#40;20&#41;,
	geonameid INT
&#41;;

DROP TABLE postalcodes;
CREATE TABLE postalcodes &#40;
	countrycode char&#40;2&#41;,
	postalcode varchar&#40;10&#41;,
	placename varchar&#40;180&#41;,
	admin1name varchar&#40;100&#41;,
	admin1code varchar&#40;20&#41;,
	admin2name varchar&#40;100&#41;,
	admin2code varchar&#40;20&#41;,
	admin3name varchar&#40;100&#41;,
	latitude float,
	longitude float,
	accuracy smallint
&#41;;

ALTER TABLE ONLY alternatename
      ADD CONSTRAINT pk_alternatenameid PRIMARY KEY &#40;alternatenameid&#41;;
ALTER TABLE ONLY geoname
      ADD CONSTRAINT pk_geonameid PRIMARY KEY &#40;geonameid&#41;;
ALTER TABLE ONLY countryinfo
      ADD CONSTRAINT pk_iso_alpha2 PRIMARY KEY &#40;iso_alpha2&#41;;

ALTER TABLE ONLY countryinfo
      ADD CONSTRAINT fk_geonameid FOREIGN KEY &#40;geonameid&#41; REFERENCES geoname&#40;geonameid&#41;;
ALTER TABLE ONLY alternatename
      ADD CONSTRAINT fk_geonameid FOREIGN KEY &#40;geonameid&#41; REFERENCES geoname&#40;geonameid&#41;;
EOT

# check if needed directories do already exsist
if &#91; -d "$WORKPATH" &#93;; then
	sleep 0
else
	mkdir $WORKPATH
	mkdir $WORKPATH/$TMPPATH
	mkdir $WORKPATH/$PCPATH
	echo "created $WORKPATH"
fi
echo
echo ",---- STARTING &#40;downloading, unpacking and preparing&#41;"
cd $WORKPATH/$TMPPATH
for i in $FILES
do
	wget -N -q "http://download.geonames.org/export/dump/$i" # get newer files
	if  &#91; $i -nt $PREFIX$i &#93; || &#91; ! -e $PREFIX$i &#93; ; then
		cp -p $i $PREFIX$i
		unzip -u -q $i
		case "$i" in
		iso-languagecodes.txt&#41;
			tail -n +2 iso-languagecodes.txt &gt; iso-languagecodes.txt.tmp;
		;;
		countryInfo.txt&#41;
			grep -v '^#' countryInfo.txt | tail -n +2 | sed 's/                FI/     FI/g'  &gt; countryInfo.txt.tmp;
		;;
		timeZones.txt&#41;
			tail -n +2 timeZones.txt &gt; timeZones.txt.tmp;
		;;
		esac
		echo "| $1 has been downloaded";
	else
		echo "| $i is already the latest version" 

	fi
done
# download the postalcodes. You must know yourself the url
cd $WORKPATH/$PCPATH
wget -q -N "http://.../....zip"
if &#91; $WORKPATH/$PCPATH/....zip -nt $WORKPATH/$PCPATH/allCountries$PREFIX.zip &#93; || &#91; ! -e $WORKPATH/$PCPATH/....zip &#93;; then
	unzip -u -q $WORKPATH/$PCPATH/....zip
	cp -p $WORKPATH/$PCPATH/....zip $WORKPATH/$PCPATH/allCountries$PREFIX.zip
	echo "| ....zip has been downloaded"
else
	echo "| ....zip is already the latest version" 
fi

echo "+---- FILL DATABASE &#40; this takes 2 days on my machine :&#41;"

psql -e -U $DBUSER geonames &lt;&lt;EOT
copy geoname &#40;geonameid,name,asciiname,alternatenames,latitude,longitude,fclass,fcode,country,cc2,admin1,admin2,admin3,admin4,population,elevation,gtopo30,timezone,moddate&#41; from '${WORKPATH}/${TMPPATH}/allCountries.txt' null as '';
copy postalcodes &#40;countrycode,postalcode,placename,admin1name,admin1code,admin2name,admin2code,admin3name,latitude,longitude,accuracy&#41; from '${WORKPATH}/${PCPATH}/allCountries.txt' null as '';
copy timeZones &#40;timeZoneId,GMT_offset,DST_offset&#41; from '${WORKPATH}/${TMPPATH}/timeZones.txt.tmp' null as '';
copy featureCodes &#40;code,name,description&#41; from '${WORKPATH}/${TMPPATH}/featureCodes.txt' null as '';
copy admin1CodesAscii &#40;code,name,nameAscii,geonameid&#41; from '${WORKPATH}/${TMPPATH}/admin1CodesASCII.txt' null as '';
copy admin1Codes &#40;code,name&#41; from '${WORKPATH}/${TMPPATH}/admin1Codes.txt' null as '';
copy iso_languagecodes &#40;iso_639_3,iso_639_2,iso_639_1,language_name&#41; from '${WORKPATH}/${TMPPATH}/iso-languagecodes.txt.tmp' null as '';
copy countryInfo &#40;iso_alpha2,iso_alpha3,iso_numeric,fips_code,country,capital,areainsqkm,population,continent,tld,currency_code,currency_name,phone,postal,postalRegex,languages,geonameId,neighbours&#41; from '${WORKPATH}/${TMPPATH}/countryInfo.txt.tmp' null as '';
copy alternatename  &#40;alternatenameid,geonameid,isoLanguage,alternateName,isPreferredName,isShortName&#41; from '${WORKPATH}/${TMPPATH}/alternateNames.txt' null as '';
INSERT INTO continentCodes VALUES &#40;'AF', 'Africa', 6255146&#41;;
INSERT INTO continentCodes VALUES &#40;'AS', 'Asia', 6255147&#41;;
INSERT INTO continentCodes VALUES &#40;'EU', 'Europe', 6255148&#41;;
INSERT INTO continentCodes VALUES &#40;'NA', 'North America', 6255149&#41;;
INSERT INTO continentCodes VALUES &#40;'OC', 'Oceania', 6255150&#41;;
INSERT INTO continentCodes VALUES &#40;'SA', 'South America', 6255151&#41;;
INSERT INTO continentCodes VALUES &#40;'AN', 'Antarctica', 6255152&#41;;
CREATE INDEX index_countryinfo_geonameid ON countryinfo USING hash &#40;geonameid&#41;;
CREATE INDEX index_alternatename_geonameid ON alternatename USING hash &#40;geonameid&#41;;
EOT
echo "'----- DONE &#40; have fun... &#41;"
</pre>
		</div>]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/preList/926/5020.page#5020</guid>
				<link>http://forum.geonames.org/gforum/posts/preList/926/5020.page#5020</link>
				<pubDate><![CDATA[Wed, 26 Nov 2008 10:31:01]]> GMT</pubDate>
				<author><![CDATA[ bwakkie]]></author>
			</item>
			<item>
				<title>Re:Import GeoNames dump into Postgres</title>
				<description><![CDATA[ http://forum.geonames.org/gforum/posts/list/926.page does more automatically]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/preList/67/5018.page#5018</guid>
				<link>http://forum.geonames.org/gforum/posts/preList/67/5018.page#5018</link>
				<pubDate><![CDATA[Wed, 26 Nov 2008 10:23:50]]> GMT</pubDate>
				<author><![CDATA[ bwakkie]]></author>
			</item>
	</channel>
</rss>