-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathJunctionSegments.m
146 lines (131 loc) · 3.55 KB
/
JunctionSegments.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function JunctionSegments(S,IX,junctions)
% Usage:
% JunctionSegments(S,IX,junctions);
%
% Description:
% Function to create a shapefile(s) showing the segments up and downstream
% of the confluence used to measure the junction angle. Will produce
% one shapefile for each fit distance you provided when running JunctionAngle
%
% Required Inputs:
% S - STREAMobj
% IX - IX cell array output from Junction Angle
% junctions - junctions table output from JunctionAngle, if you provided multiple
% fit_distances to JunctionAngle, the output 'links' will be a cell
% array of similar dimensions as the input 'junctions'.
%
% Examples:
% JunctionSegments(S,IX,junctions);
%
% Related Functions:
% JunctionAngle, JunctionLinks, InspectJunction
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function Written by Adam M. Forte - Created : 10/02/20 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parse Inputs
p = inputParser;
p.FunctionName = 'JunctionSegments';
addRequired(p,'S',@(x) isa(x,'STREAMobj'));
addRequired(p,'IX',@(x) iscell(x));
addRequired(p,'junctions',@(x) istable(x) | iscell(x));
parse(p,S,IX,junctions);
S=p.Results.S;
IX=p.Results.IX;
JIN=p.Results.junctions;
if istable(JIN)
J=JIN;
ms=struct;
% Thin the junction table and IX table removing any non-viable junctions
ja=J.junction_angle;
idx=~isnan(ja);
J=J(idx,:);
IX=IX(idx,:);
w1=waitbar(0,'Building shapefile');
% Start loop
num_juncs=size(J,1);
ind=1;
for ii=1:num_juncs
ds=IX{ii,2};
us1=IX{ii,3};
us2=IX{ii,4};
ms(ind,1).Geometry='PolyLine';
ms(ind,1).X=S.x(us1);
ms(ind,1).Y=S.y(us1);
ms(ind,1).Confl_ID=J.junction_number(ii);
ms(ind,1).Part='upstream_1';
ind=ind+1;
ms(ind,1).Geometry='PolyLine';
ms(ind,1).X=S.x(us2);
ms(ind,1).Y=S.y(us2);
ms(ind,1).Confl_ID=J.junction_number(ii);
ms(ind,1).Part='upstream_2';
ind=ind+1;
ms(ind,1).Geometry='PolyLine';
ms(ind,1).X=S.x(ds);
ms(ind,1).Y=S.y(ds);
ms(ind,1).Confl_ID=J.junction_number(ii);
ms(ind,1).Part='downstream';
ind=ind+1;
waitbar(ii/num_juncs);
end
close(w1);
shapewrite(ms,'junction_segments.shp');
else
num_lengths=size(JIN,2);
for jj=1:num_lengths
% Grab junction table
J=JIN{2,jj};
fit_distance=JIN{1,jj};
ms=struct;
% Thin the junction table and IX table removing any non-viable junctions
ja=J.junction_angle;
idx=~isnan(ja);
J=J(idx,:);
IXN=IX(idx,:);
w1=waitbar(0,['Building shapefile ' num2str(jj) ' of ' num2str(num_lengths)]);
% Start loop
num_juncs=size(J,1);
ind=1;
for ii=1:num_juncs
ds=IXN{ii,2};
us1=IXN{ii,3};
us2=IXN{ii,4};
% Thin out based on distances
n=floor(fit_distance/hypot(S.cellsize,S.cellsize));
if n<1
n=1;
end
if n<numel(ds)
ds=ds(1:n);
end
if n<numel(us1)
us1=us1(1:n);
end
if n<numel(us2)
us2=us2(1:n);
end
ms(ind,1).Geometry='PolyLine';
ms(ind,1).X=S.x(us1);
ms(ind,1).Y=S.y(us1);
ms(ind,1).Confl_ID=J.junction_number(ii);
ms(ind,1).Part='upstream_1';
ind=ind+1;
ms(ind,1).Geometry='PolyLine';
ms(ind,1).X=S.x(us2);
ms(ind,1).Y=S.y(us2);
ms(ind,1).Confl_ID=J.junction_number(ii);
ms(ind,1).Part='upstream_2';
ind=ind+1;
ms(ind,1).Geometry='PolyLine';
ms(ind,1).X=S.x(ds);
ms(ind,1).Y=S.y(ds);
ms(ind,1).Confl_ID=J.junction_number(ii);
ms(ind,1).Part='downstream';
ind=ind+1;
waitbar(ii/num_juncs);
end
close(w1);
shapewrite(ms,['junction_segments_' num2str(jj) '.shp']);
end
end