Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@turf/length
Advanced tools
@turf/length is a module from the Turf.js library that allows you to calculate the length of a GeoJSON LineString or MultiLineString. It is useful for geographic data analysis and manipulation, particularly when working with spatial data in web applications.
Calculate Length of LineString
This feature allows you to calculate the length of a LineString in the specified units (e.g., miles, kilometers). The code sample demonstrates how to create a LineString and calculate its length in miles.
const turf = require('@turf/length');
const line = {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[-77.031669, 38.878605],
[-77.029609, 38.881946],
[-77.020339, 38.884084],
[-77.025661, 38.885821]
]
}
};
const length = turf(line, {units: 'miles'});
console.log(length);
Calculate Length of MultiLineString
This feature allows you to calculate the length of a MultiLineString in the specified units (e.g., kilometers). The code sample demonstrates how to create a MultiLineString and calculate its length in kilometers.
const turf = require('@turf/length');
const multiLine = {
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[-77.031669, 38.878605],
[-77.029609, 38.881946]
],
[
[-77.020339, 38.884084],
[-77.025661, 38.885821]
]
]
}
};
const length = turf(multiLine, {units: 'kilometers'});
console.log(length);
Geolib is a library for geospatial calculations, including distance and length calculations. It provides similar functionality to @turf/length but also includes additional features like calculating the distance between two points, finding the center of a collection of points, and more. It is more versatile but may be more complex to use for simple length calculations.
Geodesy is a library for geodesic calculations, including distance and length calculations. It offers similar functionality to @turf/length but focuses more on precise geodesic calculations, which can be useful for applications requiring high accuracy. It is more specialized and may be overkill for simple length calculations.
Takes a GeoJSON and measures its length in the specified units, (Multi)Point's distance are ignored.
geojson
Feature<(LineString | MultiLineString)> GeoJSON to measure
options
Object Optional parameters (optional, default {}
)
options.units
string can be degrees, radians, miles, or kilometers (optional, default kilometers
)var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);
var length = turf.length(line, {units: 'miles'});
//addToMap
var addToMap = [line];
line.properties.distance = length;
Returns number length of GeoJSON
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.
Install this single module individually:
$ npm install @turf/length
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf length module
The npm package @turf/length receives a total of 735,912 weekly downloads. As such, @turf/length popularity was classified as popular.
We found that @turf/length demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.