QGIS – Specifying Line Length in Geometry Generator QGIS 3

geometry-generatorqgis

I'm working in Geometry Generator trying to produce a line from a point in an x,y direction with a specific length of 50m. I have the direction and line but I can't figure out how to specify the length.

make_line($geometry,make_point(x($geometry)+ "A-R-Xvalue",y($geometry)+ "A-R-Yvalue"))

Field example
enter image description here

Best Answer

Given a your layer is in a projected (metric) CRS, this should do it:

make_line($geometry,project($geometry,50,atan2("A-R-Yvalue","A-R-Xvalue")))

Since I dont know what your field contains you may need to adjust the content of atan2(). It expects atan2(dy: y coordinate difference,dx: x coordinate difference). In pseudocode:

deltaX = x2 - x1
deltaY = y2 - y1
radians = atan2(deltaY, deltaX)
projectedpoint = project(startpoint,distance,radians)
line = make_line(startpoint,projectedpoint)
Related Question