Installing PostGIS CentOS5.4

Install PostgreSQL

$ sudo /usr/sbin/adduser postgres
wget http://www.ring.gr.jp/pub/misc/db/postgresql/source/v8.4.4/postgresql-8.4.4.tar.gz
$ ./configure 
$ make 
$ sudo make install
$ sudo chown -R postgres:postgres /usr/local/pgsql

.zshrc

export PGHOME=/usr/local/pgsql
export PGLIB=$PGHOME/lib
export PGBIN=$PGHOME/bin
export PGDATA=$PGHOME/data
export PATH=$PATH:$PGBIN
export LD_LIBRARY_PATH=/usr/local/lib:$PGLIB

Start PostgreSQL

$ su postgres -c "initdb --no-locale --encoding=UTF8"
$ su postgres -c "pg_ctl -w start"
---
LOG:  database system is ready to accept connections
 done
server started

PostgreSQL startup script

$ sudo cp /home/postgres/postgresql-8.4.4/contrib/start-scripts/linux /etc/rc.d/init.d/postgresql
$ sudo chmod 755 /etc/rc.d/init.d/postgresql
$ sudo chkconfig --add postgresql
$ sudo chkconfig postgresql on  
$ service postgresql start

/etc/ld.so.conf

include ld.so.conf.d/*.conf
/usr/local/lib
/usr/local/pgsql/lib/

then

/sbin/ldcondig

Install Proj

wget http://download.osgeo.org/proj/proj-4.7.0.tar.gz
$ ./configure
$ make 
$ sudo make install

Install Geos

wget http://download.osgeo.org/geos/geos-3.2.2.tar.bz2
$ ./confiture
-----
Swig: false
Python: false
Ruby: false

$ make 
$ sudo make install

Install libxml2

$sudo yum install libxml2-devel

Install PostGIS

wget http://postgis.refractions.net/download/postgis-1.5.1.tar.gz
$ ./configure --with-geosconfig=/usr/local/bin/geos-config --with-projdir=/usr/local/lib
PostGIS is now configured for i686-pc-linux-gnu

 -------------- Compiler Info -------------
  C compiler:           gcc -g -O2
  C++ compiler:         g++ -g -O2

 -------------- Dependencies --------------
  GEOS config:          /usr/local/bin/geos-config
  GEOS version:         3.2.2
  PostgreSQL config:    /usr/local/pgsql/bin/pg_config
  PostgreSQL version:   PostgreSQL 8.4.4
  PROJ4 version:        47
  Libxml2 config:       /usr/bin/xml2-config
  Libxml2 version:      2.6.26
  PostGIS debug level:  0

 -------- Documentation Generation --------
  xsltproc:             /usr/bin/xsltproc
  xsl style sheets:    
  dblatex:             
  convert:              /usr/bin/convert

$ make 
$ sudo make install

Test Installation

$ su postgres
$ cd /home/postgres/postgis-1.5.1
$ make test
--- 
 ok
 regress_buffer_params. ok
 hausdorff. ok

Run tests: 49
Failed: 0

Create GIS database

$ createdb gistest
$ createlang plpgsql gistest
$ psql -d gistest -f /usr/local/pgsql/share/contrib/postgis-1.5/postgis.sql
$ psql -d gistest -f /usr/local/pgsql/share/contrib/postgis-1.5/spatial_ref_sys.sql

SQL

$ psql -U postgres gistest
gistest=# CREATE TABLE gis(id SERIAL);
gistest=# SELECT AddGeometryColumn('gis', 'latlng', 4326, 'POINT', 2);
gistest=# SELECT AddGeometryColumn('gis', 'line', 4326, 'LINESTRING', 2);
gistest=# SELECT AddGeometryColumn('gis', 'polygon', 4326, 'POLYGON', 2);
gistest=# INSERT INTO gis (latlng, line, polygon) VALUES (GeomFromText('POINT(50 50)', 4326), GeomFromText('LINESTRING(1 1, 99 99)', 4326), GeomFromText('POLYGON((25 25, 75 25, 75 75, 25 75, 25 25))', 4326));
gistest=# select AsText(latlng), AsText(line), AsText(polygon) from gis;
    astext    |        astext         |                  astext                 
--------------+-----------------------+------------------------------------------
 POINT(50 50) | LINESTRING(1 1,99 99) | POLYGON((25 25,75 25,75 75,25 75,25 25))
(1 row)
Posted: July 21st, 2010 | Author: | Filed under: 技術 | No Comments »

Leave a Reply