【GIS部署系列】3、CentOS 7下载OpenStreetMap并导入PostgreSQL(ArcGIS、Mapnik、geoserver、osm2pgsql、TileMill)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/envon123/article/details/81034356
1、下载地图

到OpenStreetMap官网下载地图数据
我下载“china-latest.osm.pbf”这文件,存为:/tmp/china-latest.osm.pbf

2、安装osm2pgsql


先安装依赖库

sudo yum -y install epel-release
sudo yum install -y postgresql10-devel
sudo yum install -y cmake make gcc-c++ boost-devel expat-devel zlib-devel bzip2-devel proj-devel proj-epsg lua-devel

拉取源码


进入osm2pgsql 目录,执行下面指令:

mkdir build && cd build
cmake ..
make
sudo make install

上面“cmake ..”如果报“Could NOT find PostgreSQL (missing: PostgreSQL_LIBRARY_DIRS”之类的,
则把“cmake ..”换成下面语句:(参见:https://github.com/eulerto/pgquarrel/issues/27

cmake .. -DCMAKE_PREFIX_PATH=/usr/pgsql-10

(上面 “/usr/pgsql-10” 换成你的实际路径)


3、导入地图数据

创建数据库chinaosm

# su postgres
createdb chinaosm

启用一些扩展

psql -d chinaosm -c 'CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology; CREATE EXTENSION ogr_fdw; CREATE EXTENSION hstore;'

导入数据到chinaosm库

osm2pgsql --create --database chinaosm /tmp/china-latest.osm.pbf

上面语句出现错误“Node cache size is too small to fit all nodes. Please increase cache size”,
则添加“-C”参数,例如:

osm2pgsql --create --database chinaosm -C 5000 /tmp/china-latest.osm.pbf

导入过程可能比较久,我开着电脑一晚上,应该导入成功了,下面是执行过程信息:

bash-4.2$ osm2pgsql --create --database chinaosm -C 5000 /tmp/china-latest.osm.pbf
osm2pgsql version 0.96.0 (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=5000MB, maxblocks=80000*65536, allocation method=3

Reading in file: /tmp/china-latest.osm.pbf
Using PBF parser.
Processing: Node(57980k 2520.9k/s) Way(4236k 17.36k/s) Relation(48000 46.02/s)  parse time: 1311s
Node stats: total(57980764), max(5734941590) in 23s
Way stats: total(4236740), max(604382393) in 244s
Relation stats: total(48052), max(8423110) in 1044s
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads
Using built-in tag processing pipeline

Going over pending ways...
    1709004 ways are pending

Using 1 helper-processes
Finished processing 1709004 ways in 916 s

1709004 Pending ways took 916s at a rate of 1865.72/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

Going over pending relations...
    0 relations are pending

Using 1 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
警告:  没有事物在运行中
Sorting data and creating indexes for planet_osm_point
node cache: stored: 57980764(100.00%), storage efficiency: 50.42% (dense blocks: 438, sparse nodes: 55701723), hit rate: 100.00%
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 64s
Completed planet_osm_point
Sorting data and creating indexes for planet_osm_line
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 451s
Completed planet_osm_line
Sorting data and creating indexes for planet_osm_polygon
注意:  Self-intersection at or near point 13317174.283909315 3548338.7420334821
注意:  Self-intersection at or near point 11985875.572086383 4115611.18050856
Copying planet_osm_polygon to cluster by geometry finished
Creating geometry index on planet_osm_polygon
Creating indexes on planet_osm_polygon finished
All indexes on planet_osm_polygon created in 252s
Completed planet_osm_polygon
Sorting data and creating indexes for planet_osm_roads
Copying planet_osm_roads to cluster by geometry finished
Creating geometry index on planet_osm_roads
Creating indexes on planet_osm_roads finished
All indexes on planet_osm_roads created in 125s
Completed planet_osm_roads

Osm2pgsql took 3861s overall
bash-4.2$


4、导入OpenStreetMap-Carto样式

上面步骤做完后,地图数据已经完成导入了,这个Carto样式可以不用导入!

下载后解压,然后进入目录,比如我的是:/tmp/openstreetmap-carto-4.12.1,接着执行下面语句:

osm2pgsql -G --hstore --style openstreetmap-carto.style --tag-transform-script openstreetmap-carto.lua -d chinaosm -C 5000 /tmp/china-latest.osm.pbf

提示:当我做这一步的时候,发现它是又重新导入china-latest.osm.pdf数据,等了半天。。。


(完)



阅读更多

没有更多推荐了,返回首页