postgis 之一 setup

os: centos 7.4
db: postgresql 10.11
postgis 2.5.4

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 
# 
# 
# yum list installed |grep -i postgresql
postgresql10.x86_64                10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-contrib.x86_64        10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-debuginfo.x86_64      10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-devel.x86_64          10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-docs.x86_64           10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-libs.x86_64           10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-odbc.x86_64           12.00.0000-1PGDG.rhel7              @pgdg10  
postgresql10-plperl.x86_64         10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-plpython.x86_64       10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-pltcl.x86_64          10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-server.x86_64         10.11-2PGDG.rhel7                   @pgdg10  
postgresql10-tcl.x86_64            2.4.0-1.rhel7                       @pgdg10  
postgresql10-tcl-debuginfo.x86_64  2.3.1-1.rhel7                       @pgdg10  
postgresql10-test.x86_64           10.11-2PGDG.rhel7                   @pgdg10 

# su - postgres
Last login: Wed Jan 15 18:34:12 CST 2020 on pts/0
$
$
$ psql -c "select version();"
                                                 version                                                  
----------------------------------------------------------------------------------------------------------
 PostgreSQL 10.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)

下載安裝

# yum list all |grep -i postgis25*

postgis25_10.x86_64                         2.5.4-1.rhel7              pgdg10   
postgis25_10-client.x86_64                  2.5.4-1.rhel7              pgdg10   
postgis25_10-devel.x86_64                   2.5.4-1.rhel7              pgdg10   
postgis25_10-docs.x86_64                    2.5.4-1.rhel7              pgdg10   
postgis25_10-gui.x86_64                     2.5.4-1.rhel7              pgdg10   
postgis25_10-utils.x86_64                   2.5.4-1.rhel7              pgdg10

# yum install postgis25_10*

--> Finished Dependency Resolution
Error: Package: postgis25_10-client-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libgdal.so.26()(64bit)
Error: Package: postgis25_10-client-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libproj.so.19()(64bit)
Error: Package: postgis25_10-client-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libSFCGAL.so.1()(64bit)
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libproj.so.19()(64bit)
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libSFCGAL.so.1()(64bit)
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libgdal.so.26()(64bit)
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: proj70 >= 7.0.0
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: geos38 >= 3.8.1
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: SFCGAL
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: gdal30-libs >= 3.0.4
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
 

一堆的錯誤,使用 make 源碼試一把
yum 安裝一些基礎依賴

# yum install zip unzip git wget make cmake cmake3 doxygen \
gcc gcc-c++ libstdc++ libstdc++-devel libstdc++-static \
libtiff libtiff-devel libtiff-static libtiff-tools libtiff \
curl libcurl-devel libcurl-devel \
gmp gmp-devel gmp-static \
mpfr mpfr-devel \
valgrind valgrind-devel \
autoconf automake libtool  

# which 
/usr/bin/make

# mv /usr/bin/make /usr/bin/make.bak
# ln -s /usr/bin/make3 /usr/bin/make

ldconfig

# vi /etc/ld.so.conf

