I have a graph data structure representing a road network (nodes are points / intersections on the road and edges are roads). A Node object has latitude and longitude associated with it.
I use the Accord KDTree class to find the nearest nodes for a given GPS coordinate. Since Accord doesn't seem to have Haversine distance as a built-in distance function (am I mistaken?), I define my own distance function and pass it as an additional parameter to the KDTree.FromData () method as follows:
var nodes = graph.Nodes;
Func<double[], double[], double> distanceFunc = (x, y) => DistanceFunctions.ApproximateDistance(x,y);
kdTreeOfNodes = KDTree.FromData<Node>(nodes.Select(x => new double[] { x.Value.Latitude, x.Value.Longitude }).ToArray(), nodes.ToArray(), distanceFunc);
Note that "ApproximateDistance" is defined as a static method in a separate class and is a Cartesian approximation to the more correct Haversin distance.
I get an exception when trying to break the last line. On this line, I pass the data to be placed in KDTree (namely an array of lat / lon arrays), as well as related nodes, as well as my custom distance function. It looks like this FromData constructor actually (for some reason?) Calls my ApproximateDistance function, and arrays [1] and [1] as two input parameters, explicitly raising the exception, since this method expects two two-dimensional arrays.
I have no idea why this constructor calls my ApproximateDistance function (especially with these strange parameters), and it can't seem like it has detected the use of a debugger ...
source
share