Commit c039e298 authored by Henrik Grythe's avatar Henrik Grythe
Browse files

Bugfix simplification of complex road placement

parent 1dd8a530
This diff is collapsed.
......@@ -25,6 +25,7 @@ startkommune = extractfield(RLinks,'KOMMS');
endekommune = extractfield(RLinks,'KOMME');
midtkommune = extractfield(RLinks,'KOMM');
komVeg = nan(size(startkommune));
komVeg(startkommune == endekommune&(startkommune == midtkommune))=1;
komVeg(startkommune ~= endekommune) = 0;
......@@ -36,18 +37,84 @@ fprintf('Roads shared between municipalities %7i \n',length(find(komVeg==0)))
fprintf('Roads without municipality %7i \n',length(find(isnan(komVeg))))
fprintf('----------------------------------------\n')
Keep_RLinks = RLinks(find(komVeg));
t_RLinks = RLinks(komVeg==0);
Komms = extractfield(Ks,'KOMMUNENUM');
Fraction = zeros(size(t_RLinks));
% First deal with roads that are continouus.
for i=1:length(t_RLinks)
startkommune = extractfield(t_RLinks(i),'KOMMS');
endekommune = extractfield(t_RLinks(i),'KOMME');
midtkommune = extractfield(t_RLinks(i),'KOMM');
xs = extractfield(t_RLinks(i),'X');
individual(i) = length(find(isnan(xs)));
subsegments(i) = length(find(~isnan(xs)))-1;
end
idx = individual==1 & subsegments==1;
Straight_single_roads = find(idx);
Curvy_single_roads = find(individual==1 & ~idx);
Complex_roads = find(individual>1 & subsegments~=1);
fprintf('----------------------------------------\n')
fprintf('Straight_single_roads municipalities %7i \n',length(Straight_single_roads))
fprintf('Curvy_single_roads municipalities %7i \n',length(Curvy_single_roads))
fprintf('Complex_roads municipality %7i \n',length(Complex_roads))
fprintf('Unexplained roads municipality %7i \n',length(find(komVeg==0))-length(Complex_roads)-length(Curvy_single_roads)-length(Straight_single_roads) )
fprintf('----------------------------------------\n')
RDcomplexity(Straight_single_roads) = 1;
RDcomplexity(Curvy_single_roads) = 2;
RDcomplexity(Complex_roads) = 3;
% keep a backup ht = t_RLinks;
% trim some of the subnodes off the roads a bit so they are not too long,
% as the test can run out of memory.
for i = 1:length(t_RLinks)
if(RDcomplexity(i)==2 && subsegments(i)>500)
xs = extractfield(t_RLinks(i),'X');
ys = extractfield(t_RLinks(i),'Y');
lxy = length(xs);
startx = xs(1);
starty = ys(1);
stopx = xs(end-1);
stopy = ys(end-1);
while lxy > 450
segD(1) = sqrt((xs(1)-xs(2))^2 +(ys(1)-ys(2))^2);
for r = 2:length(xs)
segD(r) = sqrt((xs(r-1)-xs(r))^2 +(ys(r-1)-ys(r))^2);
end
idx = find(segD <= min(segD)+1e-0);
segD(idx) = NaN;
idx2 = ~isnan(segD);
xs = xs(idx2);
ys = ys(idx2);
lxy = length(xs);
clear segD
end
newx = [startx,xs,stopx,NaN];
newy = [starty,ys,stopy,NaN];
t_RLinks(i).X = newx;
t_RLinks(i).Y = newy;
end
end
fail = 1;
Fraction = zeros(size(t_RLinks));
for i=1:length(t_RLinks)
startkommune = extractfield(t_RLinks(i),'KOMMS');
endekommune = extractfield(t_RLinks(i),'KOMME');
midtkommune = extractfield(t_RLinks(i),'KOMM');
fprintf('%-4i',i)
fprintf('%-5i',i)
if ~isnan(startkommune)
pla = find(Komms == startkommune);
for p=1:length(pla)
......@@ -71,6 +138,7 @@ for i=1:length(t_RLinks)
fail = fail+1;
end
end
if rem(i,50)==0; fprintf('\n'); end
end
KeepT = struct2table(Keep_RLinks);
t_T = struct2table(t_RLinks);
......
......@@ -63,6 +63,8 @@ fprintf('Light=%4.1f%%\n',100*(mean(Scale.ToYearL)-1))
fprintf('Heavy=%4.1f%%\n',100*(mean(Scale.ToYearH)-1))
fprintf('Buses=%4.1f%%\n',100*(mean(Scale.ToYearB)-1))
% Tabelize Roads
Tlink = struct2table(RLinks);
......
%--------------------------------------------------------------------------
% This file is part of NERVE
%
%
% NERVE is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation version 3.
%
%
% NERVE is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
%
% You should have received a copy of the GNU General Public License
% along with NERVE. If not, see <https://www.gnu.org/licenses/>.
%--------------------------------------------------------------------------
......@@ -22,72 +22,69 @@ for s=1:length(S)
% This does not necessarily find all the intersection
in = inpolygon(S(s).X,S(s).Y,E.X,E.Y);
nn = sum(isnan(S(s).X));
DST(s) = S(s).DISTANCE;
if sum(in) == 0
% No vertices inside the domain: Road is outside and will be cut
DST(s) = S(s).DISTANCE;
if sum(in) == 0 % No vertices inside the domain: Road is outside and will be cut
fra = 0;
elseif sum(in) == length(S(s).X)-nn
% All vertices inside the domain Road is inside and will be used
elseif sum(in) == length(S(s).X)-nn % All vertices inside the domain Road is inside and will be used
fra = 1;
else % There are intersections, partly in domain. Calculate the part inside the domain.
else % There are intersections, partly in domain. Calculate the part inside the domain.
xt = S(s).X(in);
yt = S(s).Y(in);
% if i==23817; stop; end
% NEED A TEST FOR SIZE AS IT CAN EASILY RUN OUT OF MEMORY DOING
% THIS TEST
% This does not necessarily find all the intersection
% This test sometimes fail to find all the intersections
if length(S(s).X) < 500
[xi,yi] = polyxpoly(S(s).X,S(s).Y,E.X,E.Y);
else
if debug_mode
warning(sprintf('Straightened Road with %i subnodes',length(S(s).X)))
warning(sprintf('Straightened Road with %i subnodes',length(S(s).X)))
end
[xi,yi] = polyxpoly(S(s).X([1,end-1]),S(s).Y([1,end-1]),E.X,E.Y);
end
if ~isempty(xi)
if length(xi)==1
if length(xt)==1
if ~isempty(xi) % At least one intersection with the kommune border is found.
if length(xi)==1 % Exactly one intersection is found
if length(xt)==1 % Its only one point inside.
tx = [xt,xi,NaN];
ty = [yt,yi,NaN];
nd = sqrt((xt-xi)^2+(yt-yi)^2);
else
else % There are several points inside domain.
% find the nearesty point to the intersection
clear d1
for nx = 1:length(xt)
d1(nx) = sqrt((xi-xt(nx))^2 +(yi-yt(nx))^2);
end
itp = find(d1==min(d1));
itp = find(d1==min(d1));
% Replace the closest point inside municipality by the
% intersection point. For distance calculations.
xt(itp) = xi;
yt(itp) = yi;
yt(itp) = yi;
for nx = 1:length(xt)-1
d(nx) = sqrt((xt(nx)-xt(nx+1))^2 +(yt(nx)-yt(nx+1))^2);
end
tx = [xt,NaN];
ty = [yt,NaN];
for nx = 1:length(tx)-2
d(nx) = sqrt((tx(nx)-tx(nx+1))^2 +(ty(nx)-ty(nx+1))^2);
end
nd = sum(d); clear d
nd = nansum(d);
clear d
end
else
% multiple intersections:
% Straighten shit out!
% Find the maximum distance of intersections and link subnodes.
xst = [xi;xt'];
yst = [yi;yt'];
yst = [yi;yt'];
nd = sqrt((min(xst)-max(xst)).^2 +(min(yst)-max(yst)).^2);
end
else
warning('No intersection found for RL:\n')
nd = S(s).DISTANCE;
else % Did not find intersection cant deal with this right now
warning(sprintf('\nNo intersection found for RL: Border?\n'))
nd = (S(s).DISTANCE*1000);
end
fra = nd/(S(s).DISTANCE*1000);
if fra >1.01
fra = nd/(S(s).DISTANCE)
end
fra = nd/S(s).DISTANCE;
if fra >1.01
fra = nd/(S(s).DISTANCE*1000);
end
if debug_mode
fprintf('%04.4f / %04.4f (%04.1f%%) in StartGrid \n',DST(s)*fra,DST(s),fra*100)
fprintf('%04.4f / %04.4f (%04.1f%%) in StartGrid \n',DST(s)*fra,DST(s),fra*100)
end
clear xi yi tx ty xt yt
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment