2

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

1

2 Answers 2

2

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)
2
  • Thank you. It somewhat works for me. The line direction is off but it might have to do with my fields. I added an example to the question. My CRS is in a metric projection.
    – brink
    Mar 10, 2022 at 22:45
  • I also have the x,y data in compass degrees.
    – brink
    Mar 10, 2022 at 23:20
2

Thank you MrXsquared! I poked around a bit more and I worked out a solution.

make_line($geometry,project($geometry,50,radians("Direction")))

"Direction" is azimuth in radians clockwise, where 0 corresponds to north

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.