This will install PostGIS and add the R language through PLR in the current version of Ubuntu Natty 11.04
sudo apt-get install qgis
sudo apt-get install postgresql
sudo apt-get install postgresql-8.4-postgis
sudo apt-get install postgresql-8.4-plr
sudo apt-get install pgadmin3
One small step that is necessary is to change the user password for postgres. You can do this with psql. Care needed here. This has to be done correctly. The following line gets you into psql.
sudo -u postgres psql -d template1
Type this (being very careful with quotation marks and the semicolon).
alter user postgres with password 'postgres';
If successul you get a message saying ALTER ROLE (If there is any problem here then retype the single quotation marks to make sure they are simple. WordPress keeps changing them for some reason if they are not in an HTML box).
Now become the postgres user and create a postgistemplate. This is a blank data base into which you will load all the functions and tables needed for POSTGIS. All new data bases created using this template will have these functions loaded.
sudo su postgres
createlang plpgsql postgistemplate
The PostGIS functions and spatial_ref system are loaded from here on Ubuntu
psql -d postgistemplate -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
psql -d postgistemplate -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql
This cpmmand loads in the R language (to use this you must have R installed)
psql -d postgistemplate -f /usr/share/postgresql/8.4/plr.sql
To create a database under this template
createdb -T postgistemplate -O postgres gisdb
You will also have to alter the following config file
sudo gedit /etc/postgresql/8.4/main/postgresql.conf
Find the line with listen_addresses and uncomment it. If you want the database to be open to other users use’*’ instead of localhost
listen_addresses = ‘*’ # what IP address(es) to listen on;
Download a small test database with the countries of the word from this site with wget. Again the file is disguised as a word doc in order to go into the wordpress site.
Restore this database. The database was built using an old version of Postgis, so you will see many errors which you can ignore (See http://blog.cleverelephant.ca/2010/09/postgis-back-up-restore.html
sudo -u postgres psql gisdb<paises.doc
Now run qgis and connect to your new PostGIS data base.
The trial database with a single countries of the world table can also be downloaded without wget by clicking here.