include ld.so.conf.d/*.conf
/usr/local/lib
/usr/local/lib64

# ldconfig

libxml2

# cd /tmp
# wget ftp://xmlsoft.org/libxml2/libxml2-sources-2.9.9.tar.gz
# tar -zxvg libxml2-sources-2.9.9.tar.gz
# cd libxml2-sources-2.9.9
# ./configure
# make
# make install

geos

# cd /tmp
# wget http://download.osgeo.org/geos/geos-3.8.1.tar.bz2
# tar -jxvf geos-3.8.1.tar.bz2     
# cd geos-3.8.1    
# ./configure
# make -j4
# make install

sqlite3

# cd /tmp
# wget https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz
# tar -xzf sqlite-autoconf-3310100.tar.gz
# cd sqlite-autoconf-3310100
# ./configure
# make -j4
# make install

proj

Build requirements
C99 compiler
C++11 compiler
SQLite3 >= 3.11 (headers, library and executable)
libtiff >= 4.0 (headers and library)
optional (but recommended): curl >= 7.29.0
GNU make for autotools build or CMake >= 3.9

# cd /tmp
# 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 SQLITE3_CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib /usr/local/lib/libsqlite3.so"

# make -j4
# make install
# make check

proj-7.0.0 make 時報錯
降級到 proj-6.3.1 make 沒有報錯,但是最後 postgis 執行 configure時的報錯如下

checking for proj_api.h... yes
checking for pj_get_release in -lproj... no
configure: error: could not find libproj - you may need to specify the directory of a PROJ.4 installation using --with-projdir

又降級到 proj-5.2.0 make 沒有報錯,後面也沒有報錯,還是跟版本有關係

gdal

依賴 proj

# wget http://download.osgeo.org/gdal/3.0.4/gdal-3.0.4.tar.gz
# tar -zxvf gdal-3.0.4.tar.gz
# cd gdal-3.0.4
# ./configure --with-proj=/usr/local --with-pg=/usr/pgsql-10/bin/pg_config
# make -j4
# make install   

json-c

# wget https://github.com/json-c/json-c/archive/json-c-0.14-20200419.tar.gz
# tar -zxvf json-c-0.14-20200419.tar.gz    
# mkdir json-c-build && cd json-c-build  
# cmake ../json-c-json-c-0.14-20200419

# make
# make test
# make USE_VALGRIND=0 test
# make install

cgal

# yum install boost-devel

# wget https://github.com/CGAL/cgal/releases/download/releases%2FCGAL-4.14.3/CGAL-4.14.3.tar.xz
# xz -d CGAL-4.14.3.tar.xz
# tar -xvf CGAL-4.14.3.tar
# cd CGAL-4.14.3  
# mkdir build && cd build 
# cmake ..
# make -j4
# make install  

sfcgal

sfcgal對應的cgal版本,有版本對應關係

# wget https://github.com/Oslandia/SFCGAL/archive/v1.3.7.tar.gz
# tar -zxvf v1.3.7.tar.gz
# cd SFCGAL-1.3.7
# mkdir build && cd build
# cmake .. 
# make -j4
# make install

# ls -l /usr/local/lib/libSFCGAL*
# ln -s /usr/local/lib64/libSFCGAL.so /usr/local/lib/libSFCGAL.so

protobuf

# wget https://github.com/protocolbuffers/protobuf/archive/v3.11.4.tar.gz
# tar -zxvf ./v3.11.4.tar.gz
# cd ./protobuf-3.11.4
# ./autogen.sh
# ./configure
# make
# make check
# make install
# ldconfig

protobuf-c

# wget https://github.com/protobuf-c/protobuf-c/archive/v1.3.3.tar.gz
# tar -zxvf ./v1.3.3.tar.gz
# cd protobuf-c-1.3.3/
# ./autogen.sh
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# ./configure
# make
# make check
# make install
# ldconfig

imagemagick

# yum install ImageMagick*

dblatex

# yum install dblatex

cunit

# yum install CUnit CUnit-devel

ldconfig

# cat /etc/ld.so.conf

include ld.so.conf.d/*.conf
/usr/local/lib
/usr/local/lib64

# ldconfig -v |more

再次安裝 postgis25_10

安裝 postgis

# yum install postgis25_10*

Error: Package: postgis25_10-client-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libgdal.so.26()(64bit)
Error: Package: postgis25_10-client-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libproj.so.19()(64bit)
Error: Package: postgis25_10-client-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libSFCGAL.so.1()(64bit)
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libproj.so.19()(64bit)
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libSFCGAL.so.1()(64bit)
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: libgdal.so.26()(64bit)
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: proj70 >= 7.0.0
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: geos38 >= 3.8.1
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: SFCGAL
Error: Package: postgis25_10-2.5.4-1.rhel7.x86_64 (pgdg10)
           Requires: gdal30-libs >= 3.0.4
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

還是有很多錯誤,嘗試編譯安裝一下

# wget http://download.osgeo.org/postgis/source/postgis-2.5.4.tar.gz   
# tar -zxvf postgis-2.5.4.tar.gz    
# cd postgis-2.5.4 

# LDFLAGS=-lstdc++ ./configure \
--with-pgconfig=/usr/pgsql-10/bin/pg_config \
--with-xml2config=/usr/local/bin/xml2-config \
--with-gdalconfig=/usr/local/bin/gdal-config \
--with-geosconfig=/usr/local/bin/geos-config \
--with-sfcgal=/usr/local/bin/sfcgal-config \
--with-projdir=/usr/local/ \
--with-protobufdir=/usr/local/

configure 輸出信息如下


  PostGIS is now configured for x86_64-unknown-linux-gnu

 -------------- Compiler Info ------------- 
  C compiler:           gcc -g -O2
  SQL preprocessor:     /usr/bin/cpp -traditional-cpp -w -P

 -------------- Additional Info ------------- 
  Interrupt Tests:   DISABLED use: --with-interrupt-tests to enable

 -------------- Dependencies -------------- 
  GEOS config:          /usr/local/bin/geos-config
  GEOS version:         3.8.1
  GDAL config:          /usr/local/bin/gdal-config
  GDAL version:         3.0.4
  SFCGAL config:        /usr/local/bin/sfcgal-config
  SFCGAL version:       1.3.7
  PostgreSQL config:    /usr/pgsql-10/bin/pg_config
  PostgreSQL version:   PostgreSQL 10.11
  PROJ4 version:        52
  Libxml2 config:       /usr/local/bin/xml2-config
  Libxml2 version:      2.9.9
  JSON-C support:       yes
  protobuf-c support:   yes
  protobuf-c version:   1003003
  PCRE support:         yes
  Perl:                 /usr/bin/perl

 --------------- Extensions --------------- 
  PostGIS Raster:       enabled
  PostGIS Topology:     enabled
  SFCGAL support:       enabled
  Address Standardizer support:       enabled

 -------- Documentation Generation -------- 
  xsltproc:             /usr/bin/xsltproc
  xsl style sheets:     /usr/share/sgml/docbook/xsl-stylesheets
  dblatex:              /usr/bin/dblatex
  convert:              /usr/bin/convert
  mathml2.dtd:          http://www.w3.org/Math/DTD/mathml2/mathml2.dtd

# make -j8
# make check
# make install
# make installcheck

# ls -lt /usr/pgsql-10/lib/* |more
-rwxr-xr-x 1 root     root      737592 Apr 29 18:01 /usr/pgsql-10/lib/address_standardizer.so
-rwxr-xr-x 1 root     root     1552944 Apr 29 18:01 /usr/pgsql-10/lib/postgis_topology-2.5.so
-rwxr-xr-x 1 root     root     2683296 Apr 29 18:01 /usr/pgsql-10/lib/rtpostgis-2.5.so
-rwxr-xr-x 1 root     root     3972096 Apr 29 18:01 /usr/pgsql-10/lib/postgis-2.5.so

初步使用

$ psql

postgres=# select * from pg_available_extensions 
where name in (
'postgis',
'postgis_sfcgal',
'fuzzystrmatch',
'address_standardizer',
'address_standardizer_data_us',
'postgis_tiger_geocoder',
'postgis_topology'
) order by name;

             name             | default_version | installed_version |                                                       comment                  
                                     
------------------------------+-----------------+-------------------+---------------------------------------------------------------------------------------------------------------------
 address_standardizer         | 2.5.4           |                   | Used to parse an address into constituent elements. Generally used to support geocoding address normalization step.
 address_standardizer_data_us | 2.5.4           |                   | Address Standardizer US dataset example
 fuzzystrmatch                | 1.1             |                   | determine similarities and distance between strings
 postgis                      | 2.5.4           |                   | PostGIS geometry, geography, and raster spatial types and functions
 postgis_sfcgal               | 2.5.4           |                   | PostGIS SFCGAL functions
 postgis_tiger_geocoder       | 2.5.4           |                   | PostGIS tiger geocoder and reverse geocoder
 postgis_topology             | 2.5.4           |                   | PostGIS topology spatial types and functions
(7 rows)


postgres=# CREATE EXTENSION postgis;
CREATE EXTENSION postgis_sfcgal;
CREATE EXTENSION fuzzystrmatch; 
CREATE EXTENSION address_standardizer;
CREATE EXTENSION address_standardizer_data_us;
CREATE EXTENSION postgis_tiger_geocoder;
CREATE EXTENSION postgis_topology;

參考:
http://www.postgis.net/docs/manual-2.5/postgis_installation.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章