예제 #1
0
        /// <summary>
        /// Gets location of the specified stop.
        /// </summary>
        /// <param name="stop">The reference to stop to get location for.</param>
        /// <param name="sortedRouteStops">The collection of route stops sorted by their
        /// sequence numbers for the route containing the <paramref name="stop"/>.</param>
        /// <returns></returns>
        private static Point _GetStopLocation(Stop stop, IList <Stop> sortedRouteStops)
        {
            Debug.Assert(stop != null);
            Debug.Assert(sortedRouteStops != null);
            Debug.Assert(sortedRouteStops.All(item => item != null));
            Debug.Assert(sortedRouteStops.All(item => item.Route == stop.Route));

            var mapLocation = stop.MapLocation;

            if (mapLocation.HasValue)
            {
                return(mapLocation.Value);
            }

            if (stop.StopType != StopType.Lunch)
            {
                throw new InvalidOperationException(
                          Properties.Messages.Error_GrfExporterNoLocationForStop); // exception
            }

            // find stop index in collection
            var firstStopIndex   = sortedRouteStops.First().SequenceNumber;
            var currentIndex     = stop.SequenceNumber - firstStopIndex;
            var stopWithLocation = SolveHelper.GetActualLunchStop(sortedRouteStops, currentIndex);

            if (!stopWithLocation.MapLocation.HasValue)
            {
                throw new InvalidOperationException(
                          Properties.Messages.Error_GrfExporterNoLocationForStop); // exception
            }

            return(stopWithLocation.MapLocation.Value);
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Builds stop features.
        /// </summary>
        /// <param name="stops">Stops.</param>
        /// <returns>Created route stops recordset for stops.</returns>
        private RouteStopsRecordSet _BuildStopFeatures(IList <StopData> stops)
        {
            Debug.Assert(stops != null);

            // Sort stops respecting sequence.
            var sortedStops = new List <StopData>(stops);

            SolveHelper.SortBySequence(sortedStops);

            Debug.Assert(_context != null);

            SolveHelper.ConsiderArrivalDelayInStops(
                _context.SolverSettings.ArriveDepartDelay, sortedStops);

            // Format impedance attribute name.
            string impedanceAttrName = null;

            if (!string.IsNullOrEmpty(_context.NetworkDescription.ImpedanceAttributeName))
            {
                impedanceAttrName = string.Format(IMPEDANCE_ATTR_FORMAT,
                                                  _context.NetworkDescription.ImpedanceAttributeName);
            }

            var features = new List <GPFeature>();

            for (int index = 0; index < sortedStops.Count; ++index)
            {
                var feature = new GPFeature();

                // Attributes.
                feature.Attributes = new AttrDictionary();

                StopData sd = sortedStops[index];

                Guid objectId = Guid.Empty;
                if (sd.AssociatedObject != null)
                {
                    objectId = sd.AssociatedObject.Id;
                }

                feature.Attributes.Add(NAAttribute.NAME, objectId.ToString());
                feature.Attributes.Add(NAAttribute.ROUTE_NAME, sd.RouteId.ToString());

                // Effective time window.
                DateTime?twStart = null;
                DateTime?twEnd   = null;
                _GetEffectiveTW(sd, out twStart, out twEnd); // NOTE: ignore result
                feature.Attributes.Add(NAAttribute.TW_START, _FormatStopTime(twStart));
                feature.Attributes.Add(NAAttribute.TW_END, _FormatStopTime(twEnd));

                // Service time.
                if (impedanceAttrName != null)
                {
                    feature.Attributes.Add(impedanceAttrName, sd.TimeAtStop);
                }

                var geometry = new GeometryHolder();
                geometry.Value = sd.Geometry;

                if (sd.StopType == StopType.Lunch)
                {
                    var actualStop = SolveHelper.GetActualLunchStop(sortedStops, index);
                    geometry.Value = actualStop.Geometry;
                }

                // Set curb approach.
                var curbApproach = CurbApproachConverter.ToNACurbApproach(
                    _context.SolverSettings.GetOrderCurbApproach());
                if (sd.StopType == StopType.Location)
                {
                    curbApproach = CurbApproachConverter.ToNACurbApproach(
                        _context.SolverSettings.GetDepotCurbApproach());
                }

                feature.Attributes.Add(NAAttribute.CURB_APPROACH, (int)curbApproach);
                feature.Geometry = geometry;

                features.Add(feature);
            }

            var rs = new RouteStopsRecordSet();

            rs.Features = features.ToArray();

            // TODO: will be changed later when support custom AddLocations tool
            rs.DoNotLocateOnRestrictedElements = _context.SolverSettings.ExcludeRestrictedStreets;

            return(rs);
        }