之前 blog 介绍了 postgis 1.5 的安装, Postgis 2.0 已经 release 有一段时间了,和之前版本相比,需要多安装很多组件,一直没整理,这次需要在测试环境下装一套 Postgis 2.0 ,抽时间整理下。
所需组件
PostgreSQL 8.4 or higher.
Proj4 reprojection library, version 4.6.0 or greater
GEOS geometry library, version 3.2.2 or greater, but GEOS 3.3.2+ is recommended.
LibXML2, version 2.5.x or higher. LibXML2 is currently used in some imports functions
JSON-C, version 0.9 or higher. JSON-C is currently used to import GeoJSON via the function ST_GeomFromGeoJson.
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
备注:也可以在 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/projexport GEOS_HOME =/usr/local/pg_tool/geosexport GDAL_HOME =/usr/local/pg_tool/gdalexport 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=/u sr/local/ pg_tool/proj --with-geosconfig=/u sr/local/ pg_tool/geos/ bin/geos-config --with-gdalconfig=/u sr/local/ pg_tool/gdal/ bin/gdal-config --with-jsondir=/u sr/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:
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
[ - ] . . [ - ] - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - . - - . . . - - - - - - . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . - - . . . - - - - - - - - . . . - - - - - - . - - - - - - . - - - - . . . - - - - - - - - - - . . .
备注:此时说明 Postgis 安装成功。
测试 PostGIS
4.1 安装 postgis 和 postgis_topology 模块
1 2 3 4 5 6 7 8 9 10 11
postgres =# /c francsYou 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= List of data types Schema | Name | Description -------- +---------- +----------------------------------------- public | geometry | postgis type: Planar spatial data type. (1 row) francs= CREATE TABLE francs= francs- INSERT 0 1 francs= gid | geom | name ----- +------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ---------- +----------- 1 | 01030000800100000005000000000000000000000000000000000000000000000000000000000000000000000000000000000014400000000000000000000 000000000144000000000000014400000000000000000000000000000144000000000000000000000000000000000000000000000000000000000000000000000000 000000000 | 3D Square (1 row)
参考
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/237947.html