I have a .shp file, where I want to connect all points (approx. 100) by lines. I have a data field with the order (i.e. 1, 2, 3, ...).

I have tried PointConnector and Points2One, maybe I am using them wrong, but I am not able to get any results.

In my searches, I've found mention of the plugin points to paths, but that seems to be gone?

I'm using QGIS 2.6.1

3 Answers 3


First, you can still use the PointsToPaths-Plugin (https://plugins.qgis.org/plugins/pointstopaths_v02/). Maybe you must enable the option "Show also experimental plugins" under Plugins > Manage and Install Plugins (Plugin Manager) > Settings.

Second, ensure that your data field with the order has a numeric-type (e.g. integer, ...)

I tried to create lines from a point shape with my QGIS-Version (2.0.1) and everything was fine. Here a screenshot:enter image description here

Maybe this helps!

Screenshot with the results of the test_coords shape: enter image description here

  • Thanks - now I at least found and installed the PointsToPaths, but no combination of Point group field and Point order field seems to generate any data, what fields are needed here?
    – Magnus
    Mar 4, 2015 at 9:43
  • For the "Point group field" you have two options: you can use an existing field or you can create a new field with the field calculator (string-type). In case you are creating a new field, you have to write a default-text in the column. If you leave it "NULL", you will get an error. For the "Point order field" you can use your "order field" with the serial numbers (1,2,3,...). Ensure, that this is a numeric field! Anyway, if you have still problems, post your shape file and I'll try it with your datat.
    – anja
    Mar 4, 2015 at 11:48
  • Thank you. I have tried using both text and integer fields for "Point group field", and integers for the "Point order field" combined with different values (and blank) of "Gap period" without succes. Attached is the .shp I have been testing with: drive.google.com/file/d/0B160CiiWCWKUbk9PbTF3dmpZYU0/…
    – Magnus
    Mar 4, 2015 at 12:25
  • I tested it with your shape file and I found the problem. The "Point order field" combines only the points with the same "text" in the group-field. I attached a screenshot with the results to the above answer.
    – anja
    Mar 5, 2015 at 9:59
  • Ah, so I need to add a field with the same text to every point?
    – Magnus
    Mar 5, 2015 at 13:29

The MMQGIS plugin has a menu entry Create -> Hub Lines. This should do what you want.

It needs two layers (start and destination), so you might have to add your point layer twice to the canvas.

  • Perfect, my smallscale test seems to work - I just need two different attributes, I've made a number and number+1 field, and use these as to and from.
    – Magnus
    Mar 4, 2015 at 9:25

A basic approach would be:

  1. create a vector-writer for a new shapefile (see Cookbook, Section "Writing Vector Layers", 2nd example) as (multi)line/polygon or whatever you need (see enums)
  2. load your point layer from iface.legendInterface().layers()
  3. iterate through your points and add the geometry feature in your new shape

€: just for fun:

from PyQt4.QtCore import *

# easy 2 config vars
myPath = "/media/ymirsson/MyData/GIS/tmp/"
myPts = "test_coords.shp"
myLines = "test_lines.shp"
sortField = "No"
myCRS = "25832"

# load the points layer
myPtsLayer = QgsVectorLayer(myPath + myPts, "My Points", "ogr")

# field def. 4 lines-layer
fields = QgsFields()
fields.append(QgsField("id", QVariant.Int))
fields.append(QgsField("name", QVariant.String))

# create writer
writer = QgsVectorFileWriter(myPath + myLines, "utf-8", fields, QGis.WKBLineString, QgsCoordinateReferenceSystem(int(myCRS), QgsCoordinateReferenceSystem.EpsgCrsId), "ESRI Shapefile")

if writer.hasError() == QgsVectorFileWriter.NoError:
    # featureobject to list
    features = myPtsLayer.getFeatures()
    for feature in features:
        geom = feature.geometry().asPoint()
        sortID = feature.attributes()[myPtsLayer.fieldNameIndex(sortField)]

    # create lines
    for i in range(1,len(Points)):
        Line = QgsFeature()
        Line.setGeometry(QgsGeometry.fromPolyline([Points[i-1][1], Points[i][1]]))
        Line.setAttributes([i,str(Points[i-1][0]) + " to " + str(Points[i][0])])
    # don't forget the last one -.-
    Line = QgsFeature()
    Line.setGeometry(QgsGeometry.fromPolyline([Points[len(Points)-1][1], Points[0][1]]))
    Line.setAttributes([len(Points),str(Points[len(Points)-1][0]) + " to " + str(Points[0][0])])

# flush 2 disk
del writer

# load both layers into qgis-project
QgsMapLayerRegistry.instance().addMapLayer(QgsVectorLayer(myPath + myLines, "My Lines", "ogr"))

print "Done .. "
  • Sorry - I'm not an advanced user and you lost me at step one. Could you either elaborate or suggest a simpler approach?
    – Magnus
    Mar 4, 2015 at 8:47
  • i see you got a simpler solution - but i wrote you a little script .. just4fun ;)
    – ymirsson
    Mar 5, 2015 at 20:52

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.