Пример #1
0
		/*
		'*********************************************************************************
		' Create NASolver and NAContext
		'*********************************************************************************
		*/
		public INAContext CreateSolverContext(INetworkDataset pNetDataset)
		{


			IDENetworkDataset pDENDS;
			
			pDENDS=GetDENetworkDataset(pNetDataset);


			INASolver pNASolver;
			INAContextEdit pContextEdit;

			//NAClosestFacilitySolver is a network analyst solver to find a set of closest facilities from a set of incidents

			pNASolver=new NAClosestFacilitySolver();
			
			pContextEdit=pNASolver.CreateContext(pDENDS,pNASolver.Name) as INAContextEdit;
			
			pContextEdit.Bind(pNetDataset,new GPMessagesClass());



			return pContextEdit as INAContext;




		
		}//end of the function CreateSolverContext
Пример #2
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            Ctrl_Tab.SelectedIndex = 1;
            Ctrl_Tab.SelectedIndex = 0;

            IFeatureWorkspace pFWorkspace    = OpenWorkspace(@"data.gdb") as IFeatureWorkspace;
            INetworkDataset   networkDataset = OpenNetworkDataset(pFWorkspace as IWorkspace, "rdCenLineDataSet_ND", "rdCenLineDataSet");

            m_NAContext = CreateSolverContext(networkDataset);
            INetworkLayer pNetworkLayer = new NetworkLayerClass();

            pNetworkLayer.NetworkDataset = networkDataset;
            ILayer pLayer = pNetworkLayer as ILayer;

            pLayer.Name = "NetworkLayer";
            Ctrl_Map.AddLayer(pLayer, 0);

            IFeatureLayer pJunctionLayer = new FeatureLayerClass();

            pJunctionLayer.FeatureClass = pFWorkspace.OpenFeatureClass("rdCenLineDataSet_ND_Junctions");
            pJunctionLayer.Name         = pJunctionLayer.FeatureClass.AliasName;
            Ctrl_Map.AddLayer(pJunctionLayer, 0);
            IFeatureLayer pRoadLayer = new FeatureLayerClass();

            pRoadLayer.FeatureClass = pFWorkspace.OpenFeatureClass("road_toLine");
            pRoadLayer.Name         = pRoadLayer.FeatureClass.AliasName;
            Ctrl_Map.AddLayer(pRoadLayer, 0);

            INALayer pNALayer = m_NAContext.Solver.CreateLayer(m_NAContext);

            (pNALayer as ILayer).Name = m_NAContext.Solver.DisplayName;
            Ctrl_Map.AddLayer(pNALayer as ILayer, 0);
        }
Пример #3
0
        private INALayer CreateRouteAnalysisLayer(string sName, INetworkDataset pNetworkDataset)
        {
            INARouteSolver    solver   = new NARouteSolverClass();
            INASolverSettings settings = solver as INASolverSettings;
            INASolver         solver2  = solver as INASolver;

            solver.FindBestSequence  = true;
            solver.PreserveFirstStop = true;
            solver.PreserveLastStop  = false;
            solver.UseTimeWindows    = false;
            solver.OutputLines       = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;
            IStringArray restrictionAttributeNames = settings.RestrictionAttributeNames;

            restrictionAttributeNames.Add("Oneway");
            settings.RestrictionAttributeNames = restrictionAttributeNames;
            IDatasetComponent component   = pNetworkDataset as IDatasetComponent;
            IDENetworkDataset dataElement = component.DataElement as IDENetworkDataset;
            INAContext        context     = solver2.CreateContext(dataElement, sName);

            (context as INAContextEdit).Bind(pNetworkDataset, new GPMessagesClass());
            INALayer layer = solver2.CreateLayer(context);

            (layer as ILayer).Name = sName;
            return(layer);
        }
Пример #4
0
        public bool ShowModal(INALayer naLayer)
        {
            m_okClicked = false;

            // Get the NAContext and NetworkDataset
            INAContext      naContext      = naLayer.Context;
            INetworkDataset networkDataset = naContext.NetworkDataset;

            // Setup the window based on the current NALayer settings
            PopulateControls(naLayer);
            tabPropPages.SelectedIndex = 1;
            this.Text = ((ILayer)naLayer).Name + " Properties";

            this.ShowDialog();
            if (m_okClicked)
            {
                // Update the layer properties based on the items chosen
                UpdateNALayer(naLayer);

                // Update the Context so it can respond to changes made to the solver settings
                IGPMessages       gpMessages       = new GPMessagesClass();
                IDENetworkDataset deNetworkDataset = ((IDatasetComponent)networkDataset).DataElement as IDENetworkDataset;
                naContext.Solver.UpdateContext(naContext, deNetworkDataset, gpMessages);
            }

            return(m_okClicked);
        }
Пример #5
0
        public static IDENetworkDataset GetPathDENetworkDataset(INetworkDataset networkDataset)
        {
            IDatasetComponent dsComponent;

            dsComponent = networkDataset as IDatasetComponent;
            return(dsComponent.DataElement as IDENetworkDataset);
        }
