ubuntu16.4 基于OpenStreetMap地图搭建离线地理编码服务Nominatim

问题十:Nominatim安装

openstreetmap地图的地理编码服务Nominatim

本文有道笔记链接:http://note.youdao.com/noteshare?id=488a724840948f5d9b0e857ec9e7b3a2  ————可以直接打开这里看图片、附件

参考网址http://wiki.openstreetmap.org/wiki/Nominatim/Installation

参考网址2:https://github.com/twain47/Nominatim/blob/master/docs/install-on-ubuntu-16.md

https://github.com/twain47/Nominatim/blob/master/docs/Import_and_update.md

10.1预先安装

sudo apt-get install build-essential wget

sudo apt-get install libxml2-dev wget

sudo apt-get install libpq-dev wget

sudo apt-get update

sudo apt-get install libbz2-dev wget

sudo apt-get install libtool wget

sudo apt-get install automake wget

sudo apt-get install libproj-dev wget

sudo apt-get install libboost-dev wget

sudo apt-get install libboost-system-dev wget

sudo apt-get install libboost-filesystem-dev wget

sudo apt-get install libboost-thread-dev wget

sudo apt-get install libexpat-dev wget

sudo apt-get install gcc wget

sudo apt-get install  proj-bin wget

sudo apt-get install libgeos-c1 wget---有问题,用 sudo apt-get install libgeos-c1v5 wget 替换

sudo apt-get install libgeos++-dev wget

ubuntu上默认只能安装php7了,如果想要安装php5,可以按照如下命令——此处必须安装php5,php7没有用

sudo add-apt-repository ppa:ondrej/php

sudo apt update

sudo apt install php5.6

sudo apt install libapache2-mod-php5.6

sudo apt install php5.6-curl

sudo apt install php5.6-gd

sudo apt install php5.6-mbstring

sudo apt install php5.6-mcrypt

sudo apt install php5.6-mysql

sudo apt install php5.6-xml

sudo apt install php5.6-xmlrpc

sudo a2dismod php7.0

sudo a2enmod php5.6

sudo systemctl restart apache2

sudo apt-get install php-pear wget

sudo apt-get install php5.6-pgsql wget

sudo apt-get install php5-json wget

sudo apt-get install php-db wget

sudo apt-get install postgresql-server-dev-9.5 wget

sudo apt-get install  postgresql-contrib-9.5 wget

因为sudo apt-get update导致postgresql9.5升级到9.6了

sudo apt-get install postgresql-contrib-9.6 wget

sudo apt-get install postgresql-server-dev-9.6 wget

apt-get install postgresql-9.6-postgis

由于导入的地理数据格式为pbf,所以需要安装pbf支持软件

sudo apt-get install libprotobuf-c0-dev

sudo apt-get installprotobuf-c-compiler

10.2 postgresql配置

打开/etc/postgresql/9.3/main中的postgresql.conf文件,设置如下属性:

fsync = off

full_page_writes = off

synchronous_commit = off

具体命令为:

sudo gedit /etc/postgresql/9.5/main/postgresql.conf

10.3 下载Nominatim-2.5.1.tar.bz2

wgethttp://www.nominatim.org/release/Nominatim-2.5.1.tar.bz2tar xvf Nominatim-2.5.1.tar.bz2

10.4编译Nominatim

cd Nominatim-2.5.1

./configure

make

备注:The warning about missing lua libraries can be ignored. Nominatim does not make use of osm2pgsql's lua extension.

10.5 自定义安装

您可以通过创建本地配置文件设置/ local.php来自定义Nominatim。 看看settings / settings.php可用的配置设置。


您需要创建一个最小的配置文件,告知nominatim它在网络服务器上的位置:

tee settings/local.php << EOF


// Paths

@define('CONST_Postgresql_Version', '9.5');

@define('CONST_Postgis_Version', '2.3');

@define('CONST_Website_BaseURL', 'http://localhost/nominatim/');

EOF

具体如下:


// Paths

@define('CONST_Postgresql_Version', '9.5');

@define('CONST_Postgis_Version', '2.3');

// Website settings

@define('CONST_Website_BaseURL', 'http://localhost/nominatim/');

?>

bak两个命令,无需执行

sudo cp -r /etc/postgresql/9.6  /home/zhanggeoo7/document

sudo cp -r /usr/lib/postgresql/9.6 /home/zhanggeoo7/document/usr

10.6 创建导入账户

导入需要使用与执行导入的帐户同名的postgres超级用户来完成。 您可以通过运行以下命令来创建这样的postgres超级用户帐户:

sudo -u postgres createuser -s test这里test用于登录postgres数据库

sudo adduser test这里test用于登录ubuntu系统的,密码为luomouren

