PostgreSQL:PostGIS 2.0 安装

之前 blog 介绍了 postgis 1.5 的安装, Postgis 2.0 已经 release 有一段时间了,和之前版本相比,需要多安装很多组件,一直没整理,这次需要在测试环境下装一套 Postgis 2.0 ,抽时间整理下。

所需组件

  1. PostgreSQL 8.4 or higher.
  2. Proj4 reprojection library, version 4.6.0 or greater
  3. GEOS geometry library, version 3.2.2 or greater, but GEOS 3.3.2+ is recommended.
  4. LibXML2, version 2.5.x or higher. LibXML2 is currently used in some imports functions
  5. JSON-C, version 0.9 or higher. JSON-C is currently used to import GeoJSON via the function ST_GeomFromGeoJson.
  6. GDAL, version 1.6 or higher

环境信息

Postgresql: 9.2.3
Postgis: 2.0.2
OS : CentOS release 5.4 (Final)

安装 PostGIS

安装 PostGIS 首先安装 pro、GEOS、JSON-C、GDAL、libXML2 插件,以下是详细安装步骤。

安装 Proj-4.8.0

下载地址: http://trac.osgeo.org/proj/

简要步骤

1
2
3
4
# mkdir -p /usr/local/pg_tool/proj
#./configure --prefix=/usr/local/pg_tool/proj
# make
# make install

备注:安装过程中没报错,并且 /usr/local/pg_tool/proj 目录下有文件,说明 proj 安装成功。

安装 Geos-3.3.8

下载地址: http://trac.osgeo.org/geos/

简要步骤

1
2
3
4
5
# mkdir -p /usr/local/pg_tool/geos
# ./configure --prefix=/usr/local/pg_tool/geos --enable-python --enable-ruby
# make
# make check
# make install

安装 JSON-C 0.9

下载地址: http://oss.metaparadigm.com/json-c/
简要步骤

1
2
3
4
5
6
#wget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz  
# mkdir -p /usr/local/pg_tool/json
#sh autogen.sh
# ./configure --prefix=/usr/local/pg_tool/json
# make
# make install

安装 GDAL-1.9.2

下载地址:http://trac.osgeo.org/gdal/wiki/DownloadSource

简要步骤

1
2
3
4
# mkdir -p /usr/local/pg_tool/gdal
# ./configure --prefix=/usr/local/pg_tool/gdal
# make
# make install

安装 LibXML2

1
# yum install libxml2

备注:也可以在 http://www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html 下载。

安装 PostGIS-2.0.2

3.6.1 .bash_profile 新增以下环境变量

1
2
3
4
5
export PROJ_HOME=/usr/local/pg_tool/proj
export GEOS_HOME=/usr/local/pg_tool/geos
export GDAL_HOME=/usr/local/pg_tool/gdal
export JSON_HOME=/usr/local/pg_tool/json
export LD_LIBRARY_PATH=$GDAL_HOME/lib:$JSON_HOME/lib:$PROJ_HOME/lib:$GEOS_HOME/lib

备注:编缉完成后,执行.bash_profile 立即生效。

3.6.2 下载 postgis-2.0.2
下载地址: http://postgis.refractions.net/download/

3.6.3 configure

1
# ./configure --with-pgconfig=/opt/pgsql9.2.3/bin/pg_config --with-projdir=/usr/local/pg_tool/proj --with-geosconfig=/usr/local/pg_tool/geos/bin/geos-config --with-gdalconfig=/usr/local/pg_tool/gdal/bin/gdal-config --with-jsondir=/usr/local/pg_tool/json

备注:执行 configure 之后,如果没报错,会出现以下信息:

3.6.4 configure 结果信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
PostGIS is now configured for i686-pc-linux-gnu

-------------- Compiler Info -------------
C compiler: gcc -g -O2
C++ compiler: g++ -g -O2
SQL preprocessor: /usr/bin/cpp -traditional-cpp -P

