What is @turf/rhumb-distance?
@turf/rhumb-distance is a module from the Turf.js library that calculates the rhumb line distance between two geographical points. A rhumb line is a path of constant bearing, which is different from the shortest path (great-circle distance) on a sphere. This package is useful for applications that require consistent bearing, such as navigation and mapping.
What are @turf/rhumb-distance's main functionalities?
Calculate Rhumb Distance
This feature calculates the rhumb line distance between two geographical points. The `units` option allows you to specify the unit of measurement, such as miles, kilometers, etc.
const turf = require('@turf/turf');
const point1 = turf.point([-75.343, 39.984]);
const point2 = turf.point([-75.534, 39.123]);
const options = { units: 'miles' };
const distance = turf.rhumbDistance(point1, point2, options);
console.log(distance);
Other packages similar to @turf/rhumb-distance
geolib
Geolib is a library for geospatial calculations. It provides various methods for distance calculations, including great-circle distance and rhumb line distance. Compared to @turf/rhumb-distance, Geolib offers a broader range of geospatial functions but may not be as specialized in rhumb line calculations.
geodesy
Geodesy is a library that provides tools for geodesic calculations. It includes methods for calculating distances, bearings, and other geospatial properties. While it offers comprehensive geodesic calculations, it may require more configuration compared to the straightforward usage of @turf/rhumb-distance.
@turf/rhumb-distance
rhumbDistance
Calculates the distance along a rhumb line between two points in degrees, radians,
miles, or kilometers.
Parameters
from
Coord origin pointto
Coord destination pointoptions
Object? Optional parameters
options.units
string can be degrees, radians, miles, or kilometers (optional, default "kilometers"
)
Examples
var from = turf.point([-75.343, 39.984]);
var to = turf.point([-75.534, 39.123]);
var options = {units: 'miles'};
var distance = turf.rhumbDistance(from, to, options);
var addToMap = [from, to];
from.properties.distance = distance;
to.properties.distance = distance;
Returns number distance between the two points
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-distance
Or install the Turf module that includes it as a function:
$ npm install @turf/turf