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 http://mirror.chpc.utah.edu/pub/epel/6/i386/epel-release-6-7.noarch.rpm

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 http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-5.noarch.rpm
$ wget http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-redhat92-9.2-7.noarch.rpm

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 http://yum.opengeo.org/centos/6/x86_64/gdal-1.8.1-1.el6.x86_64.rpm
$ 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             192.168.1.0/24          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;
\q

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 http://geo.ou.edu/oeb/Statewide/COUNTY.zip
$ unzip COUNTRY.zip
$ 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 --------------
POTTAWATOMIE (1 row)

You may find it

How to use GIS functions.

http://postgis.refractions.net/docs/using_postgis_dbmanagement.html#id590441

 

Some interesting GIS data.

http://geo.ou.edu/DataFrame.htm

http://downloads.cloudmade.com/

 


Tweet