PgRouting CentOs6 安装以及使用

来源:互联网 发布:淘宝怎样延长收货时间 编辑:程序博客网 时间:2024/06/11 16:19

安装

添加yum源

wget http://repo.enetres.net/enetres.repo -O /etc/yum.repos.d/enetres.repowget http://nextgis.ru/programs/centos/nextgis.repo -O /etc/yum.repos.d/nextgis.repoyum install epel-release

安装PostgreSQL and PostGIS

注意:由于yum源中目前只有pgrouting94版本,所以 PostgreSQL 和 PostGIS也应该安装94版本,避免在安装pgrouting的时候产生依赖问题

配置yum

vi /etc/yum.repos.d/CentOS-Base.repo# 在[end] section 后添加exclude=postgresql*# 在[updates] section 后添加exclude=postgresql*

下载安装Postgres rpm 包

官网地址http://yum.postgresql.org/repopackages.php
下载后安装

rpm -ivh pgdg-centos94-9.4-1.noarch.rpm

安装PostGis

PostGis 依赖proj 4.8 ,安装前首先更新proj

yum update proj 

然后安装

yum install postgresql94-server postgis2_94

如果出现重复安装问题,使用如下命令

yum install yum-utilspackage-cleanup --cleandupes

安装完成后使用以下命令启动服务

service postgresql-9.4 initdbservice postgresql-9.4 startchkconfig postgresql-9.4 on

安装CGAL

yum install libCGAL10

安装pgRouting

yum install pgrouting_94

登录

默认配置下登录

# 切换到postgres账户su - postgres# 登录到postgres 数据库psql

创建新用户访问

su - postgrespsql# 创建用户以及密码create user dbuser with password '*****';# 创建数据库create database exampledb owner dbuser;# 将exampledb 的权限赋给 dbusergrant all privileges on database exampledb to dbuser;# 使用 \q 退出# 创建和刚才同名的linux用户sudo adduser dbusersudo passwd dbuser# 切换到dbuser身份 连接数据库psql -d exampledb

创建和当前用户同名的用户名以及数据库

su - postgrespsqlcreate user root with password '*****';create database root owner root;grant all privileges on database root to root\qexit# 切回到 root 账户后使用psql 命令可以直接连接到数据库# 如果找不到psql 命令,需要将postgres 路径添加到系统环境变量echo -e "export PATH=/usr/pgsql-9.4/bin:\$PATH" >> ~/.bash_profilesource ~/.bash_profile

使用pgrouting

创建database

登录后创建database

createdb mydatabase# 创建扩展create extension postgiscreate extension pgrouting

导入osm数据

导入osm数据目前可以使用以下工具
1. osm2pgrouting(导入后不需要再额外创建拓扑,还没尝试)
2. osm2pgsql (导入数据后需要创建拓扑)

编译安装osm2pgsql

  1. 下载git clone git://github.com/openstreetmap/osm2pgsql.git
  2. 安装依赖
sudo yum install epel-releasesudo yum install cmake gcc-c++ boost-devel expat-devel zlib-devel bzip2-devel \  postgresql-devel proj-devel proj-epsg lua-devel

安装依赖过程中可能会找不到boost,需要编译安装boost

#下载boost./bootstrap.sh./b2./b2 install在 /etc/ld.so.conf 添加/usr/local/libldconfig
  1. 安装
mkdir -p bulid && cd buildcmake ..makemake install
  1. Usage
createdb gispsql -d gis -c 'create extension postgis;create extension hstore'osm2pgsql --create --database gis data.osm.pbf