@spatial/point-to-line-distance
Version:
turf point-to-line-distance module
72 lines (45 loc) • 2.35 kB
Markdown
# @spatial/point-to-line-distance
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## pointToLineDistance
Returns the minimum distance between a [Point][1] and a [LineString][2], being the distance from a line the
minimum distance between the point and any segment of the `LineString`.
### Parameters
- `pt` **[Coord][3]** Feature or Geometry
- `line` **[Feature][4]<[LineString][5]>** GeoJSON Feature or Geometry
- `options` **[Object][6]** Optional parameters (optional, default `{}`)
- `options.units` **[string][7]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
- `options.mercator` **[boolean][8]** if distance should be on Mercator or WGS84 projection (optional, default `false`)
### Examples
```javascript
var pt = turf.point([0, 0]);
var line = turf.lineString([[1, 1],[-1, 1]]);
var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
//=69.11854715938406
```
Returns **[number][9]** distance between point and line
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.1
[4]: https://tools.ietf.org/html/rfc7946#section-3.2
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
./scripts/generate-readmes in the turf project. -->
---
This module is part of the [Turfjs project](http://turfjs.org/), an open source
module collection dedicated to geographic algorithms. It is maintained in the
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
PRs and issues.
### Installation
Install this module individually:
```sh
$ npm install @spatial/point-to-line-distance
```
Or install the Turf module that includes it as a function:
```sh
$ npm install @turf/turf
```