In a QGIS3-project (QGIS Version 3.4.3) I'd like to display points from a textfile and constructed lines from this points in an given length and an angle from the textfile with the geometrygenerator. The CRS of the map is ETRS89 32N (EPSG:25832) and the coordinates from the textfile are WGS84 (EPSG:4326). "On-the-fly-transformation" is turned on. In the textfile there are the values "x", "y", "xangle".

To display the lines in the given direction, I used this code in the geometrygenerator:

make_line($geometry, make_point( $x + 0.002*cos(radians(90 - "xangle")), $y + 0.002*sin(radians(90 - "xangle")) ))

The problem is, that the resulting line differs in the angle from the same construction with points which are original in EPSG:25832 and therefore are in the same projection like the map. Here one screenshot (blue line = map crs 25832; red line = crs 4326) with 90°, which looks not to problematic: Test with 90°.

Here another one, with angle 152°, which is much more worse: Test with 152°.

The other thing is, that ETRS is metric, so I can define the length of the line in Meters and not (like above) in Degrees. I tested to work in the geometrygenerator with "make_point" direct from the columns of the textfile and "transform". But then there was no line generated.

Maybe someone has got a hint for me to solve this problem. First export the txt to shape with transformation to ETRS is not an option, because the idea is to read from the file in realtime, when something is changed.

1 Answer 1


The behavior is as expected.

You must calculate the location of the endpoint in ETRS and then transform it to WGS84. In addition, to calculate the coordinates of the end point in ETRS you must transform the coordinates of the initial point to that system.

For example, to draw lines of 250m with the azimuth corresponding to the attribute "xangle" (all this in ETRS89 32N system), in a layer of geometries in WGS 84 system:

            x( transform( $geometry, 'EPSG:4326', 'EPSG:25832')) + 250 * cos( radians( 90 - "xangle")),
            y( transform( $geometry, 'EPSG:4326', 'EPSG:25832')) + 250 * sin( radians( 90 - "xangle"))),
        'EPSG:25832', 'EPSG:4326')
  • Hello Gabriel, understand what you mean. Just tested your code and it works! That's the solution. Many thanks, Michael.
    – Michael
    Jan 10, 2019 at 21:56
  • @Michael, you are welcome! Jan 10, 2019 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.