Пример #6
0
        /// <summary>
        /// Update the CheckedListBox control based on the network dataset attributes (checking the ones currently chosen by the solver)
        /// </summary>
        private void PopulateAttributeControl(CheckedListBox chklstBox, INetworkDataset networkDataset, IStringArray strArray, esriNetworkAttributeUsageType usageType)
        {
            chklstBox.Items.Clear();

            //  Loop through the network dataset attributes
            for (int i = 0; i < networkDataset.AttributeCount; i++)
            {
                INetworkAttribute networkAttribute = networkDataset.get_Attribute(i);
                if (networkAttribute.UsageType == usageType)
                {
                    string     attributeName = networkAttribute.Name;
                    CheckState checkState    = CheckState.Unchecked;

                    // If the attribute is in the strArray, it should be checked
                    for (int j = 0; j < strArray.Count; j++)
                    {
                        if (strArray.get_Element(j) == attributeName)
                        {
                            checkState = CheckState.Checked;
                        }
                    }

                    // Add the attribute to the control
                    chklstBox.Items.Add(attributeName, checkState);
                }
            }
        }
 /// <summary>
 /// 打开网络数据集
 /// </summary>
 /// <param name="GDBfileName"></param>
 /// <param name="featureDatasetName"></param>
 /// <param name="sNDSName"></param>
 /// <returns></returns>
 public static INetworkDataset OpenNetworkDataset(string GDBfileName, string featureDatasetName, string sNDSName)
 {
     try
     {
         IWorkspace        pWorkspace        = OpenWorkspace(GDBfileName);
         IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
         if (pFeatureWorkspace == null)
         {
             return(null);
         }
         IFeatureDatasetExtensionContainer pFeatureDatasetExtensionContainer = pFeatureWorkspace.OpenFeatureDataset(featureDatasetName) as IFeatureDatasetExtensionContainer;
         if (pFeatureDatasetExtensionContainer == null)
         {
             return(null);
         }
         IDatasetContainer2 pDatasetContainer2 = pFeatureDatasetExtensionContainer.FindExtension(esriDatasetType.esriDTNetworkDataset) as IDatasetContainer2;
         INetworkDataset    pNetworkDataset    = pDatasetContainer2.get_DatasetByName(esriDatasetType.esriDTAny, sNDSName) as INetworkDataset;
         return(pNetworkDataset);
     }
     catch (Exception ex)
     {
         Debug.Print(ex.Message);
         return(null);
     }
 }
