perliedman / geojson-path-finder

Find shortest path through a network of GeoJSON
https://www.liedman.net/geojson-path-finder/
ISC License
300 stars 86 forks source link

Destination on one-way feature not possible #63

Open andreasherzog opened 4 years ago

andreasherzog commented 4 years ago

First off, I really like this library, it works well and fast. Thanks for maintaining.

I am using it to calculate paths in a self-recorded network. After some adjustments to the network, it does what we need.

However, when I add one-way features, I cannot get a path if the destination is on that one-way feature. The start can be placed on it and it works. Also, the one-way feature is included for "through" paths that have a working destination.

I am using this weightFunction:

weightFunction = (a, b, props) => {
    const distance = turf.distance(turf.point(a), turf.point(b)) * 1000;
    let forward = distance;
    let backward = distance;
    if (props.oneway && props.oneway === true) {
      backward = 0;
    } else if (props.oneway && props.oneway === 'backward') {
      forward = 0;
    }
    return {
      forward: forward,
      backward: backward,
    };
  };

My features can have a "oneway" property that is set to true if the feature should be one-way. I do not use the "backward" value at the moment. If I remove the "oneway" property, I can place the destination on the feature with no issue.

Any guidance would be dearly appreciated.

perliedman commented 4 years ago

Hi, sorry about a late reply, but is there any chance you could publish an example, or at least a network, that exhibits this problem?

andreasherzog commented 4 years ago

Hi, sorry for replying late.

Actually, you can try this out on your example page by putting the destination "B" on Road "Oscarsleden" - which is a road with separated lanes for each direction:

grafik

However, this road is part of the network and can be used for "passing-through" if you put your destination on a two-way road:

grafik

Does this help to illustrate the issue?

nemosmithasf commented 3 years ago

Ran into a similar problem; check if there are any line segments that unintentionally return "0" in your calculation.

On a side note, I think from a design perspective; its a mistake to have "0" mean impassible.

  1. Its possible a regular calculation can return 0 without intending it
  2. The behaviour is inconsistent with returning a single value (vs an object of backward and forward)
  3. Its very difficult to debug