PostGIS 3.0.1編譯安裝



PostGIS 3.0.1編譯安裝

PostGIS和PostgreSQL的版本依賴矩陣詳見UsersWikiPostgreSQLPostGIS

image


centos如何配置本地yum源(如果可以鏈接外網請跳過此步)

請參考另一篇博客:https://www.cnblogs.com/haolb123/p/14140632.html


依賴包安裝

依賴包下載

PostGIS依賴了大量的外部包,都需要編譯安裝,所需要的資源可以在PostGIS 3.0.1依賴包中下載,筆者已經確定版本無誤,能夠安裝成功

或者,參考官方的PostGIS的依賴包版本關系,依次下載對應版本

官方PostGIS依賴關系圖


必須安裝的軟件或函數庫

  • PostgreSQL    ——    PostGIS構建於PostgreSQL之上,所以PostgreSQL必須要安裝。
  • GNU C 編譯器(gcc)    ——    gcc是一個Linux中最標准的C語言編譯器,需要安裝gcc來編譯PostGIS和其他軟件或函數庫的源碼。
  • GNU Make(gmake或make)——    這個也是用於編譯源碼。
  • Proj4    ——    Proj4 重投影庫用於在PostGIS中提供坐標重投影功能。
  • GEOS   ——    GEOS幾何圖形庫,用於支持PostGIS中的幾何信息處理、分析等功能,也可以直接認為GEOS是一個幾何算法庫。
  • LibXML2    ——    LibXML2目前用於PostGIS中的一些導入函數,比如ST_GeomFromGML()和ST_GeomFromKML()。
  • JSON-C    ——    目前使用JSON-C通過ST_GeomFromGeoJSON()函數導入GeoJSON格式的數據
  • GDAL    ——    用於PostGIS對柵格數據的支持。
  • 其他。。。待更新


可選的軟件或函數庫

  • SFCGAL    ——    用於提供額外的二維和三維的高級分析功能。允許對一些函數使用基於SFCGAL的實現,而不是使用基於GEOS的實現(例如ST_Intersection()和ST_Area()函數),如果安裝了SFCGAL,PostgreSQL的配置變量postgis.backend允許終端用戶控制他想使用哪個實現(默認情況下是GEOS的實現)。另外,SFCGAL依賴於CGAL和Boost這兩個軟件,即如果想安裝SFCGAL,就先要安裝這兩個軟件。最后pgrouting插件也依賴於CGAL和Boost


上傳依賴包位置:/usr/local/src目錄

下載好源碼包后,把相關源碼包拷貝到centos中的/usr/local/src這個目錄里。另外,推薦使用root用戶進行安裝,否則可能會權限不夠。

[root@localhost src]# pwd
/usr/local/src
[root@localhost src]# ll
總用量 71000
-rw-r--r--. 1 root root 15618196 12月 15 13:58 CGAL-4.14.3.tar.xz
-rw-r--r--. 1 root root  9473549 12月 15 13:58 cmake-3.17.4.tar.gz
-rw-r--r--. 1 root root 14379480 12月 15 13:58 gdal-3.0.4.tar.gz
-rw-r--r--. 1 root root  2505407 12月 15 13:58 geos-3.8.1.tar.bz2
-rw-r--r--. 1 root root   622640 12月 15 13:58 json-c-json-c-0.13-20171207.tar.gz
-rw-r--r--. 1 root root 16839923 12月 15 13:58 postgis-3.0.1.tar.gz
-rw-r--r--. 1 root root  2698759 12月 15 13:58 proj-6.2.1.tar.gz
-rw-r--r--. 1 root root  7571215 12月 15 13:58 protobuf-all-3.14.0.tar.gz
-rw-r--r--. 1 root root   500100 12月 15 13:58 protobuf-c-1.3.2.tar.gz
-rw-r--r--. 1 root root  2473776 12月 15 13:58 SFCGAL-1.3.7.tar.gz
[root@localhost src]#


安裝gcc

[root@localhost ~]# yum install -y gcc
[root@localhost ~]# yum install -y gcc-c++


GEOS編譯安裝:

源碼下載參考:wget https://download.osgeo.org/geos/geos-3.7.0.tar.bz2

 
        
/usr/local/src

tar -jxvf geos-3.8.1.tar.bz2

cd geos-3.8.1

./configure

make && make install


PROJ編譯安裝

源碼下載參考:wget http://download.osgeo.org/proj/proj-5.2.0.tar.gz

 
        

/usr/local/src

tar -zxvf proj-6.2.1.tar.gz

cd proj-6.2.1

./configure

make && make install

執行./configure時,可能報錯 No package ‘sqlite3’ found,執行yum -y install sqlite sqlite-devel即可


升級protobuf

源碼下載參考:wget https://github.com/protocolbuffers/protobuf/archive/v2.6.1.tar.gz

protobuf-c依賴protobuf,所以先安裝protobuf。

tar -zxvf protobuf-all-3.14.0.tar.gz

cd protobuf-3.14.0

./configure 

make && make install

安裝完成后,需要修改LD_LIBRARY_PATH和PKG_CONFIG_PATH環境變量,防止系統找不到新安裝的protobuf。可編輯/etc/profile如下

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

刷新環境變量:source /etc/profile

