Welcome to Step Two in our exploration of open source GIS using Ubuntu. In order to grasp the full power of GIS, we need to spatially extend our database (PostgreSQL, which was installed in the previous step). The spatial extension for PostgreSQL is PostGIS, which we will eventually be installing. But before we can get to that, there are a lot of prerequisites to install, and not all of them are available in the Ubuntu Software Center.
Warning: If you haven’t completed the previous step, installing and configuring PostgreSQL, none of the following will work at all – you’ll get all kinds of crazy errors. So unless you have PostgreSQL installed and working on your machine already, you’ll need to go back and do that before proceeding.
1. Before we can start installing the dependencies of PostGIS, we have to install the dependencies of the dependencies of PostGIS. This could be done using the Ubuntu Software Center, but that would take forever, because you would have to search for each package by name and then install it. So I’m going to introduce a new way to install software – apt-get. Apt-get is the main engine behind the Ubuntu Software Center, which we can access directly by using the terminal. Enter the following commands into the terminal, providing your password when prompted:
sudo apt-get install postgresql-server-dev-9.1 proj libjson0-dev xsltproc docbook-mathml docbook-xsl
(this command will prompt you to install these 6 packages, plus 7 or more additional packages)
When that’s done, there are four more apt-get commands to run:
sudo apt-get install gettext dblatex openjdk-7-jre openjdk-7-jdk icedtea-7-plugin libxml2-dev
(this command will prompt you to install these 6 packages, plus 53 or more additional packages)
(note: the icedtea plugin package is not required for this tutorial, but you might as well get it now so you can use this version of Open Java (openjdk) in your web browser)
sudo apt-get install swig php5-dev phpunit openjpeg-tools libopenjpeg-dev libkml-dev
(this command will prompt you to install these 6 packages, plus 5 or more additional packages)
sudo apt-get install libpoppler19 libpoppler-dev expat libexpat1-dev libxerces-c-dev libcurl4-openssl-dev
(this command will prompt you to install these 6 packages, plus 4 or more additional packages)
sudo apt-get install g++ python-dev ruby
(this command will prompt you to install these 3 packages, plus 3 or more additional packages)
2. Now we can begin by downloading and installing GEOS. GEOS, or Geometry Engine Open Source is a library of routines for handling spatial geometry and topology. An older version of this package could be installed using apt-get or the Ubuntu Software Center, but we need the latest version, so we have to download the source package, which can be found at:
The latest version as of this writing is geos-3.3.5.tar.bz2, which you should save to the Downloads folder on your hard drive.
3. Installing GEOS is fairly simple. In the terminal, change the directory to the location where you saved the file:
In this case, the ~ is short for your home directory. The first thing to do is uncompress the downloaded file. Recall that it had an extension of .tar.bz2. Tar is an archive format, and bzip2 is a compression algorithm – you might say that the file has been compressed two ways. It only takes one command to decompress the file:
tar jxf geos-3.3.5.tar.bz2
tar is the decompression program, j tells it to use the bzip2 algorithm, x is to extract, and f means file. This will create a directory called geos-3.3.5, and you can delete the tar.bz2 file (also called a tarball) if you want. Now we’ll change into that directory:
Before the installation, we need to set up which options we will use. This is done using a script called ‘configure’, which can be found in this directory. Running the script with the -h flag will provide us a list of options, so let’s do that first.
Uh-oh! You probably got an error there:
configure: command not found
That’s because this directory is not part of the system’s path, which is a list of locations where executable programs live. To see you path, enter this command:
We could add the current directory to the path, but that’s a lot of work. It’s much easier to prepend the command with a ./, which means to “run from here”:
You’ll see a long list of configuration options fly by, giving you an idea just how much customization can be done. I’ve selected the most useful options for you already:
./configure –enable-python –enable-php –enable-ruby
This will take a couple minutes, but don’t get up and stretch your legs just yet. When configuration is complete, without any errors, it’s time for the really long command:
Now is the time to get up and stretch, because you’re compiling software from source, which will probably take about 15 minutes. When it finishes, you can install the new libraries into their proper locations by running:
sudo make install
One of the things you have just installed is a small utility app that provides some information about GEOS to the system. You can use this app to check the installation by entering:
If everything went well, you should see:
4. Now it’s time to download GDAL, the Geospatial Abstraction Data Library. This library is the backbone of open source GIS. You can find it here:
The latest version as of this writing is gdal-1.9.1.tar.gz, which you should save to the Downloads folder on your hard drive.
5. Installing GDAL will be very similar to installing GEOS, but with a couple exceptions. The first is that the GDAL tarball uses gzip compression instead of bzip2 compression, so we’ll call tar with the z flag instead of the j flag. Also, the number of configuration options is considerably longer. But otherwise, the process is the same. Here’s the complete list of commands to run:
tar zxf gdal-1.9.1.tar.gz
./configure –with-python –with-poppler –with-pg –with-curl –with-openjpeg –with-geos –with-geotiff –with-jpeg –with-png –with-expat –with-xerces –with-java
sudo make install
Afterwards, you can check the installation using gdal-config:
Which should let you know that we have successfully installed:
6. We’ve just installed a ton of new libraries and header files. Now we need to add all these libraries to an indexing database so that the dynamic linker (which is called ld) can find them. This is done automatically after running apt-get, but it has to be done manually when installing software from source. Fortunately, it’s a simple command:
Once you have done this, you can delete the tarballs you downloaded earlier, and the install directories from your Downloads folder.
Coming up in Step Three, we’ll be downloading, installing, and exploring PostGIS. The process will be very similar to the one we used here, so if you’ve made it this far, you should have no trouble with any of the other installation tutorials I have planned.