perliedman / geojson-path-finder

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

How to model barriers? #7

Closed s9eenk closed 7 years ago

s9eenk commented 7 years ago

In a closer reading of the API it looks like barriers/ impediments haven't been included here . As, i want the shortest route to be calculated by excluding paths which have barriers .

Any help is appreciated. Thankx for advance :)

perliedman commented 7 years ago

Yeah, this is a very basic implementation, no support for barriers.

I imagine it wouldn't be too hard to add support for something like this by modifying how topology is created: https://github.com/perliedman/geojson-path-finder/blob/master/topology.js

perliedman commented 7 years ago

This can be modelled by using a custom weightFn, something along these lines:

var roundCoord = require('geojson-path-finder/round-coord');
var barriers = { /* geojson Point FeatureCollection */ };
var barrierSet = explode(barriers).features.reduce(function(bs, p) {
    var roundedCoord = roundCoord(p.geometry.coordinate);
    bs[c[0] + ',' + c[1]] = true;
    return bs;
}, {});
var pathFinder = new PathFinder(geojson, {
    weightFn: function(a, b) {
        var keyA = a[0] + ',' + a[1];
        var keyB = b[0] + ',' + b[1];
        if (barriers[keyA] || barriers[keyB]) {
            return null;
        }

        // Calculate weight
    }

The actual method to find out if a point is a barrier could of course be implemented in a lot of different ways.

s9eenk commented 6 years ago

Hi @perliedman , Thanks for the logic of barriers . Now , i want to incorporate wall boundaries as LineStrings. Is it possible to generate shortest route in between them ?.

Thank you for your help!.

perliedman commented 6 years ago

@s9eenk hm, not sure I follow what you want to achieve - do you want to find the shortest path from one boundary to another? Can you describe with a figure or so?

s9eenk commented 6 years ago

@perliedman . Please find the attached figure. Here, the Green colored one are lineStrings (like walls) and the red colored one is a shortest path. Now , i don't want the shortest route to get intersected with the wall boundaries, instead find an alternative path. Is this possible using this API ?. err1