OSM数据有几种下载方式:1)直接通过wget下载; 2)通过官网直接导出指定区域; 3)通过osm2pgsql导入postgis; 4)geoserver或其他地图服务发布
1.通过wget下载数据
进入http://download.geofabrik.de/, 可以按照自己的需求下载不同国家不同区域的数据。本文提供了一下几个例子
全球数据下载:
wget -c http://planet.openstreetmap.org/pbf/planet-latest.osm.pbf
中国数据下载:
wget -c http://download.geofabrik.de/asia/china-latest.osm.pbf
2.通过官网直接导出指定区域数据
进入https://www.openstreetmap.org 点击导出,拖动地图就可以按照范围导出自己想要的范围
3.通过osm2pgsql导入postgis
CentOS7安装osm2pgsql ,Git下载osm2pgsql.zip压缩包,完成后 osm2pgsql -v 出现版本号,说明成功安装。
cd osm2pgsql
cmake ..
make
sudo make install
在postgis数据库中建好名为osm库,并且执行将库设置为postgis空间库的操作。
CREATE EXTENSION postgis;
进入下载好的osm文件夹,按照如下方式,-u:数据库用户名 -p:端口,-h:地址,-d:导入到的数据库名,最后一项,为需要导入的文件地址与名称。
osm2pgsql -U postgres -H 127.0.0.1 -P 5432 -d osm map.osm
导入完成后如下显示,表示已经导入到postgis的osm库中
Database version: 9.4.15
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=800MB, maxblocks=12800*65536, allocation method=3
Using projection SRS 3857 (Spherical Mercator)
Using built-in tag processing pipeline
Setting up table: planet_osm_point
Setting up table: planet_osm_line
Setting up table: planet_osm_polygon
Setting up table: planet_osm_roads
Reading in file: map.osm
Using XML parser.
Processing: Node(14k 14.0k/s) Way(2k 2.00k/s) Relation(388 388.0/s) parse t
Node stats: total(14336), max(8050788257) in 0s
Way stats: total(2284), max(860113624) in 0s
Relation stats: total(388), max(11643624) in 0s
node cache: stored: 14336(100.00%), storage efficiency: 38.90% (dense blockse: 100.00%
Sorting data and creating indexes for planet_osm_line
Sorting data and creating indexes for planet_osm_polygon
Sorting data and creating indexes for planet_osm_point
Sorting data and creating indexes for planet_osm_roads
Using native order for clustering
Using native order for clustering
Using native order for clustering
Using native order for clustering
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 0s
Completed planet_osm_roads
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
Copying planet_osm_polygon to cluster by geometry finished
Creating geometry index on planet_osm_polygon
Creating indexes on planet_osm_polygon finished
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_polygon created in 0s
Completed planet_osm_polygon
All indexes on planet_osm_line created in 0s
Completed planet_osm_line
Osm2pgsql took 1s overall
4.postgis发布geoserver图层
自信点你知道的