public static async Task <shPath> FindShortPathWithArrayNodes(string ScenarioId, int[] arrNodeId, enOSMhighwayFilter[] arrHighwayFilter) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // string strUri = "api/Routing/FindShortPathWithArrayNodes?ScenarioId=" + ScenarioId + "&highwayFilter=" + (int)highwayFilter + "&x=" + x + "&y=" + y + "&NodeidFromTo=" + NodeidFromTo + "&isPointFrom=" + isPointFrom; ArrNodes nodes = new ArrNodes(); nodes.ScenarioId = ScenarioId; nodes.arrNodeId = arrNodeId; nodes.arrHighwayFilter = arrHighwayFilter; HttpResponseMessage response = await client.PostAsJsonAsync <ArrNodes>("api/Routing/FindShortPathWithArrayNodes/", nodes); //FindShortPathWithArrayNodes if (response.StatusCode != System.Net.HttpStatusCode.OK) { return(null); } HttpContent content = response.Content; string v = await content.ReadAsStringAsync(); // shPath tmp = null; shPath tmp = JsonConvert.DeserializeObject <shPath>(v); return(tmp); } }
public static async Task <shPath> FindShortPath(string ScenarioId, double StartX, double StartY, double DestinationX, double DestinationY, bool isPriorityAboveNormal) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string strUri = "api/Routing/FindShortPath?ScenarioId=" + ScenarioId + "&StartX=" + StartX + "&StartY=" + StartY + "&DestinationX=" + DestinationX + "&DestinationY=" + DestinationY + "&isPriorityAboveNormal=" + isPriorityAboveNormal; HttpResponseMessage response = null; try { response = await client.GetAsync(strUri); if (response.StatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine("NOT OK: " + response.StatusCode.ToString()); return(null); } } catch (System.Net.WebException e) { return(null); } catch (TaskCanceledException e) { return(null); } catch (Exception e) { return(null); } HttpContent content = response.Content; string v = await content.ReadAsStringAsync(); shPath tmp = JsonConvert.DeserializeObject <shPath>(v); return(tmp); } } catch (Exception ex) { } return(null); }
// Yinon Douchan: Only find the shortest path between two points. public async Task <typRoute> createRouteByShortestPathOnly(double StartX, double StartY, double ReferencePointX, double ReferencePointY) { List <DPoint> Result = new List <DPoint>(); DPoint ReferPoint = new DPoint(ReferencePointX, ReferencePointY); shPath Path = await clsRoadRoutingWebApi.FindShortPath("0", StartX, StartY, ReferencePointX, ReferencePointY, false); if (Path != null && Path.Points.Count > 0) { shPoint refPoint = Path.Points[Path.Points.Count - 1]; ReferPoint = new DPoint(refPoint.x, refPoint.y); foreach (shPoint p in Path.Points) { Result.Add(new DPoint(p.x, p.y)); } } if (Result.Count == 0) { Result.Add(new DPoint(StartX, StartY)); } else { if (Result[0].x != StartX || Result[0].y != StartY) { Result.Insert(0, new DPoint(StartX, StartY)); } } Route routeResult = new Route(); routeResult.Points = Result; typRoute tRoute = new typRoute(routeResult); return(tRoute); }
public async Task <typRoute> CreateRoute(double StartX, double StartY, double ReferencePointX, double ReferencePointY, string RouteGuid) { try { List <DPoint> Result = new List <DPoint>(); Route route = TDS.DAL.RoutesDB.GetRouteByGuid(RouteGuid); DPoint ReferPoint = new DPoint(ReferencePointX, ReferencePointY); shPath Path = await clsRoadRoutingWebApi.FindShortPath("0", StartX, StartY, ReferencePointX, ReferencePointY, false); if (Path != null && Path.Points.Count > 0) { shPoint refPoint = Path.Points[Path.Points.Count - 1]; ReferPoint = new DPoint(refPoint.x, refPoint.y); foreach (shPoint p in Path.Points) { Result.Add(new DPoint(p.x, p.y)); } } if (Result.Count == 0) { Result.Add(new DPoint(StartX, StartY)); } else { if (Result[0].x != StartX || Result[0].y != StartY) { Result.Insert(0, new DPoint(StartX, StartY)); } } int leg = 0; DPoint minP = null; double mainDist = double.MaxValue; int i = -1; foreach (DPoint p in route.Points) { i++; // double dist = MathEngine.CalcDistanceForCompare(ReferPoint.x, ReferPoint.y, p.x, p.y); double dist = MathEngine.GreatCircleDistance(ReferPoint.x, ReferPoint.y, p.x, p.y); if (dist < mainDist) { mainDist = dist; minP = p; leg = i; } } if (mainDist != 0.0) { List <DPoint> R = route.Points.ToList <DPoint>().GetRange(leg, route.Points.Count() - leg); Result.AddRange(R); } else { if (leg < route.Points.Count() - 1) // Not Last element { List <DPoint> R = route.Points.ToList <DPoint>().GetRange(leg + 1, route.Points.Count() - (leg + 1)); Result.AddRange(R); } } Route routeResult = new Route(); routeResult.Points = Result; typRoute tRoute = new typRoute(routeResult); return(tRoute); } catch (Exception ex) { } return(null); }