itinero / routing

The routing core of itinero.
Apache License 2.0
221 stars 70 forks source link

Bus profile doesn't route via psv-access marked routes properly #241

Closed lol768 closed 5 years ago

lol768 commented 5 years ago

Here is a way: https://www.openstreetmap.org/way/134832729

Note that this street is clearly sign-posted as being available for buses to use and marked psv=true AND bus=true:

Now consider that a bus (as well as e.g. a Taxi) is clearly a psv.

Look at this simple code. I am a bus:

private static void MinExample()
{
    var routerDb = new RouterDb();
    using (var stream = new FileInfo(@"england-latest.osm.pbf").OpenRead())
    {
        routerDb.LoadOsmData(stream, Vehicle.Bus);
    }

    var router = new Router(routerDb);
    var coordinates = new Coordinate[]
    {
        new Coordinate(52.40545f, -1.51172f),

        new Coordinate(52.4047f, -1.5134f)
    };
    var route = router.Calculate(Vehicle.Bus.Fastest(), coordinates);
    var geoJson = route.ToGeoJson();
    Console.WriteLine(geoJson);
}

The following route is yielded:

Why am I not routed via the way I linked earlier?

xivk commented 5 years ago

Not all busses everywhere in all countries are always considered to be psvs but you can customize profiles. Adding psv in that array should do it I think:

https://github.com/itinero/routing/blob/develop/src/Itinero/Osm/Vehicles/bus.lua#L3

You can load any local vehicle profile like this:

var vehicle = DynamicVehicle.LoadFromStream(File.OpenRead("path/to/custom.lua"));

lol768 commented 5 years ago

This way also seems to be tagged as bus=true, too - if I'm reading the OSM site correctly. Surely buses should always be considered to be buses?

xivk commented 5 years ago

Yes :+1:

Feel free to do a pull-request to do the change to the bus profile.

lol768 commented 5 years ago

Can confirm a local profile works, will open a new PR

lol768 commented 5 years ago

Cheers @xivk