天天看點

Linux源碼安裝PostGIS

官方網址: http://www.postgis.org/

下載下傳源碼安裝包,我這裡下載下傳的是postgis的最新版本:postgis-2.3.3.tar.gz

環境依賴需要:

1 postgresql 資料庫版本在9.2 到 9.4之間(需要提前安裝)
2 需要安裝依賴包:gcc 
                gmake or make 
                Proj4 version 4.6.0 or greater   (下載下傳位址:http://proj4.org/download.html#linux)
                GEOS version 3.3 or greater      (下載下傳位址:http://trac.osgeo.org/geos/)
                LibXML2, version 2.5.x or higher
                JSON-C, version 0.9 or higher     (下載下傳:wget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz)
                       ./configure
                        make 
                        sudo make install   
                GDAL, version 1.8 or higher      (下載下傳位址:http://trac.osgeo.org/gdal/wiki/DownloadSource)           

安裝PostGIS

1 解壓源碼安裝包:
  tar -zxvf postgis-2.3.3.tar.gz
2 安裝:
(1)./configure --prefix=/opt/pg963 --with-pgconfig=/opt/pg963/bin/pg_config --with-gdalconfig=/usr/local/bin/gdal-config --with-geosconfig=/usr/local/bin/geos-config --with-xml2config=/usr/bin/xml2-config --with-projdir=/usr/local/share/proj --with-jsondir=/usr/local/include/json

報錯:
checking for library containing GDALAllRegister... no
configure: error: could not find GDAL

解決方法:
:~/postgis-2.3.3$ sudo vi /etc/ld.so.conf

include /etc/ld.so.conf.d/*.conf
添加
/opt/pg963/lib

是參數生效
:~/postgis-2.3.3$ sudo /sbin/ldconfig -v

(2) make
(3) make install            

添加postgis 擴充

先登入安裝postgis的資料庫
postgres@:~$ /opt/pg963/bin/psql -p 6432
psql (9.6.3)
Type "help" for help.
 
postgres=# \dx
                 List of installed extensions
  Name   | Version |   Schema   |         Description          
---------+---------+------------+------------------------------
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
(1 row)

安裝擴充
postgres=# create extension postgis;
CREATE EXTENSION
postgres=# \dx
                                     List of installed extensions
  Name   | Version |   Schema   |                             Description                             
---------+---------+------------+---------------------------------------------------------------------
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis | 2.3.3   | public     | PostGIS geometry, geography, and raster spatial types and functions
(2 rows)

postgres=#            

安裝postgis_topology

postgres=# create extension postgis_topology;
CREATE EXTENSION
postgres=# \dx
                                                                    List of installed extensions
          Name          | Version |   Schema   |                                                     Description                                                     
------------------------+---------+------------+---------------------------------------------------------------------------------------------------------------------
 plpgsql                | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis                | 2.3.3   | public     | PostGIS geometry, geography, and raster spatial types and functions
 postgis_topology       | 2.3.3   | topology   | PostGIS topology spatial types and functions           

安裝postgis_tiger_geocoder

postgres=# CREATE EXTENSION postgis_tiger_geocoder FROM unpackaged;
ERROR:  required extension "fuzzystrmatch" is not installed
HINT:  Use CREATE EXTENSION ... CASCADE to install required extensions too.
postgres=# CREATE EXTENSION postgis_tiger_geocoder cascade;
ERROR:  could not open extension control file "/opt/pg963/share/postgresql/extension/fuzzystrmatch.control": 沒有那個檔案或目錄

原因:fuzzystrmatch已經包含在了postgresql的源碼擴充中,需要去postgresql源碼目錄中安裝:
root@:~/postgresql-9.6.3/contrib/fuzzystrmatch# pwd
/home/~/postgresql-9.6.3/contrib/fuzzystrmatch

postgres=# CREATE EXTENSION postgis_tiger_geocoder cascade;
NOTICE:  installing required extension "fuzzystrmatch"
CREATE EXTENSION
postgres=# \dx
                                                                    List of installed extensions
          Name          | Version |   Schema   |                                                     Description                                                     
------------------------+---------+------------+---------------------------------------------------------------------------------------------------------------------
 fuzzystrmatch          | 1.1     | public     | determine similarities and distance between strings
 plpgsql                | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis                | 2.3.3   | public     | PostGIS geometry, geography, and raster spatial types and functions
 postgis_tiger_geocoder | 2.3.3   | tiger      | PostGIS tiger geocoder and reverse geocoder
 postgis_topology       | 2.3.3   | topology   | PostGIS topology spatial types and functions           

安裝address_standardizer

root@:~/postgis-2.3.3/extensions/address_standardizer# make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fpic -I/usr/local/include -I/usr/local/share/proj/include -I/usr/include/libxml2  -I/usr/local/include/json/include   -g -O0 -I. -I./ -I/opt/pg963/include/postgresql/server -I/opt/pg963/include/postgresql/internal -D_GNU_SOURCE   -c -o address_parser.o address_parser.c
address_parser.c:10:18: fatal error: pcre.h: 沒有那個檔案或目錄

解決方法:
root@:~/postgis-2.3.3/extensions/address_standardizer# apt-get update
root@:~/postgis-2.3.3/extensions/address_standardizer# apt-get install libpcre3 libpcre3-dev
root@:~/postgis-2.3.3/extensions/address_standardizer# make
root@:~/postgis-2.3.3/extensions/address_standardizer# make install

postgres=# CREATE EXTENSION address_standardizer;
CREATE EXTENSION
postgres=# \dx
                                                                    List of installed extensions
          Name          | Version |   Schema   |                                                     Description                                                     
------------------------+---------+------------+---------------------------------------------------------------------------------------------------------------------
 address_standardizer   | 2.3.3   | public     | Used to parse an address into constituent elements. Generally used to support geocoding address normalization step.
 fuzzystrmatch          | 1.1     | public     | determine similarities and distance between strings
 plpgsql                | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis                | 2.3.3   | public     | PostGIS geometry, geography, and raster spatial types and functions
 postgis_tiger_geocoder | 2.3.3   | tiger      | PostGIS tiger geocoder and reverse geocoder
 postgis_topology       | 2.3.3   | topology   | PostGIS topology spatial types and functions