private bool _FindTargetFeature(GPFeatureRecordSetLayer orders, Order order, out GPFeature orderFeature) { orderFeature = null; bool found = false; foreach (GPFeature feature in orders.Features) { string idStr = null; if (feature.Attributes.TryGet <string>(NAAttribute.NAME, out idStr)) { Guid id = new Guid(idStr); if (id == order.Id) { orderFeature = feature; found = true; break; } } } return(found); }
/// <summary> /// Convert collection of Barriers to GPFeature collection of specified type. /// </summary> /// <param name="barrier">Barriers collection to convert.</param> /// param name="type">Type of barriers to convert in.</param> /// <returns>GPFeature of specified type. barrier.</returns> private GPFeature _ConvertBarrier(Barrier barrier, BarrierGeometryType type) { Debug.Assert(barrier != null); GPFeature feature = new GPFeature(); if (type == BarrierGeometryType.Point) { feature = _ConvertToPointFeature(barrier); } else if (type == BarrierGeometryType.Polygon) { feature = _ConvertToPolygonFeature(barrier); } else if (type == BarrierGeometryType.Polyline) { feature = _ConvertToPolylineFeature(barrier); } else { // Not supported. Debug.Assert(false); } return(feature); }
private static bool _IsSpecBelongToRoute(Guid specId, GPFeature rtFeature) { Guid routeSpecId; return(_AttrToObjectId(NAAttribute.SPECIALTY_NAMES, rtFeature.Attributes, out routeSpecId) && routeSpecId == specId); }
/// <summary> /// Converts the specified feature to the <see cref="Direction"/> value. /// </summary> /// <param name="feature">The reference to the feature to be converted.</param> /// <returns>A new <see cref="Direction"/> value corresponding to the /// <paramref name="feature"/>.</returns> public static DirectionEx ConvertToDirection(GPFeature feature) { Debug.Assert(feature != null); var direction = new DirectionEx { DirectionType = ArcLogistics.DirectionType.ManeuverDirection, Length = feature.Attributes.Get <double>(NAAttribute.DirectionsDriveDistance), Text = feature.Attributes.Get <string>(NAAttribute.DirectionsText), }; var geometry = default(IEnumerable <Point>); Debug.Assert(feature.Geometry != null && feature.Geometry.Value != null); var points = (GPPolyline)feature.Geometry.Value; var allPoints = points.Paths.SelectMany(Identity); var haveMCoordinate = allPoints.All(point => point.Length == 3); if (haveMCoordinate) { geometry = allPoints.Select(point => new Point(point[0], point[1], point[2])); } else { geometry = allPoints.Select(point => new Point(point[0], point[1])); } direction.Geometry = CompactGeometryConverter.Convert(geometry); // Read maneuver type and drive time. var type = NADirectionsManeuverType.esriDMTUnknown; var subItemType = feature.Attributes.Get <NADirectionsSubItemType>( NAAttribute.DirectionsSubItemType); if (subItemType == NADirectionsSubItemType.ManeuverItem) { type = feature.Attributes.Get <NADirectionsManeuverType>( NAAttribute.DirectionsStringType); // Elapsed time is equal to drive time for maneuver direction items which are // not arrive/depart ones. if (type != NADirectionsManeuverType.esriDMTStop && type != NADirectionsManeuverType.esriDMTDepart) { direction.Time = feature.Attributes.Get <double>( NAAttribute.DirectionsElapsedTime); } } else { direction.DirectionType = DirectionType.Other; } direction.ManeuverType = _ConvertManeuverType(type); return(direction); }
/// <summary> /// Convert Point Barrier into GPFeature. /// </summary> /// <param name="barrier">Barrier to convert</param> /// <returns>Point barrier GPFeature</returns> private GPFeature _ConvertToPointFeature(Barrier barrier) { Debug.Assert(barrier != null); GPFeature feature = new GPFeature(); feature.Geometry = new GeometryHolder(); // Convert geometry. feature.Geometry.Value = GPObjectHelper.PointToGPPoint((Point)barrier.Geometry); // Fill attributes. feature.Attributes = _GetAttributes(barrier, BarrierGeometryType.Point); return(feature); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <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); }
/// <summary> /// Method do conversion of separate route Breaks to GP Breaks collection. /// </summary> /// <param name="routeBreaks">Route breaks.</param> /// <param name="route">Route, to which breaks belong to.</param> /// <param name="addSequence">Flag, showing that we must add /// sequence attribute to break GP feature.</param> /// <returns>GP Breaks collection.</returns> private List <GPFeature> _ConvertToGPBreaks(Breaks routeBreaks, Route route, bool addSequence) { Debug.Assert(routeBreaks != null); Debug.Assert(route != null); List <GPFeature> features = new List <GPFeature>(); routeBreaks.Sort(); // Precedence should always start from 1. int precedence = 1; double cumulBreakServiceTime = 0; // Get feature collections of route breaks. foreach (Break currentBreak in routeBreaks) { GPFeature feature = new GPFeature(); AttrDictionary attrs = new AttrDictionary(); if ((currentBreak != null) && (currentBreak.Duration > 0.0)) { // Get specific attributes for every break type. if (currentBreak is TimeWindowBreak) { attrs = _GetTimeWindowBreakAttributes(currentBreak); } else if (currentBreak is DriveTimeBreak) { DriveTimeBreak driveTimeBreak = currentBreak as DriveTimeBreak; attrs = _GetDriveTimeBreakAttributes(driveTimeBreak, ref cumulBreakServiceTime); } else if (currentBreak is WorkTimeBreak) { WorkTimeBreak workTimeBreak = currentBreak as WorkTimeBreak; attrs = _GetWorkTimeBreakAttributes(workTimeBreak); } else { // Unsupported breaks type. Debug.Assert(false); } // Get common attributes. _FillCommonGPBreakAttributes(route.Id, precedence++, attrs); // Add sequence atribute if we must to. if (addSequence) { var sequenceNumber = _GetSequenceNumber(route, currentBreak); attrs.Add(NAAttribute.SEQUENCE, sequenceNumber); } feature.Attributes = attrs; } features.Add(feature); } return(features); }