Calculate terrain XY coordinates from mouse click on TChart
Posted: Fri Jan 05, 2007 8:54 pm
I have written a mapping application uses a Tchart where I have plotted several series of data that represent ground points and Aerial camera XY stations. On this graph, I would like to be able to click anywhere on the screen and then get the real world XY ground (terrain) coordinates of where the mouse was when the user clicked the screen. I did a search in the forum and found suggested code which I modified as follows:
procedure TfrmGraphBackend.Chart1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Terrain_X, Terrain_Y : double;
msg : string;
begin
If (AeroMatchUsed) then
begin
if (AutoCorrelate) then
begin
If (Button = mbRight) then
begin
Terrain_X := chart1.Axes.Bottom.CalcXPosValue(X);
Terrain_Y := chart1.Axes.Left.CalcYPosValue(Y);
msg := Format('Clicked at: X = %14.3f (meters), Y = %14.3f (meters)',
[Terrain_X,Terrain_Y]);
ShowMessage( msg );
end;
end;
end;
end;
Unfortunately, this does not compute the correct XY coordinates. When a I click on a known camera station symbol that is displayed in an existing plotted series, I get the following (incorrect) coordinates:
X = -197492 Y = 1328142
Where the true coordinates should be (approximately) :
X = 628810 Y = 4761040
Is it possible to make a call to one of Tcharts native methods to compute the correct coordinates?
Another possibility is to compute a coordinate transformation using a simple 2-dimensional conformal coordinate transformation. For a given chart, the user would have to click on 2 diagonally opposition known points to compute a transformation from the Chart1 axis coordinate to the real world system, but would this change if the user changed the zoom setting on the chart?
Thanks in advance,
Matt
procedure TfrmGraphBackend.Chart1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Terrain_X, Terrain_Y : double;
msg : string;
begin
If (AeroMatchUsed) then
begin
if (AutoCorrelate) then
begin
If (Button = mbRight) then
begin
Terrain_X := chart1.Axes.Bottom.CalcXPosValue(X);
Terrain_Y := chart1.Axes.Left.CalcYPosValue(Y);
msg := Format('Clicked at: X = %14.3f (meters), Y = %14.3f (meters)',
[Terrain_X,Terrain_Y]);
ShowMessage( msg );
end;
end;
end;
end;
Unfortunately, this does not compute the correct XY coordinates. When a I click on a known camera station symbol that is displayed in an existing plotted series, I get the following (incorrect) coordinates:
X = -197492 Y = 1328142
Where the true coordinates should be (approximately) :
X = 628810 Y = 4761040
Is it possible to make a call to one of Tcharts native methods to compute the correct coordinates?
Another possibility is to compute a coordinate transformation using a simple 2-dimensional conformal coordinate transformation. For a given chart, the user would have to click on 2 diagonally opposition known points to compute a transformation from the Chart1 axis coordinate to the real world system, but would this change if the user changed the zoom setting on the chart?
Thanks in advance,
Matt