为OpenStreetMap瓦片服务器添加3弧秒全球DEM图层

上一篇文章里,我们试着测试了局部3弧秒(即1/1200度)分辨率的 DEM等高线嵌入OSM图层的效果。下面,来分享一下批量导入全球的DEM数据。
经笔者测试,如果一次性导入全球OpenStreetMap PBF(32GB,2017-01)、全球3弧秒 DEM(hgt压缩包转为PBF 约28GB),需要一块 2TB 的 SSD。尽管最终的数据库规模可通过缩减中间表,压缩到300GB,但导入过程中会吃掉约1TB多的空间。若在导入OSM后进行一次收缩,而后导入DEM,则1TB SSD 勉强刚好。

导入全球数据的原始DEM、转换后PBF、导入后数据库镜像(pg_dump)以及完整虚拟机镜像可从ArchOSM共享地址下载。为了多线程压缩,其使用了7z16.0版本LZMA2算法。解压缩需要512MB空闲内存。我的缓存服务器位置在这里RaspberryPI OSM 缓存服务器,如果渲染服务器没有开机,仅能看到缓存的数据。

1.使用下载工具批量下载DEM压缩包

有心人会注意到,在使用phyghtmap下载局部数据时,会得到一个任务列表,位于hgt文件夹下。
viewfinderHgtIndex_3.txt
这个文件里记录了所有的原始数据地址,类似:

# VIEW3 index file, VERSION=4
...
[http://viewfinderpanoramas.org/ANTDEM3/01-15.zip]
...
S61W091
...

中括号里的都是地址。二话不说,复制所有内容到 Wps 电子表格,排序,便收集到了所有的网址。查找替换清除[]后,在下载工具里批量下载即可。

2.从本地FTP服务器创建全球高程PBF

下载完毕后,把所有ZIP文件拷贝到一个独立的文件夹,设置为FTP地址。而后,把上述文件viewfinderHgtIndex_3.txt的所有地址替换为本地FTP。这样处理后,下载全球数据就变得非常迅速啦。
修改好后的viewfinderHgtIndex_3.txt类似下面的样子。

# VIEW3 index file, VERSION=4
[ftp://192.168.1.10/zip/01-15.zip]
...
[ftp://192.168.1.10/zip/16-30.zip]
...

使用命令生成全球PBF

phyghtmap -a -180:-85:180:85 --source=view3 --pbf --max-nodes-per-tile 0

此时,该程序会自动读取已经存在的viewfinderHgtIndex_3.txt,从本地服务器下载、执行。

转换过程需要约1天,最终生成一个 PBF文件,28GB

3.导入全球PBF

留好磁盘空间,而后,进行导入:

[archosm@archosm ~]$  osm2pgsql -c -s -S"./contour/contour.style" -C24000 -dcontours --drop --flat-nodes "./cache/nodes/flat_node" ./contour/lon-180.00_180.00lat-85.00_85.00_view3.osm.pbf
osm2pgsql version 0.93.0-dev (64 bit id space)

Using built-in tag processing pipeline
Using projection SRS 3857 (Spherical Mercator)
Setting up table: planet_osm_point
Setting up table: planet_osm_line
Setting up table: planet_osm_polygon
Setting up table: planet_osm_roads
Allocating memory for dense node cache
Allocating dense node cache in one big chunk
Allocating memory for sparse node cache
Sharing dense sparse
Node-cache: cache=24000MB, maxblocks=384000*65536, allocation method=11
Mid: loading persistent node cache from ./cache/nodes/flat_node
Allocated space for persistent node cache file
Maximum node in persistent node cache: 0
Mid: pgsql, scale=100 cache=24000
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels

Reading in file: ./contour/lon-180.00_180.00lat-85.00_85.00_view3.osm.pbf
Using PBF parser.
Processing: Node(10198222k 6803.4k/s) Way(141003k 11.63k/s) Relation(0 0.00/s)  parse time: 13621s
Node stats: total(10198222219), max(10208222218) in 1499s
Way stats: total(141003653), max(151003652) in 12122s
Relation stats: total(0), max(0) in 0s
Maximum node in persistent node cache: 10208935935
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads
Mid: loading persistent node cache from ./cache/nodes/flat_node
Maximum node in persistent node cache: 10208935935
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels
Using built-in tag processing pipeline
Mid: loading persistent node cache from ./cache/nodes/flat_node
Maximum node in persistent node cache: 10208935935
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels
Using built-in tag processing pipeline
Mid: loading persistent node cache from ./cache/nodes/flat_node
Maximum node in persistent node cache: 10208935935
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels
Using built-in tag processing pipeline
Mid: loading persistent node cache from ./cache/nodes/flat_node
Maximum node in persistent node cache: 10208935935
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels
Using built-in tag processing pipeline

Going over pending ways...
        0 ways are pending

Using 4 helper-processes
Finished processing 0 ways in 0 s

Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads

Going over pending relations...
        0 relations are pending

Using 4 helper-processes
Finished processing 0 relations in 0 s

Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Sorting data and creating indexes for planet_osm_polygon
Stopping table: planet_osm_nodes
Sorting data and creating indexes for planet_osm_roads
Sorting data and creating indexes for planet_osm_point
Stopping table: planet_osm_ways
Stopping table: planet_osm_rels
Sorting data and creating indexes for planet_osm_line
Stopped table: planet_osm_rels in 0s
Stopped table: planet_osm_nodes in 0s
Copying planet_osm_polygon to cluster by geometry finished
Creating geometry index on planet_osm_polygon
Copying planet_osm_roads to cluster by geometry finished
Creating geometry index on planet_osm_roads
Creating indexes on planet_osm_polygon finished
Creating indexes on planet_osm_roads finished
Copying planet_osm_point to cluster by geometry finished
Creating geometry index on planet_osm_point
Creating indexes on planet_osm_point finished
All indexes on planet_osm_point created in 0s
Completed planet_osm_point
All indexes on planet_osm_roads created in 0s
Completed planet_osm_roads
All indexes on planet_osm_polygon created in 0s
Completed planet_osm_polygon
Stopped table: planet_osm_ways in 1s
Copying planet_osm_line to cluster by geometry finished
Creating geometry index on planet_osm_line
Creating indexes on planet_osm_line finished
All indexes on planet_osm_line created in 6804s
Completed planet_osm_line
Maximum node in persistent node cache: 10208935935
Maximum node in persistent node cache: 10208935935
Maximum node in persistent node cache: 10208935935
Maximum node in persistent node cache: 10208935935
node cache: stored: 3145729419(30.85%), storage efficiency: 100.00% (dense blocks: 384000, sparse nodes: 2432), hit rate: 30.78%

Osm2pgsql took 20429s overall

4 显示效果

显示效果还是很棒的,我们看看南美洲的山脉
img-P52NeXaZ-1657602347042
连南极都有了
img-2fk1XIcr-1657602347044

离线地图_openstreetmap_postgresql_瓦片 离线地图_openstreetmap_postgresql_postgis_mapnik_osm2pgsql_osm数据 写于20150414 关于软件地址 事先说明这其实就是我全部放到百度网盘空间里了。 所以万一一不小心我手抖删了,请mail我。 haibinzhagncn@qq.com 软件包括 leaflet osm里面中国和台湾的数据 openlayers geoserver mabox_studio mapnik 和生成瓦片工具需要的前置包等 postgresql osm2pgsql postgis python 一次只能上传一份那我就少点多几份吧: 介绍(免积分) http://download.csdn.net/detail/a137015127302/8594877 如果懒得自己慢慢找,我想你不介意花点积分的吧。 1.postgreSql_1.&postgis_install http://download.csdn.net/detail/a137015127302/8594903 2.postgreSql_2.mapnik&python_install http://download.csdn.net/detail/a137015127302/8594915 3.postgreSql_3.环境变量配置_osm数据导入 http://download.csdn.net/detail/a137015127302/8594919 4.postgreSql_4.生成图片瓦片byMapnik http://download.csdn.net/detail/a137015127302/8594921 其他:postgreSql_psql_乱码问题 http://download.csdn.net/detail/a137015127302/8594937 上传什么的好烦-- 我再试一次要是还是不能上传我就不玩了。切~ 核心内容(英文版公开资料):http://wiki.openstreetmap.org/wiki/Creating_your_own_tiles 以下本人写的中文版本的核心:只要注意这个基本上就没什么大问题了。 当然你要是懒得自己一步一步走,我想你应该也不介意多花点积分的。 摘录 首先版本请用 postgresql-9.3.6-2-windows.exe + postgis-bundle-pg93x32-setup-2.1.5-1.exe 因为至少如果是 postgresql-9.4.1-3-windows.exe + postgis-bundle-pg94x32-setup-2.1.7-1.exe 存在sample数据库无法创建问题。 同时32位下中文客户端提示信息异常问题,你只能改为英文显示,但是又会有warn信息提示你与本地不符(很烦不是么) 所以结论最新的未必就是最好的。 而且貌似他们已经开始放弃32位了。 还有这个2.1.7貌似是赶工出来的,因为提示信息写的是支援9.3而事实是否定的。 以上是我重装了n多遍的结论。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丁劲犇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值