其中test是将用于执行安装的帐户的名称。 您应该确保此用户可以登录到数据库,而不需要密码(例如,使用ident身份验证)。 这是大多数发行版的默认值。 有关详细信息,请参阅信任身份验证。

您不能以用户www-data或root运行导入。

创建网站用户

将网站用户www-data创建为PostgreSQL数据库角色

10.7 新建网站用户

su - postgres

createuser -SDR www-data

对于安装过程,您必须具有此用户。如果要在其他用户下运行网站,请参阅设置网站一节中的注释。

10.8 更改nominatim的读取权限

sudo chmod +x -R /home/zhanggeoo7

sudo chmod +x -R/home/zhanggeoo7/Nominatim-2.5.1

sudo chmod +x -R/home/zhanggeoo7/Nominatim-2.5.1/module

10.9下载pdf 格式的osm数据

http://download.bbbike.org/osm/

http://download.bbbike.org/osm/bbbike/Beijing/

10.10导入pdf数据

su - test

/home/zhanggeoo7/Nominatim-2.5.1/utils/setup.php --osm-file /home/zhanggeoo7/Beijing.osm.pbf --all

或者是下面的命令

/home/zhanggeoo7/Nominatim-2.5.1/utils/setup.php --osm-file /home/zhanggeoo7/Beijing.osm.pbf--all --osm2pgsql-cache 400] 2>&1 | tee setup.log

如果出现问题,您可能需要通过删除数据库进行清理,因为在尝试重新创建现有数据库时脚本将失败。使用此命令来执行此操作:sudo -u postgres dropdb nominatim

出现错误及解决方案如下

error.txt  见有道笔记分项链接


10.11 添加额外字段

sudo chmod 777/home/zhanggeoo7/Nominatim-2.5.1/data-R

su - test

Add country codes and country names to the search index:

/home/zhanggeoo7/Nominatim-2.5.1/utils/specialphrases.php --countries >/home/zhanggeoo7/Nominatim-2.5.1/data/specialphrases_countries.sql

psql -d nominatim -f/home/zhanggeoo7/Nominatim-2.5.1/data/specialphrases_countries.sql

If you want to be able to search for special amenities likepubs in Dublin, you need to import special phrases from this wiki like this:

/home/zhanggeoo7/Nominatim-2.5.1/utils/specialphrases.php --wiki-import >/home/zhanggeoo7/Nominatim-2.5.1/data/specialphrases.sql

psql -d nominatim -f/home/zhanggeoo7/Nominatim-2.5.1/data/specialphrases.sql

This may be repeated from time to time when there are changes in the wiki. There is no need to repeat it after each update.

If you do not need phrases for all languages, editsettings/phrase_settings.phpand delete unneeded languages at the beginning of the file.

10.12 建立网站

Create the directory for the website and make sure it is writable by the install user and readable by Apache:

sudo mkdir -m 755/var/www/html/nominatim

sudo chmod 777/var/www/html/nominatim-R

Populate the website directory with the necessary symlinks:

/home/zhanggeoo7/Nominatim-2.5.1/utils/setup.php --create-website /var/www/html/nominatim

You will need to make sure settings/local.php is configured with correct values forCONST_Website_BaseURL. see above.

10.13 配置apache环境

打开/etc/apache2/sites-enabled/000-default.conf,在最后添加如下内容:

Options FollowSymLinks MultiViews

AddType text/html .php

重启apache

service apache2 restart

10.14 增加test对数据库nominatim的权限

su – postgres

psql template1

GRANT ALL PRIVILEGES ON DATABASE nominatim to test

\q

10.15 运行nominatim

浏览器登陆http://localhost/nominatim/

看www-data用户有没有数据库读写权限,若没有,则打开/etc/apache2/envvars,修改

export APACHE_RUN_USER=test

export APACHE_RUN_GROUP=test

如果想要局域网都可以访问

local.php为


// Paths

@define('CONST_Postgresql_Version', '9.5');

@define('CONST_Postgis_Version', '2.3');

// Website settings

@define('CONST_Website_BaseURL', 'http://172.16.0.14/nominatim/');

?>

修改后重启Apache

service apache2 restart

使用参数说明:http://wiki.openstreetmap.org/wiki/Nominatim#Reverse_Geocoding_.2F_Address_lookup

在线服务:http://nominatim.openstreetmap.org/

demo测试html  见有道笔记分享链接

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 156,069评论 4 358
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,212评论 1 287
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 105,912评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,424评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,741评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,194评论 1 206
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,553评论 2 307
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,289评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 33,923评论 1 237
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,251评论 2 240
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,775评论 1 255
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,144评论 2 249
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,698评论 3 228
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 25,936评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,658评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,214评论 2 267
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,159评论 2 258

推荐阅读更多精彩内容