Ejemplo n.º 1
0
 public ActionResult <RouteSearchResponseDTO> Post([FromBody] RouteSearchRequestDTO request)
 {
     //return new RouteSearchResponseDTO(500, "NO no NO");
     try
     {
         return(_searchEngine.FindRoute2(request));
     }
     catch (Exception e)
     {
         return(new RouteSearchResponseDTO(500, e.Message));
     }
 }
Ejemplo n.º 2
0
        public RouteSearchResponseDTO FindRoute(RouteSearchRequestDTO request)
        {
            var requestJson = JsonConvert.SerializeObject(request);

            var loadedData = Loader.Load(
                request.ToLoadRequest()
                );

            var graph = new Graph(loadedData.AllFeatures, request.SearchOptions);

            if (request.Points.Length == 0)
            {
                var path = graph.FindShortestPath(
                    loadedData.StartFeature,
                    loadedData.EndFeature,
                    null);

                var route = PathToRoute(path,
                                        new PointPosition
                {
                    Latitude  = request.Start.Lat,
                    Longitude = request.Start.Lng
                },
                                        new PointPosition
                {
                    Latitude  = request.End.Lat,
                    Longitude = request.End.Lng
                });

                return(new RouteSearchResponseDTO(new[] { route }));
            }
            else
            {
                var route = FindRoute(new RouteRequest()
                {
                    Request = request,
                    Graph   = graph,
                    Data    = loadedData
                });


                return(new RouteSearchResponseDTO(new[] { route }));
            }
        }
Ejemplo n.º 3
0
        private void CheckIfAllPoinsInsidePolygon(RouteSearchRequestDTO request)
        {
            var polygon = request.PolygonPoints.Select(x => x.ToDoubleArray()).ToArray();

            foreach (var p in request.Points)
            {
                if (!DistanceHelpers.IsInside(p.ToDoubleArray(), polygon))
                {
                    throw  new Exception("Ne visi tarpiniai taškai patenka į apibrėžtą poligoną");
                }
            }

            if (!DistanceHelpers.IsInside(request.Start.ToDoubleArray(), polygon))
            {
                throw new Exception("Pradžia nepatenka į apibrėžtą poligoną");
            }

            if (!DistanceHelpers.IsInside(request.End.ToDoubleArray(), polygon))
            {
                throw new Exception("Pabaiga nepatenka į apibrėžtą poligoną");
            }
        }
Ejemplo n.º 4
0
        public RouteSearchResponseDTO FindRoute2(RouteSearchRequestDTO request)
        {
            if (request.Start == null)
            {
                throw new Exception("Maršruto pradžios taškas turi būti nurodytas");
            }

            if (request.End == null)
            {
                throw new Exception("Maršruto pabaigos taškas turi būti nurodytas");
            }

            if (request.PolygonPoints.Length < 4)
            {
                throw new Exception("Turėtų būti bent 3 duomenų ribokliai");
            }


            CheckIfAllPoinsInsidePolygon(request);


            var line = new[] { request.Start.ToDoubleArray() }.Concat(request.Points.Select(x => x.ToDoubleArray()))
            .Concat(new[] { request.End.ToDoubleArray() }).ToArray();

            var segments = DistanceHelpers.SplitFeatureIntoLineSegments(line);

            var usedFeatures = new List <RouteFeature>();

            RouteDTO route = null;

            foreach (var s in segments)
            {
                var loadedData = Loader.LoadDataBetweenTwoPoints(s.Item1, s.Item2, request.PolygonPoints.Select(x => x.ToDoubleArray()).ToArray());

                var graph = new Graph(loadedData.AllFeatures, request.SearchOptions);

                var path = graph.FindShortestPath(loadedData.StartFeature, loadedData.EndFeature, usedFeatures);


                if (path == null)
                {
                    throw  new Exception("Kelias nerastas");
                }

                usedFeatures.AddRange(path);

                var tempRoute = PathToRoute(path,
                                            new PointPosition
                {
                    Latitude  = s.Item1[1],
                    Longitude = s.Item1[0]
                },
                                            new PointPosition
                {
                    Latitude  = s.Item2[1],
                    Longitude = s.Item2[0]
                });

                route = MergeTwoRoutes(route, tempRoute);
            }

            RecalculateLength(route);

            return(new RouteSearchResponseDTO(new[] { route }));
        }