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 line and returns a point at a specified distance along the line.
Parameters
line
Feature<LineString> input linedistance
number distance along the lineunits
[String] can be degrees, radians, miles, or kilometers (optional, default miles
)
Examples
var line = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[-77.031669, 38.878605],
[-77.029609, 38.881946],
[-77.020339, 38.884084],
[-77.025661, 38.885821],
[-77.021884, 38.889563],
[-77.019824, 38.892368]
]
}
};
var along = turf.along(line, 1, 'miles');
var result = {
"type": "FeatureCollection",
"features": [line, along]
};
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