Skip to content

KBE3D / KBCore / turf / pointToLineDistance

函数: pointToLineDistance()

pointToLineDistance(pt: Coord, line: LineString | Feature<LineString, GeoJsonProperties>, options?: { units?: Units; method?: "geodesic" | "planar"; }): number

Function

Calculates the distance between a given point and the nearest point on a line. Sometimes referred to as the cross track distance.

参数

pt

Coord

Feature or Geometry

line

GeoJSON Feature or Geometry

LineString | Feature<LineString, GeoJsonProperties>

options?

Optional parameters

units?

Units

Supports all valid Turf Units

method?

"geodesic" | "planar"

whether to calculate the distance based on geodesic (spheroid) or planar (flat) method. Valid options are 'geodesic' or 'planar'.

返回

number

distance between point and line

示例

ts
var pt = turf.point([0, 0]);
var line = turf.lineString([[1, 1],[-1, 1]]);

var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
//=69.11854715938406

KBE3D @3.0.0 Copyright © 2024-present KBE3D