[GIS] Creating points projected on line using QGIS

draw-interactionpoints-to-lineqgisvector-layer

How can we create points perpendicularly on a line with QGis ?

Otherwise, how can we draw a line between one point and a line ?

Here is a picture to show what we want :

enter image description here

Best Answer

If you only need to show these lines/points, you can do this with a geometry generator marker style. This is a fairly new feature in QGIS, and it makes it easy to do things that would have needed a database before. I did this in QGIS 2.18

I assume you have a line layer called "ligne", with a unique id field. I called this "unid", and set to 1

then use the following formula on your points layer in the geometry generator. Make sure you set the output type to be "linestring". If it's not, nothing will appear.

shortest_line($geometry, geometry(get_feature('ligne','unid',1)))

Here's an example. I've using a normal dot symbol and a generator on the points layer

enter image description here

To show the points projected onto the line, add another geometry generator marker, this time make it a POINT

closest_point( geometry(get_feature('ligne','unid',1)), $geometry)

enter image description here

This is not guaranteed to be perpendicular to the line, for example:-

  • if the point is near a vertex.
  • if the point is far from the line

If a point is quite close to the line, the shortest line is likely to be perpendicular.