centos安装postgis

前期准备:

安装postgresql9.1以上的版本,因为pg9.1以上版本才支持postgis扩展

安装gdal-1.11.2geos-3.5.0、libxml2-2.9.2proj-4.9.1json-c-0.12这些扩展能够更好地搭配postgis

对应的资源包地址:

postgresql=>  https://www.postgresql.org/ftp/source/

gdal=>                  http://trac.osgeo.org/gdal/wiki/DownloadSource

geos=>                 http://trac.osgeo.org/geos

libxml2=>             http://xmlsoft.org/downloads.html

proj=>                       http://download.osgeo.org/proj/

json-c=>                   https://s3.amazonaws.com/json-c_releases/releases/index.html

在以上地址下载对应所需版本,linux常用的下载指令是 “ wegt + url下载地址”。


1、安装postgresql9.4

[root@test ~]# wget https://ftp.postgresql.org/pub/source/v9.4.1/postgresql-9.4.1.tar.gz

[root@testsource]# tar zxf postgresql-9.4.1.tar.gz 
[root@testsource]# cd postgresql-9.4.1
[root@test  postgresql-9.4.1]# ./configure --prefix=/usr/local/pgsql  --with-perl  --with-python  --with-libxml 
--with-libxslt
[root@testpostgresql-9.4.1]# gmake
[root@testpostgresql-9.4.1]# gmake install


2、安装gdal扩展

[root@test gdal-1.11.2]#tar xzf gdal-1.11.2.tar.gz 
[root@test gdal-1.11.2]#cd gdal-1.11.2 
[root@test gdal-1.11.2]#./configure --prefix=/usr/local/gdal-1.11.2
[root@test gdal-1.11.2]#make 
[root@test gdal-1.11.2]#make install 


3、安装geos扩展

[root@test source]# tar -jxf geos-3.4.2.tar.bz2 
[root@test source]# cd geos-3.4.2
[root@test geos-3.4.2]# ./configure --prefix=/usr/local/geos-3.4.2
[root@test geos-3.4.2]# gmake -j 4
[root@test geos-3.4.2]# gmake install


4、安装libxml2扩展

[root@test source]# tar -xzf libxml2-git-snapshot.tar.gz 
[root@test source]# cd libxml2-2.9.2/
[root@test libxml2-2.9.2]# ./configure --prefix=/usr/local/libxml2-2.9.2
[root@test libxml2-2.9.2]# gmake -j 4
[root@test libxml2-2.9.2]# gmake install


5、安装proj扩展

[root@test source]# tar -zxf proj-4.9.1.tar.gz
[root@test source]# cd proj-4.9.1
[root@test proj-4.9.1]# ./configure --prefix=/usr/local/proj-4.9.1
[root@test proj-4.9.1]# gmake -j 4
[root@test proj-4.9.1]# gmake install


6、安装json-c扩展

[root@test source]# tar -zxf json-c-json-c-0.12-20140410.tar.gz 
[root@test source]# cd json-c-json-c-0.12-20140410
[root@test json-c-json-c-0.12-20140410]# ./configure --prefix=/usr/local/json-0.12
[root@test json-c-json-c-0.12-20140410]# gmake -j 4 
[root@test json-c-json-c-0.12-20140410]# gmake install

以上扩展可根据个人需要进行安装。


7、安装postgis

[root@test source]# tar zxf postgis-2.1.6.tar.gz 
[root@test source]# cd postgis-2.1.6
[root@test  postgis-2.1.6]#./configure  --with-prefix=/usr/local/postgis-2.1.6 
--with-pgconfig=/usr/local/pgsql/bin/pg_config  --with-gdalconfig=/usr/local/gdal-1.11.2/bin/gdal-config 
--with-geosconfig=/usr/local/geos-3.4.2/bin/geos-config 
--with-xml2config=/usr/local/libxml2-2.9.2/bin/xml2-config  --with-projdir=/usr/local/proj-4.9.1/ 
--with-jsondir=/usr/local/json-0.12/

