Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        /// Check if given direction is for Break.
        /// </summary>
        /// <param name="dirs">Directions list.</param>
        /// <returns>True - if it is Break Direction, otherwise - false.</returns>
        private static bool _IsBreakDirection(DirectionEx[] dirs)
        {
            Debug.Assert(dirs != null);

            bool result = false;

            if (dirs.Length > 0)
            {
                // Check arrive direction.
                DirectionEx dir = dirs.Last();

                string breakPropertyName =
                    (string)Properties.Resources.BreakDirectionName;

                result = dir.Text.Contains(breakPropertyName);
            }

            return(result);
        }