RedHat7下PostGIS源码安装
本文介绍在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
参考资料
- Linux环境下源码安装PostgreSQL+PostGIS: http://www.voidcn.com/article/p-yesruvml-bdv.html
- 空间索引 - 各数据库空间索引使用报告: http://www.cnblogs.com/zhenbianshu/p/6817569.html
- PostgreSQL+PostGIS 的使用: http://www.cnblogs.com/kaituorensheng/p/4647901.html
- 空间索引(GiST、BRIN、R-Tree)选择、优化 - 阿里云RDS PostgreSQL最佳实践: https://yq.aliyun.com/articles/175035
RedHat7下PostGIS源码安装的更多相关文章
- debian下如何源码安装tmux
一.源码安装ncurses库 1.1 获取源码 wget https://invisible-island.net/datafiles/release/ncurses.tar.gz tar xvf n ...
- Cenos(6.6/7.1)下从源码安装Python+Django+uwsgi+nginx到写nginx的环境部署(一)
梳理下这几个的关系: centos是redhat的社区版操作系统. Python2.7.5是开发语言(centos6.5下自带的python是2.6.6版本,所以需要源码更新,而centos7.1下面 ...
- Linux(CentOS或RadHat)下MySQL源码安装
安装环境: CentOS6.3 64位 软件: Mysql-5.6 所需包: gcc/g++ :MySQL 5.6开始,需要使用g++进行编译.cmake :MySQL 5.5开始,使用cmake进 ...
- centos6下从源码安装setuptools和pip
1. 下载setuptools及pip的源码包 setuptools与pip都是python的模块 setuptools源码包: https://pypi.python.org/pypi/setupt ...
- linux下如何源码安装expect
1.作用 自动交互.比如如果用ssh登陆服务器,每次都输入密码,然而你觉得麻烦,那你就可以使用expect来做自动交互,这样的话就不用每次都输入密码 2.依赖 依赖tcl 3.获取源码 wget ht ...
- Windows下sklearn源码安装
简介 在Windows下编译sklearn源码,主要注意二点: 编译环境的搭建 编译顺序 编译环境的搭建 如果环境没有搭建好,最常见的报错,就是"error: Unable to find ...
- centos下kong源码安装
参考资料: https://docs.konghq.com/install/source/ 环境准备:操作系统 centeros7.3 1 :openssl和pcre一般系统自带,如果没有可自己安装 ...
- Ubuntu 14.04下从源码安装qt4.x
转自:http://www.cnblogs.com/crazywangzx/p/3505293.html 1.到官网http://qt-project.org/downloads或者ftp://ftp ...
- linux下python3源码安装及卸载
Linux下Python3的源码编译安装和卸载方法 [日期:2019-06-21] 来源:博客园 作者:wuli潇萧 [字体:大 中 小] (一)Linux下软件的源码编译安装和卸载方法 L ...
随机推荐
- 一句话搞定webmap(一)——轻地图组件
摘要: 遥想当年.在APP中增加LBS元素相当困难:要刻苦学习java,要刻苦学习iOS开发,要刻苦学习javascript-- 而现在.要制作一张地图真是越来越easy了!居然仅仅须要一句话.就能够 ...
- Python: The _imagingft C module is not installed错误的解决
Python: The _imagingft C module is not installed错误的解决 By 白熊花田(http://blog.csdn.net/whiterbear) 转载需注明 ...
- hdu 4869 Turn the pokers (思维)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Oracle集合操作
在Oracle中提供了三种类型的集合操作: 并(UNION).交(INTERSECT).差(MINUS) UNION:将多个查询的结果组合到一个查询结果之中,并去掉反复值 UNION ALL:将多个查 ...
- json与xml的比较
l 可读性: JSON和XML的可读性都很好,XML略占上风. l 可扩展性 XML天生有很好的扩展性,JSON当然也有,没有什么是XML能扩展,JSON不能的. l 编码难度 XML有丰富的编码工具 ...
- html5笔记——<section> 标签
定义和用法 <section> 标签定义文档中的节(section.区段).比如章节.页眉.页脚或文档中的其他部分. 注意: section 不是一个专用来做容器的标签,如果仅仅是用于设置 ...
- Mybatis-----优化配置文件,基于注解CR
这篇主要写配置文件的优化,例如 jdbc.properties 配置文件 ,引入数据库的文件,例如driver,url,username,password 等,然后在 SqlMapConfig.x ...
- c语言文件分割与合并
一.综述 c语言操作文件通过文件指针FILE*,每个要操作的文件必须打开然后才能读写. 注意事项: @1分割与合并文件最好使用二进制模式即"rb"或"wb",这 ...
- tensorflow ckpt文件转caffemodel时遇到的坑
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ".PingFang SC"; color: #454545 } p.p2 ...
- arcgis api for js入门开发系列十六迁徙流动图
最近公司有个arcgis api for js的项目,需要用到百度echarts迁徙图效果,而百度那个效果实现是结合百度地图的,怎么才能跟arcgis api结合呢,网上搜索,终于在github找到了 ...