本文介绍在RedHat7环境下安装使用PostGIS的流程。

1. PostgreSQL

1.1 yum安装PostgreSQL

这个比较简单,直接使用yum安装即可。

$ sudo yum install -y postgresql-server postgresql-devel libxml2 libxml2-devel

顺便安装postgresql-devel、libxml2-devel,后边编译安装PostGIS会用到。

postgresql.x86_64               9.2.13-1.1
postgresql-devel.x86_64 9.2.13-1.1
postgresql-libs.x86_64 9.2.13-1.1
postgresql-server.x86_64 9.2.13-1.1
libxml2 2.9.1-6
libxml2-devel.x86_64 2.9.1-6

然后切换到postgres账户。

$ sudo su postgres
postgres $

1.2 初始化PostgreSQL

确认PostgreSQL数据目录。

postgres $ cat /var/lib/pgsql/.bash_profile
[ -f /etc/profile ] && source /etc/profile PGDATA=/var/lib/pgsql/data
export PGDATA

执行初始化操作。

postgres $ initdb

目录/var/lib/pgsql/data下存储了PostgreSQL的所有数据文件和配置。

1.3 启动PostgreSQL

使用pg_ctl启动PostgreSQL。

postgres $ pg_ctl start

使用psql客户端连接。

postgres $ psql
psql (9.2.13)
输入 "help" 来获取帮助信息. postgres=# \l
资料库列表
名称 | 拥有者 | 字元编码 | 校对规则 | Ctype | 存取权限
------------------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres

2. PostGIS

2.1 准备源码包

准备gdal、proj、geos和postgis的源码包,postgis版本注意和postgresql保持兼容。

兼容信息可以查看: http://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS

$ wget http://download.osgeo.org/gdal/2.2.3/gdal-2.2.3.tar.gz
$ wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
$ wget http://download.osgeo.org/geos/geos-3.3.3.tar.bz2
$ wget http://download.osgeo.org/postgis/source/postgis-2.2.6.tar.gz

2.2 解压编译安装gdal、proj、geos和postgis

依次解压、编译、安装以上软件包。

$ tar xf gdal-2.2.3.tar.gz && cd gdal-2.2.3 && ./configure --prefix=/usr/local/gdal && make && sudo make install
$ tar xf proj-4.8.0.tar.gz && cd proj-4.8.0 && ./configure --prefix=/usr/local/proj && make && sudo make install
$ tar xf geos-3.3.3.tar.bz2 && cd geos-3.3.3 && ./configure --prefix=/usr/local/geos && make && sudo make install
$ tar xf postgis-2.2.6.tar.gz && cd postgis-2.2.6 && ./configure -prefix=/usr/local/postgis --with-geosconfig=/usr/local/geos/bin/geos-config --with-projdir=/usr/local/proj --with-gdalconfig=/usr/local/gdal/bin/gdal-config && make && sudo make install

2.3 配置ldconfig

将gdal、proj、geos的lib目录添加到ldconfig。

