示例#1
0
        public void Can_Set_Stop_Geography()
        {
            // Arrange
            var stop = new Stop();
            stop.StopGeography = SqlGeography.STGeomFromText(
                new SqlChars("POLYGON((10 10, 20 10, 30 20, 10 10))"), 4326);

            // Assert
            Assert.AreNotEqual(null, stop.StopGeography);
            Assert.AreNotEqual(null, stop.StopBin);
        }
示例#2
0
        public void Can_Get_Stop_Geography()
        {
            // Arrange
            var stop = new Stop();
            stop.StopGeography = SqlGeography.STGeomFromText(
                new SqlChars("POLYGON((10 10, 20 10, 30 20, 10 10))"), 4326);

            var anotherStop = new Stop();
            anotherStop.StopBin = SqlGeography.STPolyFromText(stop.StopGeography.STAsText(), 4326).STAsBinary().Buffer;

            // Assert
            Assert.AreNotEqual(null, stop.StopGeography);
            Assert.AreNotEqual(null, anotherStop.StopGeography);
        }
示例#3
0
 /// <summary>
 /// Finds the start index.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <param name="stop">The stop.</param>
 /// <returns>Start index</returns>
 private static int FindStartIndex(Route route, Stop stop)
 {
     var result = 0;
       /* Parallel.For(1, (int) route.RouteGeography.STNumPoints() + 1, i =>
                                                                       {
                                                                           if (route.RouteGeography.STStartPoint().STDistance(stop.StopGeography)
               > route.RouteGeography.STStartPoint().STDistance(route.RouteGeography.STPointN(i)))
                                                                           {
                                                                               result = i;
                                                                           }
                                                                       });*/
     for (int j = 1; j < route.RouteGeography.STNumPoints() ; j++)
     {
         if (route.RouteGeography.STStartPoint().STDistance(stop.StopGeography)
             > route.RouteGeography.STStartPoint().STDistance(route.RouteGeography.STPointN(j)))
         {
             result = j ;
         }
     }
     return result;
 }
示例#4
0
        /// <summary>
        /// Finds the nearest stop.
        /// </summary>
        /// <param name="stops">The stops.</param>
        /// <param name="findRoute">The find route.</param>
        /// <param name="startMarker">The start marker.</param>
        /// <param name="endMarker">The end marker.</param>
        /// <returns>Neareres stop for startMarker</returns>
        private static Stop FindNearestStop(List<Stop> stops, Route findRoute, SqlGeography startMarker, SqlGeography endMarker)
        {
            var buffer = StopBuffer;
            var result = new Stop();
            var foundNearestStop = false;

            do
            {
                Parallel.For(0, stops.Count(), i =>
                                                   {
                                                       if (
                       stops[i].StopGeography.STIntersects(
                           endMarker.STBuffer(buffer)) &&
                       stops[i].StopGeography.STIntersects(findRoute.RouteGeography))
                                                       {
                                                           result = new Stop
                                                           {
                                                               Name = stops[i].Name,
                                                               StopGeography = stops[i].StopGeography.STIntersection(findRoute.RouteGeography).EnvelopeCenter()
                                                           };
                                                           foundNearestStop = true;
                                                       }
                                                   });
              /*  foreach (Stop stop in stops)
                {
                    if (
                        stop.StopGeography.STIntersects(
                            endMarker.STBuffer(buffer)) &&
                        stop.StopGeography.STIntersects(findRoute.RouteGeography))
                    {
                        result = new Stop
                        {
                            Name = stop.Name,
                            StopGeography = stop.StopGeography.STIntersection(findRoute.RouteGeography).EnvelopeCenter()
                        };
                        foundNearestStop = true;
                    }
                 }*/
                buffer += StopBuffer;
            } while (foundNearestStop == false && buffer < MaxBuffer);
            return result;
        }
示例#5
0
        /// <summary>
        /// Builds the route geography.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="endIndex">The end index.</param>
        /// <param name="nearestStop">The nearest stop.</param>
        /// <param name="furtherStop">The further stop.</param>
        /// <param name="route">The route.</param>
        /// <returns>Geography of appropriate route</returns>
        private static Route BuildRouteGeography(int startIndex,int endIndex,Stop nearestStop, Stop furtherStop,Route route)
        {
            var geographyBuilder = new SqlGeographyBuilder();
                geographyBuilder.SetSrid(4326);
                geographyBuilder.BeginGeography(OpenGisGeographyType.LineString);
                SqlGeography beginGb = nearestStop.StopGeography;
                geographyBuilder.BeginFigure((double) beginGb.Lat, (double) beginGb.Long);
                for (var j = startIndex; j <= endIndex; j++)
                {

                    var point = route.RouteGeography.STPointN(j);
                    geographyBuilder.AddLine((double) point.Lat, (double) point.Long);

                }
                SqlGeography endFigure = furtherStop.StopGeography;
                geographyBuilder.AddLine((double) endFigure.Lat, (double) endFigure.Long);
                geographyBuilder.EndFigure();
                geographyBuilder.EndGeography();
                route.RouteGeography = geographyBuilder.ConstructedGeography;

            return route;
        }
示例#6
0
 /// <summary>
 /// Gets the points from stops.
 /// </summary>
 /// <param name="stop">The route.</param>
 /// <returns>Points of stops to paint this stops on map</returns>
 private MapPoint GetPointsFromStops(Stop stop)
 {
     return stop.Points = new MapPoint((double)stop.StopGeography.Long, (double)stop.StopGeography.Lat);
 }