[root@test  postgis-2.1.6]#make

PostGIS was built successfully. Ready to install.

[root@test  postgis-2.1.6]#make install

自此成功安装postgis了。


接下来为postgres创建postgis扩展,检验是否成功。

[root@test  postgis-2.1.6]#su postgres

[postgres @test  postgis-2.1.6]#cd ~

[postgres@test ~]psql--连接数据库

postgres=# create database postgis;

postgres=# \c postgis

You are now connected to database "postgis" as user "postgres".

postgis=# create extension postgis;

CREATE EXTENSION

postgis=SELECT name, default_version,installed_version FROM pg_available_extensions WHERE name LIKE 'postgis%' ;

         name          | default_version | installed_version 
------------------------+-----------------+-------------------
 postgis                | 2.1.6           | 2.1.6
 postgis_topology       | 2.1.6           | 
 postgis_tiger_geocoder | 2.1.6           | 
(3 rows)

#为了更好的使用postgis功能,决定把所有的扩展都装了

postgis=# create extension postgis_topology;      

CREATE EXTENSION

postgis=# create extension postgis_tiger_geocoder;

ERROR:  required extension "fuzzystrmatch" is not installed

postgis=#  CREATE EXTENSION fuzzystrmatch;

ERROR:  could not open extension control file 

postgis=#\q

#居然报错了,说明没有安装成功fuzzystrmatch

#解决方案,把fuzzystrmatch这个扩展装了


8、安装fuzzystrmatch扩展

[root@cqs ~]# find / -name fuzzystrmatch

/home/cqs/postgresql-9.4.1/contrib/fuzzystrmatch

[root@testsource]# cd /home/cqs/postgresql-9.4.1/contrib/fuzzystrmatch

[root@test fuzzystrmatch]# make
[root@test fuzzystrmatch]#make install

[root@test fuzzystrmatch]#find / -name  fuzzystrmatch.control

/usr/local/postgresql-9.4.1/share/extension/fuzzystrmatch.control

[root@test fuzzystrmatch]su postgres

[postgres@test fuzzystrmatch]cd ~

[postgres@test ~]psql--连接数据库

postgres=# create database postgis;

postgres=# \c postgis

You are now connected to database "postgis" as user "postgres".

postgis=#  CREATE EXTENSION fuzzystrmatch;

CREATE EXTENSION

安装成功了

postgis=# create extension postgis_tiger_geocoder;

CREATE EXTENSION

postgis=# SELECT name, default_version,installed_version FROM pg_available_extensions WHERE name LIKE 'postgis%';

         name          | default_version | installed_version 
------------------------+-----------------+-------------------
 postgis                | 2.1.6           | 2.1.6
 postgis_topology       | 2.1.6           | 2.1.6
 postgis_tiger_geocoder | 2.1.6           |2.1.6 
(3 rows)

测试插入和查询表数据:

postgis=# create table test_global_points(id serial primary key,name varchar(64),location geography(point,4326));

CREATE TABLE

postgis=# insert into test_global_points (name,location) values('Town',ST_GeographyFromText('SRID=4326; POINT(-100 30)'));

INSERT 0 1

postgis=# insert into test_global_points (name,location) values('Forest',ST_GeographyFromText('SRID=4326; POINT(-109 29)'));    

INSERT 0 1

postgis=# insert into test_global_points (name,location) values('London',ST_GeographyFromText('SRID=4326; POINT(0 49)'));         

INSERT 0 1

postgis=# select * from test_global_points;

 id |  name  |                      location                      

----+--------+----------------------------------------------------

  1 | Town   | 0101000020E610000000000000000059C00000000000003E40

  2 | Forest | 0101000020E61000000000000000405BC00000000000003D40

  3 | London | 0101000020E610000000000000000000000000000000804840






  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值