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

posted @ 2020-12-15 17:40  我命由我不由天—hao  阅读(3254)  评论(0编辑  收藏  举报