Page 1 of 1

Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Thu Jun 14, 2018 9:58 am
by 16582679
Hi Support

I have a series of Latitude and Longitude values that I wish to plot with a connecting line between the points. The points are recorded GPS data and all have a correct sequence order of data events. They were recorded from a GPS equipped vehicle traveling a known path and are in chronological order.

If I use a TPoint Series, the points are shown in the correct expected locations on the graph.
LatLongPointsPlotOK.jpg
When plotted with individual points, the presentation is as expected.
LatLongPointsPlotOK.jpg (67.03 KiB) Viewed 18022 times
If I use the same data with a TLineSeries or TFastLine Series, the tracking line incorrectly connects to other points, giving an obscure and inaccurate plot.
LatLongLinePlotFail.jpg
Same data but using TFastLine series, incorrect path.
LatLongLinePlotFail.jpg (70.71 KiB) Viewed 18014 times
There must presumably be a setting that allows the LineSeries to correctly interconnect the adjacent points instead of the erratic lines drawing that occurs.
Typical sample data is shown below

Hopefully someone can advise of my error.
Thanks and regards
Trevor
DataPointsSample.jpg
Data points used sample
DataPointsSample.jpg (92.16 KiB) Viewed 18012 times

Re: Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Fri Jun 15, 2018 10:49 am
by yeray
Hello,

This probably happens because the values are x-sorted by default. You can disable this with:

Code: Select all

Series1.XValues.Order:=loNone;

Re: Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Sat Jun 16, 2018 1:39 pm
by 16582679
Yeray wrote:Hello,

This probably happens because the values are x-sorted by default. You can disable this with:

Code: Select all

Series1.XValues.Order:=loNone;
Thanks Yeeray, that's a minor improvement, but the start/end points lines are still being incorrectly connected. The graphic below shows the real vehicle path (green arrows). The graph has shown that, and also taken a shortcut, joining the start and end of the route with straight lines.

I tried also Series.YValues.Order:=loNone; but that did not make a difference

Re: Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Mon Jun 18, 2018 7:05 am
by yeray
Hello,

I've done a simple example trying to reproduce the problem here, but it seems to work fine for me.
Project3_2018-06-18_09-04-40.png
Project3_2018-06-18_09-04-40.png (38.26 KiB) Viewed 17984 times

Code: Select all

uses Series;

const
  xPoints: array[0..6] of double =
  (
    145.114, 145.113, 145.109, 145.115,
    145.124, 145.123, 145.122
  );
  yPoints: array[0..6] of double =
  (
    -37.847, -37.850, -37.850, -37.817,
    -37.818, -37.82, -37.82
  );

procedure TForm1.FormCreate(Sender: TObject);

  procedure GoAndBack;
  var i: Integer;
  begin
    for i:=0 to Length(xPoints)-1 do
      Chart1[0].AddXY(xPoints[i]+random*0.001-0.0005, yPoints[i]+random*0.001-0.0005);

    for i:=Length(xPoints)-1 downto 0 do
      Chart1[0].AddXY(xPoints[i]+random*0.001-0.0005, yPoints[i]+random*0.001-0.0005);
  end;

var i: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Legend.LegendStyle:=lsSeries;

  Chart1.Axes.Bottom.SetMinMax(145.101, 145.131);
  Chart1.Axes.Bottom.LabelsAngle:=90;
  with Chart1.AddSeries(TFastLineSeries) as TFastLineSeries do
  begin
    Title:='A';
    XValues.Order:=loNone;

    for i:=0 to 4 do
      GoAndBack;
  end;
end;
Could you please modify the above or arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.

Re: Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Tue Jun 19, 2018 2:00 pm
by 16582679
Thank you Yeeray for your valuable support, it is appreciated.
I may have located the cause, but I don't yet know how to resolve.

I have found that the vehicle records when it goes 'online' and travels from A(north) to B(south). It then goes 'offline' while it tracks back to point A again, goes online, and then starts recording the track from A to B again. Sometimes it is two-way data and other times it is one-way only.
2018-06-20_00-05-04.jpg
Path A to B
2018-06-20_00-05-04.jpg (67.64 KiB) Viewed 17973 times
The unintended line was drawn when point A was the next available point after the previous last point B

