The documentation states that a C# profile can be created instead of using a .lua file, but no example is given. Can anyone point me at a working example?
I need to be able to calculate times/distances between points with user-defined road speeds, so a .lua file is impractical. Being able to set a routing profile in code is what I need, but I cannot find any examples of how this is done.
RouterDb routerDb = null;
using (var stream = new FileInfo(@"great-britain.routerdb").OpenRead())
{
routerDb = RouterDb.Deserialize(stream);
}
var router = new Router(routerDb);
// get a profile.
var fastcar = Vehicle.Car.Fastest(); // the default OSM car profile.
var directcar = Vehicle.Car.Shortest(); // the default OSM car profile.
// HOW DO I SET ROAD SPEEDS DYNAMICALLY ON MY PROFILES?
// what goes here...
// create a routerpoint from a location.
// snaps the given location to the nearest routable edge.
var start = router.Resolve(fastcar, 51.284043f, 0.516308f);
var end = router.Resolve(fastcar, 51.277406f, 0.492423f);
// calculate a route.
var fast = router.Calculate(fastcar, start, end);
Console.WriteLine(string.Format("Fastest: distance {0:0.00} miles, taking {1:0.00} mins", fast.TotalDistance / 1609.34, (fast.TotalTime / 60)));
start = router.Resolve(directcar, 51.284043f, 0.516308f);
end = router.Resolve(directcar, 51.277406f, 0.492423f);
var shortr = router.Calculate(directcar, start, end);
Console.WriteLine(string.Format("Shortest: distance {0:0.00} miles, taking {1:0.00} mins", shortr.TotalDistance / 1609.34, (shortr.TotalTime / 60)));
// write router to file
using (var writer = new StreamWriter(@"short-route.geojson"))
{
shortr.WriteGeoJson(writer);
}`
The documentation states that a C# profile can be created instead of using a .lua file, but no example is given. Can anyone point me at a working example?
I need to be able to calculate times/distances between points with user-defined road speeds, so a .lua file is impractical. Being able to set a routing profile in code is what I need, but I cannot find any examples of how this is done.
RouterDb routerDb = null; using (var stream = new FileInfo(@"great-britain.routerdb").OpenRead()) { routerDb = RouterDb.Deserialize(stream); } var router = new Router(routerDb);