Пример #8
0
        public static void GetPermittedAttributes(INALayer layer, out string[] impedences, out string[] restrictions,
                                                  out string[] hierarchies)
        {
            ArrayList       list           = new ArrayList();
            ArrayList       list2          = new ArrayList();
            ArrayList       list3          = new ArrayList();
            INetworkDataset networkDataset = layer.Context.NetworkDataset;

            for (int i = 0; i < networkDataset.AttributeCount; i++)
            {
                INetworkAttribute attribute = networkDataset.get_Attribute(i);
                if (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
                {
                    list.Add(attribute.Name);
                }
                else if (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTRestriction)
                {
                    list2.Add(attribute.Name);
                }
                else if (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTHierarchy)
                {
                    list3.Add(attribute.Name);
                }
            }
            impedences   = (string[])list.ToArray(typeof(string));
            restrictions = (string[])list2.ToArray(typeof(string));
            hierarchies  = (string[])list3.ToArray(typeof(string));
        }
Пример #9
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 List <string> FindParameterizedSourceNames(INetworkDataset nds, string baseName, VarType vt)
        {
            List <string>             sourceNamesList       = new List <string>();
            Dictionary <string, int?> sourceNamesDictionary = new Dictionary <string, int?>();

            int?dummyValue      = null;
            int?foundDummyValue = null;

            string prefix = GetEIDArrayPrefixFromBaseName(baseName);

            INetworkSource netSource;
            string         sourceName;
            string         searchParamName;
            int            count = nds.SourceCount;

            for (int i = 0; i < count; ++i)
            {
                netSource  = nds.get_Source(i);
                sourceName = netSource.Name;
                if (sourceNamesDictionary.TryGetValue(sourceName, out foundDummyValue))
                {
                    continue;
                }

                searchParamName = GetSourceParameterName(prefix, sourceName);

                if (ParameterExists(nds, searchParamName, vt))
                {
                    sourceNamesList.Add(sourceName);
                    sourceNamesDictionary.Add(sourceName, dummyValue);
                }
            }

            return(sourceNamesList);
        }
Пример #11
0
        private void Initialize()
        {
            this.CheckOutNetworkAnalystExtension();
            IFeatureWorkspace workspace =
                this.OpenWorkspace(Application.StartupPath + @"\..\..\..\..\Data\NetworkAnalyst") as IFeatureWorkspace;
            INetworkDataset pNetDataset = this.OpenNetworkDataset(workspace as IWorkspace, "Streets_nd");

            this.m_pNAContext = this.CreateSolverContext(pNetDataset);
            for (int i = 0; i < (pNetDataset.AttributeCount - 1); i++)
            {
                INetworkAttribute attribute = pNetDataset.get_Attribute(i);
                if (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
                {
                    this.cboCostAttribute.Items.Add(attribute.Name);
                    this.cboCostAttribute.SelectedIndex = 0;
                }
            }
            this.txtTargetFacility.Text = "1";
            this.txtCutOff.Text         = "";
            IFeatureClass pInputFC = workspace.OpenFeatureClass("BayAreaIncident");

            this.LoadNANetworkLocations("Incidents", pInputFC, 100.0);
            pInputFC = workspace.OpenFeatureClass("BayAreaLocations");
            this.LoadNANetworkLocations("Facilities", pInputFC, 100.0);
            INetworkLayer layer2 = new NetworkLayerClass
            {
                NetworkDataset = pNetDataset
            };
            ILayer layer = layer2 as ILayer;

            layer.Name = "Network Dataset";
            layer      = this.m_pNAContext.Solver.CreateLayer(this.m_pNAContext) as ILayer;
            layer.Name = this.m_pNAContext.Solver.DisplayName;
        }
Пример #12
0
        /// <summary>
        /// Geodatabase function: get network dataset
        /// </summary>
        /// <param name="networkDataset">Input network dataset</param>
        /// <returns>DE network dataset</returns>
        public IDENetworkDataset GetDENetworkDataset(INetworkDataset networkDataset)
        {
            // Cast from the network dataset to the DatasetComponent
            IDatasetComponent dsComponent = networkDataset as IDatasetComponent;

            // Get the data element
            return(dsComponent.DataElement as IDENetworkDataset);
        }
Пример #13
0
        /// <summary>
        /// Create the analysis layer, load the locations, solve the analysis, and write to disk
        /// </summary>
        public void SolveRoute()
        {
            // Open the feature workspace, input feature class, and network dataset
            // As Workspace Factories are Singleton objects, they must be instantiated with the Activator
            IWorkspaceFactory workspaceFactory = System.Activator.CreateInstance(System.Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory")) as IWorkspaceFactory;
            IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(Application.StartupPath + FGDB_WORKSPACE, 0) as IFeatureWorkspace;
            IFeatureClass     inputStopsFClass = featureWorkspace.OpenFeatureClass(INPUT_STOPS_FC);

            // Obtain the dataset container from the workspace
            ESRI.ArcGIS.Geodatabase.IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset(FEATURE_DATASET);
            var featureDatasetExtensionContainer = featureDataset as ESRI.ArcGIS.Geodatabase.IFeatureDatasetExtensionContainer;

            ESRI.ArcGIS.Geodatabase.IFeatureDatasetExtension featureDatasetExtension = featureDatasetExtensionContainer.FindExtension(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTNetworkDataset);
            var datasetContainer3 = featureDatasetExtension as ESRI.ArcGIS.Geodatabase.IDatasetContainer3;

            // Use the container to open the network dataset.
            ESRI.ArcGIS.Geodatabase.IDataset dataset = datasetContainer3.get_DatasetByName(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTNetworkDataset, NETWORK_DATASET);
            INetworkDataset networkDataset           = dataset as INetworkDataset;

            // Create the Route NALayer
            INALayer      naLayer      = CreateRouteAnalysisLayer("Route", networkDataset);
            INAContext    naContext    = naLayer.Context;
            INAClass      stopsNAClass = naContext.NAClasses.get_ItemByName("Stops") as INAClass;
            IFeatureClass routesFC     = naContext.NAClasses.get_ItemByName("Routes") as IFeatureClass;

            // Load the Stops
            INAClassFieldMap naClassFieldMap = new NAClassFieldMapClass();

            naClassFieldMap.set_MappedField("Name", INPUT_NAME_FIELD);

            INAClassLoader naLoader = new NAClassLoaderClass();

            naLoader.Locator  = naContext.Locator;
            naLoader.NAClass  = stopsNAClass;
            naLoader.FieldMap = naClassFieldMap;

            // Avoid loading network locations onto non-traversable portions of elements
            INALocator3 locator = naContext.Locator as INALocator3;

            locator.ExcludeRestrictedElements = true;
            locator.CacheRestrictedElements(naContext);

            int rowsInCursor = 0;
            int rowsLocated  = 0;

            naLoader.Load(inputStopsFClass.Search(new QueryFilterClass(), false) as ICursor, new CancelTrackerClass(), ref rowsInCursor, ref rowsLocated);

            //Message all of the network analysis agents that the analysis context has changed
            ((INAContextEdit)naContext).ContextChanged();

            //Solve
            INASolver naSolver = naContext.Solver;

            naSolver.Solve(naContext, new GPMessagesClass(), new CancelTrackerClass());

            //Save the layer to disk
            SaveLayerToDisk(naLayer as ILayer, System.Environment.CurrentDirectory + @"\Route.lyr");
        }
        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();
        }
Пример #15
0
        public static IDENetworkDataset GetPathDENetworkDataset(INetworkDataset networkDataset)
        {
            //The IDatasetComponent interface is used to access the data element and parent dataset of this dataset.
            IDatasetComponent dsComponent;

            dsComponent = networkDataset as IDatasetComponent;
            //The data element corresponding to the dataset component.DataElement attribute returns a parameter type IDEDataset.
            return(dsComponent.DataElement as IDENetworkDataset);
        }
        /// <summary>
        ///  根据网络数据集创建网络分析上下文
        /// </summary>
        /// <param name="networkDataset"></param>
        /// <returns></returns>
        private static INAContext CreateNAContext(INetworkDataset networkDataset)
        {
            IDENetworkDataset pDENetworkDataset = GetDENetworkDataset(networkDataset);
            INASolver         pNASolver         = new NARouteSolverClass();
            INAContextEdit    pNAContextEdit    = pNASolver.CreateContext(pDENetworkDataset, pNASolver.Name) as INAContextEdit;

            pNAContextEdit.Bind(networkDataset, new GPMessagesClass());
            return(pNAContextEdit as INAContext);
        }
Пример #17
0
        private INAContext CreateSolverContext(INetworkDataset networkDataset)
        {
            IDENetworkDataset dENetworkDataset = GetDENetworkDataset(networkDataset);
            INASolver         nASolver         = new NARouteSolver();
            INAContextEdit    nAContextEdit    = nASolver.CreateContext(dENetworkDataset, nASolver.Name) as INAContextEdit;

            nAContextEdit.Bind(networkDataset, null);
            return(nAContextEdit as INAContext);
        }
Пример #18
0
        /// <summary>
        /// 得到创建网络分析上下文所需的IDENETWORKDATASET类型参数
        /// </summary>
        public IDENetworkDataset GetDENetworkDataset(INetworkDataset networkDataset)
        {
            //将网络分析数据集QI添加到DATASETCOMPOENT
            IDatasetComponent dstComponent;

            dstComponent = networkDataset as IDatasetComponent;
            //获得数据元素
            return(dstComponent.DataElement as IDENetworkDataset);
        }
Пример #19
0
        public INAContext CreateSolverContext(INetworkDataset pNetDataset)
        {
            IDENetworkDataset dENetworkDataset = this.GetDENetworkDataset(pNetDataset);
            INASolver         solver           = new NAClosestFacilitySolverClass();
            INAContextEdit    edit             = solver.CreateContext(dENetworkDataset, solver.Name) as INAContextEdit;

            edit.Bind(pNetDataset, new GPMessagesClass());
            return(edit as INAContext);
        }
Пример #20
0
        public NetworkTurns(string turnClassName, IDataset osmDataset, INetworkDataset nds)
        {
            _turnClassName = turnClassName;
            _osmDataset = osmDataset;
            _networkDataset = nds;

            IGPUtilities gpUtil = new GPUtilitiesClass();
            IDataElement de = gpUtil.MakeDataElementFromNameObject(osmDataset.FullName);
            _dsPath = de.CatalogPath;
        }
Пример #21
0
		}//end of the function CreateSolverContext

		//DENetworkDataset is a light weight object that holds information about a network dataset

		public IDENetworkDataset GetDENetworkDataset(INetworkDataset pNetDataset)
		{
			
			IDatasetComponent pDSComponent;
			pDSComponent=pNetDataset as IDatasetComponent;
			return pDSComponent.DataElement as IDENetworkDataset;


		
		}
        /// <summary>
        /// Create a layer for the network dataset and add it to the map
        /// </summary>
        private void AddNetworkDatasetLayerToMap(INetworkDataset networkDataset)
        {
            INetworkLayer networkLayer = new NetworkLayerClass();

            networkLayer.NetworkDataset = networkDataset;
            ILayer layer = networkLayer as ILayer;

            layer.Name = "Network Dataset";
            axMapControl.AddLayer(layer);
        }
        /// <summary>
		/// Initialize the solver by calling the ArcGIS Network Analyst extension functions.
		/// </summary>
		private void Initialize()
		{
			IFeatureWorkspace featureWorkspace = null;
			INetworkDataset networkDataset = null;
			try
			{
				// Open the Network Dataset
				IWorkspace workspace = OpenWorkspace(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"ArcGIS\data\SanFrancisco\SanFrancisco.gdb"));
                networkDataset = OpenNetworkDataset(workspace, "Transportation", "Streets_ND");
				featureWorkspace = workspace as IFeatureWorkspace;
			}
			catch (Exception ex)
			{
				System.Windows.Forms.MessageBox.Show("Unable to open dataset. Error Message: " + ex.Message);
				this.Close();
				return;
			}

			// Create NAContext and NASolver
			m_NAContext = CreateSolverContext(networkDataset);

			// Get available cost attributes from the network dataset
			INetworkAttribute networkAttribute;
			for (int i = 0; i < networkDataset.AttributeCount - 1; i++)
			{
				networkAttribute = networkDataset.get_Attribute(i);
				if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
				{
					comboCostAttribute.Items.Add(networkAttribute.Name);
				}
			}
			comboCostAttribute.SelectedIndex = 0;

			textTargetFacility.Text = "";
			textCutoff.Text = "";

			// Load locations from feature class
			IFeatureClass inputFClass = featureWorkspace.OpenFeatureClass("Stores");
			LoadNANetworkLocations("Origins", inputFClass, 100);
			inputFClass = featureWorkspace.OpenFeatureClass("Hospitals");
			LoadNANetworkLocations("Destinations", inputFClass, 5100);

			// Create layer for network dataset and add to ArcMap
			INetworkLayer networkLayer = new NetworkLayerClass();
			networkLayer.NetworkDataset = networkDataset;
			var layer = networkLayer as ILayer;
			layer.Name = "Network Dataset";
			axMapControl.AddLayer(layer, 0);

			// Create a network analysis layer and add to ArcMap
			INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext);
			layer = naLayer as ILayer;
			layer.Name = m_NAContext.Solver.DisplayName;
			axMapControl.AddLayer(layer, 0);
		}
		/// <summary>
		/// Create NASolver and NAContext
		/// </summary>
		/// <param name="networkDataset">Input network dataset</param>
		/// <returns>NAContext</returns>
		public INAContext CreateSolverContext(INetworkDataset networkDataset)
		{
			//Get the data element
			IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);
			INASolver naSolver = new NAODCostMatrixSolver();
			INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.Name) as INAContextEdit;
			//Bind a context using the network dataset 
			contextEdit.Bind(networkDataset, new GPMessagesClass());

			return contextEdit as INAContext;
		}