-------------- Dependencies --------------
GEOS config: /usr/local/pg_tool/geos/bin/geos-config
GEOS version: 3.3.8
GDAL config: /usr/local/pg_tool/gdal/bin/gdal-config
GDAL version: 1.9.2
PostgreSQL config: /opt/pgsql9.2.3/bin/pg_config
PostgreSQL version: PostgreSQL 9.2.3
PROJ4 version: 48
Libxml2 config: /usr/bin/xml2-config
Libxml2 version: 2.6.26
JSON-C support: yes
PostGIS debug level: 0
Perl: /usr/bin/perl

--------------- Extensions ---------------
PostGIS Raster: enabled
PostGIS Topology: enabled

-------- 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

3.6.5 编译并安装

1
2
3
# make
# make check
# make install

3.6.6 安装完成后,在 $PGHOME/share/extension 下会产生以下文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[pg92@mpchat-server1 extension]$ pwd
/opt/pgsql9.2.3/share/extension

[pg92@mpchat-server1 extension]$ ll postgis*
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0alpha1--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0alpha2--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0alpha3--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0alpha4--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0alpha5--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0alpha6--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0beta1--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0beta2--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0beta3--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0beta4--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0rc1--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.0rc2--2.0.2.sql
-rw-r--r-- 1 root root 486K Mar 29 16:27 postgis--2.0.1--2.0.2.sql
-rw-r--r-- 1 root root 4.0M Mar 29 16:27 postgis--2.0.2.sql
-rw-r--r-- 1 root root 185 Mar 29 16:27 postgis.control
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0alpha1--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0alpha2--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0alpha3--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0alpha4--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0alpha5--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0alpha6--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0beta1--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0beta2--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0beta3--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0beta4--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0rc1--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.0rc2--2.0.2.sql
-rw-r--r-- 1 root root 281K Mar 29 16:27 postgis_topology--2.0.1--2.0.2.sql
-rw-r--r-- 1 root root 278K Mar 29 16:27 postgis_topology--2.0.2.sql
-rw-r--r-- 1 root root 169 Mar 29 16:27 postgis_topology.control
-rw-r--r-- 1 root root 8.0K Mar 29 16:27 postgis_topology--unpackaged--2.0.2.sql
-rw-r--r-- 1 root root 77K Mar 29 16:27 postgis--unpackaged--2.0.2.sql

备注:此时说明 Postgis 安装成功。

测试 PostGIS

4.1 安装 postgis 和 postgis_topology 模块

1
2
3
4
5
6
7
8
9
10
11
postgres=# /c francs
You are now connected to database "francs" as user "postgres".

francs=# create extension postgis;
CREATE EXTENSION

francs=# create extension postgis_topology;
CREATE EXTENSION

francs=#CREATE EXTENSION fuzzystrmatch;
CREATE EXTENSION

4.2 创建测试表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
francs=# /dT geometry
List of data types
Schema | Name | Description
--------+----------+-----------------------------------------
public | geometry | postgis type: Planar spatial data type.
(1 row)

francs=# CREATE TABLE geom_test ( gid int4, geom geometry, name varchar(25) );
CREATE TABLE

francs=# INSERT INTO geom_test ( gid, geom, name )
francs-# VALUES ( 1, 'POLYGON((0 0 0,0 5 0,5 5 0,5 0 0,0 0 0))', '3D Square');
INSERT 0 1

francs=# SELECT * from geom_test WHERE geom && 'BOX3D(2 2 0,3 3 0)'::box3d;
gid |
geom
| name
-----+------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------
----------+-----------
1 | 01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000
000000000144000000000000014400000000000000000000000000000144000000000000000000000000000000000000000000000000000000000000000000000000
000000000 | 3D Square
(1 row)

参考

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/237947.html

(0)
上一篇 2022年1月29日
下一篇 2022年1月29日

相关推荐

发表回复

登录后才能评论