Skip to content

@turf/shortest-path does not accept Feature<Polygon> as obstacles #2941

@ziegler-daniel

Description

@ziegler-daniel

Summary

According to the docs shortestPath accepts Polygon | Feature<Polygon> | FeatureCollection<Polygon> as obstacles. However an invalid obstacles error is thrown if you provide a Feature<Polygon> as obstacle.

Example

When you run the following code an invalid obstacles error is thrown.

import { shortestPath } from '@turf/turf';

const start = [13.811772324108205, 52.15187842149308];

const end = [13.80780718427863, 52.15711694225445];

const obstacle = {
    type: 'Feature',
    properties: {},
    geometry: {
        type: 'Polygon',
        coordinates: [
            [
                [13.809135109049322, 52.1533094692154],
                [13.809135109049322, 52.152020775802356],
                [13.8130016727888, 52.152020775802356],
                [13.8130016727888, 52.1533094692154],
                [13.809135109049322, 52.1533094692154],
            ],
        ],
    },
};

const result = shortestPath(start, end, {
    obstacles: obstacle,
});

Version

I tested this with @turf/shortest-path version 7.2.0

Note

I'll create a pull request to fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions