Is there a faster way of doing the following? I am using GetLineOnALine below to find the next vertext on a line from a given point on that line. The reason I am doing this is I already have stops that are displayed on the map indexed by vertex. Some of the LineShapes I am dealing with have over 1000 vertices so it can take quite a while to do it this way -
public ServiceableStop GetNextStopOnRoute(
PointShape pointNearRoute,
LineShape routePath,
Route route)
{
PointShape intersectionPoint =
routePath.GetClosestPointTo(pointNearRoute, GeographyUnit.Meter);
EllipseShape intersectionSphere = new EllipseShape(
intersectionPoint,
10,
GeographyUnit.Meter,
ThinkGeo.MapSuite.Core.DistanceUnit.Meter);
RectangleShape intersectionRect = intersectionSphere.GetBoundingBox();
int intersectionIndex = -1;
for (int index = 0; index < routePath.Vertices.Count - 1; index++)
{
Vertex vertex0 = routePath.Vertices[index];
Vertex vertex1 = routePath.Vertices[index + 1];
LineBaseShape lineSegment = routePath.GetLineOnALine(
new PointShape(vertex0),
new PointShape(vertex1));
if ((((LineShape)lineSegment).Vertices.Count > 0) &&
lineSegment.Intersects(intersectionRect))
{
intersectionIndex = index + 1;
break;
}
}
ServiceableStop nextStopOnRoute = null;
for (int index = 0; index < route.StopIndices.Length; index++)
{
if (route.StopIndices[index] >= (intersectionIndex - 1))
{
// TODO - FirstTrip is incorrect need to rework
nextStopOnRoute = route.FirstTrip.Stops[index] as ServiceableStop;
break;
}
}
return nextStopOnRoute;
}