Exemplo n.º 1
0
        /// <summary>
        /// Method converts collection of Barriers into GPFeature collection of
        /// BarrierGeometryType type.
        /// </summary>
        /// <param name="barriersByTypes">Typed Barriers collection.</param>
        /// <param name="type">Type to convert.</param>
        /// <param name="attributes">Network attributes used to get barrier attributes.</param>
        /// <returns>GPFeature collection of specified barriers type.</returns>
        private static GPFeature[] _ConvertBarriers(ILookup <BarrierGeometryType, Barrier> barriersByTypes,
                                                    BarrierGeometryType type, IEnumerable <NetworkAttribute> attributes)
        {
            Debug.Assert(barriersByTypes != null);

            // Convert Lookup Table of barriers to enumerable
            // collection of Barriers of specified type.
            var barriers = barriersByTypes[type];

            GPFeature[] result = null;

            // Convert barriers to GPFeatures.
            BarriersConverter converter = new BarriersConverter(attributes);

            // Convert barrier by its type.
            if (type == BarrierGeometryType.Point)
            {
                result = converter.ConvertToPointBarriersFeatures(barriers);
            }
            else if (type == BarrierGeometryType.Polygon)
            {
                result = converter.ConvertToPolygonBarriersFeatures(barriers);
            }
            else if (type == BarrierGeometryType.Polyline)
            {
                result = converter.ConvertToLineBarriersFeatures(barriers);
            }
            else
            {
                // Not supported type.
                Debug.Assert(false);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determine barrier geometry type.
        /// </summary>
        /// <param name="barrier">Barrier.</param>
        /// <returns>Barrier geometry type.</returns>
        private static BarrierGeometryType _GetBarrierType(Barrier barrier)
        {
            Debug.Assert(barrier != null);

            BarrierGeometryType result = BarrierGeometryType.None;

            if (barrier.Geometry != null)
            {
                if (barrier.Geometry is Point)
                {
                    result = BarrierGeometryType.Point;
                }
                else if (barrier.Geometry is Polygon)
                {
                    result = BarrierGeometryType.Polygon;
                }
                else if (barrier.Geometry is Polyline)
                {
                    result = BarrierGeometryType.Polyline;
                }
                else
                {
                    // Not supported.
                    Debug.Assert(false);
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method gets attributes for barriers.
        /// </summary>
        /// <param name="barrier">Barrier to set attributes for.</param>
        /// <param name="barrierType">Barrier type.</param>
        /// <returns>Attributes for barrier.</returns>
        private AttrDictionary _GetAttributes(Barrier barrier,
                                              BarrierGeometryType barrierType)
        {
            // Fill common barriers attributes.
            var attr = new AttrDictionary();

            attr.Add(NAAttribute.NAME, barrier.Id.ToString());

            // Adjust type and time attributes for Polygon barriers.
            if (barrierType == BarrierGeometryType.Polygon)
            {
                if (barrier.BarrierEffect.BlockTravel == false)
                {
                    attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierScaledCost);
                }
                else
                {
                    attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierRestriction);
                }

                double timeFactor = _GetTimeFactor(barrier.BarrierEffect.SpeedFactorInPercent);

                attr.Add(NAAttribute.AttributeTimeScale, timeFactor);
            }
            // Adjust type and time attributes for Polyline barriers.
            else if (barrierType == BarrierGeometryType.Polyline)
            {
                attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierRestriction);
            }
            // Adjust type and time attributes for Point barriers.
            else if (barrierType == BarrierGeometryType.Point)
            {
                if (barrier.BarrierEffect.BlockTravel == false)
                {
                    attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierAddedCost);
                }
                else
                {
                    attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierRestriction);
                }

                attr.Add(NAAttribute.FullEdge, false);
                attr.Add(NAAttribute.CURB_APPROACH,
                         (int)NACurbApproachType.esriNAEitherSideOfVehicle);

                attr.Add(NAAttribute.AttributeTimeDelay, barrier.BarrierEffect.DelayTime);
            }
            else
            {
                // Not supported type of barrier.
                Debug.Assert(false);
            }

            return(attr);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generate GPFeatureRecordSetLayer of specified barrier type.
        /// </summary>
        /// <param name="barriers">Collection of Typed Barriers to include into layer.</param>
        /// <param name="type">Type of barriers to convert in.</param>
        /// <param name="solverSR">Reference to GP spatial.</param>
        /// <returns>GPFeatureRecordSetLayer of barriers of specified type.</returns>
        private GPFeatureRecordSetLayer _GenerateLayer(IEnumerable <Barrier> barriers,
                                                       BarrierGeometryType type, GPSpatialReference solverSR)
        {
            Debug.Assert(barriers != null);

            GPFeatureRecordSetLayer layer = null;

            GPFeature[] features = _ConvertBarriers(barriers, type);

            if (features.Length > 0)
            {
                layer = new GPFeatureRecordSetLayer();
                layer.SpatialReference = solverSR;
                layer.Features         = features;

                switch (type)
                {
                case BarrierGeometryType.Point:
                    layer.GeometryType = NAGeometryType.esriGeometryPoint;
                    break;

                case BarrierGeometryType.Polygon:
                    layer.GeometryType = NAGeometryType.esriGeometryPolygon;
                    break;

                case BarrierGeometryType.Polyline:
                    layer.GeometryType = NAGeometryType.esriGeometryPolyline;
                    break;

                case BarrierGeometryType.None:
                    // Not supported type.
                    Debug.Assert(false);
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
            }

            return(layer);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Convert collection of baTypedBarriers to collection of GPFeature of specified
        /// geometry type.
        /// </summary>
        /// <param name="barriers">Collection of TypedBarriers to convert.</param>
        /// <param name="type">Geometry type to convert in.</param>
        /// <returns>Collection of barrier feature with geometry type.</returns>
        private GPFeature[] _ConvertBarriers(IEnumerable <Barrier> barriers,
                                             BarrierGeometryType type)
        {
            Debug.Assert(barriers != null);

            List <GPFeature> features = new List <GPFeature>();

            foreach (Barrier barrier in barriers)
            {
                if (_CanConvert(barrier, type))
                {
                    features.Add(_ConvertBarrier(barrier, type));
                }
                else
                {
                    // Type should appropriate to barrier, so it should be convertable.
                    Debug.Assert(false);
                }
            }

            return(features.ToArray());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Determine if barrier can be converted into specified type.
        /// </summary>
        /// <param name="barrier">Barrier to convert from.</param>
        /// <param name="type">Type to convert.</param>
        /// <returns>True - if can be converted, otherwise - false.</returns>
        private bool _CanConvert(Barrier barrier, BarrierGeometryType type)
        {
            Debug.Assert(barrier != null);

            bool result = false;

            if (barrier.Geometry != null)
            {
                if ((type == BarrierGeometryType.Point && barrier.Geometry is Point) ||
                    (type == BarrierGeometryType.Polygon && barrier.Geometry is Polygon) ||
                    (type == BarrierGeometryType.Polyline && barrier.Geometry is Polyline))
                {
                    result = true;
                }
                else
                {
                    // Not supported.
                    Debug.Assert(false);
                }
            }

            return(result);
        }
        /// <summary>
        /// Method converts collection of Barriers with its Geometry Types into GPFeatureRecordSetLayer of
        /// BarrierGeometryType type.
        /// </summary>
        /// <param name="barriersByTypes">Typed Barriers collection.</param>
        /// <param name="type">Type to convert.</param>
        /// <param name="attributes">Collection of network attribute units.</param>
        /// <returns>GPFeatureRecordSetLayer of specified barriers type.</returns>
        private static GPFeatureRecordSetLayer _ConvertBarriers(ILookup<BarrierGeometryType, Barrier> barriersByTypes,
            BarrierGeometryType type, IEnumerable<NetworkAttribute> attributes)
        {
            Debug.Assert(barriersByTypes != null);

            // Convert Lookup Table of barriers to enumerable collection of Barriers of specified type.
            var barriers = barriersByTypes[type];

            GPFeatureRecordSetLayer result = null;

            if (barriers.Any())
            {
                // Convert barriers by its types.
                BarriersConverter converter = new BarriersConverter(attributes);
                if (type == BarrierGeometryType.Point)
                    result = converter.ConvertToPointBarriersLayer(barriers, solverSR);
                else if (type == BarrierGeometryType.Polygon)
                    result = converter.ConvertToPolygonBarriersLayer(barriers, solverSR);
                else if (type == BarrierGeometryType.Polyline)
                    result = converter.ConvertToLineBarriersLayer(barriers, solverSR);
                else
                    // Not supported type.
                    Debug.Assert(false);
            }

            return result;
        }