testAddMetricDistanceToEdges.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:policosm 作者: ComplexCity 项目源码 文件源码
def addMetricDistanceToEdges(graph, epsgCode):
    # we assume initial epsg is wsg84 (merctor projection)
    metricDistance = {}

    if epsgCode != 4326:
        sourceProjection = osr.SpatialReference()
        sourceProjection.ImportFromEPSG(4326)
        destinationProjection = osr.SpatialReference()
        destinationProjection.ImportFromEPSG(epsgCode) # https://epsg.io/2154
        coordTrans = osr.CoordinateTransformation(sourceProjection, destinationProjection)

    for edge in graph.edges():
        node1, node2 =  edge
        line = ogr.Geometry(ogr.wkbLineString)
        line.AddPoint(graph.node[node1]['longitude'], graph.node[node1]['latitude'])
        line.AddPoint(graph.node[node2]['longitude'], graph.node[node2]['latitude'])
        if epsgCode != 4326:
            line.Transform(coordTrans)
        length = line.Length()
        metricDistance[edge] = length
    nx.set_edge_attributes(graph, 'length', metricDistance)

    return graph
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号