nearestPointOnLine function
Takes a Point and a LineString and calculates the closest Point on the LineString.
The properties of returned Point will contain three values:
- index: closest point was found on nth line part
- dist: distance between
point
and the closest point on line - location: distance along the line between start and the closest point.
Example:
var line = LineString(
coordinates: [
Position.of([-77.031669, 38.878605]),
Position.of([-77.029609, 38.881946]),
Position.of([-77.020339, 38.884084]),
Position.of([-77.025661, 38.885821]),
Position.of([-77.021884, 38.889563]),
Position.of([-77.019824, 38.892368)]
]);
var pt = Point(coordinates: Position(lat: -77.037076, lng: 38.884017));
var snapped = nearestPointOnLine(line, pt, Unit.miles);
Implementation
Feature<Point> nearestPointOnLine(
LineString line,
Point point, [
Unit unit = Unit.kilometers,
]) {
return _nearestPointOnLine(line, point, unit).toFeature();
}