問題十:Nominatim安裝
openstreetmap地圖的地理編碼服務Nominatim
本文有道筆記鏈接:http://note.youdao.com/noteshare?id=488a724840948f5d9b0e857ec9e7b3a2 ?————可以直接打開這里看圖片循榆、附件
參考網(wǎng)址http://wiki.openstreetmap.org/wiki/Nominatim/Installation
參考網(wǎng)址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
由于導入的地理數(shù)據(jù)格式為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 自定義安裝
您可以通過創(chuàng)建本地配置文件設置/ local.php來自定義Nominatim盗尸。 看看settings / settings.php可用的配置設置。
您需要創(chuàng)建一個最小的配置文件帽撑,告知nominatim它在網(wǎng)絡服務器上的位置:
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兩個命令泼各,無需執(zhí)行
sudo?cp?-r?/etc/postgresql/9.6 ?/home/zhanggeoo7/document
sudo?cp?-r?/usr/lib/postgresql/9.6?/home/zhanggeoo7/document/usr
10.6 創(chuàng)建導入賬戶
導入需要使用與執(zhí)行導入的帳戶同名的postgres超級用戶來完成。 您可以通過運行以下命令來創(chuàng)建這樣的postgres超級用戶帳戶:
sudo -u postgres createuser -s test這里test用于登錄postgres數(shù)據(jù)庫
sudo?adduser?test這里test用于登錄ubuntu系統(tǒng)的亏拉,密碼為luomouren
其中test是將用于執(zhí)行安裝的帳戶的名稱扣蜻。 您應該確保此用戶可以登錄到數(shù)據(jù)庫,而不需要密碼(例如及塘,使用ident身份驗證)莽使。 這是大多數(shù)發(fā)行版的默認值。 有關詳細信息笙僚,請參閱信任身份驗證吮旅。
您不能以用戶www-data或root運行導入。
創(chuàng)建網(wǎng)站用戶
將網(wǎng)站用戶www-data創(chuàng)建為PostgreSQL數(shù)據(jù)庫角色
10.7 新建網(wǎng)站用戶
su - postgres
createuser -SDR www-data
對于安裝過程,您必須具有此用戶庇勃。如果要在其他用戶下運行網(wǎng)站檬嘀,請參閱設置網(wǎng)站一節(jié)中的注釋。
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數(shù)據(jù)
http://download.bbbike.org/osm/
http://download.bbbike.org/osm/bbbike/Beijing/
10.10導入pdf數(shù)據(jù)
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
如果出現(xiàn)問題责嚷,您可能需要通過刪除數(shù)據(jù)庫進行清理鸳兽,因為在嘗試重新創(chuàng)建現(xiàn)有數(shù)據(jù)庫時腳本將失敗。使用此命令來執(zhí)行此操作:sudo -u postgres dropdb nominatim
出現(xiàn)錯誤及解決方案如下
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 建立網(wǎng)站
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環(huán)境
打開/etc/apache2/sites-enabled/000-default.conf,在最后添加如下內(nèi)容:
Options FollowSymLinks MultiViews
AddType text/html .php
重啟apache
service apache2 restart
10.14 增加test對數(shù)據(jù)庫nominatim的權限
su – postgres
psql template1
GRANT ALL PRIVILEGES ON DATABASE nominatim to test
\q
10.15 運行nominatim
瀏覽器登陸http://localhost/nominatim/
看www-data用戶有沒有數(shù)據(jù)庫讀寫權限罕拂,若沒有揍异,則打開/etc/apache2/envvars,修改
export APACHE_RUN_USER=test
export APACHE_RUN_GROUP=test
如果想要局域網(wǎng)都可以訪問
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
使用參數(shù)說明:http://wiki.openstreetmap.org/wiki/Nominatim#Reverse_Geocoding_.2F_Address_lookup
在線服務:http://nominatim.openstreetmap.org/
demo測試html ?見有道筆記分享鏈接