Hi,
Does this component supports turn restrictions(prohibited maneuvers) ?
Hi,
Does this component supports turn restrictions(prohibited maneuvers) ?
Federico,
Yes we can support turn restrictions in two different way. The first way is while building the index one the building event for each node you can interrogate the data to find the turn restriction and then leave off the adjacent node that is restricted. The second way is very similar but you can do it while the routing is happening in real-time. It is similar to the first except you are doing it during runtime and not during the building of the index. Each has its advantage. Doing it during the index build means faster route times as it is pre-determined. Doing the restriction during runtime is slower but allows for dynamic changes. If for example you want to add a turn restriction on the fly this would be the way to handle it. You could also do a combination of both. I am posting some sample code below to show you both ways and we will add this to our samples. Thanks for pointing this out.
David
• Use the BuildingRoutingData event when generate routing data
private void RtgRoutingSource_BuildingRoadData(object sender, BuildingRoutingDataRtgRoutingSourceEventArgs e)
{
featureSource.Open();
Feature feature = featureSource.GetFeatureById(e.LineShape.Id, new string[] { "TurnRestrictions" });
string turnRestrictions = feature.ColumnValues["TurnRestrictions"];
// Pass in current lineShape and get the adjacent lineShapes by feature ids from feature source, calculate turn directions.
Dictionary<string, DrivingDirection> directions = GetAdjacentDirections(e.LineShape, e.RouteSegment.StartPointAdjacentIds, featureSource);
if (turnRestrictions == "Right")
{
foreach (var item in directions.Keys)
{
if (directions[item] == DrivingDirection.Right)
{
e.RouteSegment.StartPointAdjacentIds.Remove(item);
e.RouteSegment.EndPointAdjacentIds.Remove(item);
}
}
}
else if (turnRestrictions == "Left")
{
foreach (var item in directions.Keys)
{
if (directions[item] == DrivingDirection.Left)
{
e.RouteSegment.StartPointAdjacentIds.Remove(item);
e.RouteSegment.EndPointAdjacentIds.Remove(item);
}
}
}
}
• Use the FindingRoute event when get route
private void Algorithm_FindingPath(object sender, FindingRouteRoutingAlgorithmEventArgs e)
{
featureSource.Open();
Feature feature = featureSource.GetFeatureById(e.RouteSegment.FeatureId, new string[] { "TurnRestrictions" });
string turnRestrictions = feature.ColumnValues["TurnRestrictions"];
// Pass in current lineShape and get the adjacent lineShapes by feature ids from feature source, calculate turn directions.
Dictionary<string, DrivingDirection> directions = GetAdjacentDirections((LineShape)feature.GetShape(), e.RouteSegment.StartPointAdjacentIds, featureSource);
if (turnRestrictions == "Right")
{
foreach (var item in directions.Keys)
{
if (directions[item] == DrivingDirection.Right)
{
e.RouteSegment.StartPointAdjacentIds.Remove(item);
e.RouteSegment.EndPointAdjacentIds.Remove(item);
}
}
}
else if (turnRestrictions == "Left")
{
foreach (var item in directions.Keys)
{
if (directions[item] == DrivingDirection.Left)
{
e.RouteSegment.StartPointAdjacentIds.Remove(item);
e.RouteSegment.EndPointAdjacentIds.Remove(item);
}
}
}
}