3

I followed this suggestion to join points to nearest lines in QGIS. While most points get attached there are instances of points, often in close proximity to a line, that do not get connected (see figure).

Is this a numerical rounding issue?

unconnectedPoints

1

I think that this is not a numerical rounding issue, but it could be a problem with your point vector layer. I tried out Detlev script; as you can see at the next image (where point into green circle is only 8 mm from the line).

enter image description here

Details can be observed at the next image where I used the Zoom In tool. Segment was effectively produced with only 8 mm of separation (corroborated with Measure Line tool).

enter image description here

1

QgsPoint objects store coordinates as double precision values. Following several documents on Python and data types this allows for a precision of 17 significant digits (eg http://floating-point-gui.de/formats/fp/). I tested the (my) script with a series of points with decreasing distances from a line.

If you print out the distance, and the nearest point coordinate:

print min([l.geometry().closestSegmentWithContext(
    QgsPoint(p.geometry().asPoint())) for l in l_lyr.getFeatures()])

you see, that if the point and the nearest point on the line are equal up to the 17th digit, the length is reported as 0.0, and the nearest point on the line is considered to be equal to the point being evaluated.

  • I tested your script with vector layers projected in meters and degrees and it works nicely. I think that the problem could be his point vector layer. – xunilk Nov 8 '15 at 19:40
  • xunilk can you elaborate on "problem could be his point vector layer"? – Gavan McGrath Nov 11 '15 at 4:25

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.