Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@turf/nearest-point-on-line
Advanced tools
@turf/nearest-point-on-line is a module from the Turf.js library that allows you to find the nearest point on a line from a given point. This can be useful in various geospatial analyses, such as snapping a point to a road network or finding the closest point of interest along a path.
Find Nearest Point on Line
This feature allows you to find the nearest point on a given line from a specified point. In the code sample, a line and a point are defined, and the nearest point on the line to the given point is calculated and logged.
const turf = require('@turf/turf');
const line = turf.lineString([[0, 0], [2, 2], [3, 3]]);
const point = turf.point([1, 2]);
const snapped = turf.nearestPointOnLine(line, point);
console.log(snapped);
Geolib is a library for geospatial calculations in JavaScript. It provides various functions for distance calculations, finding nearest points, and more. Compared to @turf/nearest-point-on-line, Geolib offers a broader range of geospatial utilities but may not be as specialized in line-specific operations.
Geodesy is a library for geodesic and trigonometric calculations. It includes functions for distance calculations, bearing, and more. While it provides some similar functionalities, it is more focused on geodesic calculations rather than finding the nearest point on a line.
Takes a Point and a LineString and calculates the closest Point on the (Multi)LineString.
lines
(Geometry | Feature<(LineString | MultiLineString)>) lines to snap to
pt
(Geometry | Feature<Point> | Array<number>) point to snap from
options
Object Optional parameters (optional, default {}
)
options.units
string can be degrees, radians, miles, or kilometers (optional, default 'kilometers'
)var line = turf.lineString([
[-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 pt = turf.point([-77.037076, 38.884017]);
var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});
//addToMap
var addToMap = [line, pt, snapped];
snapped.properties['marker-color'] = '#00f';
Returns Feature<Point> closest point on the line
to point
. The properties object will contain three values: index
: closest point was found on nth line part, dist
: distance between pt and the closest point, location
: distance along the line between start and the closest point.
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/nearest-point-on-line
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf nearest-point-on-line module
The npm package @turf/nearest-point-on-line receives a total of 359,538 weekly downloads. As such, @turf/nearest-point-on-line popularity was classified as popular.
We found that @turf/nearest-point-on-line 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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.