# Calculating angle using three WGS 84 points

I am looking for a way to calculate an angle between two points at a specific third point. My coordinate system is WGS 84. I can measure the angle with QGIS clicken on those three points, but I want to calculate it to ensure that I have the correct coordinates plus I have more than 8000 angles to calculate. Therefore, I am looking for a way to calculate it. I cannot figure it out.

• Welcome to GIS:SE @Maike! Perhaps this post might help: How to calculate correct angles for lat/lon points with the QGIS API?. – Joseph Feb 3 '16 at 10:47
• Thanks Joseph. I have seen this post before but do not get it. I am new with QGIS and not familiar with programming. As far as I understand the source code, they only use two points. Is that correct? I want to use three points. More accurately: I have a triangle with city A, B, C. I want to figure out the angle at B where the cathetus AB and BC meet. Is there maybe a source code that shows how QGIS calculates when measuring the angle through the tool? – Maike Feb 3 '16 at 11:12
• Yes, that was for 2 points. I think this post contains the source code for the Measure angle tool. This is something I haven't looked so hopefully others can advise =) – Joseph Feb 3 '16 at 11:27
• I hope so, too, that others can advise =) – Maike Feb 3 '16 at 13:13

QGIS >= 2.18

New function (after this question was posted) azimuth() has become available, and made this calculation easier.

If we have two point layers, one of which is your samples layer and the other is the specific third point. In the example below they correspond to:

• TargetPoints_4326:sample points. Only unique id (id) field is required. I have only three (id= 1,2,3) pink-colored points in this example.
• ObsPoints_4326: your observation points to measure the angle. I have three overlapping points (green color). This layer has to have "EPSG_code" field to define the CRS you want to work, along with "Start" and "End" fields as pointers to the id field of the sample points layer. Then open the attribute table of your observation points layer (e.g. ObsPoints_4326) and create a new field ("angle") with following expression:

degrees(
azimuth(transform($geometry,'EPSG:4326',"EPSG_code"), transform(geometry(get_feature('TargetPoints_4326', 'id', "Start")), 'EPSG:4326',"EPSG_code")) -azimuth(transform($geometry,'EPSG:4326',"EPSG_code"),
transform(geometry(get_feature('TargetPoints_4326', 'id', "End")),
'EPSG:4326',"EPSG_code")))


Output ("angle") field is measured anti-clockwise (e.g. first row on the attached picture shows angle= 27.185). If you want clockwise- measurement, please edit the above expression to switch "Start" and "End".

Note) This example used Lambert Conformal Conic (EPSG:3034) which will be good if your points are spread across large area in Europe. If your study area is local, UTM would do.