2

I have a point and line shapefile.

I am new to QGIS and Python, but have been able to get a working method to snap some of the points to the line. The method I am using is "closestSegmentWithContext", which works where the points are further from the line, but when the points are close (i.e. less than 5-10 meter) it returns a sqrt distance(?) of 0.0, and cannot find the closest point on the line. See for example the below outputs:

Var1:  (4.4249768536154936e-08, <QgsPointXY: POINT(27.9118715303157181 -26.09893318956183705)>, 35, 1)
Var2:  (0.0, <QgsPointXY: POINT(27.94594999999999985 -26.09562199999999876)>, 65, -1)

With Var1 I am able to snap the point onto the line, but the Var2, the point cannot be snapped onto the line and returns the coordinate of the point.

I am using EPSG:4326 - WSG 84, and I am assuming that the projection is in degrees, although I have set the distance to be in meters in the project settings.

Is there anything that I need to add to my code to get the points to snap onto the line.

  • Can you post more of your code? E.g. the linestring you are trying to snap to? – ndawson Jan 4 '19 at 21:51

Your Answer

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

Browse other questions tagged or ask your own question.