Пример #25
0
        public NetworkTurns(string turnClassName, IDataset osmDataset, INetworkDataset nds)
        {
            _turnClassName  = turnClassName;
            _osmDataset     = osmDataset;
            _networkDataset = nds;

            IGPUtilities gpUtil = new GPUtilitiesClass();
            IDataElement de     = gpUtil.MakeDataElementFromNameObject(osmDataset.FullName);

            _dsPath = de.CatalogPath;
        }
Пример #26
0
        public void SolveRoute()
        {
            IWorkspaceFactory factory = new ShapefileWorkspaceFactoryClass();

            this.m_pWorkspace = factory.OpenFromFile(this.SHAPE_WORKSPACE, 0);
            this.SetMemberVariables();
            this.Solve();
            this.m_pWorkspace        = null;
            this.m_pNetworkDataset   = null;
            this.m_pInputStopsFClass = null;
        }
        //*********************************************************************************
        // ArcGIS Network Analyst extension functions
        // ********************************************************************************

        //*********************************************************************************
        // Create NASolver and NAContext
        //*********************************************************************************
        public INAContext CreateSolverContext(INetworkDataset networkDataset)
        {
            //Get the Data Element
            IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);

            INASolver      naSolver    = new NALocationAllocationSolverClass();
            INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.Name) as INAContextEdit;

            contextEdit.Bind(networkDataset, new GPMessagesClass());
            return(contextEdit as INAContext);
        }
