shortestPath
Description
Returns the shortest path from start to end without colliding with any Feature in obstacles
Parameters
Name | Type | Description |
---|---|---|
start | Coord | point |
end | Coord | point |
options? | Object | optional parameters (default {}) |
options.obstacles? | Geometry | Feature | FeatureCollection<Polygon> | areas which path cannot travel |
options.units? | string | unit in which resolution & minimum distance will be expressed in; it can be degrees, radians, miles, kilometers, ... (default 'kilometers') |
options.resolution? | number | distance between matrix points on which the path will be calculated (default 100) |
Returns
Feature<LineString> shortest path between start and end
Examples
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);
Installation
$ npm install @turf/shortest-path
import { shortestPath } from "@turf/shortest-path";
const result = shortestPath(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.shortestPath(...);