Ubuntu GIS from Scratch: Step Six – QGIS

Welcome to Step Six in our exploration of open source GIS using Ubuntu. In the previous installments, we uploaded some spatial data into a PostGIS database, and experimented with spatial SQL. Finally, we’re ready to install QGIS, the most popular open source GIS desktop available. QGIS is a lot like ESRI’s ArcMap, in that it presents the users with a familiar environment of vector layers, rasters, and attribute tables in which to do analysis. QGIS also has its own Python-based scripting API, and is extensible through plug-ins and code samples. Best of all, QGIS can connect to a wide variety of databases, including those running PostgreSQL and PostGIS.

1. QGIS is fairly easy to install, but we have to get our hands on the packages first. Since we’ve gone through all the work to install GDAL and GEOS, and know how to build from source, it would make sense to just download a tarball and install it by hand. But QGIS has an unbelievable number of package dependencies, and many of them are different versions from the ones we installed earlier. Instead, we’re going to install a pre-built package, which comes with a set of pre-compiled dependencies. This package is provided by QGIS, so we know it will be complete. In order to install packages from QGIS, we have to add their servers to our package installation database. This is easy to do. Start the terminal, and then execute:
sudo gedit /etc/apt/sources.list

This will bring up the sources.list file in a text editor, ready for modification. Go down to the very end of the document and add the following lines:
## Sources for QGIS
deb     http://ppa.launchpad.net/ubuntugis/ppa/ubuntu precise main
deb-src http://ppa.launchpad.net/ubuntugis/ppa/ubuntu precise main

These are the package servers for Ubuntu Precise, which is the codename for 12.04. Save the file and then exit gedit to be returned to the terminal.

Next we have to modify our package security settings in order to accept packages from this new source. Basically, we are adding a public key to our security keyring, which lets the system know that we trust packages from this server, as long as they match our key:
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 314DF160
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.hV5DAdIWJ2 --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv-keys 314DF160
gpg: requesting key 314DF160 from hkp server keyserver.ubuntu.com
gpg: key 314DF160: public key "Launchpad ubuntugis-stable" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Well, that’s that. Now we can start installing:
sudo apt-get install qgis
This will add a ton of packages to your system, and it will take close to half an hour. But when it is all done, QGIS 1.8 (codename: Lisboa) will be installed!

2. During the install process, a custom directory is created in your home folder. This directory contains a database where all your customizations and add-ons will be stored. Unfortunately, this directory is read-only after installation. This is a bug that has been dealt with in version 1.9, but we’re stuck with it for now. However, it’s easy to fix – just delete the folder. To find the folder, change to your home directory:
cd ~
If you list the contents of this directory, you won’t see the .qgis directory, because it has a . at the beginning of its name, and ‘dotfiles’ are hidden by default. So we need to list everything. The -la flag shows you everything in convenient table form:
ls -la
There are probably a lot of hidden folders in your home directory – that’s where applications store your personalized settings. The permissions string of .qgis will look like:
drw_r__r__
And its owner and group will be root. This means that root can read and write in this directory, but all other users, including users in the root group, can read only. You could change the settings yourself, by running the chmod, chgrp, and chown commands, and that’s what you’d do if there was anything stored in the directory that you wanted to save. But it’s empty, so there’s no reason to keep it around:
sudo rm -Rf .qgis
rm is the remove command. -R makes the command run recursively, deleting any folders inside the folder, and -f forces the command to override any failsafes. This is a very powerful command, you do not want to use it lightly!
The next time you start QGIS, this folder will be recreated, but with you as the owner and group, and with a permission string of:
drwxrwxr_x
Which means that you and any member of your group can read, write, and execute, while other users can read and execute. One could write a whole book on managing permissions alone: all you need to know is that you can now use this directory to store customizations. Which will come in handy later.

That’s all there is to it. Feel free to play around with QGIS – you should be able to load many shapefiles, KML files, rasters, and even non-spatial tables, right out of the box. But the real power lies in connecting to a spatial database, which we will get to in Step Seven, the final installment in this series.

1 Comment

jarda on December 24, 2012 at 20:31.

fantastic job, possibly the best gis guide online. I cannot wait for the 7th lesson!