In QGIS I wanted to move points to the nearest lines. I checked the solutions here, but there are using tools which I am not familiar to yet (PostGIS or GRASS GIS). I figured out my own way with using QGIS but it is giving me weird results.

My problem is that moved points are not exactly on the lines, there is 0.0000 length line beetwen them.

Working process: I connected the lines with points using v.net.connect, then I extracted only the lines beetween points and orignal lines layer (let's call them join). I created start and ending points on the join layer using small python code:

from qgis.core import * 
import qgis.utils

layers = iface.legendInterface().layers()

points = []

for i in layers[2].getFeatures():
    geom = i.geometry()
    a = geom.asPolyline()

vl = QgsVectorLayer("Point", "beg_end", "memory") 
pr = vl.dataProvider()


for i in range(len(points)-1):
    fet = QgsFeature()
    fet2 = QgsFeature()



In the end I saved the end points of the join which are supposed to lie on my line layer (and they look like they are there). But if I use connect tool from networks plugin it turns out that it is creating 0.0000 length line between moved points and original lines to join them.

Why the points are not on the lines and what is the reason of this small differences? Is it possible to snap them to the lines and how?

  • It is not mathematically possible for some point values to lie exactly on some line segments using binary computers. Research into floating-point representation will explain why this is the case.
    – Vince
    Commented Jun 3, 2016 at 10:46

2 Answers 2


Because of precision limitations, as stated in a commen, it might be impossible to make a point be exactly on top of a line segment. On the other hand, if that is mandatory ( for network analysis for example) you may want to do the opposite, create a new vertex for your line in the exact place on the point. That. Should work.


@sweet.sugar.cola answered to her own question

I solved my problem, trying different approach suggested in answers (creating new vertex on a line, as it is not possible to create point directly on the line).

I use "connect" tool from Networks plugin. It join the point with closest line, as well as split the line into two parts. Then I create points at the end and beggining of the connection (using the python code above). Finally I save points which lie on original lines layer as a moved ones. Seems to work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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