Пример #28
0
        //创建网络分析上下文
        public static INAContext CreatePathSolverContext(INetworkDataset networkDataset)
        {
            IDENetworkDataset deNDS = GetPathDENetworkDataset(networkDataset);
            INASolver         naSolver;

            naSolver = new NARouteSolver();
            INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.Name) as INAContextEdit;

            contextEdit.Bind(networkDataset, new GPMessagesClass());
            return(contextEdit as INAContext);
        }
Пример #29
0
        /// <summary>Creates an new (unbuilt) Network Dataset</summary>
        private void CreateBuildableNDS()
        {
            IDENetworkDataset2 deNetworkDataset = new DENetworkDatasetClass();

            deNetworkDataset.Buildable = true;

            ((IDataElement)deNetworkDataset).Name = _ndsName;

            // Copy the feature dataset's extent and spatial reference to the network dataset
            IDEGeoDataset deGeoDataset = (IDEGeoDataset)deNetworkDataset;

            deGeoDataset.Extent           = _extent;
            deGeoDataset.SpatialReference = _spatialReference;

            deNetworkDataset.ElevationModel = esriNetworkElevationModel.esriNEMNone;
            deNetworkDataset.SupportsTurns  = true;

            // General Network Directions
            GeneralNetworkDirectionInfo dirInfo = _xml.GeneralNetworkDirections();

            if (dirInfo != null)
            {
                INetworkDirections netdir = new NetworkDirectionsClass();
                netdir.LengthAttributeName      = dirInfo.LengthAttr;
                netdir.DefaultOutputLengthUnits = dirInfo.LengthUnits;
                netdir.RoadClassAttributeName   = dirInfo.RoadClassAttr;
                netdir.TimeAttributeName        = dirInfo.TimeAttr;

                deNetworkDataset.Directions = netdir;
            }

            IArray sources = new ArrayClass();

            foreach (INetworkSource ns in EnumerateNetworkSources())
            {
                sources.Add(ns);
            }

            IArray attrs = new ArrayClass();

            foreach (var na in _networkAttrs)
            {
                attrs.Add(na);
            }

            deNetworkDataset.Sources    = sources;
            deNetworkDataset.Attributes = attrs;

            // Get the feature dataset extension and create the network dataset from the data element.
            IFeatureDatasetExtension fdExtension = ((IFeatureDatasetExtensionContainer)_osmDataset).FindExtension(esriDatasetType.esriDTNetworkDataset);

            _networkDataset = (INetworkDataset)((IDatasetContainer2)fdExtension).CreateDataset((IDEDataset)deNetworkDataset);
        }
Пример #30
0
        /// <summary>
        /// 创建网络分析上下文
        /// </summary>
        public INAContext CreateSolverContext(INetworkDataset networkDataset)
        {
            //获取创建网络分析上下文所需的IDENETWORKDATASET类型参数
            IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);
            INASolver         naSolver;

            naSolver = new NARouteSolver();
            INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.Name) as INAContextEdit;

            contextEdit.Bind(networkDataset, new GPMessagesClass());
            return(contextEdit as INAContext);
        }
Пример #31
0
        //创建网络分析上下文
        public static INAContext CreatePathSolverContext(INetworkDataset networkDataset)
        {
            IDENetworkDataset deNDS = GetPathDENetworkDataset(networkDataset);
            INASolver         naSolver;

            naSolver = new NARouteSolver();
            INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.DisplayName) as INAContextEdit;

            contextEdit.Bind(networkDataset, new GPMessagesClass());//将网络数据集与网络上下文对象绑定在一起
            //GPMessagesClass对象用于记录错误信息。
            return(contextEdit as INAContext);
        }
Пример #32
0
        public INAContext CreateRouteSolverContext(INetworkDataset pNetDataset)
        {
            INAContextEdit pContextEdit;
            IDENetworkDataset pDENDS= GetDENetworkDataset(pNetDataset);
            INASolver pNASolver=(new NARouteSolverClass()) as INASolver;

            pContextEdit = pNASolver.CreateContext(pDENDS, "Route") as INAContextEdit;

            pContextEdit.Bind(pNetDataset,new GPMessagesClass());

            return pContextEdit as INAContext;
        }
