@@ -41,15 +41,17 @@ function graph_from_object(osm_data_object::Union{XMLDocument,Dict};
4141 graph_type:: Symbol = :static ,
4242 precompute_dijkstra_states:: Bool = false ,
4343 largest_connected_component:: Bool = true ,
44- filter_network_type:: Bool = true
44+ filter_network_type:: Bool = true ,
45+ custom_tags:: Dict{String, Vector{String}} = Dict {String, Vector{String}} ()
4546 ):: OSMGraph
46- g = init_graph_from_object (osm_data_object, network_type, filter_network_type= filter_network_type)
47+ g = init_graph_from_object (osm_data_object, network_type, custom_tags, filter_network_type= filter_network_type)
4748 add_node_and_edge_mappings! (g)
4849 add_weights! (g, weight_type)
4950 add_graph! (g, graph_type)
5051 # Finding connected components can only be done after LightGraph object has been constructed
5152 largest_connected_component && trim_to_largest_connected_component! (g, g. graph, weight_type, graph_type) # Pass in graph to make type stable
5253 add_node_tags! (g)
54+ ! isempty (custom_tags) && add_custom_node_tags! (g, custom_tags)
5355 ! (network_type in [:bike , :walk ]) && add_indexed_restrictions! (g)
5456
5557 if precompute_dijkstra_states
@@ -95,7 +97,8 @@ function graph_from_file(file_path::String;
9597 graph_type:: Symbol = :static ,
9698 precompute_dijkstra_states:: Bool = false ,
9799 largest_connected_component:: Bool = true ,
98- filter_network_type:: Bool = true
100+ filter_network_type:: Bool = true ,
101+ custom_tags:: Dict{String, Vector{String}} = Dict {String, Vector{String}} ()
99102 ):: OSMGraph
100103
101104 ! isfile (file_path) && throw (ArgumentError (" File $file_path does not exist" ))
@@ -107,7 +110,8 @@ function graph_from_file(file_path::String;
107110 graph_type= graph_type,
108111 precompute_dijkstra_states= precompute_dijkstra_states,
109112 largest_connected_component= largest_connected_component,
110- filter_network_type= filter_network_type)
113+ filter_network_type= filter_network_type,
114+ custom_tags= custom_tags)
111115end
112116
113117"""
@@ -264,6 +268,31 @@ function add_node_tags!(g::OSMGraph)
264268 push! (g. node_coordinates, [data. location. lat, data. location. lon])
265269 end
266270end
271+ """
272+ add_custom_node_tags!(g::OSMGraphcustom_tags::Dict{String, Vector} = Dict{String, String}())
273+
274+ Based on the provided dictionary of custom tags adds them to the node
275+ """
276+ function add_custom_node_tags! (g:: OSMGraph , custom_tags)
277+ for (id, data) in g. nodes
278+ custom_tags_dict = Dict {String, Any} ()
279+ ways = g. node_to_way[id]
280+ for way_id in ways
281+ way = g. ways[way_id]
282+ for (key, value) in pairs (custom_tags)
283+ ! haskey (way. tags[" custom_tags" ], key) && continue
284+ ! haskey (custom_tags_dict, key) && (custom_tags_dict[key] = Dict ())
285+ for v in value
286+ ! haskey (way. tags[" custom_tags" ][key], v) && continue
287+ ! haskey (custom_tags_dict[key], v) && (custom_tags_dict[key][v] = [])
288+ push! (custom_tags_dict[key][v], way. tags[" custom_tags" ][key][v])
289+ end
290+ end
291+ end
292+ g. nodes[id]. tags[" custom_tags" ] = custom_tags_dict
293+ end
294+ end
295+
267296
268297"""
269298 adjacent_node(g::OSMGraph, node::T, way::T)::Union{T,Vector{<:T}} where T <: DEFAULT_OSM_ID_TYPE
@@ -292,6 +321,8 @@ function adjacent_node(g::OSMGraph, node::T, way::T)::Union{T,Vector{<:T}} where
292321 end
293322end
294323
324+
325+
295326"""
296327 add_indexed_restrictions!(g::OSMGraph{U,T,W}) where {U <: DEFAULT_OSM_INDEX_TYPE, T <: DEFAULT_OSM_ID_TYPE, W <: Real}
297328
0 commit comments