how to perform spline interpolation on GPS coordinations?

151 Views Asked by At

this may look like a programming problem but actually it have to do with math more than programming.

I have GPS coordinations in a csv file that I predict it using a regression model, just two columns with longitudes and latitudes that represent a race track. Now I want to plot it on Google maps to see how it looks like.

When I do that, I noticed that the curve is not smooth which make sense since I predicted those value with my regression model and they are not taking directly from a GPS.

I made a search on how to solve this problem and I find out that usually a spline interpolation is used for this, but I have no idea how to use it. All the examples that I found in the internet assume that we have the x which are the data and y which is the function, in my case there is no function, I just give the data to the model and it predict those values that's it. so if I have longitudes and latitudes, is it possible to make some sort of interpolation so that the curve would look smooth if I plot it?

Example:

let's say those are my data

latitudes = array([58.846563, 58.846573, 58.846586, 58.846601, 58.846618, 58.846637,
                   58.846658, 58.846681, 58.846705, 58.846731])

longitudes = array([9.903741, 9.903733, 9.903724, 9.903713, 9.9037  , 9.903686,
                    9.90367 , 9.903652, 9.903633, 9.903612])

and when I plot this data it give me some sort of a plot where each point is connected to the other point with a straight line but what I want is to smooth it up. Is this possible to do only if I have longitudes and latitudes as variables and nothing more? I'd appreciate any help

Edit:

I'm sorry that I can't upload my plot for confidential purposes but here is a plot Example, the blue one is how it should be(how I want it to be) and the black one is my result for now which I want to smooth it to be like the blue one

enter image description here

1

There are 1 best solutions below

0
On

To better see the numbers I am playing with (I am almoast blind), I started muliplying all of them by $10^6$ and took the differences with respect to the first point. This does not change anything to the problem.

This means that the data I worked with are $$\left( \begin{array}{cc} x & y \\ 0 & 0 \\ 10 & -8 \\ 23 & -17 \\ 38 & -28 \\ 55 & -41 \\ 74 & -55 \\ 95 & -71 \\ 118 & -89 \\ 142 & -108 \\ 168 & -129 \end{array} \right)$$

The parameter used for the cubic splines is the cumulated distance from the origin (in my former research group, we selected on purpose this parameter for applications similar to your - interpolation along $S$-shape curves).

Here are the results of the interpolations (to which you would add the base points given above). $$\left( \begin{array}{cc} 0.00000 & 0.00000 \\ 3.30174 & -2.73105 \\ 6.64637 & -5.42804 \\ 10.0768 & -8.05692 \\ 13.6189 & -10.5972 \\ 17.2354 & -13.0787 \\ 20.8739 & -15.5435 \\ 24.4830 & -18.0327 \\ 28.0375 & -20.5663 \\ 31.5460 & -23.1371 \\ 35.0188 & -25.7367 \\ 38.4665 & -28.3561 \\ 41.8991 & -30.9873 \\ 45.3254 & -33.6232 \\ 48.7544 & -36.2570 \\ 52.1947 & -38.8818 \\ 55.6550 & -41.4909 \\ 59.1393 & -44.0812 \\ 62.6405 & -46.6582 \\ 66.1500 & -49.2287 \\ 69.6592 & -51.7996 \\ 73.1595 & -54.3775 \\ 76.6430 & -56.9685 \\ 80.1086 & -59.5737 \\ 83.5587 & -62.1911 \\ 86.9954 & -64.8189 \\ 90.4209 & -67.4553 \\ 93.8377 & -70.0984 \\ 97.2479 & -72.7466 \\ 100.653 & -75.3987 \\ 104.053 & -78.0544 \\ 107.449 & -80.7130 \\ 110.842 & -83.3740 \\ 114.232 & -86.0371 \\ 117.621 & -88.7016 \\ 121.008 & -91.3672 \\ 124.393 & -94.0342 \\ 127.775 & -96.7032 \\ 131.154 & -99.3748 \\ 134.529 & -102.049 \\ 137.899 & -104.728 \\ 141.263 & -107.411 \\ 144.620 & -110.098 \\ 147.971 & -112.790 \\ 151.317 & -115.486 \\ 154.659 & -118.185 \\ 157.997 & -120.886 \\ 161.333 & -123.590 \\ 164.667 & -126.295 \\ 168.000 & -129.000 \end{array} \right)$$

For sure, we could generate as many points as desired.

I must underline that, even if unnecessary, our producure iterates on the distances (these are updated from the previous splines).