其他分享
首页 > 其他分享> > Get A Transportation Network From OSMFile

Get A Transportation Network From OSMFile

作者:互联网

# Obtain a transportation network from an osm file.
# get  osm file 方式1:OpenStreetMap Homepage
# .osm.pbf下载地址 方式2:http://download.openstreetmap.fr/extracts/asia/china/
# get  osm file 方式3:Geofabrik  https://download.geofabrik.de/
# get  osm file 方式4: BBBike(可支持多边形范围) https://extract.bbbike.org/

import osm2gmns as og
import osm2gmns.settings as defaultsettings
# pip install -i http://mirrors.aliyun.com/pypi/simple/ osm2gmns --trusted-host mirrors.aliyun.com

# FromOSMFile
# net = og.getNetFromOSMFile(r'D:/DataWorkspace/data/beijing.osm',
#                       network_type=('auto',), link_type='all',
#                       POIs=False, POI_sampling_ratio=1.0,
#                       strict_mode=True,
#                       offset='no',
#                       min_nodes=1,
#                       combine=False,
#                       int_buffer=defaultsettings.default_int_buffer,
#                       bbox=None,
#                       default_lanes=False,
#                       default_speed=False)

# FromPBFFile
net = og.getNetFromPBFFile(r'D:/DataWorkspace/data/beijing.osm.pbf',
                           network_type=('auto',), link_type='all',
                           POIs=False, POI_sampling_ratio=1.0,
                           strict_mode=True,
                           offset='no',
                           min_nodes=1,
                           combine=False,
                           int_buffer=defaultsettings.default_int_buffer,
                           bbox=None,
                           default_lanes=False,
                           default_speed=False)
# Recommend using getNetFromPBFFile() for large networks
# net = og.getNetFromPBFFile('***.osm.pbf')

default_lanes_dict = {'motorway': 4, 'trunk': 3, 'primary': 3, 'secondary': 2, 'tertiary': 2,
                      'residential': 1, 'service': 1, 'cycleway':1, 'footway':1, 'track':1,
                      'unclassified': 1, 'connector': 2}
default_speed_dict = {'motorway': 59, 'trunk': 39, 'primary': 39, 'secondary': 39, 'tertiary': 29,
                      'residential': 29, 'service': 29, 'cycleway':9, 'footway':4, 'track':29,
                      'unclassified': 29, 'connector':59}

# 保存成CSV Output Networks to CSV
og.outputNetToCSV(net, output_folder='netcsv', projection=False, enconding=None)

# 合并交叉路口 Consolidate Intersections
og.consolidateComplexIntersections(net)
og.outputNetToCSV(net, output_folder='netcsv_csd', projection=False, enconding=None)

# # 也可以先保存成csv,然后人工编辑,最后再合并
# net = og.getNetFromPBFFile(r'D:/DataWorkspace/data/beijing.osm.pbf')
# og.outputNetToCSV(net, output_folder='', projection=False, enconding=None)
# # check the main_node_id column in node.csv
# net = og.getNetFromCSV(folder='', enconding=None)
# og.consolidateComplexIntersections(net)
# og.outputNetToCSV(net, output_folder='consolidated', projection=False, enconding=None)

# # 连接POI
# # Network with POIs
# net = og.getNetFromPBFFile(r'D:/DataWorkspace/data/beijing.osm.pbf',
#                            network_type=('auto',), link_type='all',
#                            POIs=True, POI_sampling_ratio=1.0,
#                            strict_mode=True,
#                            offset='no',
#                            min_nodes=1,
#                            combine=False,
#                            int_buffer=defaultsettings.default_int_buffer,
#                            bbox=None,
#                            default_lanes=False,
#                            default_speed=False)
# # Connect POIs with network
# og.connectPOIWithNet(net)

# Visualization
# You can visualize generated networks using NeXTA or QGis.
# NeXTA:https://github.com/xzhou99/NeXTA-GMNS

  

标签:None,False,Network,OSMFile,og,default,osm,Transportation,net
来源: https://www.cnblogs.com/jeshy/p/14853969.html