PostGIS源代码安装指南

前言

使用PostGIS提供的st_asmvt函数返回MapBox格式的矢量切片时,PostGIS报错missing libprotobuf-c,为了解决这个问题,需要从源码编译postgis,添加对protobuf的支持,特此记录。

1.安装postgresql

通过yum安装postgresql10 ,安装目录/var/lib/pgsql/10

2.安装gcc

yum install -y gcc gcc-c++

3.编译安装GEOS

cd /mysoft
wget https://download.osgeo.org/geos/geos-3.7.0.tar.bz2
tar -jxvf geos-3.7.0.tar.bz2
cd geos-3.7.0
./configure --prefix=/usr/local/geos-3.7.0
make
make install

4.编译安装Proj

wget http://download.osgeo.org/proj/proj-5.2.0.tar.gz
tar -zxvf proj-5.2.0.tar.gz
cd proj-5.2.0
./configure  --prefix=/usr/local/proj-5.2.0
make
make install

5.编译安装GDAL

wget https://download.osgeo.org/gdal/2.3.2/gdal-2.3.2.tar.gz
tar -zxvf gdal-2.3.2.tar.gz
cd gdal-2.3.2
./configure  --prefix=/usr/local/gdal-2.3.2 --with-pg=/usr/pgsql-10/bin/pg_config
make
make install

6.编译安装json-c,添加对geojson支持

wget https://github.com/json-c/json-c/archive/json-c-0.13.1-20180305.tar.gz
tar -zxvf json-c-0.13.1-20180305.tar.gz
cd json-c-0.13.1-20180305
./configure  --prefix=/usr/local/json-c-0.13.1
make
make install

7.编译安装libxml2

wget https://github.com/GNOME/libxml2/archive/v2.9.7.tar.gz
tar -zxvf libxml2-sources-2.9.7.tar.gz
cd libxml2-2.9.7
./configure  --prefix=/usr/local/libxml2-2.9.7
make
make install

8.编译安装protobuf

wget https://github.com/google/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz
tar zxvf protobuf-all-3.6.1.tar.gz
./autogen.sh
#配置安装目录
./configure  --prefix=/usr/local/protobuf-3.6.1
make
make install
#配置环境变量,增加/usr/local/protobuf-3.6.1安装目录
vi /etc/profile
export CMAKE_HOME=/usr/bin/cmake
export PKG_CONFIG_PATH=/usr/local/protobuf-3.6.1/lib/pkgconfig
export PROTOBUF_HOME=/usr/local/protobuf-3.6.1
export PATH=$CMAKE_HOME/bin:$PROTOBUF_HOME/bin:$PATH
#保存退出
source /etc/profile
#验证protobuf执行程序
protoc --version
#出现libprotoc 3.6.1说明安装成功

9.安装protobuf-c

wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.3.1/protobuf-c-1.3.1.tar.gz
tar -zxvf protobuf-c-1.3.1.tar.gz    
cd protobuf-c-1.3.1  
#导入protobuf的pkgconfig,否则"--No package 'protobuf' found"
export PKG_CONFIG_PATH=/usr/local/protobuf-3.6.1/lib/pkgconfig
./configure  --prefix=/usr/local/protobuf-c-1.3.1
make    
make install   
#配置环境变量,增加下protobuf-c-1.3.1/bin
vi /etc/profile
export PATH=:/usr/local/protobuf-c-1.3.1/bin
#保存退出
source /etc/profile

10.安装cgal,根据遥想公瑾当年的简书所述,安装cgal不能指定安装目录

#boost
[root@VM_0_4_centos opt]#  yum install boost-devel
# 安装指定版本cgal-4.13
[root@VM_0_4_centos opt]# wget https://github.com/CGAL/cgal/archive/releases/CGAL-4.13.tar.gz
[root@VM_0_4_centos opt]# tar -zxvf CGAL-4.13.tar.gz   
[root@VM_0_4_centos opt]# cd CGAL-4.13  
[root@VM_0_4_centos CGAL-4.13]#mkdir build & cd build 
#cmake不要指定安装路径
[root@VM_0_4_centos build]# cmake ..
[root@VM_0_4_centos build]# make    
[root@VM_0_4_centos build]# make install

10.安装sfcgal

wget https://github.com/Oslandia/SFCGAL/archive/v1.3.6.tar.gz
tar -zxvf v1.3.6.tar.gz   
cd SFCGAL-1.3.6  
mkdir build & cd build 
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/sfcgal-1.3.6 ..
make    
make install

10.编译安装postgis

10.1配置ld.so.conf

[root@VM_0_4_centos opt]# vim /etc/ld.so.conf
#编辑内容如下
include ld.so.conf.d/*.conf
/home/postgres/lib
/usr/local/proj-5.2.0/lib
/usr/local/gdal-2.3.2/lib
/usr/local/geos-3.7.0/lib
/usr/local//sfcgal-1.3.6/lib64
/usr/local/json-c-0.13.1/lib
/usr/local/libxml2-2.9.7/lib
/usr/local/protobuf-3.6.1/lib
/usr/local/protobuf-c-1.3.1/lib
#编辑完成后wq!保存退出
#保存配置,重启生效
[root@VM_0_4_centos opt]# ldconfig -v

10.2编译安装

wget http://download.osgeo.org/postgis/source/postgis-2.5.0.tar.gz    
tar -zxvf postgis-2.5.0.tar.gz    
cd postgis-2.5.0 
#根据安装不同的要求,选择任意一个configure
#基本安装,不带protobuf,sfcgal
./configure --prefix=/home/postgres --with-gdalconfig=/usr/local/gdal-2.3.2/bin/gdal-config --with-pgconfig=/home/postgres/bin/pg_config --with-geosconfig=/usr/local/geos-3.7.0/bin/geos-config --with-projdir=/usr/local/proj-5.2.0 --with-xml2config=/usr/local/libxml2-2.9.7/bin/xml2-config --with-jsondir=/usr/local/json-c-0.13.1
#带protobuf安装,支持mvt
./configure --prefix=/home/postgres --with-gdalconfig=/usr/local/gdal-2.3.2/bin/gdal-config --with-pgconfig=/home/postgres/bin/pg_config --with-geosconfig=/usr/local/geos-3.7.0/bin/geos-config --with-projdir=/usr/local/proj-5.2.0 --with-xml2config=/usr/local/libxml2-2.9.7/bin/xml2-config --with-jsondir=/usr/local/json-c-0.13.1 --with-protobufdir=/usr/local/protobuf-c-1.3.1
# 带protobuf,sfcgal安装
./configure --prefix=/home/postgres --with-gdalconfig=/usr/local/gdal-2.3.2/bin/gdal-config --with-pgconfig=/home/postgres/bin/pg_config --with-geosconfig=/usr/local/geos-3.7.0/bin/geos-config --with-projdir=/usr/local/proj-5.2.0 --with-xml2config=/usr/local/libxml2-2.9.7/bin/xml2-config --with-jsondir=/usr/local/json-c-0.13.1 --with-protobufdir=/usr/local/protobuf-c-1.3.1 --with-sfcgal=/usr/local/sfcgal-1.3.6/bin/sfcgal-config

make
make install

转载自:https://blog.csdn.net/weixin_34224941/article/details/87275193

You may also like...

退出移动版