What is @turf/rhumb-bearing?
@turf/rhumb-bearing is a module from the Turf.js library that calculates the bearing between two geographical points along a rhumb line (a line of constant bearing). This is useful for navigation and mapping applications where you need to determine the direction from one point to another.
What are @turf/rhumb-bearing's main functionalities?
Calculate Rhumb Bearing
This feature calculates the rhumb bearing between two geographical points. The code sample demonstrates how to use the `rhumbBearing` function to find the bearing from point1 to point2.
const turf = require('@turf/turf');
const point1 = turf.point([0, 0]);
const point2 = turf.point([10, 10]);
const bearing = turf.rhumbBearing(point1, point2);
console.log(bearing);
Other packages similar to @turf/rhumb-bearing
geolib
Geolib is a library for geospatial calculations. It provides a variety of functions for distance, bearing, and other geographical calculations. Unlike @turf/rhumb-bearing, Geolib offers a broader range of geospatial utilities but may not be as specialized in rhumb line calculations.
geodesy
Geodesy is a library for geodesic and rhumb line calculations. It offers detailed and precise methods for calculating distances, bearings, and other geospatial metrics. Compared to @turf/rhumb-bearing, Geodesy provides more comprehensive geodesic calculations but may be more complex to use.
@turf/rhumb-bearing
rhumbBearing
Takes two points and finds the bearing angle between them along a Rhumb line
i.e. the angle measured in degrees start the north line (0 degrees)
Parameters
Examples
var point1 = {
"type": "Feature",
"properties": {
"marker-color": "#F00"
},
"geometry": {
"type": "Point",
"coordinates": [-75.343, 39.984]
}
};
var point2 = {
"type": "Feature",
"properties": {
"marker-color": "#00F"
},
"geometry": {
"type": "Point",
"coordinates": [-75.534, 39.123]
}
};
var bearing = turf.rhumbBearing(point1, point2);
point1.properties.bearing = bearing
point2.properties.bearing = bearing
var addToMap = [point1, point2]
Returns number bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise)
This module is part of the Turfjs project, an open source
module collection dedicated to geographic algorithms. It is maintained in the
Turfjs/turf repository, where you can create
PRs and issues.
Installation
Install this module individually:
$ npm install @turf/rhumb-bearing
Or install the Turf module that includes it as a function:
$ npm install @turf/turf