# Create "mean" line from multiple lines using QGIS

I have multiple lines features (also have them in multipoints...) representing similar path (mountain trails, in this case) with various GPS precision, resulting in many lines close to each other, but not perfectly overlapping.

For the purpose of this project, I'm looking for a way to calculate a "mean" line from all of them and generate a resulting line of the most probable position of the trail.

How would you proceed, using QGIS or any other tool (I thought of OGR...)?

• Take a look at Average tracks on the OpenStreetMap wiki, which describes a method using R.
– Jake
Nov 27, 2014 at 21:59
• This sounds a similar to "conflation" and on this site there's been a few threads about it: gis.stackexchange.com/search?q=conflation do any of the questions and answers there get you closer? Nov 28, 2014 at 2:37
• I'll take a look at "conflation" today, but so far, the "Average tracks" proposed earlier seems to do the trick. I'm simply looking a bit more to see if it can be done directly through QGIS, but both your answers are great, thanks! Nov 28, 2014 at 19:22
– John
Feb 12, 2018 at 14:15

Test Data:

• QGIS 2.18.16, GRASS GIS 7
• 4 GPS Tracks
• within a grid of 1x1km

I.)

Create points along your GPS Tracks with the QGIS Plugin `Locate Points Along Lines` (https://plugins.qgis.org/plugins/LocatePoints/). I've used an interval of 5m in my exmaple.

II.)

Create a `Concave Hull` with `Processing > Toolbox > QGIS geoalgorithms >Vector geometry tools > Concave hull`. I used a threshold of `0.1` in my example. If the threshold is to low, there could be holes within the output polygon.

III.)

Now, you can calculate the "mean" line with the help of the skeleton algorithm. Search for skeleton in the `Processing Toolbox`. Use `v.voronoi.skeleton` tool from the `GRASS GIS 7 commands`.

The heat map approach:

The approach is more time consuming, due to the calculating time of the processing steps. It could be seen as an idea maybe to get closer to a more general solution.

Test Data:

• QGIS 2.18.16, GRASS GIS 7
• 4 GPS Tracks
• within a grid of 1x1km

I.)

Create points along your GPS Tracks with the QGIS Plugin Locate Points Along Lines (https://plugins.qgis.org/plugins/LocatePoints/). For the heat map approach I've used an interval of 2m.

II.)

Create a heat map with the QGIS heat map plugin. I've used a radius of 40m. I increase the radius until there are no holes in the output raster. You have to try this with different radius values.

III.)

EDITED There is no need to hold the exact heat map raster value.

Now I want to thin out the raster to the "white" areas, where the most points are concentrated. Therefor I recalculate the output raster. The min/max values of the output raster is `0` and `89.7935`. I only use values above `44`. Therefor I used a "rule of thumb". Round down the max value and divide it by two. Round down this value another time. `89/2 = 44,5` --> `44`. I've used the OSGeo4W Shell: `gdal_calc -A heatmap.tif --calc="A>=44" --NoDataValue=0 --outfile=heatmap_44_NoData.tif`.

IV.)

EDITED

a) Polygonize the recalculated heat map with `Raster > Conversion > Polygonize ...`

b) Simplify the polygon `Vector > Geometry Tools > Simplify geometries`. I've used a tolerance of `2`. A simpler polygon reduces the processing time for the skeletons.

c) Calculate skeletons: search for skeleton in the Processing Toolbox. Use `v.voronoi.skeleton` tool from the GRASS GIS 7 commands.

You can see that the resulting line represents more the most probable position of the trail than in my first answer. Especially for the bend in the North the mean line follows the three tracks which are more close to each other. The same for the bend in the East.

• reasonable good results exclusively using QGIS

• I understand. Thank you for your response. The Heat Map Plugin in QGIS provides some advanced options, where you can `use weight from field`. Can information like velocity (traverse slow/quick) or others to be used to weight the data in some way? The weighting could be used to improve the heat map. Feb 16, 2018 at 6:40