阅读更多
Postgis安装手册
1、 准备
A、 需要先安装好postgresql,本人目前安装的是9.3的版本,安装过程详见:http://jjxliu306.iteye.com/blog/2222106,具体版本可以去官网下载:http://www.postgresql.org/ftp/source/ 。
B、 准备postgis安装包和相关依赖,包含:gdal-1.9.2.tar.gz geos-3.4.2.tar.bz2 postgis-2.1.7.tar.gz proj-4.9.1.tar.gz libxml2.9.2.tar.gz。具体版本自定。
2、 安装gdal、geos、proj、libxml
[pumpkin@hl231 postgis_package]$ tar zxf gdal-1.9.2.tar.gz
[pumpkin@hl231 postgis_package]$ tar xf geos-3.4.2.tar.bz2
[pumpkin@hl231 postgis_package]$ tar zxf proj-4.9.1.tar.gz
[pumpkin@hl231 postgis_package]$ tar zxf libxml2.9.2.tar.gz
- - 创建依赖的安装目录
[pumpkin@hl231 postgis_package]$ mkdir ~/gis_lib
[pumpkin@hl231 postgis_package]$ mkdir ~/gis_lib/geos
[pumpkin@hl231 postgis_package]$ mkdir ~/gis_lib/gdal
[pumpkin@hl231 postgis_package]$ mkdir ~/gis_lib/proj
[pumpkin@hl231 postgis_package]$ mkdir ~/gis_lib/libxml2
- - 安装geos
[pumpkin@hl231 postgis_package]$ cd geos-3.4.2
[pumpkin@hl231 geos-3.4.2]$ ./configure --prefix=/home/pumpkin/gis_lib/geos/
…..
[pumpkin@hl231 geos-3.4.2]$ make
……
[pumpkin@hl231 geos-3.4.2]$ make install
……
- - 安装gdal
[pumpkin@hl231 geos-3.4.2]$ cd gdal-1.9.2
[pumpkin@hl231 gdal-1.9.2]$ ./configure --prefix=/home/pumpkin/gis_lib/gdal/
….
[pumpkin@hl231 gdal-1.9.2]$ make
…..
- - 安装proj
[pumpkin@hl231 proj-4.9.1]$ ./configure --prefix=/home/pumpkin/gis_lib/proj/
….
[pumpkin@hl231 proj-4.9.1]$ make
……
[pumpkin@hl231 proj-4.9.1]$ make install
……
- - 安装libxml2
[pumpkin@hl231 proj-4.9.1]$cd ../libxml2-2.9.2/
[pumpkin@hl231 libxml2-2.9.2]$ ./configure --prefix=/home/pumpkin/gis_lib/libxml2/
…..
[pumpkin@hl231 libxml2-2.9.2]$ make
…..
[pumpkin@hl231 libxml2-2.9.2]$ make install
…..
备注:安装过程中可能会出现gcc not found的异常,这时候需要检查一下gcc是否安装或者版本太旧。(这部分依赖项太多,建议通过yum自动去打)通过命令更新和安装:
yum -y update gcc
yum -y install gcc+ gcc-c++
安装libxml2中可能会出现没找到python,那么需要安装python,需要三个包:
python-2.6.6-52.el6.x86_64.rpm ,python-devel-2.6.6-52.el6.x86_64.rpm ,python-libs-2.6.6-52.el6.x86_64.rpm 或者通过yum自动安装 :yum –y install python-devel
python默认root安装的话,可能安装libxml2中会出现写文件到/usr/lib/python目录没有权限,这时候需要手动修改一下目录权限,或者libxml2通过root用户去安装.
3、 安装postgis
[pumpkin@hl231 postgis_package]$ tar zxf postgis-2.1.7.tar.gz
[pumpkin@hl231 postgis_package]$ cd postgis-2.1.7
[pumpkin@hl231 postgis-2.1.7]$ ./configure --with-pgconfig=/home/pumpkin/pg9.3/bin/pg_config --with-projdir=/home/pumpkin/gis_lib/proj/ --with-gdalconfig=/home/pumpkin/gis_lib/gdal/bin/gdal-config --with-geosconfig=/home/pumpkin/gis_lib/geos/bin/geos-config --prefix=/home/pumpkin/pg9.3/ --with-xml2config=/home/pumpkin/gis_lib/libxml2/bin/xml2-config
…..
PostGIS is now configured for x86_64-unknown-linux-gnu
-------------- Compiler Info -------------
C compiler: gcc -g -O2
C++ compiler: g++ -g -O2
SQL preprocessor: /usr/bin/cpp -w -traditional-cpp -P
-------------- Dependencies --------------
GEOS config: /home/pumpkin/gis_lib/geos/bin/geos-config
GEOS version: 3.4.2
GDAL config: /home/pumpkin/gis_lib/gdal/bin/gdal-config
GDAL version: 1.9.2
PostgreSQL config: /home/pumpkin/pg9.3/bin/pg_config
PostgreSQL version: PostgreSQL 9.3.5
PROJ4 version: 49
Libxml2 config: /home/pumpkin/gis_lib/libxml2/bin/xml2-config
Libxml2 version: 2.9.2
JSON-C support: no
PostGIS debug level: 0
Perl: /usr/bin/perl
--------------- Extensions ---------------
PostGIS Raster: enabled
PostGIS Topology: enabled
SFCGAL support: disabled
-------- Documentation Generation --------
xsltproc: /usr/bin/xsltproc
xsl style sheets:
dblatex:
convert: /usr/bin/convert
mathml2.dtd: http://www.w3.org/Math/DTD/mathml2/mathml2.dtd
- - 待出现上面提示以后说明一切正常
[pumpkin@hl231 postgis-2.1.7]$ make
…..
PostGIS was built successfully. Ready to install.
[pumpkin@hl231 postgis-2.1.7]$ make install --安装
…….
make[2]: Leaving directory `/home/pumpkin/postgis_package/postgis-2.1.7/extensions/postgis_topology'
make[1]: Leaving directory `/home/pumpkin/postgis_package/postgis-2.1.7/extensions'
[pumpkin@hl231 postgis-2.1.7]$ -- 至此已经安装完毕
4、 测试
通过创建一个gis数据库挂载postgis扩展。然后创建一张gis表插入数据,一切正常就好。
[pumpkin@hl231 postgis-2.1.7]$ psql -U postgres
psql (9.3.5)
Type "help" for help.
postgres=# \timing
Timing is on.
postgres=# create database test_postgis;
CREATE DATABASE
Time: 1682.990 ms
postgres=# \c test_postgis
You are now connected to database "test_postgis" as user "postgres".
test_postgis=# create extension postgis; -- 这一步挂载postgis扩展
CREATE EXTENSION
Time: 2445.074 ms
test_postgis=# create table test_point(id int , point geometry(point , 4326));
CREATE TABLE
Time: 43.941 ms
test_postgis=# insert into test_point select generate_series(1,100) , st_setsrid
(st_point(100 + random() , 30 + random()) , 4326);
INSERT 0 100
Time: 19.161 ms
test_postgis=# select id , st_astext(point) from test_point limit 4;
id | st_astext
----+------------------------------------------
1 | POINT(100.629254838452 30.457803351339)
2 | POINT(100.677935550455 30.9276350429282)
3 | POINT(100.476794262417 30.3782760496251)
4 | POINT(100.088196526747 30.1213041353039)
(4 rows)
Time: 0.755 ms
test_postgis=#
5、