1 . 安装环境
安装postgis先安装postgresql,安装步骤参考:postgresql源码安装
#检查环境:
rpm -qa | grep gcc-c++
---如果没安装参考postgresql源码安装配置环境
#安装依赖包:geos,proj,gdal,json-c,libxml2
# 编译 geos
wget https://download.osgeo.org/geos/geos-3.7.0.tar.bz2 #提前下载打包
tar -zxvf geos-3.7.0.tar.bz2
cd geos-3.7.0
./configure --help #查看帮助命令
./configure --prefix=/usr/local/geos
#成功有configure.status 文件
make
make install
# 编译 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
#成功有configure.status 文件
make
make install
# 编译 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 --with-pg=/usr/local/pgsql/bin/pg_config
#成功有configure.status 文件
make
make install
# 编译 json-c
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
./configure --prefix=/usr/local/json-c
#成功有configure.status 文件
make
make install
# 编译 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
#成功有configure.status 文件
make
make install
2. 安装PostGis
# 配置环境
vi /etc/id.so.conf
include ld.so.conf.d/*.conf
/usr/local/pgsql/lib
/usr/local/proj/lib
/usr/local/gdal/lib
/usr/local/geos/lib
/usr/local/json-c/lib
/usr/local/libxml2/lib
#保存
ldconfig -v
下载postgis
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 --prefix=/usr/local/pgsql --with-gdalconfig=/usr/local/gdal/bin/gdal-config --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=/usr/local/geos/bin/geos-config --with-projdir=/usr/local/proj--with-xml2config=/usr/local/libxml2/bin/xml2-config --with-jsondir=/usr/local/json-c
make
make install
3 postgresql 数据库安装postgis扩展
su -postgres
password:
create database gis_demo;
\c gis_demo;
create extension postgis;
CREATE EXTENSION
---成功
如果出现编译错误:libmpc.so.3: cannot open shared object file: No such file or directory
参考这篇文章:https://blog.csdn.net/vickytong1018/article/details/53186899