Пример #33
0
        /*
        '*********************************************************************************
        ' Create NASolver and NAContext
        '*********************************************************************************
        */
        public INAContext CreateSolverContext(INetworkDataset pNetDataset)
        {
            IDENetworkDataset pDENDS;

            pDENDS=GetDENetworkDataset(pNetDataset);

            INASolver pNASolver;
            INAContextEdit pContextEdit;

            //NAClosestFacilitySolver is a network analyst solver to find a set of closest facilities from a set of incidents

            pNASolver=new NAClosestFacilitySolver();

            pContextEdit=pNASolver.CreateContext(pDENDS,pNASolver.Name) as INAContextEdit;

            pContextEdit.Bind(pNetDataset,new GPMessagesClass());

            return pContextEdit as INAContext;
        }
        /// <summary>Creates an new (unbuilt) Network Dataset</summary>
        private void CreateBuildableNDS()
        {
            IDENetworkDataset2 deNetworkDataset = new DENetworkDatasetClass();
            deNetworkDataset.Buildable = true;

            ((IDataElement)deNetworkDataset).Name = _ndsName;

            // Copy the feature dataset's extent and spatial reference to the network dataset
            IDEGeoDataset deGeoDataset = (IDEGeoDataset)deNetworkDataset;
            deGeoDataset.Extent = _extent;
            deGeoDataset.SpatialReference = _spatialReference;

            deNetworkDataset.ElevationModel = esriNetworkElevationModel.esriNEMNone;
            deNetworkDataset.SupportsTurns = true;

            // General Network Directions
            GeneralNetworkDirectionInfo dirInfo = _xml.GeneralNetworkDirections();
            if (dirInfo != null)
            {
                INetworkDirections netdir = new NetworkDirectionsClass();
                netdir.LengthAttributeName = dirInfo.LengthAttr;
                netdir.DefaultOutputLengthUnits = dirInfo.LengthUnits;
                netdir.RoadClassAttributeName = dirInfo.RoadClassAttr;
                netdir.TimeAttributeName = dirInfo.TimeAttr;

                deNetworkDataset.Directions = netdir;
            }

            IArray sources = new ArrayClass();
            foreach (INetworkSource ns in EnumerateNetworkSources())
                sources.Add(ns);

            IArray attrs = new ArrayClass();
            foreach (var na in _networkAttrs)
                attrs.Add(na);

            deNetworkDataset.Sources = sources;
            deNetworkDataset.Attributes = attrs;

            // Get the feature dataset extension and create the network dataset from the data element.
            IFeatureDatasetExtension fdExtension = ((IFeatureDatasetExtensionContainer)_osmDataset).FindExtension(esriDatasetType.esriDTNetworkDataset);
            _networkDataset = (INetworkDataset)((IDatasetContainer2)fdExtension).CreateDataset((IDEDataset)deNetworkDataset);
        }
        /// <summary>
        /// Create a layer for the network dataset and add it to the map
        /// </summary>
        private void AddNetworkDatasetLayerToMap(INetworkDataset networkDataset)
		{
			INetworkLayer networkLayer = new NetworkLayerClass();
			networkLayer.NetworkDataset = networkDataset;
			ILayer layer = networkLayer as ILayer;
			layer.Name = "Network Dataset";
			axMapControl.AddLayer(layer);
		}
        /// <summary>
        /// Find and load the cost attributes into a combo box
        /// <summary>
        private void LoadCostAttributes(INetworkDataset networkDataset)
		{
			cbCostAttribute.Items.Clear();

			int attrCount = networkDataset.AttributeCount;
			for (int attrIndex = 0; attrIndex < attrCount; attrIndex++)
			{
				INetworkAttribute networkAttribute = networkDataset.get_Attribute(attrIndex);
				if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
					cbCostAttribute.Items.Add(networkAttribute.Name);
			}

			if (cbCostAttribute.Items.Count > 0)
				cbCostAttribute.SelectedIndex = 0;
		}
        /// <summary>
        /// Create NASolver and NAContext
        /// </summary>
        /// <param name="networkDataset">Input network dataset</param>
        private void CreateSolverContext(INetworkDataset networkDataset)
		{
			if (networkDataset == null) return;

            //Get the Data Element
            IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);

            INASolver naSolver = new NAServiceAreaSolverClass();
            m_NAContext = naSolver.CreateContext(deNDS, naSolver.Name);
            ((INAContextEdit)m_NAContext).Bind(networkDataset, new GPMessagesClass());
        }
		/// <summary>
		/// Create NASolver and NAContext
		/// </summary>
		/// <param name="networkDataset">Input network dataset</param>
		/// <returns>NAContext</returns>
		public INAContext CreateSolverContext(INetworkDataset networkDataset)
		{
			//Get the data element
			IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);
			INASolver naSolver = new NAODCostMatrixSolver();
			INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.Name) as INAContextEdit;
			//Bind a context using the network dataset 
			contextEdit.Bind(networkDataset, new GPMessagesClass());

			return contextEdit as INAContext;
		}
Пример #39
0
 private INAContext CreateNAContext(INetworkDataset networkDataset)
 {
     IDENetworkDataset pDENetworkDataset = GetDENetworkDataset(networkDataset);
     INASolver pNASolver = new NARouteSolverClass();
     INAContextEdit pNAContextEdit = pNASolver.CreateContext(pDENetworkDataset, pNASolver.Name) as INAContextEdit;
     pNAContextEdit.Bind(networkDataset, new GPMessagesClass());
     return pNAContextEdit as INAContext;
 }
Пример #40
0
        private void Form1_Load(object sender, EventArgs e)
        {
            j = 3;
            comboBox1.Items.Clear();

            string filePath = Application.StartupPath + "\\..\\..\\..\\..\\最新arcsense\\无标题11.sxd";
            if (axSceneControl1.CheckSxFile(filePath))
            {
                axSceneControl1.LoadSxFile(filePath);
                axTOCControl1.SetBuddyControl(axSceneControl1);
            }
            lyrCount = axSceneControl1.Scene.LayerCount;
            //MessageBox.Show(axSceneControl1.Scene.LayerCount.ToString());
            for (i = 0; i <= lyrCount - 1; i++)
            {
              //  MessageBox.Show(axSceneControl1.Scene.get_Layer(i).Name);
                comboBox1.Items.Add(axSceneControl1.Scene.get_Layer(i).Name);
            }
            String sFilename;
            sFilename = @"C:\Users\dull\Desktop\新文件\校园代码\最新底图制作\无标题.mxd";
            if (axMapControl1.CheckMxFile(sFilename))
            {
                axMapControl1.LoadMxFile(sFilename);
             //       axTOCControl1.SetBuddyControl(axMapControl1);
             }

            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            int t;
            for (t = 0; t < path.Length; t++)
            {
                if (path.Substring(t, 24) == "WindowsFormsApplication1")
                {
                    break;
                }
            }
            string name = path.Substring(0, t - 1) + "\\WindowsFormsApplication1\\road.gdb";
            pFeatureWorkspace = OpenWorkspace(name) as IFeatureWorkspace;
            pNetworkDataset = OpenNetworkDataset_Other(pFeatureWorkspace as IWorkspace, "zhz_ND", "zhz");

            pNAContext = CreateNAContext(pNetworkDataset);
            pInputFC = pFeatureWorkspace.OpenFeatureClass("zhz_ND_Junctions");
            //pInputFC = pFeatureWorkspace.OpenFeatureClass("woqu");
            pVertexFC = pFeatureWorkspace.OpenFeatureClass("zhz_ND_Junctions");

            IFeatureLayer pVertexFL = new FeatureLayerClass();
            pVertexFL.FeatureClass = pFeatureWorkspace.OpenFeatureClass("zhz_ND_Junctions");
            pVertexFL.Name = pVertexFL.FeatureClass.AliasName;
            axMapControl2.AddLayer(pVertexFL, 0);

            IFeatureLayer pRoadFL = new FeatureLayerClass();
            pRoadFL.FeatureClass = pFeatureWorkspace.OpenFeatureClass("road1");
            pRoadFL.Name = pRoadFL.FeatureClass.AliasName;
            axMapControl2.AddLayer(pRoadFL, 0);

            ILayer pLayer;
            INetworkLayer pNetworkLayer = new NetworkLayerClass();
            pNetworkLayer.NetworkDataset = pNetworkDataset;
            pLayer = pNetworkLayer as ILayer;
            pLayer.Name = "Network Dataset";
            axMapControl2.AddLayer(pLayer, 0);

            //Create a Network Analysis Layer and add to ArcMap
            INALayer naLayer = pNAContext.Solver.CreateLayer(pNAContext);
            pLayer = naLayer as ILayer;
            pLayer.Name = pNAContext.Solver.DisplayName;
            axMapControl2.AddLayer(pLayer, 0);

            pActiveView = axMapControl2.ActiveView;
            pMap = pActiveView.FocusMap;
            pGraphicsContainer = pMap as IGraphicsContainer;

              //  string CurrentPath = Directory.GetCurrentDirectory();
             //   Directory.SetCurrentDirectory(CurrentPath + "\\..\\..\\..\\..\\最新底图制作");
             //   string FilePath = Directory.GetCurrentDirectory();
             //   axMapControl1.AddShapeFile(FilePath, "教学区.shp");
             //   axMapControl1.AddShapeFile(FilePath, "活动区.shp");
              //  axMapControl1.AddShapeFile(FilePath, "宿舍.shp");
              //  axMapControl1.AddShapeFile(FilePath, "场馆区.shp");
            //    axMapControl1.AddShapeFile(FilePath, "办公区.shp");
            //    axMapControl1.AddShapeFile(FilePath, "其他.shp");
             //   axMapControl1.AddShapeFile(FilePath, "底图.shp");
             //   axMapControl1.AddShapeFile(FilePath, "无标题.mxd");
        }
Пример #41
0
        /// <summary>
        /// 获取网络分析上下文,这个接口是网络分析中很重要的一个
        /// </summary>
        /// <param name="_pNaSolver"></param>
        /// <param name="_pNetworkDataset"></param>
        /// <returns></returns>
        public INAContext GetSolverContext(INASolver _pNaSolver, INetworkDataset _pNetworkDataset)
        {
            //Get the Data Element

            IDatasetComponent pDataComponent = _pNetworkDataset as IDatasetComponent;

            IDEDataset pDeDataset = pDataComponent.DataElement;

            INAContextEdit pContextEdit = _pNaSolver.CreateContext(pDeDataset as IDENetworkDataset, _pNaSolver.Name) as INAContextEdit;

            //Prepare the context for analysis based upon the current network dataset schema.
            pContextEdit.Bind(_pNetworkDataset, new GPMessagesClass());
            return pContextEdit as INAContext;
        }
Пример #42
0
        /// <summary>
        /// 加载NetworkDataset到Map中
        /// </summary>
        /// <param name="_pMap"></param>
        /// <param name="_pNetworkDataset"></param>
        void loadNet(IMap _pMap,INetworkDataset _pNetworkDataset)
        {
            INetworkLayer pNetLayer = new NetworkLayerClass();

               pNetLayer.NetworkDataset = _pNetworkDataset;

               _pMap.AddLayer(pNetLayer as ILayer);
        }
		public static bool ParameterExists(INetworkDataset nds, string searchName, VarType vt)
		{
			bool found = false;

			INetworkAttribute2 netAttribute;
			IArray netParams;
			INetworkAttributeParameter netParam;

			int cAttributes = nds.AttributeCount;
			for (int a = 0; a < cAttributes; ++a)
			{
				netAttribute = nds.get_Attribute(a) as INetworkAttribute2;
				netParams = null;
				int cParams = 0;
				if (netAttribute != null)
					netParams = netAttribute.Parameters;

				if (netParams != null)
					cParams = netParams.Count;

				string compareName;
				for (int p = 0; p < cParams; ++p)
				{
					netParam = netParams.get_Element(p) as INetworkAttributeParameter;
					compareName = netParam.Name;
					if (String.Compare(searchName, compareName, true) == 0)
					{
						found = true;
						break;
					}
				}
				if (found)
					break;
			}

			return found;
		}
		public static List<string> FindParameterizedSourceNames(INetworkDataset nds, string baseName, VarType vt)
		{
			List<string> sourceNamesList = new List<string>();
			Dictionary<string, int?> sourceNamesDictionary = new Dictionary<string, int?>();

			int? dummyValue = null;
			int? foundDummyValue = null;

			string prefix = GetEIDArrayPrefixFromBaseName(baseName);

			INetworkSource netSource;
			string sourceName;
			string searchParamName;
			int count = nds.SourceCount;
			for (int i = 0; i < count; ++i)
			{
				netSource = nds.get_Source(i);
				sourceName = netSource.Name;
				if (sourceNamesDictionary.TryGetValue(sourceName, out foundDummyValue))
					continue;

				searchParamName = GetSourceParameterName(prefix, sourceName);

				if (ParameterExists(nds, searchParamName, vt))
				{
					sourceNamesList.Add(sourceName);
					sourceNamesDictionary.Add(sourceName, dummyValue);
				}
			}

			return sourceNamesList;
		}
        /// <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;
        }
		public IDENetworkDataset GetDENetworkDataset(INetworkDataset networkDataset)
		{
			// Cast from the Network Dataset to the DatasetComponent
			IDatasetComponent dsComponent = networkDataset as IDatasetComponent;

			// Get the Data Element
			return dsComponent.DataElement as IDENetworkDataset;
		}
		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 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>();
		}
Пример #49
0
 //DENetworkDataset is a light weight object that holds information about a network dataset
 public IDENetworkDataset GetDENetworkDataset(INetworkDataset pNetDataset)
 {
     IDatasetComponent pDSComponent;
     pDSComponent=pNetDataset as IDatasetComponent;
     return pDSComponent.DataElement as IDENetworkDataset;
 }
		/// <summary>
		/// Create a new network analysis layer and set some solver settings
		/// </summary>
		private INALayer CreateRouteAnalysisLayer(String layerName, INetworkDataset networkDataset)
		{
			INARouteSolver naRouteSolver = new NARouteSolverClass();
			INASolverSettings naSolverSettings = naRouteSolver as INASolverSettings;
			INASolver naSolver = naRouteSolver as INASolver;

			//Get the NetworkDataset's Data Element
			IDatasetComponent datasetComponent = networkDataset as IDatasetComponent;
			IDENetworkDataset deNetworkDataset = datasetComponent.DataElement as IDENetworkDataset;

			//Create the NAContext and bind to it
			INAContext naContext;
			naContext = naSolver.CreateContext(deNetworkDataset, layerName);
			INAContextEdit naContextEdit = naContext as INAContextEdit;
			naContextEdit.Bind(networkDataset, new GPMessagesClass());

			//Create the NALayer
			INALayer naLayer;
			naLayer = naSolver.CreateLayer(naContext);
			(naLayer as ILayer).Name = layerName;

			//Set properties on the route solver interface
			naRouteSolver.FindBestSequence = true;
			naRouteSolver.PreserveFirstStop = true;
			naRouteSolver.PreserveLastStop = false;
			naRouteSolver.UseTimeWindows = false;
			naRouteSolver.OutputLines = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;

			//Set some properties on the general INASolverSettings interface
			IStringArray restrictions = naSolverSettings.RestrictionAttributeNames;
			restrictions.Add("Oneway");
			naSolverSettings.RestrictionAttributeNames = restrictions;

			// Update the context based on the changes made to the solver settings
			naSolver.UpdateContext(naContext, deNetworkDataset, new GPMessagesClass());

			//Return the layer
			return naLayer;
		}
		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();
		}
Пример #52
0
 private IDENetworkDataset GetDENetworkDataset(INetworkDataset networkDataset)
 {
     IDatasetComponent dsComponent;
     dsComponent = pNetworkDataset as IDatasetComponent;
     return dsComponent.DataElement as IDENetworkDataset;
 }
		//*********************************************************************************
		// ArcGIS Network Analyst extension functions
		// ********************************************************************************

		//*********************************************************************************
		// Create NASolver and NAContext
		//*********************************************************************************
		public INAContext CreateSolverContext(INetworkDataset networkDataset)
		{
			//Get the Data Element
			IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);

			INASolver naSolver = new NALocationAllocationSolverClass();
			INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.Name) as INAContextEdit;
			contextEdit.Bind(networkDataset, new GPMessagesClass());
			return contextEdit as INAContext;
		}
Пример #54
0
 //��鹤�������Ƿ������������
 private bool CheckNetWorkExtension(string strWorkspace)
 {
     IFeatureWorkspace pFeatWS = Utility.OpenWorkspace(strWorkspace) as IFeatureWorkspace;
     INetworkDataset pNetDataset = Utility.OpenNetworkDataset(pFeatWS as IWorkspace, "streets_nd");
     if (pNetDataset != null)
     {
         //  m_NAContext = Utility.CreateSolverContext(pNetDataset, "��ʩ");
         m_pNetDataset = pNetDataset;
         return true;
     }
     else
     {
         return false;
     }
 }
        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);
        }
Пример #56
0
        //创建解决器上下文
        public static INAContext CreateSolverContext(INetworkDataset networkDataset,string ServiceType)
        {
            //Get the Data Element
            IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);

            INASolver naSolver=null;
            switch (ServiceType)
            {
                case "路线":
                    naSolver = new NARouteSolverClass();
                    break;
                case "服务":
                    naSolver = new NAServiceAreaSolverClass();
                    break;
                case "设施":
                    naSolver = new NAClosestFacilitySolverClass();
                    break;
                case "费用":
                    naSolver = new NAODCostMatrixSolverClass();
                    break;
            }
             
            INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.Name) as INAContextEdit;
            contextEdit.Bind(networkDataset, new GPMessagesClass());
            return contextEdit as INAContext;
        }