-
Notifications
You must be signed in to change notification settings - Fork 46
/
plot_nodes.m
60 lines (52 loc) · 1.58 KB
/
plot_nodes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function [] = plot_nodes(ax, parsed_osm, only_node_indices, show_id)
% plot (selected) nodes and label each with index and id
%
% usage
% PLOT_NODES(ax, parsed_osm, only_node_indices, show_id)
%
% input
% ax = axes object handle where to plot the nodes.
% parsed_osm = MATLAB structure containing the OpenStreetMap XML data
% after parsing, as returned by function
% parse_openstreetmap.
% only_node_indices = selected node indices in the global node matrix.
% show_id = select whether to show or not the ID numbers of nodes as text
% labes within the plot
% = 0 (do not show labels) | 1 (show labels)
%
% 2012.04.24 (c) Ioannis Filippidis, [email protected]
%
% See also PARSE_OPENSTREETMAP, ROUTE_PLANNER.
% do not show node id (default)
if nargin < 4
show_id = 0;
end
nodes = parsed_osm.node;
node_ids = nodes.id;
node_xys = nodes.xy;
% which nodes to plot ?
n = size(node_xys, 2);
if nargin < 3
only_node_indices = 1:n;
end
%% plot
held = takehold(ax);
% nodes selected exist ?
if n < max(only_node_indices)
warning('only_node_indices contains node indices which are too large.')
return
end
% plot nodes
xy = node_xys(:, only_node_indices);
plotmd(ax, xy, 'yo')
% label plots
for i=only_node_indices
node_id_txt = num2str(node_ids(1, i) );
if show_id
curtxt = {['index=', num2str(i) ], ['id=', node_id_txt] }.';
else
curtxt = ['index=', num2str(i) ];
end
textmd(node_xys(:, i), curtxt, 'Parent', ax)
end
restorehold(ax, held)