To test out PostGIS I decided to install it on my laptop. It should at least fit there
. PostGIS is an extension of PostgreSQL, so you need to install PostgreSQL first. You can find the download of PostgreSQL for your platform here. I use a Mac and it turned out that there is no straightforward package installation for the Mac. (Actually there is but it is maintained by a vendor of PostgreSQL and PostGIS services.) The other alternative is to build both PostgreSQL (and then PostGIS) from source. Even though I was not thrilled with the approach I soldiered on. Turns out, it isn’t as bad an experience as I thought it would be.
On a Mac, there is a build engine available called Fink that provides a tool that downloads source code, applies patches, resolves dependencies, configures and builds software. Obviously, you need to install Fink first on your Mac. For Fink to work, you need to have the right compilers installed also. It turns out that on a Mac, these compilers and whatnots come in a separate downloadable package called Xcode. You need to create a free account and jump through some links once you are logged in before you can download and install Xcode. Once you find it, the process of installation is straightforward.
With Xcode installed, I downloaded and installed Fink. Figuring out how to use Fink to download the PostgreSQL database (and then the PostGIS extensions later on) was also not difficult. I just followed the instructions on the Fink site. The command was: $fink install postgre for the PostgreSQL database. (I will get to the PostGIS part a little bit later.) Once you issue this command, it took quite a while for Fink to go through the entire process of installing the entire database. There was tonnes of output as can be expected from a full-blown build process. But the whole process was fairly smooth.
Finally the time came to install the PostGIS extensions. The extensions are actually a bunch of data types and functions that reside as a schema in the PostgreSQL database. However, these need to be built also and so Fink needs to be used once again. This time the command was: $fink install postgis83 (the 83 represents the 8.3 version of the PostgreSQL database with which it is compatible). Again there will be a huge amount of output and activity. The end result is a file called lwpostgis.sql that will be created in the directory /sw/share/doc/postgis83 on your Macintosh HD. For this file to run, you need to create a database called ‘postgis’ in your PostgreSQL database. The documentation for the database explains how to create the database.
In a nutshell, you first need to define the environment variable PGDATA to a location where the data files of PostgreSQL will be stored and then run the script ‘initdb’. Next the stored procedure language support needs to be installed on the database ‘template1′ by running the command $createlang plpgsql template1. Then you can create the database ‘postgis’ by running the command $createdb postgis. Since this is based of the ‘template1′ database, ‘postgis’ will have the stored procedure support already built-in. (All the steps mentioned in this paragraph are very nicely explained in the PostgreSQL database documentation.)
With the ‘postgis’ database created, you can now run the lwpostgis.sql script to create the data types and the spatial functions in ‘postgis’. The command is $psql -f /sw/share/doc/postgis83/lwpostgis.sql -d postgis.