| SN=tgeocode(TX,TY,FX1,FY1,FX2,FY2,FX3,FY3,SN,stammname,stammpfad)
|
function SN=tgeocode(TX,TY,FX1,FY1,FX2,FY2,FX3,FY3,SN,stammname,stammpfad)
% function SN=tgeocode(TX,TY,FX1,FY1,FX2,FY2,FX3,FY3,SN,stammname,stammpfad)
%
% Geocoding with on Screen Digitizing using affine and projective Transformation
% - Digitizing the New Points, Transformation of the der New Points
%
% 19.02.03 Markus Penzkofer
global HFG
global HE_TRAFO
global HA_NN HA_SN
global STATUS
% Control of the Status
if (STATUS < 1)
disp('Please load data first!');
set(HFG,'Name','MATLAB DIGITIZER: Please load data first!');
return;
end
if (STATUS < 2)
disp('Please digitize Control Points first!');
set(HFG,'Name','MATLAB DIGITIZER: Please digitize Control Points first!');
return;
end
if (STATUS < 3)
disp('Please compute Transformation Parameters first!');
set(HFG,'Name','MATLAB DIGITIZER: Please compute Transformation Parameters first!');
return;
end
% File: New Points
neuname = [stammname '_new.mdg'];
% File: transformed New Points
ntrname = [stammname '_ntr.mdg'];
% Digitizing: New Points
disp('Digitize New Points and end with Return Button!');
set(HFG,'Name','MATLAB DIGITIZER: Digitize New Points and end with Return Button!');
figure(HFG);
[xnd,ynd] = ginput;
set(gca,'Layer','top')
hold on
plot(xnd,ynd,'co');
% Save: digitized New Points
eval(['cd ' stammpfad]);
if (STATUS == 3)
[neufid,mess] = fopen(neuname,'w');
elseif (STATUS == 4)
[neufid,mess] = fopen(neuname,'a');
fprintf(neufid,'NaN NaN\n');
end
if (neufid == -1)
disp([' ! File ' stammpfad neuname ' cannot be opened.']);
error(mess);
end
disp([' < Output File ' stammpfad neuname ' opened.']);
for i=1:length(xnd)
fprintf(neufid,'%f %f\n', xnd(i), ynd(i));
end
% Number of New Points
NN = length(xnd);
% Initialization
YN = zeros(1,NN);
XN = zeros(1,NN);
YNZ = zeros(1,NN);
XNZ = zeros(1,NN);
% Transformation Type
trafo = get(HE_TRAFO,'Value');
if (trafo == 1)
% AFFINE TRANSFORMATION: Transformation of the New Points
XO = TX;
YO = TY;
DX = FX1;
CX = FY1;
CY = FX2;
DY = FY2;
for S = 1:NN
YN(S) = ynd(S);
XN(S) = xnd(S);
YNZ(S) = YO + CY * XN(S) + DY * YN(S);
XNZ(S) = XO + DX * XN(S) + CX * YN(S);
end
else
% PROJECTIVE TRANSFORMATION: Transformation of the New Points
c1 = TX;
c2 = TY;
a1 = FX1;
b1 = FY1;
a2 = FX2;
b2 = FY2;
a3 = FX3;
b3 = FY3;
for S = 1:NN
YN(S) = ynd(S);
XN(S) = xnd(S);
YNZ(S) = (a2 * XN(S) + b2 * YN(S) + c2)/(a3 * XN(S) + b3 * YN(S) + 1);
XNZ(S) = (a1 * XN(S) + b1 * YN(S) + c1)/(a3 * XN(S) + b3 * YN(S) + 1);
end
end
xnt = XNZ;
ynt = YNZ;
% Save: transformed the New Points
eval(['cd ' stammpfad]);
if (STATUS == 3)
[ntrfid,mess] = fopen(ntrname,'w');
elseif (STATUS == 4)
[ntrfid,mess] = fopen(ntrname,'a');
fprintf(ntrfid,'NaN NaN\n');
end
if (ntrfid == -1)
disp([' ! File ' stammpfad ntrname ' cannot be opened.']);
error(mess);
end
disp([' < Output File ' stammpfad ntrname ' opened.']);
for i=1:length(xnt)
fprintf(ntrfid,'%f %f\n', xnt(i), ynt(i));
end
fclose('all');
SN = SN + NN;
set(HA_NN,'String',num2str(NN));
set(HA_SN,'String',num2str(SN));
disp('New Points transformed und saved!');
set(HFG,'Name','MATLAB DIGITIZER: New Points transformed und saved!');
% Status
STATUS = 4;
|
|