I thought I might resolve this by only plotting if the distance between the two points is less than a 'threshold' value.

I can calculate the great circle distance between the two adjacent points, and if it is greater than a threshold, I want to avoid drawing that 'track' on the graph.

I tried just bypassing the call if the distance was greater than 300 metres:

Code: Select all

          ThisPt.X := BusRec.Long;
          ThisPt.Y := BusRec.Lat;
          if (LastPt.X = 0.0) and (LastPt.Y = 0) then LastPt := ThisPt; {first time through}
          Dist := GetDistanceBetweenTwoLocations(ThisPt, LastPt, False);
          if (Dist < 300) then {Less than 300 metres traveled since last location was recorded? Plot it}
            begin
            TBtwnLineSeries[TBtwnLineSeriesCount].AddXY(BusRec.Long, BusRec.Lat);
            end
          LastPt := ThisPt   {update for next time}

However, even though the distance was much greater than 300 meters, the line still was drawn (presumably) on the following point from the array.

I also tried using Series.AddNull, unsuccessfully.

How can avoid drawing the line if the distance from B to A is greater than a specific value?

Many thanks for your kind assistance

Re: Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Tue Jun 19, 2018 11:10 pm
by 16582679
Hi Team
I have created a program that reproduces my issue.
It needs the csv data file to be copied to the same location as the exe.
Click on a point on the grid to draw the chart to that point. The problem occurs at row 148.
2018-06-20_09-03-42.jpg
Sample Program that produces tracking issue
2018-06-20_09-03-42.jpg (172.56 KiB) Viewed 17969 times

Code: Select all

procedure TForm5.Button1Click(Sender: TObject);
var
i : Integer;
begin
if not (FileExists('TrackPath.csv')) then exit;
ResultsSG.Clear;
Series1.Clear;
Chart1.Axes.Bottom.SetMinMax(145.101, 145.131);
Chart1.Axes.Bottom.LabelsAngle:=90;
Chart1.View3D:=False;
Chart1.Legend.LegendStyle:=lsSeries;
Series1.XValues.Order:=loNone;
ResultsSG.LoadFromCSV('TrackPath.csv');
for i := 1 to ResultsSG.RowCount-1 do
    Series1.AddXY( ResultsSG.Floats[3, i], ResultsSG.Floats[2, i]);
end;

procedure TForm5.ResultsSGClickCell(Sender: TObject; ARow, ACol: Integer);
var
i : Integer;
Lt, Ln : Real;
begin
{temporarily replot the graph from index 1 to current position to see where the faulty trace line occurs.}
if assigned(Series1) then Series1.Clear;
for i := 1 to ARow do
  begin
  Lt := ResultsSG.Floats[2, i];
  Ln := ResultsSG.Floats[3, i];
  Series1.AddXY(Ln, Lt);
  end;
end;
If I can determine how to avoid plotting those points where the distance is excessive, this would allow me to solve my problem.

I have uploaded a sample program that reproduces my issue (ChartTrackingIssueWithSrc.zip).

Many thanks.

Re: Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Wed Jun 20, 2018 6:53 am
by yeray
Hello,

The null points should do the trick for you. If you are using a TFastLineSeries, try changing it to a TLineSeries to see if it makes any difference.

If you still find problems with it, please try to arrange a simple example we can run as-is to reproduce the problem here.

Re: Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Wed Jun 20, 2018 12:13 pm
by 16582679
Thank you

Both changing from FastLineSeries to LineSeries, and adding the null worked.

Code: Select all

  
Dist := GetDistanceBetweenTwoLocations(ThisPt, LastPt, False);
  if (Dist < 500) then 
    Series1.AddXY(ThisPt.X, ThisPt.Y)
    else
    Series1.AddNull;
Your assistance is greatly appreciated

Re: Plotting Lat/Long data as LineSeries gives incorrect display

Posted: Thu Jun 21, 2018 6:25 am
by yeray
Great! I'm glad to hear it works fine now.