Returns the shortest path from start to end without colliding with any Feature in obstacles.
npm install @turf/shortest-pathReturns the shortest [path][1] from [start][2] to [end][2] without colliding with
any [Feature][3] in obstacles [FeatureCollection][4]<[Polygon][5]>
* start [Coord][6] point
* end [Coord][6] point
* options [Object][7] optional parameters (optional, default {})
* options.obstacles ([Polygon][5] | [Feature][3]<[Polygon][5]> | [FeatureCollection][4]<[Polygon][5]>)? areas which path cannot travel
* options.units Units unit in which resolution & minimum distance will be expressed in; Supports all valid Turf [Units][8]. (optional, default 'kilometers')
* options.resolution [number][9] distance between matrix points on which the path will be calculated (optional, default 100)
``javascript
var start = [-5, -6];
var end = [9, -6];
var options = {
obstacles: turf.polygon([[[0, -7], [5, -7], [5, -3], [0, -3], [0, -7]]]).geometry
};
var path = turf.shortestPath(start, end, options);
//addToMap
var addToMap = [start, end, options.obstacles, path];
`
Returns [Feature][3]<[LineString][1]> shortest path between start and end
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[3]: https://tools.ietf.org/html/rfc7946#section-3.2
[4]: https://tools.ietf.org/html/rfc7946#section-3.3
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.6
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.1
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[8]: https://turfjs.org/docs/api/types/Units
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
---
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 single module individually:
`sh`
$ npm install @turf/shortest-path
Or install the all-encompassing @turf/turf module that includes all modules as functions:
`sh``
$ npm install @turf/turf