CentOS7下安裝PostGIS
注意 本人的博客都遷移到本人自己搭建的博客地址,通過此處可查看。
寫在安裝之前
PostGIS的安裝和運行需要在PostgreSQL環境下,故本人安裝的環境是:
-
CentOS 7 64位
-
PostgreSQL 10.3,具體安裝可參考CentOS7 下安裝 PostgreSQL10
-
PostGIS 2.4.3, 安裝過程看本文介紹
-
geos 3.4.2, 可以使用
yum install geos geos-devel
-
gdal 1.11.4, 可以使用
yum install jdal gdal-devel
-
libxml 2 2.9.1, 可以使用
yum install libxml libxml-devel
-
proj 4.8.0, 可以使用
yum install proj proj-devel
-
json-c 0.11, 可以使用
yum install json-c json-c-devel
-
pcre 8.32, 可以使用
yum install pcre pcre-devel
注: 具體PostgreSQL與PostGIS之間版本的對應可查看osgeo官網說明文檔
PostGIS及其擴展的安裝
-
安裝PostGIS
wget https://download.osgeo.org/postgis/source/postgis-2.4.3.tar.gz tar -zxvf postgis-2.4.3.tar.gz cd postgis-2.4.3 ./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config make make install
-
安裝PostGIS擴展
PostGIS擴展文件在解壓後的源文件夾的
extension
文件夾下,具體安裝如下所示:cd extension cd postgis_sfcgal make clean & make & make install cd postgis_tiger_geocoder make clean & make & make install cd postgis_topology make clean & make & make install cd address_standardizer make clean & make & make install
在PostgresSQL數據庫創建PostGIS
-
使用已有的sql文件創建
所有的SQL語句文件在PostGIS安裝成功後,存放在
/usr/local/pgsql/data/share/contrib/postgis-2.4/
文件夾下具體使用方法:
./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/postgis.sql ./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/postgis_comments.sql ./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/spatial_ref_sys.sql ./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/topology.sql ./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/topology_comments.sql --Raster-- ./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/rtpostgis.sql ./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/raster_comments.sql -sfcgal-- ./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/sfcgal.sql ./bin/psql -d postgisdb -f ./share/contrib/postgis- 2.4/sfcgal_comments.sql
-
通過語言創建
具體創建方式如下:
./bin/psql -d postgisdb -c "CREATE EXTESNSION postgis" ./bin/psql -d postgisdb -c "CREATE EXTESNSION postgis_topology"