I am having a weird interpolation error with large gps track given as CZML

Working Part:

https://gist.github.com/s093294/6d9a8c80b029c327f863

Not Working Part.

https://gist.github.com/s093294/1dbd43af008fa64d67e4

Pressed the button to fast. Rest of the post coming in a sec

The two pictures below shows the issue. The right picture shows the first czml file where the position is correct. Its the first 530 gps points of the track. THe car drives up to the end of the (in paint drawn red line) and return down the same path.

When adding the last part of the gps track in the left picture, then the last part of the track is correct, its returning at the end and driving down the same path. But notice how the start of the gps track just became a long line totally off.

Guessing its doign some wrong interpolation. Is there some known limits to the size of gps points in a czml source or ?

I forgot to mention that the car actually moves on the correct path, but only the path is drawn wrong.

Heres content for copy paste into sandcaste: https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=CZML.html&label=Showcases

https://gist.githubusercontent.com/s093294/55986524856facabd2cf/raw/e1c8b635e43d322f1f9b3bb33f47eb3bf97c6aaa/sandcastle.js

I have identified that if I remove all entries after time 527.9374476000012 then the path is drawn correctly up to 527.9374476000012.

Hers the snippet around 527.93744

525.9373249000018,

12.3344337266101,

55.6608497623009,

0,

526.9653905000014,

12.3344487081422,

55.6608500551438,

0,

527.9374476000012,

12.3344503526775,

55.6608503617742,

0,

528.9545126000012,

12.3344503526775,

55.6608503617742,

0,

529.9725714999986,

12.3344503526775,

55.6608503617742,

0,

530.940634999999,

12.3344503526775,

55.6608503617742,

0,

I have found the problem.

In the gps sequence, there can not be a sequence of identical coordinates with different time code. This can happen in the real world for a car that is not moving.

I removed those in my backend, but think that it is something we would want to check for when adding samples in cesium instead.

public class SampledProperty

{

public List Times = new List();

public List Coords = new List();

public void AddSample(JulianDate date, Cartographic coord)

{

if(Coords.Any())

{

var last = Coords.Last();

if (last.Latitude == coord.Latitude && last.Longitude == coord.Longitude && last.Height == coord.Height)

return;

}

Times.Add(date);

Coords.Add(coord);

//var index = Times.BinarySearch(date.ToUniversalTime().Ticks);

}

}

Can you try putting the duplicates back but also removing the two lines below everywhere they occur in your CZML?

“interpolationAlgorithm”: “LAGRANGE”,

“interpolationDegree”: 5

My assumption is that everything is working as intended but you probably don’t want to use Lagrange interpolation with a car (or anything that stops and starts for that matter). Removing these settings will have it default to linear interpolation; which is what you probably want in this case.

Thanks.

I am still learning cesium. Can you elaborate a little on why one would not use Lagrange or similar interpolations. I was hoping that it could fit curves nicely when cars are driving in soft curves instead of doing linear interpolation between each point.

No worries, everyone has to start somewhere. To be honest; I was being a little lazy in my reply because linear interpolation is the easiest way to address your issue. That being said, you are correct in that you can smooth things out using Lagrange and there is a way to do this in Cesium and CZML. It involves breaking up your positional data into multiple intervals to prevent the looping behavior that you’re seeing.

Assuming you have an interval similar to the following (this is completely made up but should get the point across).

“position”: {

“interpolationAlgorithm”: “LAGRANGE”,

“interpolationDegree”: 5,

“epoch”: “2014-09-01T00:00:00Z”,

“cartographicDegrees”: [

0, 0, 0, 0,

1, 0, 1, 0,

2, 1, 1, 0,

3, 2, 1, 0,

4, 2, 1, 0,

5, 2, 2, 0,

6, 2, 1, 0,

7, 1, 1, 0,

8, 0, 1, 0,

9, 0, 0, 0]

}

Since time 3 and 4 have the same position, you’ll see the unexpected behavior that you have already encountered. What you want to do is break this up into 3 distinct intervals of time: movement 1, stopped, movement 2. Here’s what that looks like in the updated CZML.

“position”: [

{

“interval”: “2014-09-01T00:00:00Z/2014-09-01T00:00:03Z”

“interpolationAlgorithm”: “LAGRANGE”,

“interpolationDegree”: 5,

“epoch”: “2014-09-01T00:00:00Z”,

“cartographicDegrees”: [

0, 0, 0, 0,

1, 0, 1, 0,

2, 1, 1, 0,

3, 2, 1, 0]

},

{

“interval”: “2014-09-01T00:00:03Z/2014-09-01T00:00:04Z”

“cartographicDegrees”: [2, 1, 0]

},

{

“interval”: “2014-09-01T00:00:04Z/2014-09-01T00:00:09Z”

“interpolationAlgorithm”: “LAGRANGE”,

“interpolationDegree”: 5,

“epoch”: “2014-09-01T00:00:00Z”,

“cartographicDegrees”: [

4, 2, 1, 0,

5, 2, 2, 0,

6, 2, 1, 0,

7, 1, 1, 0,

8, 0, 1, 0,

9, 0, 0, 0]

}

]

Notice the use of the “interval” property, Cesium will only interpolate data within the interval it’s defined. So splitting it up like this will cause the vehicle to come to a stop, wait there, and then start again. Data before the stop can’t be used to interpolate the start of the movement after the stop.

Of course in order to do this, it means you need to detect the duplicate times on your end and create the additional intervals. This isn’t something we can do automatically on the client because we don’t know what the intent of the user is.

Hopefully this all makes sense to you. I want to do a blog post/writeup on the different interpolation options and what each means and when you would use it; but we don’t have anything like that yet. (and to be honest, this isn’t my area of expertise and I need to do some research myself).

Let me know if you are still having issues.

Thanks,

Matt

No problem.

I already solved my issues before by removing these gps dublicates from the czml response at our backend. But its always nice to understand things and not just apply a fix without understanding why.

We have some really huge logs, so I am in the process of breaking it up into packages (still reading abouy that in the czml guide), and doing stop events could be a feature here too :slight_smile:

Thanks for explaning.

I just tested your approach on my example data. It didnt work.

I found out why also and applying it on your example it should have been the following instead:

“position”: [

{

“interval”: “2014-09-01T00:00:00Z/2014-09-01T00:00:03Z”

“interpolationAlgorithm”: “LAGRANGE”,

“interpolationDegree”: 5,

“epoch”: “2014-09-01T00:00:00Z”,

“cartographicDegrees”: [

0, 0, 0, 0,

1, 0, 1, 0,

2, 1, 1, 0]

},

{

“interval”: “2014-09-01T00:00:03Z/2014-09-01T00:00:04Z”

“cartographicDegrees”: [2, 1, 0]

},

{

“interval”: “2014-09-01T00:00:04Z/2014-09-01T00:00:09Z”

“interpolationAlgorithm”: “LAGRANGE”,

“interpolationDegree”: 5,

“epoch”: “2014-09-01T00:00:00Z”,

“cartographicDegrees”: [

5, 2, 2, 0,

6, 2, 1, 0,

7, 1, 1, 0,

8, 0, 1, 0,

9, 0, 0, 0]

}

]

where the dublicate coordinate needs to be removed so its only present once in the constant part.