6

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?

4
  • 2
    Welcome to GIS:SE @Maike! Perhaps this post might help: How to calculate correct angles for lat/lon points with the QGIS API?.
    – Joseph
    Commented Feb 3, 2016 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
    Commented Feb 3, 2016 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
    Commented Feb 3, 2016 at 11:27
  • I hope so, too, that others can advise =)
    – Maike
    Commented Feb 3, 2016 at 13:13

2 Answers 2

2

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.

1

Despite the @Kazuhito's answer that solves the OP's problem, here is my workflow that also includes the calculation of distance in meters between one point and other two points.

Use case

I have a CSV file with the coordinates of three points in the EPSG:4326 coordinate system. Point 2 is my reference coordinate. I want to find the distance between point 2 and points 1 and 3. I also want to find the angle between the line from points 3 to 2, and the line from point 1 to 2:

post workflow image

Workflow

  1. Insert new text delimited layer from CSV file
  2. Convert CSV layer to shapefile
  3. Use 'Reproject layer' tool in Processing Toolbox to reproject to a suitable Projected Coordinate System
  4. Duplicate the reprojected layer twice. In 1 copy, keep only point 2 in the Attribute table, and delete the rest. In the other copy, keep only points 1 and 3.
  5. Use the 'Distance to nearest hub (line to hub)' tool in the Processing toolbox. Set source points later to the reprojected points 1 and 3 layer, and target hub layer to reprojected point 2 layer. This should create a new Hub distance layer.
  6. In the Attribute table of your Hub distance layer, toggle on the edit mode, and open the Field Calculator, inputting the following Field calculator
  7. Now for each of your lines in the Hub distance layer, you will have an azimuth under the Angle attribute. The absolute difference between the 2 azimuths will give the angle between the 2 lines.

Links to other questions and solutions I used: calculate angle between two lines

1

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.