@@ -41,15 +41,17 @@ function graph_from_object(osm_data_object::Union{XMLDocument,Dict};
41
41
graph_type:: Symbol = :static ,
42
42
precompute_dijkstra_states:: Bool = false ,
43
43
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}} ()
45
46
):: 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)
47
48
add_node_and_edge_mappings! (g)
48
49
add_weights! (g, weight_type)
49
50
add_graph! (g, graph_type)
50
51
# Finding connected components can only be done after LightGraph object has been constructed
51
52
largest_connected_component && trim_to_largest_connected_component! (g, g. graph, weight_type, graph_type) # Pass in graph to make type stable
52
53
add_node_tags! (g)
54
+ ! isempty (custom_tags) && add_custom_node_tags! (g, custom_tags)
53
55
! (network_type in [:bike , :walk ]) && add_indexed_restrictions! (g)
54
56
55
57
if precompute_dijkstra_states
@@ -95,7 +97,8 @@ function graph_from_file(file_path::String;
95
97
graph_type:: Symbol = :static ,
96
98
precompute_dijkstra_states:: Bool = false ,
97
99
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}} ()
99
102
):: OSMGraph
100
103
101
104
! isfile (file_path) && throw (ArgumentError (" File $file_path does not exist" ))
@@ -107,7 +110,8 @@ function graph_from_file(file_path::String;
107
110
graph_type= graph_type,
108
111
precompute_dijkstra_states= precompute_dijkstra_states,
109
112
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)
111
115
end
112
116
113
117
"""
@@ -264,6 +268,31 @@ function add_node_tags!(g::OSMGraph)
264
268
push! (g. node_coordinates, [data. location. lat, data. location. lon])
265
269
end
266
270
end
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
+
267
296
268
297
"""
269
298
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
292
321
end
293
322
end
294
323
324
+
325
+
295
326
"""
296
327
add_indexed_restrictions!(g::OSMGraph{U,T,W}) where {U <: DEFAULT_OSM_INDEX_TYPE, T <: DEFAULT_OSM_ID_TYPE, W <: Real}
297
328
0 commit comments