4

I'm looking for a way or tool in QGIS that could create a mean line between two line features, from a line shapefile (not a polygon). See sketch image below for clarification.

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Aurora
  • 143
  • 7
  • Alright updated for QGIS only – Aurora Dec 14 '22 at 08:30
  • 2
    In PostGIS, you could creata a central axis https://postgis.net/docs/ST_ApproximateMedialAxis.html or skeleton https://postgis.net/docs/ST_StraightSkeleton.html – Babel Dec 14 '22 at 08:36
  • 2
    Can you build polygons from your lines, then create a center line from that such as discussed here: https://gis.stackexchange.com/questions/423137/creating-centre-line-of-odd-shaped-polygon-in-qgis. If not I came across this which includes a method using Voroni tesseation that might work for you: https://www.reddit.com/r/gis/comments/siuaoo/how_to_get_a_line_through_middle_of_two_lines/ – John Dec 14 '22 at 15:40
  • @John, when I create a polygon it comes out very jagged and not suitable for my goal. Thank you for those other suggestions they look very interesting, I will definitely check them out!

    I managed to get a solution by creating a polygon by hand/editing a then with the Skeleton function similar Babel mentioned above. But there must be an easier solution out there..

    – Aurora Dec 15 '22 at 13:39
  • https://gis.stackexchange.com/questions/318721/creating-centerline-of-river-in-qgis – BERA Dec 16 '22 at 19:25
  • @BERA that one refers to https://gis.stackexchange.com/questions/33887/finding-centrelines-from-polygons-in-qgis – Liane Dec 19 '22 at 13:09

1 Answers1

7

Generic/algorithmic description

On one of the lines, create points in a regular interval. Connect these points to the closest point of the other line by creating a line. Get the centroid of these lines. Now connect the centroids to a line and you're done.

Implementation

Run the mentioned tools from Menu Processing > Toolbox:

  1. Select one of the lines and run Points along geometry and be sure to check the box Selected features only.

  2. On the created point layer, run Geometry by expression with this expression:

     centroid(
         make_line (
             $geometry, 
             closest_point (
                 overlay_nearest ('line', $geometry, limit:=2)[1],  -- replace `line` with the name of your line layer
                 $geometry
             )
         )
     )
    
  3. Run Points to path to connect the points from step 2.

Blue points: step 1; red points: step 2; red line: step 3: enter image description here

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Babel
  • 71,072
  • 14
  • 78
  • 208