本文介绍在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. startup alter.log spfile.ora

    SQL> select * from v$version where rownum=1; BANNER --------------------------------------------- ...

  2. 腾讯Web工程师的前端书单

    2014年一月以来,自己接触web前端开发已经两年多了,记录一下自己前端学习路上看过的,以及道听途说的一些书,基本上按照由浅入深来介绍. JavaScript 入门 <JavaScript权威指 ...

  3. intellij idea svn使用一 导入、更新、提交、解决冲突

    大体上是转载,针对版本14有一些特殊的添加. 查看svn的资源库: 下面的多出了一个svn的窗口,在左边有加号可以添加一个svn的库 输入svn的地址,我用的是本地的测试,所以地址为svn://127 ...

  4. fatal: Authentication failed for “someurl”

    一.前言 我们在公司做项目,很多时候会遇到这个问题:Git failed with a fatal error. Authentication failed for ‘ http// xxx..... ...

  5. html5中将图片的绝对路径转换成文件对象

    html5中将图片的绝对路径转换成文件对象 将图片的绝对路径转换成base64编码,请看这篇文章 我们先来理解基本知识点: 1. 理解HTML5中的FileList对象与file对象. 在HTML5中 ...

  6. iOS手势之pinch

    今天用地图的时候有用到pinch 捏合手势 通过捏合手势动作可以很轻松的来改变视图元素的一个比例 手势的动作状态有如下三种,一般是按照顺序来进行转换的. 1. UIGestureRecognizerS ...

  7. Android开发之常见事件响应方式

    常见的事件有   (1)单击事件 onClickListener (2)长按事件 onLongClickListener (3)滑动事件 onTouchListener (4)键盘事件 onKeyLi ...

  8. 【ANT】一个简单的ANT生成文件build.xml

    <?xml version="1.0" ?> <project default="test"> <target name=&quo ...

  9. 网关 php-cgi fastcgi phpfpm

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/88 关于网关的理解,一句话就是:作为一种翻译器,抽象出了一种能够 ...

  10. [Count the numbers satisfying (m + sum(m) + sum(sum(m))) equals to N]

    Given an integer N, the task is to find out the count of numbers M that satisfy the condition M + su ...