%%% Script to add the survey grid to the plotted survey

hold on;

%%% Reference line (app at the position of the fence)
Refline=[69133 447456 ; 67973 446152]; %NE to SW

% angle reference line wrt N (Clockwise positive)
% 
% volgens mij gaat dit fout !!! (sierd)
% is dit niet East met counter clockwise positief ???

angle_refline=-180 + atand( (Refline(2,2)-Refline(1,2)) / (Refline(2,1)-Refline(1,1)) );

plot(Refline(:,1), Refline(:,2),'--k')


%%% Beach poles (position of the green fencepoles/Jarkus beachpoles)

Bpoles=[69133 447456 ; 
        69087 447402 ;
        69031 447339 ;
        68976 447277 ;
        68925 447221 ;
        68870 447159 ;
        68815 447096 ;
        68764 447040 ;
        68705 446972 ;
        68645 446907 ;
        68585 446838 ;
        68525 446771 ;
        68448 446684 ;
        68408 446639 ;
        68355 446579 ;
        68300 446517 ;
        68252 446463 ;
        68202 446407 ;
        68150 446349 ;
        68093 446285 ;
        68032 446218 ;
        67973 446152]; %NE to SW

plot(Bpoles(:,1), Bpoles(:,2),'or')

%%% calculate alongshore beach pole coordinate
%%% origin at SW beach pole

for n = 1:22    
norm_vec(n) = norm(Bpoles(n,:)-Bpoles(22,:));
end

%%% Add survey lines jetski
% dan is dit haaks op de reference line
angle_surveyline= angle_refline-90;
for j=1:length(Bpoles)
    Surveylines{j,1}.lineno=j;
    Surveylines{j,1}.beachpole_position=Bpoles(j,:);
    Surveylines{j,1}.angle_surveyline=angle_surveyline;
    Surveylines{j,1}.along_shore = norm_vec(j);
    Surveylines{j,1}.cross_shore = [-300:5:1500];
    Surveylines{j,1}.xi=Bpoles(j,1)+ Surveylines{j,1}.cross_shore*cosd(angle_surveyline);
    Surveylines{j,1}.yi=Bpoles(j,2)+ Surveylines{j,1}.cross_shore*sind(angle_surveyline);
    
end

for j=1:length(Bpoles)
plot(Surveylines{j,1}.xi,Surveylines{j,1}.yi,'k')
text(Surveylines{j,1}.xi(1),Surveylines{j,1}.yi(1)+10,num2str(Surveylines{j,1}.lineno))
end


%%% Add dune vegetation limits

vegLim = [  68731   446645 ;
            68779   446710 ;
            68835   446826 ;
            68853   446860 ;
            68891   446914 ;
            68952   446999 ;
            68994   447052 ;
            69060   447131 ;
            69102   447181 ;
            69143   447238 ;          
            69184   447294 ;
            69245   447367
            ];
        
plot(vegLim(:,1),vegLim(:,2),'g')
                
            
            

%%% Don't forget to save the surveylines.mat file if you changed it and you're sure it's better ;) 


% hold off;
