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
testAddMetricDistanceToEdges.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录