系统性整理项目:第一篇(续篇)-osm存入PostgreSQL+PostGIS并构建路网表结构

一、PostgreSQL 10+ PostGIS 3已经安装完成

二、OSM(beijing-latest.osm)文件已经成功转换成EPSG:2436平面坐标系,并且已经完成在交点处分割道路,最后保存成OSM格式(也可以是shp格式)

三、利用osmosis将.osm文件存入PostgreSQL+PostGIS中,步骤如下:

1. 新建db-epm数据库,并新建扩展:hstore、postgis和pgrouting,可以用用DBeaver来新建扩展,也可通过命令来实现:

   create extension hstore;

   create extension postgis;

   create extension pgrouting;

2. 打开cmd

3. C:Usersjiangshan>cd C:Program Files (x86)osmosisin

4. C:Program Files (x86)osmosisin>psql -h localhost -p 5432 -U postgres -d db-epm -f ../script/pgsnapshot_schema_0.6.sql

   用户 postgres 的口令:*****

5. 用DBeaver来查看db-epm数据库,此时就会多了几个表,如下:

 

 接下来,构建网络

6. C:Program Files (x86)osmosisin>osmosis --read-xml D:/EngineeringProjectManagement/beijing-latest-cars.osm --write-pgsql host="localhost" database=“db-epm" user="postgres" password="jiangshan"

成功后,db-epm数据库中,就有数据了,如下:

 

 7. 切换至xml文本文件beijing.osm所在目录(cd D:EngineeringProjectManagementconverted.shp-2436-seg)

   >osm2pgrouting --file D:/EngineeringProjectManagement/converted.shp-2436-se/Beijing-2436.osm --conf S:/PostgreSQL/10/bin/mapconfig_for_cars.xml --schema public --addnodes --prefix bj_ --suffix _car --clean -d db-epm -U postgres -h localhost -p 5432 -W jiangshan

或者 采用以下带全部参数

   >osm2pgrouting --file D:/EngineeringProjectManagement/converted.shp-2436-seg/beijing-2436.osm --conf S:/PostgreSQL/10/bin/mapconfig_for_cars.xml --schema public --prefix bj_ --suffix _car --addnodes --attributes --tags --clean -d db-epm -U postgres -h localhost -p 5432 -W jiangshan

正常应该输出以下:

   Creating tables...

   TABLE: public.bj_ways_car created ... OK.

   TABLE: public.bj_ways_car_vertices_pgr ... OK.

   TABLE: public.bj_pointsofinterest_car created ... OK.

   TABLE: public.configuration created ... OK.

   TABLE: public.osm_nodes created ... OK.

   TABLE: public.osm_ways created ... OK.

   TABLE: public.osm_relations created ... OK.

   Opening configuration file: S:/PostgreSQL/10/bin/mapconfig_for_cars.xml

   ………………………………………..

   Elapsed time: 285.297 Seconds.

   User CPU time: -> 285.299 seconds

   #########################

8. 用DBeaver来查看新建的表及导入的路网数据(表名称可能不一样,在实际中请注意表名称统一)

   public.bj_ways_car

   public.bj_ways_car_vertices_pgr

   public.bj_pointsofinterest_car

   public.configuration

   public.osm_nodes

   public.osm_ways

   public.osm_relations

个人学习记录
原文地址:https://www.cnblogs.com/jeshy/p/15137330.html