Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
podcast
Filter by Categories
ArcGIS Pro
GDAL
GeoJson
Map
Python
QGIS
Uncategorized

How to calculate bearing between two coordinates

What is a Bearing?

A bearing is a direction of one point relative to another point, usually given as an angle measured clockwise from north. In navigation, bearings are often used to determine the direction to a destination or to plot a course on a map. There are two main types of bearings: absolute bearing and relative bearing.

Absolute bearing

Absolute bearing refers to the angle between the magnetic north (magnetic bearing) or true north (true bearing) and an object. For example, an object due east would have an absolute bearing of 90 degrees.

Relative bearing

Relative bearing refers to the angle between the forward direction of a craft (heading) and the location of another object. For example, an object with a relative bearing of 0 degrees would be immediately in front of the craft, while an object with a relative bearing of 180 degrees would be behind it.

For example, if you are standing at point A and you want to go to point B, the bearing from A to B is the direction that you would need to follow to get to B from A. Bearings are often used in navigation to determine the direction to a destination or to plot a course on a map.

Bearings can be measured in degrees, with 0 degrees being north, 90 degrees being east, 180 degrees being south, and 270 degrees being west. Bearings can also be expressed as a three-figure number, with the first digit representing the direction of the tens of degrees, the second digit representing the direction of the units of degrees, and the third digit representing the direction of the minutes. For example, a bearing of 045 degrees would be expressed as 045, and a bearing of 122 degrees would be expressed as 122.

Here are a few other terms that are sometimes used instead of Bearing

  • Heading: This term is often used to describe the direction that a vehicle, such as a boat or an airplane, is currently traveling in.
  • Course: This term is similar to heading, but it can also refer to the intended direction of travel, rather than the current direction.
  • Orientation: This term refers to the position or alignment of something in relation to its surroundings.
  • Direction: This term refers to the way that something is facing or the path that it is moving in.
  • Compass bearing: This term is used to describe the direction of one point relative to another point, measured in degrees clockwise from north, as indicated by a compass.
  • Angle: This term refers to describing the direction to a destination.

How to calculate a Bearing between two coordinates

To calculate the bearing between two coordinates, you can use the following formula:

bearing = atan2(sin(long2-long1)*cos(lat2), cos(lat1)*sin(lat2) – sin(lat1)*cos(lat2)*cos(long2-long1))

This formula assumes that the coordinates are given in terms of latitude and longitude. The variables in the formula are as follows:

  • lat1: the latitude of the first coordinate
  • long1: the longitude of the first coordinate
  • lat2: the latitude of the second coordinate
  • long2: the longitude of the second coordinate

The resulting angle is the bearing from the first coordinate to the second coordinate, measured in radians clockwise from north. You can convert the result to degrees by multiplying it by 180/pi.

How to calculate a Bearing between two coordinates in Python

import math

def calc_bearing(lat1, long1, lat2, long2):
  # Convert latitude and longitude to radians
  lat1 = math.radians(lat1)
  long1 = math.radians(long1)
  lat2 = math.radians(lat2)
  long2 = math.radians(long2)
  
  # Calculate the bearing
  bearing = math.atan2(
      math.sin(long2 - long1) * math.cos(lat2),
      math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(long2 - long1)
  )
  
  # Convert the bearing to degrees
  bearing = math.degrees(bearing)
  
  # Make sure the bearing is positive
  bearing = (bearing + 360) % 360
  
  return bearing

How to calculate a Bearing between two coordinates in Microsoft Excel

In Microsoft Excel, you can use the ATAN2 function to calculate the bearing between two points. The ATAN2 function takes two arguments: the y-coordinate and the x-coordinate of a point, and returns the angle (in radians) between the positive x-axis and the point.

To calculate the bearing between two points in Excel, you can use the following formula:

=ATAN2(y2-y1, x2-x1)

Where (x1, y1) and (x2, y2) are the coordinates of the two points.

The resulting angle is the bearing from the first point to the second point, measured in radians counterclockwise from the positive x-axis. You can convert the result to degrees by multiplying it by 180/pi.

Here is an example of how this formula can be used in Excel:

  |  A   B   C   D   E
1 |      X1  Y1  X2  Y2
2 |  B   =ATAN2(D2-C2, E2-D2)

In this example, the bearing from (X1, Y1) to (X2, Y2) is calculated in cell B2.

How to calculate a Bearing between two coordinates in QGIS

In QGIS, there are several tools that you can use to calculate the bearing between two points.

One option is to use the $bearing function in an expression. This function takes two point geometries as arguments and returns the bearing in degrees clockwise from north. You can use the $bearing function to create a new field in the attribute table that contains the bearings, or to display the bearings on the map canvas using labels or data-defined symbology.

Another option is to use the “Measure Azimuth” tool in the “Measure” toolbar. To use this tool:

  1. Open the “Measure” toolbar by going to View > Toolbars > Measure.
  2. Select the “Measure Azimuth” tool.
  3. Click on the starting point of the measurement.
  4. Click on the ending point of the measurement.

The bearing will be displayed in the Measurements panel, as well as on the map canvas as a line connecting the two points.

You can also use the “Measure Line” tool to measure the distance between the two points and the “Measure Angle” tool to measure the angle between the line and north.

About the Author
I'm Daniel O'Donohue, the voice and creator behind The MapScaping Podcast ( A podcast for the geospatial community ). With a professional background as a geospatial specialist, I've spent years harnessing the power of spatial to unravel the complexities of our world, one layer at a time.

Leave a Reply