# How can I smooth LineString coordinates with 1D Gaussian Filter?

I'm trying to smooth a LineString through 1D Gaussian Smoothing and I'm having a doubt on the steps required to implement it, regardless of programming language. I couldn't find by myself anything explaining how to do it.

The linestring is a vector of coordinates, each having longitude and latitude. I'm supposed to use a 1D Gaussian Smoothing method, so that means I have to pass 2 times on the coordinates. I'm not very used to this kind of subject, so I'm a bit confused on how to apply this method.

If anyone had any experience doing this, I'd like to receive documentation or articles on the subject.

(Analogy) I'm trying to do what the least squares method does to XY coordinates. We feed it with the coordinates and calculate using some degree (linear, quadratic, etc.), then we'd get the best fitting polynomial. But in my case, I have to smooth both axis (longitude and latitude) using the 1D Gaussian filter.

## 1 Answer

I have implemented such algorithm in Java using JTS. Here is the source code: https://github.com/jgaffuri/OpenCarto/blob/gh-pages/src/main/java/org/opencarto/algo/line/GaussianLineSmoothing.java

The main steps are the following:

1. Densify the input line with additional vertices along each segment.
2. Prepare gaussian coefficients.
3. Compute the position of the smoothed geometry as the average of the neighbor points, weighted by the gaussian coefficients (that is the trickiest part).
4. Filter (with Douglas-Peucker) the final line to remove unnecessary vertices.

See below how it looks like: The black line shows the input line and red lines show smoothed versions with increasing smoothing parameter.

Note that closed lines are handled.

• I should push it to JTS maybe. Sep 17, 2019 at 12:43