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

本文详细介绍了如何在Ubuntu16.04系统中搭建OpenStreetMap的离线地理编码服务Nominatim,包括预安装必要的库,配置postgresql,下载和编译Nominatim,创建数据库用户,导入OSM数据,添加额外字段,建立网站以及配置Apache环境等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题十:Nominatim安装

openstreetmap地图的地理编码服务Nominatim

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

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

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数据

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

看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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值