Ejemplo n.º 1
0
        /// <summary>
        /// Gets the stops in view model.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>Valid stops </returns>
        private static List<SimpleStop> GetStopsInViewModel(Route route)
        {
            var stops = route.Stops.Select(stop => new SimpleStop()
            {
                Name = stop.Name,
                Points = stop.Points
            }).ToList();

            return stops;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the summary walking distance.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>Summary walking distance in route</returns>
        private static double GetSummaryWalkingDistance(Route route)
        {
            var summaryDistance = route.WalkingRoutes.Sum(walk => walk.Length);

            return summaryDistance;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the walking routes in view model.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>Valid walking routes</returns>
        private static List<SimpleWalkingRoute> GetWalkingRoutesInViewModel(Route route)
        {
            var walkingRoutes = route.WalkingRoutes.Select(walk => new SimpleWalkingRoute()
            {
                Name = walk.Name,
                Length = DimensionConverter.GetRoundDistance(walk.Length),
                MapPoints = walk.MapPoints,
                Speed = walk.Speed,
                Steps = walk.Steps,
                Time = DimensionConverter.GetRoundTime(walk.Time),
                Type = walk.Type,
            }).ToList();

            return walkingRoutes;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Intersections the specified route.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <param name="startMarker">The start marker.</param>
 /// <param name="endMarker">The end marker.</param>
 /// <returns>return bool value of intersections for routes</returns>
 private bool Intersection(Route route, SqlGeography startMarker, SqlGeography endMarker)
 {
     return (bool)route.RouteGeography.STIntersects(startMarker.STBuffer(GeneralSettings.RouteRadiusSeach))
            && (bool)route.RouteGeography.STIntersects(endMarker.STBuffer(GeneralSettings.RouteRadiusSeach));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Sorts the stops.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>Sorting list of stops</returns>
        private List<Stop> SortStops(Route route)
        {
            for (var i = route.Stops.Count - 1; i > 0; i--)
            {
                for (var j = 0; j < i; j++)
                {
                    if (route.RouteGeography.STStartPoint().STDistance(route.Stops[j].StopGeography)
                        >= route.RouteGeography.STStartPoint().STDistance(route.Stops[j + 1].StopGeography))
                    {
                        var temp = route.Stops[j];
                        route.Stops[j] = route.Stops[j + 1];
                        route.Stops[j + 1] = temp;
                    }
                }
            }

            return route.Stops as List<Stop>;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the time.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>
        /// Summary time of route
        /// </returns>
        private TimeSpan GetSumamryTime(Route route)
        {
            double walkLength = route.WalkingRoutes.Sum(walkingRoute => walkingRoute.Length);
            var walkTime = this.GetTimeInMinutes(GeneralSettings.WalkingSpeed, walkLength);

            return
                TimeSpan.FromMinutes(
                    this.GetTimeInMinutes(route.Speed, route.Length, (int)route.WaitingTime.TotalMinutes) + walkTime);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the walking route.
        /// </summary>
        /// <param name="startPoint">The start point.</param>
        /// <param name="endPoint">The end point.</param>
        /// <param name="invalidDirections">The invalid directions.</param>
        /// <param name="validWords">The valid words.</param>
        /// <param name="invalidWords">The invalid words.</param>
        /// <returns>
        /// Walking route
        /// </returns>
        private Route GetWalkingRoute(
            SqlGeography startPoint, 
            SqlGeography endPoint,
            IEnumerable<string> invalidDirections,
            IEnumerable<string> validWords,
            IEnumerable<string> invalidWords 
            )
        {
            var urlForDirection = GoogleMapHelper.CreateUrlForDirectionRequest(
                GeneralSettings.GoogleApiKey, startPoint, endPoint);
            var responce = GoogleMapHelper.GetResponceFromGoogleApi(urlForDirection);
            var polyline = (List<MapPoint>)GoogleMapHelper.GetSummaryPolyline(responce);
            var summaryDistance = GoogleMapHelper.GetDistanceOfDirection(responce);
            var summaryTime = this.GetTimeInMinutes(GeneralSettings.WalkingSpeed, summaryDistance);
            var walkingType = new TransportType { Type = "Walking" };
            var walkingRoute = new Route
            {
                Name = string.Empty,
                MapPoints = polyline,
                RouteType = (int)Transport.Walking,
                Speed = GeneralSettings.WalkingSpeed,
                Time = TimeSpan.FromMinutes(summaryTime),
                Stops = new List<Stop>(),
                Type = walkingType,
                Steps = GoogleMapHelper.GetStepsOfDirection(responce,invalidDirections,validWords,invalidWords),
                Length = GoogleMapHelper.GetDistanceOfDirection(responce)
            };

            return walkingRoute;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the length of the route.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>Length of route</returns>
        private double GetRouteLength(Route route)
        {
            double length = 0;
            for (var i = 1; i < route.CurrentPath.STNumPoints(); i++)
            {
                length += (double)route.CurrentPath.STPointN(i).STDistance(route.CurrentPath.STPointN(i + 1));
            }

            return length;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Finds the start stop.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <param name="marker">The marker.</param>
        /// <returns>Geography of stop</returns>
        private Stop GetStop(Route route, SqlGeography marker)
        {
            Stop result = route.Stops[0];

            foreach (Stop stop in route.Stops)
            {
                if (stop.StopGeography.STDistance(marker) < result.StopGeography.STDistance(marker))
                {
                    result = stop;
                }
            }

            List<Stop> possibleStops =
                route.Stops.Where(stop => (bool)result.StopGeography.STBuffer(GeneralSettings.MaxStopRadiusSeach).STIntersects(stop.StopGeography)).ToList();
            var urlForDistanceMatrix = GoogleMapHelper.CreateUrlForDisntanceMatrixRequest(
                GeneralSettings.GoogleApiKey, marker, possibleStops);
            var responce = GoogleMapHelper.GetResponceFromGoogleApi(urlForDistanceMatrix);
            var distances = GoogleMapHelper.GetMatrixOfDistanceForOneStop(responce);
            if (distances.Count != 0)
            {
                var index = distances.IndexOf(distances.Min(stop => stop));
                return possibleStops[index];
            }
            else
            {
                return result;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the possible stop.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <param name="marker">The marker.</param>
        /// <returns>Possible stop of route.</returns>
        private Stop GetPossibleStop(Route route, SqlGeography marker)
        {
            Stop result = route.Stops[0];

            foreach (Stop stop in route.Stops)
            {
                if (stop.StopGeography.STDistance(marker) < result.StopGeography.STDistance(marker))
                {
                    result = stop;
                }
            }

            return result;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the route in points.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>Points for paint route on map</returns>
        private List<MapPoint> GetRouteInPoints(Route route)
        {
            var result = new List<MapPoint>();

            for (int i = 1; i <= route.CurrentPath.STNumPoints(); i++)
            {
                var point = route.CurrentPath.STPointN(i);
                result.Add(new MapPoint((double)point.Long, (double)point.Lat));
            }

            return result;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the index of the path.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <param name="point">The point.</param>
        /// <returns>Index for rechenge route</returns>
        private int GetPathIndex(Route route, SqlGeography point)
        {
            int position = 1;

            for (int i = 1; i < route.RouteGeography.STNumPoints(); i++)
            {
                position++;
                if (route.RouteGeography.STPointN(i).STDistance(point) <= GeneralSettings.MaxFindIndexDeflection)
                {
                    break;
                }
            }

            return position;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the length of part route.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>
        /// Length of part route.
        /// </returns>
        private double GetLengthOfPartRoute(Route route)
        {
            double length = 0;
            for (var i = route.StartRouteIndex; i < route.EndRouteIndex; i++)
            {
                length += (double)route.RouteGeography.STPointN(i).STDistance(route.RouteGeography.STPointN(i + 1));
            }

            return length;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the cross stops.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>
        /// Route with new cross stops
        /// </returns>
        private Route GetCrossStops(Route route)
        {
            var crossStops = new List<Stop>();
            crossStops.AddRange(
                route.Stops.Where(stop => (bool)stop.StopGeography.STBuffer(1).STIntersects(route.CurrentPath)));
            route.Stops = crossStops;
            route.Stops = this.SortStops(route);

            return route;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Adds the walking steps to route.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <param name="startMarker">The start marker.</param>
        /// <param name="endMarker">The end marker.</param>
        /// <returns>
        /// Route with walking steps
        /// </returns>
        private Route BuildRouteProperties(
            Route route, 
            SqlGeography startMarker,
            SqlGeography endMarker,
            IEnumerable<string> invalidDirections,
            IEnumerable<string> validWords,
            IEnumerable<string> invalidWords 
            )
        {
            if (!route.Type.Type.Equals("Walking"))
            {
                route = this.GetCrossStops(route);
                route.Length = this.GetRouteLength(route);
                route.MapPoints = this.GetRouteInPoints(route);
                route.WalkingRoutes = new List<WalkingRoute>
                    {
                        this.GetWalkingStepsForRoute(
                            endMarker, route.StartStop.StopGeography, invalidDirections, validWords, invalidWords),
                        this.GetWalkingStepsForRoute(
                            route.EndStop.StopGeography, startMarker, invalidDirections, validWords, invalidWords)
                    };
                route.Time = this.GetSumamryTime(route);
                route.RouteTime = TimeSpan.FromMinutes(this.GetTimeInMinutes(route.Speed, route.Length));
                route.Stops.Select(this.GetPointsFromStops).ToList();
            }

            return route;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Builds the route geography.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>
        /// New route geography
        /// </returns>
        private Route BuildRouteGeography(Route route)
        {
            var routeBuilder = new SqlGeographyBuilder();
            routeBuilder.SetSrid(4326);
            routeBuilder.BeginGeography(OpenGisGeographyType.LineString);
            SqlGeography beginPoint = route.StartStop.StopGeography;
            routeBuilder.BeginFigure((double)beginPoint.Lat, (double)beginPoint.Long);

            for (var j = route.StartRouteIndex; j <= route.EndRouteIndex; j++)
            {
                var point = route.RouteGeography.STPointN(j);
                routeBuilder.AddLine((double)point.Lat, (double)point.Long);
            }

            SqlGeography endPoint = route.EndStop.StopGeography;
            routeBuilder.AddLine((double)endPoint.Lat, (double)endPoint.Long);

            routeBuilder.EndFigure();
            routeBuilder.EndGeography();
            route.CurrentPath = routeBuilder.ConstructedGeography;

            return route;
        }