[GIS] Calculating angle using three WGS 84 points

anglespointqgiswgs84

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's "Measure Angle" tool 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. How can I do this?

Best Answer

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.

enter image description here

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.