Install PostGIS 9.2 on RedHat 6.2

First you need to be able to resolve a few dependencies so you’ll need the epel repository.

$ wget

Now you can add the PostgreSQL repository to your system. Use the pgdg-centos92 package for CentOS and the pgdg-redhat92 package for Redhat.

$ wget
$ wget

NOTE: Redhat User’s only - I found Redhat repositories (6 and epel) do supply gdal-1.7 but it is compiled to be used with the UNIX ‘libodbc’ package that are not provided.  (I have no idea why.)  Because of this you will need to download the gdal-1.8 CentOS file.   This does not apply to CentOS user’s because the correct package is supplied.  (Go figure.)

 $ wget
$ rpm -i gdal-1.8.1-1.el6.x86_64 --nodeps

To use GIS functions you’ll need three packages.

$ yum install postgresql92
$ yum install postgresql92-server
$ yum install postgis2_92

You need to initialize (create) the default databases files before you start postgres.

$  /etc/init.d/postgresql-9.2 initdb

If you are going to connect to the servers from a workstation on your network you’ll need to let Postgres access all your network controllers (NICs).

$ vi /var/lib/pgsql/9.2/data/postgresql.conf

listen_addresses = '*'

And, you’ll need to tell Postgres from where and how users will connect.  So, you need to put in YOUR network address and netmask.

$ vi /var/lib/pgsql/9.2/data/pg_hba.conf

host    all             all             md5

Now you can start Postgres.

 $  /etc/init.d/postgresql-9.2 start

To use GIS functions you’ll need to add the postgis extension to your database. Most people create new databases from an existing template.  Change to (use) template1 before you added the extension to it.

 $ su - postgres
$ psql postgres
postgres=# \c template1
postgres=# create extension postgis;

Now you can create a GIS database for your data.

 $ createdb geodata -T template1

OR from psql you can create the extension and grant access to the GEO functions.

 postgres=# create database geodata;
postgres=# \c geodata
postgres=# create extension postgis;
postgres=# grant all on spatial_ref_sys to "postgres";
postgres=# grant all on geometry_columns to "postgres";

Here are the steps to download and load the Oklahoma county shapes into the database we created.

 $ wget
$ unzip
$ shp2pgsql county.shp  >  county.sql
$ psql geodata -f county.sql

Now lets try it.  What county is at this point on the earth?

$ psql geodata
geodata=# select name from county where ST_Contains(geom, ST_GeomFromText('POINT(-97.0 35.0)'));

name --------------

You may find it

How to use GIS functions.


Some interesting GIS data.