1. 程式人生 > >PostgreSQL外掛:Postgis編譯安裝

PostgreSQL外掛:Postgis編譯安裝

文章目錄

概述

在遷移的過程中,發現使用者資料庫中還安裝了postgis拓展,所以在測試時也需要安裝一下此拓展
PostGIS是物件關係型資料庫系統PostgreSQL的一個擴充套件,PostGIS提供如下空間資訊服務功能:空間物件、空間索引、空間操作函式和空間操作符。

安裝準備

postgis的安裝需要一些依賴軟體,這些軟體我們試著先用yum源安裝,但是好像不行,postgis在編譯時會報錯,所以最好這些軟體都需要編譯安裝

安裝Proj4

$ wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz
$ tar -xf proj-4.9.3.tar.gz
$ cd proj-4.9.3
$ ./configure --prefix=/usr/proj
$ make
$ make install
# echo "/usr/proj/lib" > /etc/ld.so.conf.d/proj-4.9.3.conf
# ldconfig

安裝GEOS

$ wget http://download.osgeo.org/geos/geos-3.6.1.tar.bz2
$ tar -jxf geos-3.6.1.tar.bz2
$ cd geos-3.6.1
$ ./configure --prefix=/usr/geos
$ make
$ make install
# echo "/usr/geos/lib" > /etc/ld.so.conf.d/geos-3.6.1.conf
# ldconfig

安裝GDAL

$ wget http://download.osgeo.org/gdal/2.1.2/gdal-2.1.2.tar.gz
$ tar -xf gdal-2.1.2.tar.gz
$ cd gdal-2.1.2
$ ./configure --prefix=/usr/gdal
$ make
$ make install
# echo "/usr/gdal/lib" > /etc/ld.so.conf.d/gdal-2.1.2.conf
# ldconfig

安裝postgis

$ wget http://download.osgeo.org/postgis/source/postgis-2.2.5.tar.gz
$ tar -xf postgis-2.2.5.tar.gz
$ cd postgis-2.2.5
$ ./configure --with-pgconfig=/usr/pgsql/bin/pg_config --with-geosconfig=/usr/geos/bin/geos-config --with-gdalconfig=/usr/gdal/bin/gdal-config  --with-projdir=/usr/proj --with-sfcgal=/usr/bin/sfcgal-config  --prefix=/usr/pgsql/share/contrib/postgis
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
...........
config.status: executing po-directories commands

  PostGIS is now configured for x86_64-pc-linux-gnu

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

 -------------- Dependencies -------------- 
  GEOS config:          /usr/geos/bin/geos-config
  GEOS version:         3.6.1
  GDAL config:          /usr/gdal/bin/gdal-config
  GDAL version:         2.1.2
  SFCGAL config:        /usr/bin/sfcgal-config
  SFCGAL version:       1.2.2
  PostgreSQL config:    /usr/pgsql/bin/pg_config
  PostgreSQL version:   PostgreSQL 10.3
  PROJ4 version:        49
  Libxml2 config:       /usr/bin/xml2-config
  Libxml2 version:      2.9.1
  JSON-C support:       yes
  protobuf-c support:   no
  PCRE support:         yes
  Perl:                 /usr/bin/perl

 --------------- Extensions --------------- 
  PostGIS Raster:       enabled
  PostGIS Topology:     enabled
  SFCGAL support:       enabled
  Address Standardizer support:       enabled

 -------- Documentation Generation -------- 
  xsltproc:             /usr/bin/xsltproc
  xsl style sheets:     
  dblatex:              
  convert:              
  mathml2.dtd:          http://www.w3.org/Math/DTD/mathml2/mathml2.dtd

configure: WARNING:  --------- GEOS VERSION WARNING ------------ 
configure: WARNING:   You are building against GEOS 3.6.1 
configure: WARNING:   To take advantage of all the features of 
configure: WARNING:   this PostGIS version requires GEOS 3.7.0 or higher which is not out yet.
configure: WARNING:   To take advantage of most of the features of this PostGIS
configure: WARNING:   we recommend GEOS 3.6 or higher
configure: WARNING:   You can download the latest versions from 
configure: WARNING:   http://trac.osgeo.org/geos 
configure: WARNING: 

make時的報錯

我們在編譯完成之後,執行make的時候報錯

lwgeom_sfcgal.h:28:34: fatal error: SFCGAL/capi/sfcgal_c.h: No such file or directory

這個錯誤的原因應該是SFCGAL這個軟體沒有安裝,這個也需要編譯安裝

安裝SFCGAL

下載地址:

http://oslandia.github.io/SFCGAL/installation.html

此軟體的編譯需要cmake,所以需要先把cmake安裝好

Compilation
The compilation process is based on CMake. On linux run:

cmake . && make && sudo make install

在這個過程中cmake可能還會報錯。gdal的類似錯誤
解決方法是:

https://www.cgal.org/download.html

將 CGAL-4.7.tar.gz 下載並安裝

cmake才會成功

測試

連線到pg資料庫上,建立拓展

proxydb=# create extension postgis;
CREATE EXTENSION
proxydb=# create extension postgis_topology ;
CREATE EXTENSION
proxydb=# 

總結

安裝時的依賴過多,且層層依賴,需要一個個解決。