Geographic Information Systems Asked by Maike on June 30, 2021
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?
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.
Answered by Kazuhito on June 30, 2021
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:
Workflow
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.reprojected points 1 and 3
layer, and target hub layer to reprojected point 2
layer. This should create a new Hub distance
layer.Hub distance
layer, toggle on the edit mode, and open the Field Calculator, inputting the following 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
Answered by Dominic Lim on June 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP