Example #1
0
        public void Initialize(INetworkDataset networkDataset, IDENetworkDataset dataElement, INetworkSource source, IEvaluatedNetworkAttribute attribute)
        {
            // Initialize is called once per session (ArcMap session, ArcCatalog session, etc.) to initialize the evaluator for an associated network dataset
            Type t = Type.GetTypeFromProgID("esriFramework.AppRef");

            try
            {
                // Activator.CreateInstance(t) is expected to error if the evaluator is created in an engine application
                // which can�t get a reference to the AppRef singleton.
                // This evaluator won�t work in Engine due to this design limitation.  It is, however,
                // fully functional in ArcMap.
                System.Object obj = Activator.CreateInstance(t);
                IApplication  app = obj as IApplication;
                if (app != null && app is IMxApplication)
                {
                    m_mxDocument = app.Document as IMxDocument;
                }
            }
            catch (Exception e)
            {
                m_mxDocument = null;
            }

            // Store reference to the network dataset and the network source
            m_networkDataset = networkDataset;
            m_networkSource  = source;

            // Create a new Dictionary hashtable for this network source
            m_sourceHashTable = new Dictionary <int, int>();
        }
        public static void SetEvaluator(IEvaluatedNetworkAttribute netAttribute, INetworkSource netSource, Type t, esriNetworkEdgeDirection dirType)
        {
            object            obj  = Activator.CreateInstance(t);
            INetworkEvaluator eval = obj as INetworkEvaluator;

            netAttribute.set_Evaluator(netSource, dirType, eval);
        }
        private IEnumerable <INetworkEdge> EnumerateAdjacentTurnEdges(OSMTurnInfo osmTurn, bool useToJunction)
        {
            INetworkQuery query = (INetworkQuery)_networkDataset;

            // get turn FROM-edge
            INetworkSource      source          = _networkDataset.get_SourceByName(((IDataset)osmTurn.FromFeature.Class).Name);
            IEnumNetworkElement enumNetElements = query.get_EdgesByPosition(source.ID, osmTurn.FromFeature.OID, 0.0, false);
            INetworkEdge        edgeFrom        = enumNetElements.Next() as INetworkEdge;

            // get the FROM-edge Junctions
            INetworkJunction fromJunction = query.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;
            INetworkJunction toJunction   = query.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;

            edgeFrom.QueryJunctions(fromJunction, toJunction);

            // Get adjacent edges from the turn center junction
            INetworkJunction junction = ((useToJunction) ? toJunction : fromJunction);

            for (int n = 0; n < junction.EdgeCount; ++n)
            {
                INetworkEdge edge = query.CreateNetworkElement(esriNetworkElementType.esriNETEdge) as INetworkEdge;
                junction.QueryEdge(n, true, edge);

                if ((edge.OID == osmTurn.FromFeature.OID) || (edge.OID == osmTurn.ToFeature.OID))
                {
                    continue;
                }

                yield return(edge);
            }
        }
Example #4
0
        /// <summary>
        /// Runs the modular graph
        /// </summary>
        /// <remarks>Makes sure all sub graphs are connected, and then makes them all run together</remarks>
        public virtual void Run()
        {
            INetworkSource networkSource = this.Source as INetworkSource;

            if (networkSource != null)
            {
                if (networkSource.Status != NetworkSourceStatus.Connected)
                {
                    throw new InvalidOperationException("The graph cannot be run unless the network source is in the Connected state!");
                }
            }

            if (!built)
            {
                Build();
            }

            for (int i = Intermediate.Count; i >= -1; i--)
            {
                if (i < Intermediate.Count)
                {
                    BridgeGraphsAt(i);
                }
                GraphAt(i).Run();
            }

            this.State = State.Running;
        }
        public void Initialize(INetworkDataset networkDataset, IDENetworkDataset DataElement, INetworkSource netSource, IEvaluatedNetworkAttribute netAttribute)
        {
            // Initialize is called once per session (ArcMap session, ArcCatalog session, etc.) to initialize the evaluator for an associated network dataset
            m_networkDataset   = networkDataset;
            m_networkSource    = netSource;
            m_networkAttribute = netAttribute;

            Refresh();
        }
        public bool SupportsSource(INetworkSource source, IEvaluatedNetworkAttribute attribute)
        {
            // This custom evaluator supports added costs only for edges in attributes with units of Minutes
            bool isEdgeSource    = (source.ElementType == esriNetworkElementType.esriNETEdge);
            bool isCostAttribute = (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost);
            bool isMinutes       = (attribute.Units == esriNetworkAttributeUnits.esriNAUMinutes);

            return(isEdgeSource && isCostAttribute && isMinutes);
        }
        private IEnumerable <INetworkEdge> EnumerateAdjacentTurnEdges(OSMTurnInfo osmTurn, bool useToJunction)
        {
            INetworkQuery query = (INetworkQuery)_networkDataset;

            // get turn FROM-edge
            INetworkSource      source          = _networkDataset.get_SourceByName(((IDataset)osmTurn.FromFeature.Class).Name);
            IEnumNetworkElement enumNetElements = null;

            IRelationalOperator relationalOperator = ((IPolyline)osmTurn.ToFeature.Shape).FromPoint as IRelationalOperator;

            bool useFromPointOfToFeature = relationalOperator.Contains(osmTurn.ViaFeature.Shape);

            if (useFromPointOfToFeature)
            {
                enumNetElements = query.get_EdgesByPosition(source.ID, osmTurn.ToFeature.OID, 0, false);
            }
            else
            {
                enumNetElements = query.get_EdgesByPosition(source.ID, osmTurn.ToFeature.OID, 1, false);
            }

            INetworkEdge edgeFrom = enumNetElements.Next() as INetworkEdge;

            // get the FROM-edge Junctions
            INetworkJunction fromJunction = query.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;
            INetworkJunction toJunction   = query.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;

            edgeFrom.QueryJunctions(fromJunction, toJunction);

            // Get adjacent edges from the turn center junction
            INetworkJunction junction = ((useFromPointOfToFeature) ? fromJunction : toJunction);

            for (int n = 0; n < junction.EdgeCount; ++n)
            {
                INetworkEdge edge = query.CreateNetworkElement(esriNetworkElementType.esriNETEdge) as INetworkEdge;
                if (useFromPointOfToFeature)
                {
                    junction.QueryEdge(n, true, edge);
                }
                else
                {
                    junction.QueryEdge(n, false, edge);
                }

                //if ((edge.SourceID == osmTurn.FromFeature.OID) || (edge.SourceID == osmTurn.ToFeature.OID))
                if ((edge.OID == osmTurn.ToFeature.OID))
                {
                    continue;
                }

                yield return(edge);
            }
        }
        public static void SetEvaluators(IEvaluatedNetworkAttribute netAttribute, INetworkSource netSource, Type t)
        {
            esriNetworkElementType eType = netSource.ElementType;

            if (eType == esriNetworkElementType.esriNETEdge)
            {
                SetEvaluator(netAttribute, netSource, t, esriNetworkEdgeDirection.esriNEDAlongDigitized);
                SetEvaluator(netAttribute, netSource, t, esriNetworkEdgeDirection.esriNEDAgainstDigitized);
            }
            else
            {
                SetEvaluator(netAttribute, netSource, t, esriNetworkEdgeDirection.esriNEDNone);
            }
        }
        /// <summary>
        /// Take a network element and return its corresponding source feature
        /// <param name="element">The return source feature corresponds to this element</param>
        /// </summary>
        private IFeature GetSourceFeature(INetworkElement element)
        {
            // To draw the network element, we will need its corresponding source feature information
            // Get the sourceID and OID from the element
            int sourceID  = element.SourceID;
            int sourceOID = element.OID;

            // Get the source feature from the network source
            INetworkSource         netSource       = m_context.NetworkDataset.get_SourceByID(sourceID);
            IFeatureClassContainer fClassContainer = m_context.NetworkDataset as IFeatureClassContainer;
            IFeatureClass          sourceFClass    = fClassContainer.get_ClassByName(netSource.Name);

            return(sourceFClass.GetFeature(sourceOID));
        }
Example #10
0
 public bool ValidateSource(IDatasetContainer2 datasetContainer, INetworkSource networkSource, IEvaluatedNetworkAttribute attribute, ref int errorCode, ref string errorDescription, ref string errorAppendInfo)
 {
     if (SupportsSource(networkSource, attribute))
     {
         errorCode        = 0;
         errorDescription = errorAppendInfo = string.Empty;
         return(true);
     }
     else
     {
         errorCode        = -1;
         errorDescription = errorAppendInfo = string.Empty;
         return(false);
     }
 }
        public void Initialize(INetworkDataset networkDataset, IDENetworkDataset DataElement, INetworkSource netSource, IEvaluatedNetworkAttribute netAttribute)
        {
            // Initialize is called once per session (ArcMap session, ArcCatalog session, etc.) to initialize the evaluator for an associated network dataset
            m_networkDataset   = networkDataset;
            m_networkSource    = netSource;
            m_networkAttribute = netAttribute;

            m_thisNetworkAttributeID = netAttribute.ID;
            m_baseNetworkAttributeID = -1;

            //The attribute name must begin with one or more non underscore characters followed by
            //an underscore character and then the name of the base cost attribute.
            //The underscore prior to the base attribute name should be the first underscore in the name.

            string thisAttributeName = netAttribute.Name;
            int    nPos     = thisAttributeName.IndexOf('_');
            int    nLastPos = thisAttributeName.Length - 1;

            string            baseNetAttributeName;
            INetworkAttribute baseNetAttribute = null;

            if (nPos > 0 && nPos < nLastPos)
            {
                baseNetAttributeName = thisAttributeName.Remove(0, nPos + 1);
                try
                {
                    baseNetAttribute = networkDataset.get_AttributeByName(baseNetAttributeName);
                }
                catch (COMException ex)
                {
                    baseNetAttribute = null;
                    string msg = string.Format("Base Attribute ({0}) not found. {1}.", baseNetAttributeName, ex.Message);
                    System.Diagnostics.Trace.WriteLine(msg, "Scale Subset Network Evaluator");
                }

                if (baseNetAttribute != null)
                {
                    if (baseNetAttribute.ID != m_thisNetworkAttributeID)
                    {
                        m_baseNetworkAttributeID = baseNetAttribute.ID;
                    }
                }
            }

            Refresh();
        }
Example #12
0
        /// <summary>IDisposable - dispose of open assets</summary>
        public void Dispose()
        {
            _xml         = null;
            _osmDataset  = null;
            _messages    = null;
            _trackCancel = null;

            if (_edgeSources != null)
            {
                foreach (var efs in _edgeSources)
                {
                    ComReleaser.ReleaseCOMObject(efs);
                }

                _edgeSources.Clear();
                _edgeSources = null;
            }

            if (_junctionSources != null)
            {
                foreach (var jfs in _junctionSources)
                {
                    ComReleaser.ReleaseCOMObject(jfs);
                }

                _junctionSources.Clear();
                _junctionSources = null;
            }

            ComReleaser.ReleaseCOMObject(_turnSource);
            _turnSource = null;

            if (_networkAttrs != null)
            {
                foreach (var na in _networkAttrs)
                {
                    ComReleaser.ReleaseCOMObject(na);
                }

                _networkAttrs.Clear();
                _networkAttrs = null;
            }

            ComReleaser.ReleaseCOMObject(_networkDataset);
            _networkDataset = null;
        }
Example #13
0
        /// <summary>Creates a new network dataset in the current OSM dataset</summary>
        public void CreateNetworkDataset()
        {
            _edgeSources     = new List <IEdgeFeatureSource>();
            _junctionSources = new List <IJunctionFeatureSource>();
            _turnSource      = null;
            _networkAttrs    = new List <IEvaluatedNetworkAttribute>();

            using (_taskManager = new RunTaskManager(_trackCancel ?? new CancelTrackerClass(), _messages))
            {
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_extractingEdges", ExtractEdgeFeatureClasses);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_extractingJunctions", ExtractJunctionFeatureClasses);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_assignConnectivity", AssignConnectivity);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_extractingTurns", ExtractTurnRestrictions);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_addingNetworkAttributes", AddNetworkAttributes);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_creating", CreateBuildableNDS);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_building", BuildNDS);
            }
        }
        public void Init(IServerObjectHelper pSOH)
        {
            IMapServer           mapServer           = pSOH.ServerObject as IMapServer;
            IMapServerDataAccess mapServerDataAccess = mapServer as IMapServerDataAccess;
            IMapServerInfo       mapServerInfo       = mapServer.GetServerInfo(mapServer.DefaultMapName);
            IMapLayerInfos       layerInfos          = mapServerInfo.MapLayerInfos;
            IMapLayerInfo        ndLayerInfo         = null;

            // Get the network dataset layer from current service
            for (var i = 0; i < layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.Element[i];
                if (layerInfo.Type.Equals("Network Dataset Layer", StringComparison.InvariantCultureIgnoreCase))
                {
                    ndLayerInfo = layerInfo;
                    break;
                }
            }

            // Get the network dataset
            if (ndLayerInfo != null)
            {
                var dt = mapServerDataAccess.GetDataSource(mapServer.DefaultMapName, ndLayerInfo.ID);
                // Cast the dataset to required network dataset interface
                networkDataset = dt as INetworkDataset;
            }

            if (networkDataset != null)
            {
                // Open the streets feature class
                IDataset          dataSet    = networkDataset as IDataset;
                IFeatureWorkspace fWorkspace = dataSet.Workspace as IFeatureWorkspace;
                streetFC = fWorkspace.OpenFeatureClass(streetsName);

                // Get the Streets source ID
                INetworkSource streetNetworkSource = networkDataset.SourceByName[streetsName];
                streetsSourceID = streetNetworkSource.ID;

                // Get the TraveTime attribute ID
                INetworkAttribute travelTimeAttribute = networkDataset.AttributeByName[costAttributeName];
                travelTimeAttributeID = travelTimeAttribute.ID;
            }
        }
Example #15
0
        private void CreateTurnFeature_ONLY(TurnFeatureClassWrapper turnFCW, OSMTurnInfo osmTurn)
        {
            IPoint    ptVia    = osmTurn.ViaFeature.Shape as IPoint;
            IPolyline lineFrom = osmTurn.FromFeature.Shape as IPolyline;

            bool   edge1End, edge2End;
            double posFrom, posTo;
            IPoint ptStart = GetTurnEndpoint(lineFrom, ptVia, out edge1End, out posFrom);

            foreach (INetworkEdge edge in EnumerateAdjacentTurnEdges(osmTurn, edge1End))
            {
                IFeature turn = turnFCW.TurnFeatureClass.CreateFeature();

                INetworkSource srcTo     = _networkDataset.get_SourceByID(edge.SourceID);
                IFeatureClass  fcTo      = ((IFeatureClassContainer)_networkDataset).get_ClassByName(srcTo.Name);
                IFeature       featureTo = fcTo.GetFeature(edge.OID);
                IPolyline      lineTo    = featureTo.Shape as IPolyline;

                // Create Turn Shape
                IPoint ptEnd = GetTurnEndpoint(lineTo, ptVia, out edge2End, out posTo);
                turn.Shape = CreateTurnGeometry(ptStart, ptVia, ptEnd, lineFrom.SpatialReference);

                // Attributes (Edge1)
                turn.set_Value(turnFCW.idxEdge1End, (edge1End) ? "Y" : "N");
                turn.set_Value(turnFCW.idxEdge1FCID, osmTurn.FromFeature.Class.ObjectClassID);
                turn.set_Value(turnFCW.idxEdge1FID, osmTurn.FromFeature.OID);
                turn.set_Value(turnFCW.idxEdge1Pos, posFrom);

                // Attributes (Edge2)
                turn.set_Value(turnFCW.idxEdge2FCID, featureTo.Class.ObjectClassID);
                turn.set_Value(turnFCW.idxEdge2FID, featureTo.OID);
                turn.set_Value(turnFCW.idxEdge2Pos, posTo);

                // Restriction Type
                turn.set_Value(turnFCW.idxRestrict, "NO");

                turn.Store();
            }
        }
Example #16
0
        /// <summary>Adds turn restriction feature class to network dataset</summary>
        private void ExtractTurnRestrictions()
        {
            string turnFeatureClass = GetFullClassName(_xml.TurnFeatureClassName());

            if (string.IsNullOrEmpty(turnFeatureClass))
            {
                return;
            }

            INetworkDataset nds = null;

            try
            {
                nds = CreateTempNDS();
                ((INetworkBuild)nds).BuildNetwork(_extent);

                NetworkTurns nt = new NetworkTurns(turnFeatureClass, _osmDataset, nds);
                nt.TaskManager           = _taskManager;
                nt.OsmPointFeatureClass  = ((IFeatureWorkspace)_osmDataset.Workspace).OpenFeatureClass(_osmPointName);
                nt.OsmEdgeFeatureClasses = _edgeSources
                                           .OfType <INetworkSource>()
                                           .Select(ns => ((IFeatureWorkspace)_osmDataset.Workspace).OpenFeatureClass(ns.Name))
                                           .ToList();

                IFeatureClass fc = ((IFeatureWorkspace)_osmDataset.Workspace).OpenFeatureClass(_osmLineName);
                nt.OsmExtVersion = fc.OSMExtensionVersion();

                _turnSource = nt.ExtractTurnRestrictions();
            }
            finally
            {
                if (nds != null)
                {
                    ((IDataset)nds).Delete();
                    ComReleaser.ReleaseCOMObject(nds);
                }
            }
        }
        private IEvaluatedNetworkAttribute CreateVehicleNetworkAttribute(string attrName, bool useByDefault, double restrUsageFactor, bool isDirectional,
                                                                         string edgeFieldName, string turnFieldName, double fgdbVersion,
                                                                         INetworkSource edgeNetworkSource, INetworkSource turnNetworkSource,
                                                                         bool usesTransport)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = CreateRestrAttrNoEvals(attrName, fgdbVersion, restrUsageFactor, useByDefault, "", "");

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression((isDirectional ? "[FT_" : "[") + edgeFieldName + "] = \"N\"", "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression((isDirectional ? "[TF_" : "[") + edgeFieldName + "] = \"N\"", "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            if (turnFieldName != "")
            {
                netFieldEval = new NetworkFieldEvaluatorClass();
                netFieldEval.SetExpression("[" + turnFieldName + "] = \"Y\" And " + (usesTransport ? "( [COND_TYPE] = 7 Or ( [COND_TYPE] = 26 And [AllTransportProhibited] = \"Y\" ) )" : "[COND_TYPE] = 7"), "");
                evalNetAttr.set_Evaluator(turnNetworkSource, esriNetworkEdgeDirection.esriNEDNone, (INetworkEvaluator)netFieldEval);
            }

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
        private IEvaluatedNetworkAttribute CreateDirectionalAvoidNetworkAttribute(string attrName, string fieldName,
                                                                                  bool useByDefault, double fgdbVersion,
                                                                                  double restrUsageFactor, INetworkSource edgeNetworkSource)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = CreateRestrAttrNoEvals(attrName, fgdbVersion, restrUsageFactor, useByDefault, "");

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("restricted", "restricted = False\n\r" +
                                       "Select Case UCase([" + fieldName + "])\n\r" +
                                       "  Case \"B\", \"FT\": restricted = True\n\r" +
                                       "End Select");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("restricted", "restricted = False\n\r" +
                                       "Select Case UCase([" + fieldName + "])\n\r" +
                                       "  Case \"B\", \"TF\": restricted = True\n\r" +
                                       "End Select");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
Example #19
0
 public bool SupportsSource(INetworkSource source, IEvaluatedNetworkAttribute attribute)
 {
     // This custom evaluator supports restriction attributes for all sources
     return(attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTRestriction);
 }
        /// <summary>IDisposable - dispose of open assets</summary>
        public void Dispose()
        {
            _xml = null;
            _osmDataset = null;
            _messages = null;
            _trackCancel = null;

            if (_edgeSources != null)
            {
                foreach (var efs in _edgeSources)
                    ComReleaser.ReleaseCOMObject(efs);

                _edgeSources.Clear();
                _edgeSources = null;
            }

            if (_junctionSources != null)
            {
                foreach (var jfs in _junctionSources)
                    ComReleaser.ReleaseCOMObject(jfs);

                _junctionSources.Clear();
                _junctionSources = null;
            }

            ComReleaser.ReleaseCOMObject(_turnSource);
            _turnSource = null;

            if (_networkAttrs != null)
            {
                foreach (var na in _networkAttrs)
                    ComReleaser.ReleaseCOMObject(na);

                _networkAttrs.Clear();
                _networkAttrs = null;
            }

            ComReleaser.ReleaseCOMObject(_networkDataset);
            _networkDataset = null;
        }
        /// <summary>Creates a new network dataset in the current OSM dataset</summary>
        public void CreateNetworkDataset()
        {
            _edgeSources = new List<IEdgeFeatureSource>();
            _junctionSources = new List<IJunctionFeatureSource>();
            _turnSource = null;
            _networkAttrs = new List<IEvaluatedNetworkAttribute>();

            using (_taskManager = new RunTaskManager(_trackCancel ?? new CancelTrackerClass(), _messages))
            {
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_extractingEdges", ExtractEdgeFeatureClasses);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_extractingJunctions", ExtractJunctionFeatureClasses);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_assignConnectivity", AssignConnectivity);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_extractingTurns", ExtractTurnRestrictions);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_addingNetworkAttributes", AddNetworkAttributes);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_creating", CreateBuildableNDS);
                _taskManager.ExecuteTask("GPTools_OSMGPCreateNetworkDataset_building", BuildNDS);
            }
        }
 private IEvaluatedNetworkAttribute CreateAvoidNetworkAttribute(string attrName, string fieldEvalExpression, bool useByDefault,
                                                                double fgdbVersion, INetworkSource edgeNetworkSource)
 {
     // CreateAvoidNetworkAttribute without a specified avoidFactor creates the attribute with an AvoidMediumFactor.
     return CreateAvoidNetworkAttribute(attrName, fieldEvalExpression, useByDefault, fgdbVersion, edgeNetworkSource, AvoidMediumFactor);
 }
		public bool SupportsSource(INetworkSource source, IEvaluatedNetworkAttribute attribute)
		{
			// This custom evaluator supports restriction attributes for all sources
			return attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTRestriction;
		}
		public static void SetEvaluator(IEvaluatedNetworkAttribute netAttribute, INetworkSource netSource, Type t, esriNetworkEdgeDirection dirType)
		{
			object obj = Activator.CreateInstance(t);
			INetworkEvaluator eval = obj as INetworkEvaluator;
			netAttribute.set_Evaluator(netSource, dirType, eval);
		}
        public bool SupportsSource(INetworkSource source, IEvaluatedNetworkAttribute attribute)
        {
            // This custom evaluator supports added costs only for edges in attributes with units of Minutes
            bool isEdgeSource = (source.ElementType == esriNetworkElementType.esriNETEdge);
            bool isCostAttribute = (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost);
            bool isMinutes = (attribute.Units == esriNetworkAttributeUnits.esriNAUMinutes);

            return (isEdgeSource && isCostAttribute && isMinutes);
        }
        public void Initialize(INetworkDataset networkDataset, IDENetworkDataset dataElement, INetworkSource source, IEvaluatedNetworkAttribute evaluatedNetworkAttribute)
        {
            // Cache the network dataset geodatabase path
            m_workspace_path_name = ((IDataset)networkDataset).Workspace.PathName;
            m_UseSpecificDates    = false;
            m_CacheOnEverySolve   = false;
            m_RidingABicycle      = false;
            m_UsingAWheelchair    = false;
            m_networkAttribute    = evaluatedNetworkAttribute as INetworkAttribute2;

            CheckForVerboseLogging();
            if (m_VerboseLogging)
            {
                WriteToOutputFile(m_LogFile, "Initialize" + Environment.NewLine + "m_workspace_path_name: " + m_workspace_path_name + Environment.NewLine + " m_UseSpecificDates defaults to: " + m_UseSpecificDates);
            }
        }
 public bool SupportsSource(INetworkSource netSource, IEvaluatedNetworkAttribute netAttribute)
 {
     // This custom evaluator supports cost attributes for all sources
     return(netAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost);
 }
        private IEvaluatedNetworkAttribute CreateMultiFieldLoadRestrictionAttribute(string attrName, bool isPreferred, string[] arrayOfFieldNameBase, double fgdbVersion,
                                                                                    INetworkSource edgeNetworkSource, INetworkSource turnNetworkSource)
        {
            int arrayLength = arrayOfFieldNameBase.Length;
            if (arrayLength <= 0)
                return null;

            string ftExpression = "[FT_" + arrayOfFieldNameBase[0] + "] = \"Y\"";
            string tfExpression = "[TF_" + arrayOfFieldNameBase[0] + "] = \"Y\"";
            string turnExpression = "[" + arrayOfFieldNameBase[0] + "] = \"Y\"";

            for (int i = 1; i < arrayLength; i++)
            {
                ftExpression += (" Or [FT_" + arrayOfFieldNameBase[i] + "] = \"Y\"");
                tfExpression += (" Or [TF_" + arrayOfFieldNameBase[i] + "] = \"Y\"");
                turnExpression += (" Or [" + arrayOfFieldNameBase[i] + "] = \"Y\"");
            }

            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = CreateRestrAttrNoEvals(attrName, fgdbVersion, (isPreferred ? PreferMediumFactor : -1.0), false, "", "");

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression(ftExpression, "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression(tfExpression, "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            if (turnNetworkSource != null)
            {
                netFieldEval = new NetworkFieldEvaluatorClass();
                netFieldEval.SetExpression(turnExpression, "");
                evalNetAttr.set_Evaluator(turnNetworkSource, esriNetworkEdgeDirection.esriNEDNone, (INetworkEvaluator)netFieldEval);
            }

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
        private IEvaluatedNetworkAttribute CreateQuantityLimitAttribute(string attrName, string fieldNameBase, 
                                                                        INetworkSource edgeNetworkSource, INetworkSource turnNetworkSource)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = new EvaluatedNetworkAttributeClass();
            INetworkAttribute2 netAttr2 = (INetworkAttribute2)evalNetAttr;
            netAttr2.Name = attrName;
            netAttr2.UsageType = esriNetworkAttributeUsageType.esriNAUTDescriptor;
            netAttr2.DataType = esriNetworkAttributeDataType.esriNADTInteger;
            netAttr2.Units = esriNetworkAttributeUnits.esriNAUUnknown;
            netAttr2.UseByDefault = false;

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("[FT_" + fieldNameBase + "]", "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("[TF_" + fieldNameBase + "]", "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            if (turnNetworkSource != null)
            {
                netFieldEval = new NetworkFieldEvaluatorClass();
                netFieldEval.SetExpression("[" + fieldNameBase + "]", "");
                evalNetAttr.set_Evaluator(turnNetworkSource, esriNetworkEdgeDirection.esriNEDNone, (INetworkEvaluator)netFieldEval);
            }

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
        private static Dictionary <string, List <int> > GetEIDListsBySourceName(INetworkAnalystExtension nax, object searchObject, string baseName)
        {
            if (nax == null)
            {
                return(null);
            }

            bool             naxEnabled = false;
            IExtensionConfig naxConfig  = nax as IExtensionConfig;

            naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled;

            if (!naxEnabled)
            {
                return(null);
            }

            INAWindow       naWindow  = nax.NAWindow;
            INALayer        naLayer   = null;
            INAContext      naContext = null;
            INetworkDataset nds       = null;

            naLayer = naWindow.ActiveAnalysis;
            if (naLayer != null)
            {
                naContext = naLayer.Context;
            }

            if (naContext != null)
            {
                nds = naContext.NetworkDataset;
            }

            INetworkQuery netQuery = nds as INetworkQuery;

            if (netQuery == null)
            {
                return(null);
            }

            bool oidSearch      = false;
            bool geometrySearch = false;

            if (searchObject == null)
            {
                return(null);
            }
            else if (searchObject is Dictionary <string, ILongArray> )
            {
                oidSearch = true;
            }
            else if (searchObject is IGeometry)
            {
                geometrySearch = true;
            }
            else
            {
                return(null);
            }

            VarType       vt          = GetEIDArrayParameterType();
            List <string> sourceNames = FindParameterizedSourceNames(nds, baseName, vt);
            Dictionary <string, List <int> > eidsBySourceName = new Dictionary <string, List <int> >();

            foreach (string sourceName in sourceNames)
            {
                INetworkSource netSource = nds.get_SourceByName(sourceName);
                int            sourceID  = netSource.ID;
                List <int>     eids      = new List <int>();

                if (oidSearch)
                {
                    Dictionary <string, ILongArray> oidArraysBySourceName = (Dictionary <string, ILongArray>)searchObject;
                    ILongArray          oids = null;
                    IEnumNetworkElement enumNetElement;
                    INetworkElement     netElement;

                    if (oidArraysBySourceName.TryGetValue(sourceName, out oids))
                    {
                        enumNetElement = netQuery.get_ElementsByOIDs(sourceID, oids);
                        enumNetElement.Reset();
                        netElement = enumNetElement.Next();
                        while (netElement != null)
                        {
                            eids.Add(netElement.EID);
                            netElement = enumNetElement.Next();
                        }
                    }
                }
                else if (geometrySearch)
                {
                    IGeometry searchGeometry = (IGeometry)searchObject;
                    if (searchGeometry != null && !searchGeometry.IsEmpty)
                    {
                        IGeometry elementGeometry          = null;
                        esriNetworkElementType elementType = esriNetworkElementType.esriNETEdge;
                        int eid = -1;

                        // Search for the network dataset layer associated with the active analysis layer or create one using the
                        // network dataset if matching one not found.
                        // If, for example, multiple network dataset layers are added to the map, the active analysis layer
                        // might not reference the current network dataset layer (nax.CurrentNetworkLayer).

                        INetworkLayer ndsLayer = new NetworkLayerClass();
                        ndsLayer.NetworkDataset = nds;

                        int count = nax.NetworkLayerCount;
                        for (int i = 0; i < count; ++i)
                        {
                            ndsLayer = nax.get_NetworkLayer(i);
                            if (ndsLayer.NetworkDataset == nds)
                            {
                                break;
                            }
                            else
                            {
                                ndsLayer = null;
                            }
                        }

                        if (ndsLayer == null)
                        {
                            ndsLayer = new NetworkLayerClass();
                            ndsLayer.NetworkDataset = nds;
                        }

                        IEnumLocatedNetworkElement enumLocatedNetElement = null;
                        if (ndsLayer != null)
                        {
                            enumLocatedNetElement = ndsLayer.SearchLocatedNetworkElements(sourceName, searchGeometry);
                            enumLocatedNetElement.Reset();
                            eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType);
                            while (eid != -1)
                            {
                                eids.Add(eid);
                                eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType);
                            }
                        }
                    }
                }

                eidsBySourceName.Add(sourceName, eids);
            }

            return(eidsBySourceName);
        }
Example #31
0
        /// <summary>Adds new Network Attribute Evaluators</summary>
        private void AddEvaluators(NetworkAttributeInfo nai, IEvaluatedNetworkAttribute netAttr)
        {
            foreach (EvaluatorInfo eval in nai.Evaluators)
            {
                INetworkEvaluator evaluator = null;

                if (eval.EvaluatorType == eEvaluatorType.Constant)
                {
                    evaluator = new NetworkConstantEvaluatorClass();
                    if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTBoolean)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = eval.Expression.Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTDouble)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToDouble(eval.Expression);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTFloat)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToSingle(eval.Expression);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTInteger)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToInt32(eval.Expression);
                    }
                }
                else if (eval.EvaluatorType == eEvaluatorType.Script)
                {
                    evaluator = new NetworkScriptEvaluatorClass();

#if ARCGIS_10_0     // Handle Python script language added in ArcGIS 10.1
                    if (eval.ScriptLanguage != "VBScript")
                    {
                        throw new ApplicationException(RESMGR.GetString("GPTools_OSMGPCreateNetworkDataset_invalidScriptLanguage"));
                    }

                    INetworkScriptEvaluator scriptEvaluator = (INetworkScriptEvaluator)evaluator;
                    scriptEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#else
                    INetworkScriptEvaluator2 scriptEvaluator = (INetworkScriptEvaluator2)evaluator;
                    scriptEvaluator.SetLanguage(eval.ScriptLanguage);
                    scriptEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#endif
                }
                else if (eval.EvaluatorType == eEvaluatorType.Field)
                {
                    evaluator = new NetworkFieldEvaluatorClass();

#if ARCGIS_10_0     // Handle Python script language added in ArcGIS 10.1
                    if (eval.ScriptLanguage != "VBScript")
                    {
                        throw new ApplicationException(RESMGR.GetString("GPTools_OSMGPCreateNetworkDataset_invalidScriptLanguage"));
                    }

                    INetworkFieldEvaluator fieldEvaluator = (INetworkFieldEvaluator)evaluator;
                    fieldEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#else
                    INetworkFieldEvaluator2 fieldEvaluator = (INetworkFieldEvaluator2)evaluator;
                    fieldEvaluator.SetLanguage(eval.ScriptLanguage);
                    fieldEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#endif
                }

                INetworkSource source = EnumerateNetworkSources()
                                        .FirstOrDefault(ns => ns.Name.Equals(GetFullClassName(eval.Source), StringComparison.CurrentCultureIgnoreCase));
                if (source != null)
                {
                    esriNetworkEdgeDirection direction = eval.Direction;
                    if (!(source is IEdgeFeatureSource))
                    {
                        direction = esriNetworkEdgeDirection.esriNEDNone;
                    }

                    netAttr.set_Evaluator(source, direction, evaluator);
                }
            }
        }
        private IEvaluatedNetworkAttribute CreateAvoidNetworkAttribute(string attrName, string fieldEvalExpression, bool useByDefault,
                                                                       double fgdbVersion, INetworkSource edgeNetworkSource, double avoidFactor)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = CreateRestrAttrNoEvals(attrName, fgdbVersion, avoidFactor, useByDefault, "", "");

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression(fieldEvalExpression, "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression(fieldEvalExpression, "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
        private IEvaluatedNetworkAttribute CreateLoadRestrictionAttribute(string attrName, bool isPreferred, string fieldNameBase, double fgdbVersion,
                                                                          INetworkSource edgeNetworkSource, INetworkSource turnNetworkSource)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = CreateRestrAttrNoEvals(attrName, fgdbVersion, (isPreferred ? PreferMediumFactor : -1.0), false, "", "");

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("[FT_" + fieldNameBase + "] = \"Y\"", "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("[TF_" + fieldNameBase + "] = \"Y\"", "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            if (turnNetworkSource != null)
            {
                netFieldEval = new NetworkFieldEvaluatorClass();
                netFieldEval.SetExpression("[" + fieldNameBase + "] = \"Y\"", "");
                evalNetAttr.set_Evaluator(turnNetworkSource, esriNetworkEdgeDirection.esriNEDNone, (INetworkEvaluator)netFieldEval);
            }

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
		public void Initialize(INetworkDataset networkDataset, IDENetworkDataset dataElement, INetworkSource source, IEvaluatedNetworkAttribute attribute)
		{
			// Initialize is called once per session (ArcMap session, ArcCatalog session, etc.) to initialize the evaluator for an associated network dataset
			Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
			try
			{
				// Activator.CreateInstance(t) is expected to error if the evaluator is created in an engine application 
				// which can�t get a reference to the AppRef singleton.  
				// This evaluator won�t work in Engine due to this design limitation.  It is, however,
				// fully functional in ArcMap.
				System.Object obj = Activator.CreateInstance(t);
				IApplication app = obj as IApplication;
				if (app != null && app is IMxApplication)
					m_mxDocument = app.Document as IMxDocument;
			}
			catch (Exception e)
			{
				m_mxDocument = null;
			}

			// Store reference to the network dataset and the network source
			m_networkDataset = networkDataset;
			m_networkSource = source;

			// Create a new Dictionary hashtable for this network source
			m_sourceHashTable = new Dictionary<int, int>();
		}
		public void Initialize(INetworkDataset networkDataset, IDENetworkDataset DataElement, INetworkSource netSource, IEvaluatedNetworkAttribute netAttribute)
		{
			// Initialize is called once per session (ArcMap session, ArcCatalog session, etc.) to initialize the evaluator for an associated network dataset            
			m_networkDataset = networkDataset;
			m_networkSource = netSource;
			m_networkAttribute = netAttribute;

			m_thisNetworkAttributeID = netAttribute.ID;
			m_baseNetworkAttributeID = -1;

			//The attribute name must begin with one or more non underscore characters followed by
			//an underscore character and then the name of the base cost attribute.
			//The underscore prior to the base attribute name should be the first underscore in the name.

			string thisAttributeName = netAttribute.Name;
			int nPos = thisAttributeName.IndexOf('_');
			int nLastPos = thisAttributeName.Length - 1;

			string baseNetAttributeName;
			INetworkAttribute baseNetAttribute = null;

			if (nPos > 0 && nPos < nLastPos)
			{
				baseNetAttributeName = thisAttributeName.Remove(0, nPos + 1);
				try
				{
					baseNetAttribute = networkDataset.get_AttributeByName(baseNetAttributeName);
				}
				catch (COMException ex)
				{
					baseNetAttribute = null;
					string msg = string.Format("Base Attribute ({0}) not found. {1}.", baseNetAttributeName, ex.Message);
					System.Diagnostics.Trace.WriteLine(msg, "Scale Subset Network Evaluator");
				}

				if (baseNetAttribute != null)
				{
					if (baseNetAttribute.ID != m_thisNetworkAttributeID)
						m_baseNetworkAttributeID = baseNetAttribute.ID;
				}
			}

			Refresh();
		}
Example #36
0
        private void frmNetworkPropertySheet_Load(object sender, EventArgs e)
        {
            int num2;

            string[]     strArray;
            ListViewItem item;

            this.lblNetworkName.Text = (this.inetworkDataset_0 as IDataset).Name;
            this.lblNetworkType.Text = this.method_0(this.inetworkDataset_0.NetworkType);
            INetworkQuery query = this.inetworkDataset_0 as INetworkQuery;
            string        str   = "";

            str = ((query.get_ElementCount(esriNetworkElementType.esriNETJunction).ToString() + "个连接点\r\n") +
                   query.get_ElementCount(esriNetworkElementType.esriNETEdge).ToString() + "条边\r\n") +
                  query.get_ElementCount(esriNetworkElementType.esriNETTurn).ToString() + "个转向\r\n";
            this.lblNetworkElements.Text = str;
            for (num2 = 0; num2 < this.inetworkDataset_0.SourceCount; num2++)
            {
                strArray = new string[3];
                INetworkSource source = this.inetworkDataset_0.get_Source(num2);
                strArray[0] = source.Name;
                strArray[1] = this.method_1(source.SourceType);
                strArray[2] = this.method_2(source.ElementType);
                item        = new ListViewItem(strArray);
                this.lsvSource.Items.Add(item);
                if (source.SourceType == esriNetworkSourceType.esriNSTEdgeFeature)
                {
                    strArray[0] = source.Name;
                    strArray[1] = "From End";
                    strArray[2] = (source as IEdgeFeatureSource).FromElevationFieldName;
                    item        = new ListViewItem(strArray);
                    this.lsvElevation.Items.Add(item);
                    strArray[1] = "To End";
                    strArray[2] = (source as IEdgeFeatureSource).ToElevationFieldName;
                    item        = new ListViewItem(strArray);
                    this.lsvElevation.Items.Add(item);
                    if (source.NetworkSourceDirections == null)
                    {
                    }
                }
                else if (source.SourceType == esriNetworkSourceType.esriNSTJunctionFeature)
                {
                    strArray[0] = source.Name;
                    strArray[1] = "";
                    strArray[2] = (source as IJunctionFeatureSource).ElevationFieldName;
                    item        = new ListViewItem(strArray);
                    this.lsvElevation.Items.Add(item);
                }
            }
            for (num2 = 0; num2 < this.inetworkDataset_0.AttributeCount; num2++)
            {
                strArray = new string[6];
                INetworkAttribute attribute = this.inetworkDataset_0.get_Attribute(num2);
                strArray[0] = "";
                strArray[1] = "";
                strArray[2] = attribute.Name;
                strArray[3] = CommonHelper.GetUsageTypeDescriptor(attribute.UsageType);
                strArray[4] = CommonHelper.GetNetworkUnitTypeDescriptor(attribute.Units);
                strArray[5] = CommonHelper.GetDataTypeDescriptor(attribute.DataType);
                item        = new ListViewItem(strArray);
                this.lsvAttributes.Items.Add(item);
            }
        }
		public bool SupportsSource(INetworkSource netSource, IEvaluatedNetworkAttribute netAttribute)
		{
			// This custom evaluator supports cost attributes for all sources
			return netAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost;
		}
        /// <summary>Adds turn restriction feature class to network dataset</summary>
        private void ExtractTurnRestrictions()
        {
            string turnFeatureClass = GetFullClassName(_xml.TurnFeatureClassName());
            if (string.IsNullOrEmpty(turnFeatureClass))
                return;

            INetworkDataset nds = null;

            try
            {
                nds = CreateTempNDS();
                ((INetworkBuild)nds).BuildNetwork(_extent);

                NetworkTurns nt = new NetworkTurns(turnFeatureClass, _osmDataset, nds);
                nt.TaskManager = _taskManager;
                nt.OsmPointFeatureClass = ((IFeatureWorkspace)_osmDataset.Workspace).OpenFeatureClass(_osmPointName);
                nt.OsmEdgeFeatureClasses = _edgeSources
                    .OfType<INetworkSource>()
                    .Select(ns => ((IFeatureWorkspace)_osmDataset.Workspace).OpenFeatureClass(ns.Name))
                    .ToList();

                IFeatureClass fc = ((IFeatureWorkspace)_osmDataset.Workspace).OpenFeatureClass(_osmLineName);
                nt.OsmExtVersion = fc.OSMExtensionVersion();

                _turnSource = nt.ExtractTurnRestrictions();
            }
            finally
            {
                if (nds != null)
                {
                    ((IDataset)nds).Delete();
                    ComReleaser.ReleaseCOMObject(nds);
                }
            }
        }
        private IEvaluatedNetworkAttribute CreateLengthNetworkAttribute(string attrName, esriNetworkAttributeUnits attrUnits,
                                                                        string fieldEvalExpression, INetworkSource edgeNetworkSource)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = new EvaluatedNetworkAttributeClass();
            INetworkAttribute2 netAttr2 = (INetworkAttribute2)evalNetAttr;
            netAttr2.Name = attrName;
            netAttr2.UsageType = esriNetworkAttributeUsageType.esriNAUTCost;
            netAttr2.DataType = esriNetworkAttributeDataType.esriNADTDouble;
            netAttr2.Units = attrUnits;
            netAttr2.UseByDefault = false;

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression(fieldEvalExpression, "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression(fieldEvalExpression, "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = false;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
		public void Initialize(INetworkDataset networkDataset, IDENetworkDataset DataElement, INetworkSource netSource, IEvaluatedNetworkAttribute netAttribute)
		{
			// Initialize is called once per session (ArcMap session, ArcCatalog session, etc.) to initialize the evaluator for an associated network dataset            
			m_networkDataset = networkDataset;
			m_networkSource = netSource;
			m_networkAttribute = netAttribute;

			Refresh();
		}
        private IEvaluatedNetworkAttribute CreateDrivingATruckNetworkAttribute(bool isDirectional, double fgdbVersion,
                                                                               INetworkSource edgeNetworkSource, INetworkSource turnNetworkSource,
                                                                               bool usesTransport)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = CreateRestrAttrNoEvals("Driving a Truck", fgdbVersion, -1.0, false, "", "");

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression((isDirectional ? "[FT_" : "[") + "AR_DELIV] = \"N\"", "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression((isDirectional ? "[TF_" : "[") + "AR_DELIV] = \"N\"", "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("( [AR_DELIVER] = \"Y\" Or [AR_TRUCKS] = \"Y\" ) And " + (usesTransport ? "( [COND_TYPE] = 7 Or ( [COND_TYPE] = 26 And [AllTransportProhibited] = \"Y\" ) )" : "[COND_TYPE] = 7"), "");
            evalNetAttr.set_Evaluator(turnNetworkSource, esriNetworkEdgeDirection.esriNEDNone, (INetworkEvaluator)netFieldEval);

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
Example #42
0
        static void Main(string[] args)
        {
            try
            {
                // Initialize ArcObjects
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);

                LicenseInitializer aoLicenseInitializer = new LicenseInitializer();
                if (!aoLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeBasic, esriLicenseProductCode.esriLicenseProductCodeStandard, esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                                new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork }))
                {
                    System.Windows.Forms.MessageBox.Show("This application could not initialize with the correct ArcGIS license and will shutdown. LicenseMessage: " + aoLicenseInitializer.LicenseMessage());
                    aoLicenseInitializer.ShutdownApplication();
                    return;
                }

                // Get the network dataset
                string networkDatasetPath = args[0];

                INetworkDataset nd = GetNetworkDatasetFromPath(networkDatasetPath);

                var networkQuery = nd as INetworkQuery3;

                // Name of source containing transit lines.  Probably hard-wired to "TransitLines"
                string sourceName = args[1];

                // Get the source object from the network
                INetworkSource networkSource   = nd.get_SourceByName(sourceName);
                int            networkSourceID = networkSource.ID;

                // The SQLDbase containing the transit schedules
                string SQLDbase_path = args[2];

                // Connect to the SQL database, loop through the network's features, and add EID values to the table for each SourceOID.
                string workspaceConnectionString = @"Data Source=" + SQLDbase_path + "; Version=3;";
                using (SQLiteConnection conn = new SQLiteConnection(workspaceConnectionString))
                {
                    conn.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn))
                    {
                        using (var transaction = conn.BeginTransaction())
                        {
                            List <int> BadSourceOIDs = new List <int>();

                            // Get all the transit lines from the network
                            IEnumNetworkElement transit_lines = networkQuery.get_ElementsForSource(networkSourceID);

                            // Loop through all the transit lines and add their EIDs to the SQL table
                            INetworkElement transit_line = transit_lines.Next();
                            while (transit_line != null)
                            {
                                // Note: We are assuming that there is a one-to-one mapping between SourceOID and EID. This should always be
                                // the case for transit lines feature classes correctly created using the Add GTFS to a Network Dataset toolbox.
                                int EID       = transit_line.EID;
                                int SourceOID = transit_line.OID;
                                try
                                {
                                    string updateStmt = string.Format("UPDATE linefeatures SET eid={0} WHERE SourceOID={1}", EID.ToString(), SourceOID.ToString());
                                    cmd.CommandText = updateStmt;
                                    cmd.ExecuteNonQuery();
                                }
                                catch
                                {
                                    // For some reason, the item couldn't be inserted into the table, likely because SourceOID couldn't be found.
                                    BadSourceOIDs.Add(SourceOID);
                                    continue;
                                }
                                transit_line = transit_lines.Next();
                            }

                            // Add the eids to the table in batch.
                            transaction.Commit();

                            if (BadSourceOIDs.Count != 0)
                            {
                                // Write out an error if something went wrong while filling the table.
                                Console.Error.WriteLine("The network EID value could not be determined for the following transit line source OIDs:");
                                foreach (int BadSourceOID in BadSourceOIDs)
                                {
                                    Console.Error.WriteLine(BadSourceOID);
                                }
                                Console.Error.WriteLine("You probably need to recreate your transit lines feature class.");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }
        private IEvaluatedNetworkAttribute CreateDimensionalLimitAttribute(string attrName, string fieldNameBase, bool createNetworkAttributeInMetric,
                                                                           bool isWeightAttr, INetworkSource edgeNetworkSource, INetworkSource turnNetworkSource)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = new EvaluatedNetworkAttributeClass();
            INetworkAttribute2 netAttr2 = (INetworkAttribute2)evalNetAttr;
            netAttr2.Name = attrName;
            netAttr2.UsageType = esriNetworkAttributeUsageType.esriNAUTDescriptor;
            netAttr2.DataType = esriNetworkAttributeDataType.esriNADTDouble;
            netAttr2.Units = esriNetworkAttributeUnits.esriNAUUnknown;
            netAttr2.UseByDefault = false;

            // Weight values are in kilograms and, if required, need to be converted to pounds
            // Distance values are in meters and, if required, need to be converted to feet
            string conversionExpr = "";
            if (!createNetworkAttributeInMetric)
                conversionExpr = isWeightAttr ? " / 0.45359237" : " / 0.3048";

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("[FT_" + fieldNameBase + "]" + conversionExpr, "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);

            netFieldEval = new NetworkFieldEvaluatorClass();
            netFieldEval.SetExpression("[TF_" + fieldNameBase + "]" + conversionExpr, "");
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);

            if (turnNetworkSource != null)
            {
                netFieldEval = new NetworkFieldEvaluatorClass();
                netFieldEval.SetExpression("[" + fieldNameBase + "]" + conversionExpr, "");
                evalNetAttr.set_Evaluator(turnNetworkSource, esriNetworkEdgeDirection.esriNEDNone, (INetworkEvaluator)netFieldEval);
            }

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
        public void Initialize(INetworkDataset networkDataset, IDENetworkDataset dataElement, INetworkSource source, IEvaluatedNetworkAttribute evaluatedNetworkAttribute)
        {
            // Cache the network dataset geodatabase path
            m_workspace_path_name = ((IDataset)networkDataset).Workspace.PathName;
            m_UseSpecificDates = false;
            m_CacheOnEverySolve = false;
            m_RidingABicycle = false;
            m_UsingAWheelchair = false;
            m_networkAttribute = evaluatedNetworkAttribute as INetworkAttribute2;

            CheckForVerboseLogging();
            if (m_VerboseLogging) WriteToOutputFile(m_LogFile, "Initialize" + Environment.NewLine + "m_workspace_path_name: " + m_workspace_path_name + Environment.NewLine + " m_UseSpecificDates defaults to: " + m_UseSpecificDates);
        }
        private IEvaluatedNetworkAttribute CreateQuantityRestrictionAttribute(string restrAttrName, string limitAttrName,
                                                                              string paramName, double fgdbVersion,
                                                                              INetworkSource edgeNetworkSource, INetworkSource turnNetworkSource)
        {
            // Create an EvaluatedNetworkAttribute object and populate its settings.
            IEvaluatedNetworkAttribute evalNetAttr = CreateRestrAttrNoEvals(restrAttrName, fgdbVersion, -1.0, false, "", paramName);

            // Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
            INetworkFunctionEvaluator netFuncEval = new NetworkFunctionEvaluatorClass();
            netFuncEval.FirstArgument = limitAttrName;
            netFuncEval.Operator = "<";
            netFuncEval.SecondArgument = paramName;
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFuncEval);

            netFuncEval = new NetworkFunctionEvaluatorClass();
            netFuncEval.FirstArgument = limitAttrName;
            netFuncEval.Operator = "<";
            netFuncEval.SecondArgument = paramName;
            evalNetAttr.set_Evaluator(edgeNetworkSource, esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFuncEval);

            netFuncEval = new NetworkFunctionEvaluatorClass();
            netFuncEval.FirstArgument = limitAttrName;
            netFuncEval.Operator = "<";
            netFuncEval.SecondArgument = paramName;
            evalNetAttr.set_Evaluator(turnNetworkSource, esriNetworkEdgeDirection.esriNEDNone, (INetworkEvaluator)netFuncEval);

            INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);

            netConstEval = new NetworkConstantEvaluatorClass();
            netConstEval.ConstantValue = 0;
            evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);

            return evalNetAttr;
        }
 public bool ValidateSource(IDatasetContainer2 datasetContainer, INetworkSource networkSource, IEvaluatedNetworkAttribute attribute, ref int errorCode, ref string errorDescription, ref string errorAppendInfo)
 {
     if (SupportsSource(networkSource, attribute))
     {
         errorCode = 0;
         errorDescription = errorAppendInfo = string.Empty;
         return true;
     }
     else
     {
         errorCode = -1;
         errorDescription = errorAppendInfo = string.Empty;
         return false;
     }
 }
		public static void SetEvaluators(IEvaluatedNetworkAttribute netAttribute, INetworkSource netSource, Type t)
		{
			esriNetworkElementType eType = netSource.ElementType;
			if (eType == esriNetworkElementType.esriNETEdge)
			{
				SetEvaluator(netAttribute, netSource, t, esriNetworkEdgeDirection.esriNEDAlongDigitized);
				SetEvaluator(netAttribute, netSource, t, esriNetworkEdgeDirection.esriNEDAgainstDigitized);
			}
			else
			{
				SetEvaluator(netAttribute, netSource, t, esriNetworkEdgeDirection.esriNEDNone);
			}
		}