这是从象素点到经纬度的转换函数。
注意:pixel_x[],pixel_y[],attitude_x[],attitude_y[]
保存的是已之的象素坐标,经纬度坐标。由下标对应。
function pixel2attitude(const pixel:tfloatpoint;var Error:boolean):Tfloatpoint;
var
p:Tfloatpoint;
i:integer;
s1,s2,t1,t2:double;
begin
if (pixel.X < pixel_x[0]) or (pixel.X > pixel_x[7]) or
(pixel.y < pixel_y[0]) or (pixel.y > pixel_y[9]) then
begin
// showmessage('非法的象素坐标值!');
p.x :=0;
p.Y :=0;
result := p;
exit;
end;
//if
for i:=1 to 7do
begin
if pixel.X = pixel_x then
begin
p.X := attitude_x;
break;
end
else
if (pixel.X > pixel_x[i-1]) and (pixel.X < pixel_x) then
begin
s1 :=(attitude_x[i-1] - trunc(attitude_x[i-1])) * 100 + trunc(attitude_x[i-1])*60;
s2 :=(attitude_x - trunc(attitude_x)) * 100 + trunc(attitude_x)*60;
t1 :=(pixel.x - pixel_x[i-1]) * (s2-s1) / (pixel_x - pixel_x[i-1]);
//从前一经度占经度多少分
t2 := t1 + s1;
// 占经度多少分
p.x := trunc(t2/60) + (t2 - (trunc(t2/60) * 60))/100;
p.x := trunc(p.x*100) /100;
break;
end;
//if
end;
//for
for i:=1 to 9do
begin
if pixel.y = pixel_y then
begin
p.y := attitude_y;
break;
end
else
if (pixel.y > pixel_y[i-1]) and (pixel.y < pixel_y) then
begin
s1 :=(attitude_y[i-1] - trunc(attitude_y[i-1])) * 100 + trunc(attitude_y[i-1])*60;
s2 :=(attitude_y - trunc(attitude_y)) * 100 + trunc(attitude_y)*60;
t1 :=(pixel_y - pixel.y ) * (s1-s2) / (pixel_y - pixel_y[i-1]);
//从前一经度占经度多少分
t2 := round(t1 + s2);
// 占纬度多少分
p.y := trunc(t2/60) + (t2 - (trunc(t2/60) * 60))/100;
p.y := trunc(p.y*100) /100;
break;
end;
//if
end;
//for
result := p;
end;
//f