正常情況下,/usr/local/lib/pkgconfig地址下應該有protobuf.pc文件,如果沒有,則是安裝異常。


安裝protobuf-c

源碼下載參考:wget https://github.com/protocolbuffers/protobuf/archive/v2.6.1.tar.gz

tar -zxvf protobuf-c-1.3.2.tar.gz

cd protobuf-c-1.3.2/

./configure

make && make install

安裝成功后,執行命令protoc --version顯示如下

libprotoc 3.14.0


安裝json-c

源碼下載參考:wget https://github.com/json-c/json-c/archive/json-c-0.13.1-20180305.tar.gz

tar -zxvf json-c-json-c-0.13-20171207.tar.gz

cd json-c-json-c-0.13-20171207/

./configure

make && make install


編譯安裝CMake(非必須,如果要裝SFCGAL)

由於PostGIS對應的版本比較新,因此CentOS 7默認的CMake版本不足,需要編譯安裝新版本的CMake

CMake安裝需要openssl相關庫

yum -y install openssl openssl-devel

安裝CMake

源碼下載參考:wget https://github.com/Kitware/CMake/releases?after=v3.16.9

cd /usr/local/src

tar -zxvf cmake-3.17.4.tar.gz

cd cmake-3.17.4

./bootstrap

gmake

make install


安裝CGAL(非必須,如果要裝SFCGAL)

源碼下載參考:wget wget https://github.com/CGAL/cgal/archive/releases/CGAL-4.13.tar.gz

sfcgal,pgRouting(網絡分析)都依賴boost,cgal,作者實際掉坑了很多次這個東西,boost,cgal安裝編譯都成功,就是無法編譯sfcgal,或者編譯好了pgrouting卻無法使用,經過一個月的不停嘗試,找出問題就是boost,cgal這兩個坑爹東西的問題,只要記住一點,只安裝到默認路徑,不要指定路徑,否則坑死活不了。

CGAL存在一些系統依賴庫必須要安裝

yum -y install gmp-devel boost-devel mpfr-devel zlib-devel libxml2-devel
cd /usr/local/src

tar -Jxf CGAL-4.14.3.tar.xz

cd CGAL-4.14.3

mkdir build

cd build

cmake ..

make && make install


安裝SFCGAL(非必須)

源碼下載參考:wget https://github.com/Oslandia/SFCGAL/archive/v1.3.6.tar.gz

cd /usr/local/src

tar xzf SFCGAL-1.3.7.tar.gc

cd SFCGAL-1.3.7

mkdir build

cd build

cmake ..

make && make install

安裝完成后,需要配置軟鏈接到libSFCGAL.so,防止后續gdal安裝找不到

ln -s /usr/local/lib64/libSFCGAL.so /usr/local/lib/libSFCGAL.so
ln -s /usr/local/lib64/libSFCGAL.so.1 /usr/local/lib/libSFCGAL.so.1


安裝GDAL

源碼下載參考:wget https://download.osgeo.org/gdal/2.3.2/gdal-2.3.2.tar.gz

GDAL的安裝,是整個安裝步驟當中最慢的一步

cd /usr/local/src

tar -zxvf gdal-3.0.4.tar.gz

cd gdal-3.0.4

./configure

make && make install


安裝PostGIS

PostGIS 3.0.1下載

PostGIS 3.0.1可以從官方渠道下載,其它下載渠道:

使用提供的庫

編譯安裝

安裝包資源路徑為/usr/local/src/postgis-3.0.1.tar.gz,執行操作如下

su postgres cd /usr/local/src

tar -zxvf postgis-3.0.1.tar.gz cd postgis-3.0.1 ./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config make && make install

以下操作,都必須在postgres用戶下進行,切換為postgres用戶的方法如下

su postgres


測試PostGIS是否安裝成功

#########切換到postgres用戶:
[root@localhost postgis-3.0.1]# su postgres

#########啟動PostgreSQL數據庫服務:
[postgres@localhost postgis-3.0.1]$ pg_ctl start

#########連接本地PG庫
[postgres@localhost postgis-3.0.1]$ psql -U postgres -h localhost -d postgres -p 5432
psql (12.0)
Type "help" for help.
postgres=#

#########創建一個數據庫test,並連接該數據庫:
postgres=# CREATE DATABASE test;
CREATE DATABASE
postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# 

#########在test數據庫中創建postgis插件:
test=# CREATE EXTENSION postgis;
CREATE EXTENSION
test=# 

#########查看postgis的版本:
test=# SELECT postgis_full_version();
                                                                       postgis_full_version                                                                  
     
-------------------------------------------------------------------------------------------------------------------------------------------------------------
-----
 POSTGIS="3.0.1 ec2a9aa" [EXTENSION] PGSQL="120" GEOS="3.8.1-CAPI-1.13.3" PROJ="6.2.1" LIBXML="2.9.1" LIBJSON="0.13" LIBPROTOBUF="1.3.2" WAGYU="0.4.3 (Intern
al)"
(1 row)

test=#

在test數據庫中創建sfcgal插件:

image

查看test數據庫中目前的所有插件:

image


至此,postgis安裝成功!



參考鏈接:

https://blog.csdn.net/qq_35732147/article/details/100708103

https://blog.csdn.net/huyl08/article/details/106999550/

https://www.jianshu.com/p/e08dbc60a3b2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM