Beispiel #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Builds request.
        /// </summary>
        /// <param name="reqData">Route solve request data.</param>
        /// <returns>Created route solve request.</returns>
        public RouteSolveRequest BuildRequest(RouteSolveRequestData reqData)
        {
            Debug.Assert(reqData != null);

            var req = new RouteSolveRequest();

            // stops
            req.Stops = _BuildStopFeatures(reqData.Route.Stops);

            // Point barriers.
            if (reqData.PointBarriers != null)
            {
                req.PointBarriers          = new RouteRecordSet();
                req.PointBarriers.Features = reqData.PointBarriers;
            }
            // Polygon barriers.
            if (reqData.PolygonBarriers != null)
            {
                req.PolygonBarriers          = new RouteRecordSet();
                req.PolygonBarriers.Features = reqData.PolygonBarriers;
            }
            // Polyline barriers.
            if (reqData.PolylineBarriers != null)
            {
                req.PolylineBarriers          = new RouteRecordSet();
                req.PolylineBarriers.Features = reqData.PolylineBarriers;
            }

            // start time
            req.StartTime = (reqData.Route.StartTime == null) ?
                            NONE_TIME_VALUE : _FormatEpochTime(reqData.Route.StartTime.Value);

            req.ReturnDirections       = true;
            req.ReturnRoutes           = false;
            req.ReturnStops            = false;
            req.ReturnBarriers         = false;
            req.OutSR                  = GeometryConst.WKID_WGS84;
            req.IgnoreInvalidLocations = _context.SolverSettings.ExcludeRestrictedStreets;
            req.OutputLines            = Enum.GetName(typeof(NAOutputLineType),
                                                      NAOutputLineType.esriNAOutputLineTrueShapeWithMeasure);
            req.FindBestSequence          = false;
            req.PreserveFirstStop         = true;
            req.PreserveLastStop          = true;
            req.UseTimeWindows            = true;
            req.AccumulateAttributeNames  = null;
            req.ImpedanceAttributeName    = _context.NetworkDescription.ImpedanceAttributeName;
            req.RestrictionAttributeNames = _FormatRestrictions();
            req.AttributeParameters       = _FormatAttrParameters();
            req.RestrictUTurns            = _GetUTurnPolicy();
            req.UseHierarchy                 = true;
            req.DirectionsLanguage           = _GetDirLanguage();
            req.OutputGeometryPrecision      = null;
            req.OutputGeometryPrecisionUnits = null;
            NANetworkAttributeUnits unit = RequestBuildingHelper.GetDirectionsLengthUnits();

            req.DirectionsLengthUnits       = unit.ToString();
            req.DirectionsTimeAttributeName = null;
            req.OutputFormat = NAOutputFormat.JSON;

            return(req);
        }
Beispiel #2
0
        /// <summary>
        /// Creates request for solve operation.
        /// </summary>
        /// <returns>BatchRouteSolveRequest.</returns>
        /// <exception cref="RouteException">In case of Invalid routes number,
        /// routes belong to different Schedules, not set Schedule or Schedule date.
        /// </exception>
        public BatchRouteSolveRequest CreateRequest()
        {
            if (_inputParams.Routes.Count == 0)
            {
                throw new RouteException(Properties.Messages.Error_InvalidRoutesNumber);
            }

            if (_schedule == null)
            {
                throw new RouteException(Properties.Messages.Error_ScheduleNotSet);
            }

            if (_schedule.PlannedDate == null)
            {
                throw new RouteException(Properties.Messages.Error_ScheduleDateNotSet);
            }

            // Check that all routes belong to the same schedule.
            foreach (Route route in _inputParams.Routes)
            {
                if (!route.Schedule.Equals(_schedule))
                {
                    throw new RouteException(Properties.Messages.Error_RoutesBelongToDifSchedules);
                }
            }

            // Get barriers for planned date.
            ICollection <Barrier> barriers = _context.Project.Barriers.Search(
                (DateTime)_schedule.PlannedDate);

            // Convert barriers its features collections.
            GPFeature[] pointBarrierFeats    = null;
            GPFeature[] polygonBarrierFeats  = null;
            GPFeature[] polylineBarrierFeats = null;
            if (barriers != null && barriers.Count > 0)
            {
                // Get barriers with its types.
                var gpBarriers = barriers.ToLookup(BarriersConverter.DetermineBarrierType);

                // Convert barriers by type.
                pointBarrierFeats = _ConvertBarriers(gpBarriers, BarrierGeometryType.Point,
                                                     _context.NetworkDescription.NetworkAttributes);
                polygonBarrierFeats = _ConvertBarriers(gpBarriers, BarrierGeometryType.Polygon,
                                                       _context.NetworkDescription.NetworkAttributes);
                polylineBarrierFeats = _ConvertBarriers(gpBarriers, BarrierGeometryType.Polyline,
                                                        _context.NetworkDescription.NetworkAttributes);
            }

            // Create request data.
            List <DirRouteData> dirRoutes = _GetDirRoutes(_inputParams.Routes);

            // Build request.
            RouteRequestBuilder builder = new RouteRequestBuilder(
                _context);

            List <RouteSolveRequest> requests = new List <RouteSolveRequest>();

            foreach (DirRouteData dirRoute in dirRoutes)
            {
                RouteSolveRequestData reqData = new RouteSolveRequestData();
                reqData.Route            = dirRoute;
                reqData.PointBarriers    = pointBarrierFeats;
                reqData.PolygonBarriers  = polygonBarrierFeats;
                reqData.PolylineBarriers = polylineBarrierFeats;

                RouteSolveRequest req = builder.BuildRequest(reqData);

                // Check if we have at least 2 stops.
                if (req.Stops.Features.Length > 1)
                {
                    requests.Add(req);
                }
            }

            return(new BatchRouteSolveRequest(requests.ToArray()));
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Builds request.
        /// </summary>
        /// <param name="reqData">Route solve request data.</param>
        /// <returns>Created route solve request.</returns>
        public RouteSolveRequest BuildRequest(RouteSolveRequestData reqData)
        {
            Debug.Assert(reqData != null);

            var req = new RouteSolveRequest();

            // stops
            req.Stops = _BuildStopFeatures(reqData.Route.Stops);

            // Point barriers.
            if (reqData.PointBarriers != null)
            {
                req.PointBarriers = new RouteRecordSet();
                req.PointBarriers.Features = reqData.PointBarriers;
            }
            // Polygon barriers.
            if (reqData.PolygonBarriers != null)
            {
                req.PolygonBarriers = new RouteRecordSet();
                req.PolygonBarriers.Features = reqData.PolygonBarriers;
            }
            // Polyline barriers.
            if (reqData.PolylineBarriers != null)
            {
                req.PolylineBarriers = new RouteRecordSet();
                req.PolylineBarriers.Features = reqData.PolylineBarriers;
            }

            // start time
            req.StartTime = (reqData.Route.StartTime == null) ?
                                NONE_TIME_VALUE : _FormatEpochTime(reqData.Route.StartTime.Value);

            req.ReturnDirections = true;
            req.ReturnRoutes = false;
            req.ReturnStops = false;
            req.ReturnBarriers = false;
            req.OutSR = GeometryConst.WKID_WGS84;
            req.IgnoreInvalidLocations = _context.SolverSettings.ExcludeRestrictedStreets;
            req.OutputLines = Enum.GetName(typeof(NAOutputLineType),
                NAOutputLineType.esriNAOutputLineTrueShapeWithMeasure);
            req.FindBestSequence = false;
            req.PreserveFirstStop = true;
            req.PreserveLastStop = true;
            req.UseTimeWindows = true;
            req.AccumulateAttributeNames = null;
            req.ImpedanceAttributeName = _context.NetworkDescription.ImpedanceAttributeName;
            req.RestrictionAttributeNames = _FormatRestrictions();
            req.AttributeParameters = _FormatAttrParameters();
            req.RestrictUTurns = _GetUTurnPolicy();
            req.UseHierarchy = true;
            req.DirectionsLanguage = _GetDirLanguage();
            req.OutputGeometryPrecision = null;
            req.OutputGeometryPrecisionUnits = null;
            NANetworkAttributeUnits unit = RequestBuildingHelper.GetDirectionsLengthUnits();
            req.DirectionsLengthUnits = unit.ToString();
            req.DirectionsTimeAttributeName = null;
            req.OutputFormat = NAOutputFormat.JSON;

            return req;
        }