Hopefully a quick question. I have an IEnumerable of type Position where Position is defined as follows:
public class Position { public double Latitude { get; set; } public double Longitude { get; set; } } What I need to do is quickly sort through the IEnumerable to find elements that fall within a certain distance of eachother. The elements in the IEnumerable do not get populated in any specific order, but at any one time I need to be able to compute which of the members of the IEnumerable fall within x kilometers of eachother.
Now, I already have a Haversine implementation and for argument's sake, we can say it's called GetDistance and has the following signature:
double GetDistance(Position one, Position two); I've got a few ideas, but none of them feel particularly efficient to my mind. To give a little more info, it's unlikely the IEnumerable will ever hold more than 10,000 items at any one time.
What I'd like to arrive at is something, perhaps an extension method, that lets me invoke it to return an IEnumerable which contains just the subset from the original collection which meets the criteria, for example:
OriginalEnumerable.GetMembersCloserThan(kilometers: 100); Any help, much appreciated.
EDIT: For clarity, consider the IEnumerable I want to search describes a circle with radius r. It's members are coordinates within the circle. I'm trying to determine which members (points) are within a given proximity of eachother.
OriginalEnumerable.GetMembersCloserThan(kilometers: 100);get thePositionobjects that are within 100 kilometers of at least 1 otherPositionobject?GetDistancemethod that compares two positions, why not simply create the desired extension method yourself? What is the problem?within x kilometers of eachotheris ambigous. Take the case where you have 4 elements each split up into pairs. each pair is only 1 kilometer from the other element in their pair, but the pairs are roughly 200 kilometers away from each-other. Do you want to select all of the elements in this case? or none of them?