3

I have two adjacent (ends meet to make one line) polylines in QGIS. I need to properly connect the two ends of the two sections. I've tried the obvious (and less obvious too) but QGIS won't forget that they started out as two lines.

On this occasion my overall aim is to create a GPX track using a set of currently unconnected lines with meeting ends (i.e. unconnected in the data, but end to end geometrically). I guess that QGIS needs to understand how each line is meant to connect together - after all it would still be a valid GPX track with one section of line in the track, followed by another random section, and then a third, and so on.

Typically the issue is that QGIS does just this - so that the GPX track isn't one continuous line (I get separate 'trkseg' sections of track).

To (try to) make one track line I have:

  • used a python script to reverse any lines drawn in the wrong direction so that they all point the same way;
  • run the Topology Checker plugin to look for 'dangling ends'; and with snapping turned on dragged the offending ends apart and then brought them back together.
  • used 'merge features' to make the two (or more) lines into one.

and then saved as a GPX track. I've done these things repeatedly and in differing orders and with more than one set of data. It rarely works.

What does work is having taken the above steps - to save the data as a MapInfo TAB file, load it in MapInfo, use MapInfo's 'combine' command, save, re-open in QGIS, save back into a SHP file... then create the GPX track (which often works).

My interpretation of this is that QGIS is never correctly combining the lines into one - even though the endpoints of the lines are correctly orientated (one in the same place as the other).

Am I missing something? Is there some hidden "permanently combine" feature which is stronger than "merge features"?

I've read (I think) that it might be possible to use GRASS to do this - but as I already have a solution using a different package I haven't pursued this. I was hoping for a simple solution.

  • Are the end points snapped? – Nathan W May 29 '14 at 13:01
  • Yes. Unless I'm missing something. I have snapping turned on for the layer, snap to vertex as the first option, 5 pixels set as the distance for snapping. I can see it working. I've used the node tool, and after I've had issues with a particular end-to-end join I've moved both end nodes apart from the join point (confirming that there aren't any additional hidden nodes messing things up) and put them back to the same location (watching that the second one snaps to the first). – Rostranimin May 29 '14 at 14:13
8

A little late, but still:

I think the easiest way is to use the Plugin Join Multiple Lines, either for connected or unconnected lines (as you see in the example below, in the latter case lines will be joined!)..

  1. Save gpx-segments to a shapefile
  2. Select segments & run plugin

enter image description here

  1. Check result and save back to gpx

enter image description here

Another approach would be to load the data to a SpatiaLite DB and then run the below query:

select 
  name as name,
  makeLine(t.ptgeom, 0) as geom 
from (
     select
        name as name,
        DissolvePoints(Collect(ST_Reverse(geometry)))  as ptgeom
     from segments group by name )
as t

This is a bit more sophisticated than the other approach - it will allow for a grouping variable, in this case the field 'name', by which the vertices are collected and connected as lines! As in the other approach, the vertices are connected in the order in which they were digitized and existing gaps are closed.

enter image description here

enter image description here

  • Thanks for the suggestion. I'll try this next time I run into a problem. I need to replicate the problem first. I had a go just now, but this set of data combined simply using 'merge' (despite lines being drawn in different directions). – Rostranimin Feb 6 '15 at 14:27

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.