In QGIS, I have two lines. The endpoints are near each other, but not quite aligned. I'd like to turn the two lines into one, with the two endpoints merged into midpoints.

The closest I've been able to come is with "Merge selected features." That gives me one feature, but it's comprised of two disjoint lines -- there's no line between the endpoints.

I'm looking for something that behaves similarly to Illustrator's Join Paths feature (Object > Paths > Join). Does QGIS do that?


Quick answer: no! There's no tool like that to do that operation directly on the layer (the "Join Two Lines" plugin requires intersection).

You could do it for a very simple layer by turning the lines to points (extract nodes) then joining with points2one (line output) but this would be MUCH slower than just editing by hand:

  1. Make sure you have snapping (Settings|Snapping options ...) turned on for your line layer (5 pixels works well for me).
  2. Create a new line from one endpoint to the other.
  3. Select all three lines (the two original lines + the new one) and merge them (Edit|Merge selected features or toolbar button).
  • 1
    Thanks. I only had a few lines to merge, so this was quick & easy. (@Michael Markieta's answer seemed better suited to complex situations.) – Evan Jan 24 '12 at 19:44

You can accomplish this with a combination of QGIS and GRASS.

  1. Import your vector layer into a GRASS mapset ( Grass | File > Import Vector Data )
  2. Open your mapset in QGIS ( QGIS | Plugins > GRASS > Open mapset )
  3. Add vector layer from your GRASS mapset to your QGIS project ( QGIS | Plugins > GRASS > Add GRASS vector layer )
  4. Use v.clean.snap ( QGIS | Plugins > GRASS > Open GRASS tools > Modules List > v.clean.snap )

Adjust the v.clean.snap 'threshold' to attain proper vertex snapping throughout study area.


I assume you are wanting to join two line segments into one line. enter image description here

This is how I did it ...

  • Enable editing.
  • Turn on snapping ( Settings -> Snapping Options ... ) enter image description here
  • Select the node node tool.enter image description here
  • Double click close to the end of one of the lines to add a node. enter image description here
  • Drag the node at the end to snap onto the the end of the other line enter image description here
  • Select both lines
  • Merge their attributes ( you cannot make therm one line if they have differing attributes)enter image description here
  • Merge the two featuresenter image description here

This should result in one line. enter image description here

  • All fine. But how about a dataset of 22,000 lines? I cannot go about doing this manually... – FaCoffee Jan 17 '17 at 9:50

If you mean that your single feature consists out of a MULTILINESTRING instead of a single LINESTRING then you can easily fix that if you are using a Postgis database:

update your_table set your_geo_column = ST_LineMerge(your_geo_column);

If you only want the 1 row to do this you should add WHERE id = your_row_id of course.


There is this QGIS plugin which says it does exactly what you want.

https://plugins.qgis.org/plugins/joinmultiplelines/ https://github.com/dgoedkoop/joinmultiplelines

(However, I was not able to use it correctly in QGIS 2.6)


Also someone could try:

  1. save .shp as .dxf
  2. open .dxf with DraftSight
  3. join polyline parts
  4. reopen .dxf with qgis and save as .shp
  5. from Vector menu -> Geometry tools -> Lines to polygons

Using OpenJUMP (Plus edition):

  1. File > Open file
  2. Plugins > Topology > Network topology cleaning ...
  3. Right click on the new layer (fixed): Save dataset as ....

This is the result: enter image description here


In my case the lines were in different layers and with different attributes. I merged the layers with mmqgis and then merged the lines in the next step with the technique of snapping and merging lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.