@@ -45,6 +45,9 @@ function path_to_endpoint(g::AbstractGraph, (ep, ep_succ)::Tuple{T,T}) where {T<
4545 return path
4646end
4747
48+ function total_weight (g:: OSMGraph , path:: Vector{<:Integer} )
49+ sum ((g. weights[path[[i, i+ 1 ]]. .. ] for i in 1 : length (path)- 1 ))
50+ end
4851"""
4952Build a new graph which simplifies the topology of osmg.graph.
5053The resulting graph only contains intersections and dead ends from the original graph.
@@ -79,17 +82,17 @@ function simplify_graph(osmg::OSMGraph)
7982 for path in paths_to_reduce (g)
8083 u = index_mapping[first (path)]
8184 v = index_mapping[last (path)]
82- edge_weight = sum (( osmg. weights[i, i + 1 ] for i in 1 : length ( path) - 1 ) )
85+ path_weight = total_weight ( osmg, path)
8386 geo = createlinestring (osmg. node_coordinates[path])
8487
8588 if add_edge! (G_simplified, (u, v))
8689 key = 0
87- weights[u, v] = edge_weight
90+ weights[u, v] = path_weight
8891 else # parallel edge
8992 key = sum ((edge_gdf. u .== u) .& (edge_gdf. v .== v))
90- weights[u, v] = min (edge_weight , weights[u, v])
93+ weights[u, v] = min (path_weight , weights[u, v])
9194 end
92- push! (edge_gdf, (u, v, key, edge_weight , geo))
95+ push! (edge_gdf, (u, v, key, path_weight , geo))
9396 end
9497
9598 return G_simplified, weights, node_gdf, edge_gdf
0 commit comments