Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RouterBaseExtension - ArgumentOutOfRangeException #363

Open
Oyekunle86 opened this issue Dec 1, 2022 · 1 comment
Open

RouterBaseExtension - ArgumentOutOfRangeException #363

Oyekunle86 opened this issue Dec 1, 2022 · 1 comment

Comments

@Oyekunle86
Copy link

Hello,

Please I get this error when I calculate route for multiple points/locations e.g.

        var locations = new[]
        {
            new Coordinate(6.43513833145211f, 3.45599909557983f),
            new Coordinate(6.43200924856121f, 3.46967836163486f)
        };

var route = router.Calculate(bus, locations);
var routeGeoJson = route.ToGeoJson();

I get this error:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List1.get_Item(Int32 index) at Itinero.RouterBaseExtensions.TryCalculate(RouterBase router, IProfileInstance profile, IMassResolvingAlgorithm resolvingAlgorithm, Single turnPenalty, Tuple2[] preferredTurns, CancellationToken cancellationToken)

Please help out

image

@bjtrounson
Copy link

bjtrounson commented Sep 19, 2023

Hi,

Don't know if you have figured this out already but I'll put this here for anyone else having issues with GPS coordinates.

Those GPS coordinates seem to show they are in the middle of the ocean, you might have your GPS coordinates reversed. I also recommend parsing the GPS points into router points. I find this gives better results when routing as it will snap the GPS point to the closest edge.

Here is a code snippet I like to use to convert, you could adapt it to process an array of coordinates if needed. This method will try different search distances incase the GPS point is pretty far away from the road / edge.

private static RouterPoint? BuildRouterPoints(RouterBase router, Coordinate coordinate, IProfileInstance profile)
{
        var routerPoint = router.TryResolve(profile, coordinate, 200);
        if (!routerPoint.IsError) return routerPoint.Value;
        Console.WriteLine($"{DateTime.Now} - [WARNING]: {routerPoint.ErrorMessage}");
        routerPoint = router.TryResolve(profile, coordinate, 2000);
        if (!routerPoint.IsError) return routerPoint.Value;
        Console.WriteLine($"{DateTime.Now} - [ERROR]: {routerPoint.ErrorMessage}");
        return null;
}

Another thing to be keep in mind is if you are getting errors with points not routing, make sure you're not on an island. I found this out when doing some routing in New Zealand the North Island roads only get added if you load island data were the South Island gets loaded without island data.

Here is how you can load island data

routerDb.AddIslandData(profile);

Hope this helps anyone that stumbles into the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants