PostGIS is a collection of GIS extensions for PostgreSQL. They can be found here:

Linux (source code):

Installation on Windows

Step 1:

Make certain that PostgreSQL is installed on your machine, and that the PostGIS extensions were not installed as part of the PostgreSQL installation. PostGIS is optional to install during the installation of PostgreSQL, but the version packaged with PostgreSQL is often several revisions behind the latest PostGIS releases. For installation of PostgreSQL, see PostgreSQL.

Step 2:

Run the PostGIS installer, install PostGIS as well as a spatial database. Call the spatial database ‘bootstrap’, as with PostgreSQL you need to connect to a database in order to do things such as DROP and CREATE other databases.

Installation on Linux

Unfortunately, the ‘fool-proof’ way to install PostGIS on Linux is to do it from sources. There are .rpms out there, but figuring out the dependencies can be an absolutely mind-numbing experience. Using sources is easier, and it works.

Step 1:

If PostgreSQL is already installed on your Linux machine, then download the appropriate PostgreSQL sources from here. Untar the sources to a directory where you have write and execute permissions.

If it is not installed, you can either install it from sources, or install it using your preferred linux install procedure (.rpm, .deb, apt, yum, etc.). See PostgreSQL

Step 2:

Download the sources for PostGIS here. Untar the sources into the contribdirectory of the source structure of PostgreSQL.

Step 3:

Do a make of the PostgreSQL sources to create the headers:

#> ./configure
#> make

Step 4:

Go into the contrib/postgis-#.#.# directory and do the following:

#> cd contrib/postgis-#.#.#
#> ./configure
#> make
#> make install

Step 5:

Create the ‘bootstrap’ database as a spatially-enabled database:

#> service postgresql start
#> su postgres
#> createdb bootstrap
#> createlang plpgsql bootstrap
#> psql -d bootstrap -f lwpostgis.sql
#> psql -d bootstrap -f spatial_ref_sys.sql

Creating a PostGIS enabled database

There are two ways to create a spatially-enabled database: using SQL or through the command-line.

Create a Spatially-Enabled Database using SQL

Use the following SQL statement:

create database ontrace template=template_postgis

Create a Spatially-Enabled Database from the Command-Line

Use the following commands:

#> createdb yourDatabase
#> createlang plpgsql yourDatabase
#> psql -d yourDatabase -f lwpostgis.sql
#> psql -d yourDatabase -f spatial_ref_sys.sql

It's only fair to share...
Share on Facebook
Tweet about this on Twitter
Share on LinkedIn

Leave a Reply