routing icon indicating copy to clipboard operation
routing copied to clipboard

Problems with calculating route from contracted graph

Open Matyz24 opened this issue 1 month ago • 0 comments

Hello, I want to calculate route and show the result on map in MAUI App. So I need to calculate the route fast even on mobile phone. To achieve this, firstly I run my app on PC, which:

  • loads data from osm.pbf file
  • adds contracted graph for profile Vehicle.Car.Fastest()
  • serialize the routerdb to file on PC This is the code:
var routerDb = new RouterDb();
var input = new FileInfo(@"C:\Users\zdene\Downloads\czech-republic-latest.osm.pbf").OpenRead();
routerDb.LoadOsmData(input, Vehicle.Car);
routerDb.AddContracted(Vehicle.Car.Fastest());
using (var output = new FileInfo(@"C:\Users\zdene\Downloads\czech-republic-cartest.routerdb").Open(FileMode.Create))
{
        routerDb.Serialize(output);
}

Then I take the generated file, transfer it to my mobile phone's documents and serialize it to AppDataDirectory of MAUI App This is the code:

var routerDb = new RouterDb();
var result = await FilePicker.Default.PickAsync();
using var stream = await result.OpenReadAsync();
routerDb = RouterDb.Deserialize(stream);
string localGdbFilePath = Path.Combine(FileSystem.Current.AppDataDirectory, "czech-republic.routerdb");
routerDb.Serialize(File.Create(localGdbFilePath));
router = new Router(routerDb);

Then when running app, I use this code to load routerdb from AppDataDirectory: router = new Router(RouterDb.Deserialize(File.OpenRead(localGdbFilePath), RouterDbProfile.NoCache)); When I try to calculate route from the same file on PC, it works perfectly and fast, but when I try the same task for the same coordinates from the same file on mobile, it fails with error:

No edge found from 576420 to 0.

I tried a lot of variants to solve this, but nothing works. Also, calculating the route on mobile without previously adding contracted graph to the file works correctly, but takes too long when calculating slightly longer distances. So I need to make it faster. I don't know where is the problem or what I am doing wrong. I would appreciate any advice. I hope someone could help me.

Matyz24 avatar May 30 '24 12:05 Matyz24