![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@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.
Parameters
geojson
Feature<(LineString | MultiLineString)> GeoJSON to measureoptions
Object Optional parameters (optional, default {}
)
options.units
string can be degrees, radians, miles, or kilometers (optional, default kilometers
)Examples
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 module individually:
$ npm install @turf/length
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf length module
The npm package @turf/length receives a total of 431,727 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 0 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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.