$ sudo cat /etc/ld.so.conf
include ld.so.conf.d/*.conf /usr/local/gdal/lib/
/usr/local/proj/lib/
/usr/local/geos/lib/ $ sudo ldconfig

2.4 创建空间数据库模板

# 创建无空间特性数据库
postgres $ createdb template_postgis # 创建相关空间数据库相关的函数,类型,操作符等
postgres $ psql -f /usr/share/pgsql/contrib/postgis-2.2/postgis.sql -d template_postgis
postgres $ psql -f /usr/share/pgsql/contrib/postgis-2.2/rtpostgis.sql -d template_postgis # 验证空间数据库版本
postgres $ psql template_postgis
psql (9.2.13)
输入 "help" 来获取帮助信息. template_postgis=# select postgis_full_version();
postgis_full_version
---------------------------------------------------------------------------------------------------------------------------------------------
POSTGIS="2.2.6 r16006" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 2.2.3, released 2017/11/20" LIBXML="2.9.1" RASTER
(1 行记录) template_postgis=# \d
关联列表
架构模式 | 名称 | 型别 | 拥有者
----------+-------------------+--------+----------
public | geography_columns | 视观表 | postgres
public | geometry_columns | 视观表 | postgres
public | raster_columns | 视观表 | postgres
public | raster_overviews | 视观表 | postgres
public | spatial_ref_sys | 资料表 | postgres
(5 行记录)

2.5 根据空间数据库模板创建新的空间数据库

postgres $ createdb -T template_postgis new_database

3. 简单测试

测试点(0, 0)是否在指定的多边形内。

new_database=# select ST_Within(ST_GeomFromText('POINT(0 0)', 4326), ST_GeomFromText('POLYGON((1 1, 1 -1, -1 -1, -1 1, 1 1))', 4326)) ;
st_within
-----------
t
(1 行记录)

详细语法规则可以参考PostGis使用手册:http://www.postgres.cn/docs/PostGis-2.2.0dev_Manual.pdf

参考资料

RedHat7下PostGIS源码安装的更多相关文章

  1. debian下如何源码安装tmux

    一.源码安装ncurses库 1.1 获取源码 wget https://invisible-island.net/datafiles/release/ncurses.tar.gz tar xvf n ...

  2. Cenos(6.6/7.1)下从源码安装Python+Django+uwsgi+nginx到写nginx的环境部署(一)

    梳理下这几个的关系: centos是redhat的社区版操作系统. Python2.7.5是开发语言(centos6.5下自带的python是2.6.6版本,所以需要源码更新,而centos7.1下面 ...

  3. Linux(CentOS或RadHat)下MySQL源码安装

    安装环境: CentOS6.3 64位 软件: Mysql-5.6 所需包: gcc/g++ :MySQL 5.6开始,需要使用g++进行编译.cmake  :MySQL 5.5开始,使用cmake进 ...

  4. centos6下从源码安装setuptools和pip

    1. 下载setuptools及pip的源码包 setuptools与pip都是python的模块 setuptools源码包: https://pypi.python.org/pypi/setupt ...

  5. linux下如何源码安装expect

    1.作用 自动交互.比如如果用ssh登陆服务器,每次都输入密码,然而你觉得麻烦,那你就可以使用expect来做自动交互,这样的话就不用每次都输入密码 2.依赖 依赖tcl 3.获取源码 wget ht ...

  6. Windows下sklearn源码安装

    简介 在Windows下编译sklearn源码,主要注意二点: 编译环境的搭建 编译顺序 编译环境的搭建 如果环境没有搭建好,最常见的报错,就是"error: Unable to find ...

  7. centos下kong源码安装

    参考资料: https://docs.konghq.com/install/source/ 环境准备:操作系统 centeros7.3 1 :openssl和pcre一般系统自带,如果没有可自己安装  ...

  8. Ubuntu 14.04下从源码安装qt4.x

    转自:http://www.cnblogs.com/crazywangzx/p/3505293.html 1.到官网http://qt-project.org/downloads或者ftp://ftp ...

  9. linux下python3源码安装及卸载

    Linux下Python3的源码编译安装和卸载方法 [日期:2019-06-21] 来源:博客园  作者:wuli潇萧 [字体:大 中 小]     (一)Linux下软件的源码编译安装和卸载方法 L ...

随机推荐

  1. Android使用gradle不同配置多项目打包

    //build.gradle该配置文件里路径均是相对路径 apply plugin: 'com.android.application' android { def suffix = "su ...

  2. 用Inferno代替React开发高性能响应式WEB应用

    什么是Inferno Inferno可以看做是React的另一个精简.高性能实现.它的使用方式跟React基本相同,无论是JSX语法.组件的建立.组件的生命周期,还是与Redux或Mobx的配合.路由 ...

  3. PHP成长之路之PHP连接MySql数据库(一)

    PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要适用于W ...

  4. 小白的Python之路 PEP8 代码风格

    转载自http://www.douban.com/note/134971609/ Python 的代码风格由 PEP 8 描述.这个文档描述了 Python 编程风格的方方面面.在遵守这个文档的条件下 ...

  5. HTML基础教程-标题

    HTML 标题 在 HTML 文档中,标题很重要. HTML 标题 标题(Heading)是通过 <h1> - <h6> 等标签进行定义的. <h1> 定义最大的标 ...

  6. 网口划VLAN

    do sho run int g0/28 int g0/18 sw mo acc sw acc vlan 220 span portfa exit do wr exit

  7. 创建一个可用的简单的SpringMVC项目,图文并茂

    转载麻烦注明下来源:http://www.cnblogs.com/silentdoer/articles/7134332.html,谢谢. 最近在自学SpringMVC,百度了很多资料都是比较老的,而 ...

  8. 使用 webpack 打包 font 字体的问题

    之前在使用 Vue 做项目的时候使用了 font 字体,然而在打包的时候 font 字体的引用路径不正确. 解决办法就是在 webpack 的配置文件中设置根路径 目录在 \config\index. ...

  9. 什么是副作用(Side Effect)

    副作用(Side Effect)是指函数或者表达式的行为依赖于外部世界.具体可参照Wiki上的定义,副作用是指 1)函数或者表达式修改了它的SCOPE之外的状态 2)函数或者表达式除了返回语句外还与外 ...

  10. P神的SDFZ考试题 C题

                                                                      探险[问题描述]          探险家小 T 好高兴! X 国要 ...