What is @turf/along?
@turf/along is a module from the Turf.js library that allows you to calculate a point at a specified distance along a line. This can be useful for various geospatial analyses, such as finding a location a certain distance from a starting point on a path or route.
What are @turf/along's main functionalities?
Calculate a point along a line
This feature allows you to calculate a point that is a specified distance along a given line. In this example, a point 5 kilometers along the line is calculated.
const turf = require('@turf/turf');
const line = turf.lineString([[0, 0], [10, 10], [20, 20]]);
const distance = 5;
const options = { units: 'kilometers' };
const point = turf.along(line, distance, options);
console.log(point);
Other packages similar to @turf/along
geolib
Geolib is a library for geospatial calculations in JavaScript. It provides various functions for distance calculations, finding points within a certain radius, and more. Compared to @turf/along, geolib offers a broader range of geospatial utilities but may not be as specialized in line-based calculations.
geodesy
Geodesy is a library for geodesic calculations in JavaScript. It includes functions for calculating distances, bearings, and points along a path. While it offers similar functionality to @turf/along, it is more focused on geodesic calculations and may be more suitable for applications requiring high precision over long distances.
@turf/along
along
Takes a LineString and returns a Point at a specified distance along the line.
Parameters
-
line
Feature<LineString> input line
-
distance
number distance along the line
-
options
Object? Optional parameters
options.units
string can be degrees, radians, miles, or kilometers (optional, default "kilometers"
)
Examples
var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
var options = {units: 'miles'};
var along = turf.along(line, 200, options);
var addToMap = [along, line]
Returns Feature<Point> Point distance
units
along the line
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/along
Or install the Turf module that includes it as a function:
$ npm install @turf/turf