Esempio n. 1
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);
        }
Esempio n. 2
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;
        }
        /// <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);
        }
Esempio n. 4
0
        public ILayer GetNetworkLayer()
        {
            INetworkLayer networkLayer = new NetworkLayerClass();

            networkLayer.NetworkDataset = _networkDataset;
            var layer = networkLayer as ILayer;

            layer.Name = "路网";
            return(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);
		}
        //*********************************************************************************
        // Initialize the form, create a NA context, load some locations and draw the map
        //*********************************************************************************
        private void Initialize()
        {
            // Open Geodatabase and network dataset
            IFeatureWorkspace featureWorkspace = OpenWorkspace(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"ArcGIS\data\SanFrancisco\SanFrancisco.gdb")) as IFeatureWorkspace;
            INetworkDataset   networkDataset   = OpenNetworkDataset(featureWorkspace as IWorkspace, "Transportation", "Streets_ND");

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

            // Get Cost Attributes and populate the combo drop down box
            INetworkAttribute networkAttribute;

            for (int i = 0; i < networkDataset.AttributeCount - 1; i++)
            {
                networkAttribute = networkDataset.get_Attribute(i);
                if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
                {
                    cboCostAttribute.Items.Add(networkAttribute.Name);
                    cboCostAttribute.SelectedIndex = 0;
                }
            }

            // Set the default number of facilities to solve for
            txtFacilitiesToLocate.Text = "1";

            // Set up the no cutoff for the Minimize Impedance case.
            // See the cboProblemType_SelectedIndexChanged routine for how this is managed for other problem types
            txtCutOff.Text = "<None>";

            // Populate combo box with Location-Allocation problem types
            cboProblemType.Items.Add("Minimize Impedance");
            cboProblemType.Items.Add("Maximize Coverage");
            cboProblemType.Items.Add("Maximize Capacitated Coverage");
            cboProblemType.Items.Add("Minimize Facilities");
            cboProblemType.Items.Add("Maximize Attendance");
            cboProblemType.Items.Add("Maximize Market Share");
            cboProblemType.Items.Add("Target Market Share");
            cboProblemType.Text = "Minimize Impedance";
            m_ProblemType       = "Minimize Impedance";

            // Populate combo box with Impedance Transformation choices
            cboImpTransformation.Items.Add("Linear");
            cboImpTransformation.Items.Add("Power");
            cboImpTransformation.Items.Add("Exponential");
            cboImpTransformation.Text = "Linear";

            // Set the default impedance transformation parameter
            txtImpParameter.Text = "1.0";

            // Set up the default percentage for the Target Market Share problem type
            txtTargetMarketShare.Text = "10.0";

            // Set up the default capacity
            txtDefaultCapacity.Text = "1.0";

            // Load facility locations from feature class
            IFeatureClass inputFClass = featureWorkspace.OpenFeatureClass("CandidateStores");

            LoadNANetworkLocations("Facilities", inputFClass, 500);

            // Load demand point locations from feature class
            inputFClass = featureWorkspace.OpenFeatureClass("TractCentroids");
            LoadNANetworkLocations("DemandPoints", inputFClass, 500);

            // Create Layer for Network Dataset and add to Ax Map Control
            ILayer        layer;
            INetworkLayer networkLayer;

            networkLayer = new NetworkLayerClass();
            networkLayer.NetworkDataset = networkDataset;
            layer      = networkLayer as ILayer;
            layer.Name = "Network Dataset";
            axMapControl.AddLayer(layer, 0);

            // Create a Network Analysis Layer and add to Ax Map Control
            INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext);

            layer      = naLayer as ILayer;
            layer.Name = m_NAContext.Solver.DisplayName;
            axMapControl.AddLayer(layer, 0);
        }
        /// <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(Application.StartupPath + @"\..\..\..\..\..\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);
		}
Esempio n. 8
0
		/// <summary>
		/// 将网络数据添加到地图中
		/// </summary>
		/// <param name="dataPath">网络数据路径</param>
		/// <param name="_mapControl">地图控件</param>
		/// <param name="_pNAContext">INAContext</param>
		/// <param name="cmbCost">获取网络数据集里面的代价字段</param>
		/// <param name="isRoute">是否使用route</param>
		public void loadNetworkData(string dataPath,AxMapControl _mapControl,ref INAContext _pNAContext,ComboBox cmbCost,bool isRoute)
		{

				     
			IFeatureWorkspace pFWorkspace;
            
			INetworkDataset pNetworkDataset;
			
			INetworkAttribute pNetworkAttribute;

			int i;

			IFeatureClass pInputFClass;
			
			//打开workspace
			pFWorkspace=OpenWorkspace(dataPath) as IFeatureWorkspace;

			//打开network Dataset

			pNetworkDataset=OpenNetworkDataset(pFWorkspace as IWorkspace,"Streets_nd");

			if(isRoute==false)
			_pNAContext=CreateSolverContext(pNetworkDataset);
			else
				_pNAContext=CreateRouteSolverContext(pNetworkDataset);

			// Get Cost Attributes
			for(i=0;i<pNetworkDataset.AttributeCount;i++)
			{

				//get the attribute of the network dataset
                			    
				pNetworkAttribute=pNetworkDataset.get_Attribute(i);
				//if it is a cost attribute,add it to combo box

				if(pNetworkAttribute.UsageType==esriNetworkAttributeUsageType.esriNAUTCost)
				{
					cmbCost.Items.Add(pNetworkAttribute.Name);

				
				}

			


			}
			cmbCost.SelectedIndex=0;

			

			if(isRoute==false)
			{
				pInputFClass = pFWorkspace.OpenFeatureClass("BayAreaIncident");
				LoadNANetworkLocations("Incidents",pInputFClass, 100,ref _pNAContext);
			}
			else
			{
			
			}


			
			pInputFClass = pFWorkspace.OpenFeatureClass("BayAreaLocations");
			if(isRoute==false)
			{
				LoadNANetworkLocations("Facilities", pInputFClass, 100,ref _pNAContext);
			}
			else
			{
				LoadNANetworkLocations("Stops", pInputFClass, 100,ref _pNAContext);
			
			}
			

			
			//'Create Layer for Network Dataset and add to ArcMap
			
			ILayer pLayer;
			INetworkLayer pNetworkLayer=new NetworkLayerClass();

			pNetworkLayer.NetworkDataset = pNetworkDataset;

			pLayer = pNetworkLayer as ILayer;

			pLayer.Name = "Network Dataset";

			_mapControl.AddLayer(pLayer,0);

			//Create a Network Analysis Layer and add to ArcMap

			
			INALayer pNALayer=_pNAContext.Solver.CreateLayer(_pNAContext);
			pLayer = pNALayer as ILayer;
			pLayer.Name = _pNAContext.Solver.DisplayName;
			_mapControl.AddLayer(pLayer,0);
			

		}
Esempio n. 9
0
        /// <summary>
        /// Initialize the solver by calling the ArcGIS Network Analyst extension functions.
        /// </summary>
        private void Initialize()
        {
            IFeatureWorkspace featureWorkspace = null;
            INetworkDataset   networkDataset   = null;

            try
            {
                // Open Geodatabase and 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; i++)
            {
                networkAttribute = networkDataset.get_Attribute(i);
                if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
                {
                    string unitType = GetAttributeUnitType(networkAttribute.Units);
                    if (unitType == "Time")
                    {
                        comboTimeAttribute.Items.Add(networkAttribute.Name);
                    }
                    else if (unitType == "Distance")
                    {
                        comboDistanceAttribute.Items.Add(networkAttribute.Name);
                    }
                }
            }
            comboTimeAttribute.SelectedIndex     = 0;
            comboDistanceAttribute.SelectedIndex = 0;

            // Populate time field unit in comboBox
            m_unitTimeList = new System.Collections.Hashtable();
            m_unitTimeList.Add("Seconds", esriNetworkAttributeUnits.esriNAUSeconds);
            m_unitTimeList.Add("Minutes", esriNetworkAttributeUnits.esriNAUMinutes);
            foreach (System.Collections.DictionaryEntry timeUnit in m_unitTimeList)
            {
                comboTimeUnits.Items.Add(timeUnit.Key.ToString());
            }
            comboTimeUnits.SelectedIndex = 1;

            // Populate distance field unit in comboBox
            m_unitDistList = new System.Collections.Hashtable();
            m_unitDistList.Add("Miles", esriNetworkAttributeUnits.esriNAUMiles);
            m_unitDistList.Add("Meters", esriNetworkAttributeUnits.esriNAUMeters);
            foreach (System.Collections.DictionaryEntry distUnit in m_unitDistList)
            {
                comboDistUnits.Items.Add(distUnit.Key.ToString());
            }
            comboDistUnits.SelectedIndex = 0;

            // Populate time window importance attribute in comboBox
            comboTWImportance.Items.Add("High");
            comboTWImportance.Items.Add("Medium");
            comboTWImportance.Items.Add("Low");
            comboTWImportance.SelectedIndex = 0;

            // Load locations
            IFeatureClass inputFClass = featureWorkspace.OpenFeatureClass("Stores");

            LoadNANetworkLocations("Orders", inputFClass as ITable);
            inputFClass = featureWorkspace.OpenFeatureClass("DistributionCenter");
            LoadNANetworkLocations("Depots", inputFClass as ITable);
            inputFClass = featureWorkspace.OpenFeatureClass("Routes");
            LoadNANetworkLocations("Routes", inputFClass as ITable);
            ITable inputTable = featureWorkspace.OpenTable("Breaks");

            LoadNANetworkLocations("Breaks", inputTable);

            // Create layer for network dataset and add to ArcMap
            INetworkLayer networkLayer = new NetworkLayerClass();

            networkLayer.NetworkDataset = networkDataset;
            ILayer 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);
        }
Esempio n. 10
0
        public void LoadData(IList ilist_0)
        {
            IEnumDataset      subsets;
            IDataset          j;
            string            str;
            IFeatureClass     dataset;
            IFeatureLayer     cadFeatureLayerClass;
            ITopologyLayer    topologyLayerClass;
            IEnumFeatureClass classes;
            IFeatureClass     m;
            IFeatureClass     n;
            IFeatureLayer     featureLayerClass;
            List <object>     objs = new List <object>();

            foreach (object ilist0 in ilist_0)
            {
                if (ilist0 is IGxDataset)
                {
                    if ((ilist0 as IGxDataset).Type != esriDatasetType.esriDTFeatureDataset)
                    {
                        objs.Add(ilist0);
                    }
                    else
                    {
                        IEnumGxObject children = (ilist0 as IGxObjectContainer).Children;
                        children.Reset();
                        for (IGxObject i = children.Next(); i != null; i = children.Next())
                        {
                            objs.Add(i);
                        }
                    }
                }
                else if (!(ilist0 is IDataset))
                {
                    objs.Add(ilist0);
                }
                else
                {
                    if ((ilist0 as IDataset).Type != esriDatasetType.esriDTFeatureDataset)
                    {
                        continue;
                    }
                    subsets = (ilist0 as IDataset).Subsets;
                    subsets.Reset();
                    for (j = subsets.Next(); j != null; j = subsets.Next())
                    {
                        objs.Add(j);
                    }
                }
            }
            ProcessAssist processAssist = new ProcessAssist();

            processAssist.InitProgress();
            processAssist.SetMaxValue(objs.Count);
            processAssist.SetMessage("正在加载数据,请稍候...");
            processAssist.Start();
            try
            {
                ILayer layer = null;
                IMap   map   = this.GetMap();
                this.list_0 = new List <ILayer>();
                List <string> strs      = new List <string>();
                IEnvelope     envelope  = null;
                IDataset      item      = null;
                IGxDataset    gxDataset = null;
                for (int k = 0; k < objs.Count; k++)
                {
                    string name = "";
                    if (objs[k] is IGxObject)
                    {
                        name = (objs[k] as IGxObject).Name;
                    }
                    else if (objs[k] is IDataset)
                    {
                        name = (objs[k] as IDataset).Name;
                    }
                    bool flag = true;
                    str = string.Format("加载图层[{0}],第{1}/{2}个", name, k + 1, objs.Count);
                    processAssist.Increment(1);
                    processAssist.SetMessage(str);
                    if (objs[k] is IGxLayer)
                    {
                        layer = (objs[k] as IGxLayer).Layer;
                        if (layer is IGeoDataset && !SpatialReferenctOperator.ValideFeatureClass(layer as IGeoDataset))
                        {
                            strs.Add(layer.Name);
                            flag = false;
                        }
                        this.AddLayer(map, layer, ref envelope, flag);
                    }
                    else if (!(objs[k] is IGxAGSObject))
                    {
                        if (objs[k] is IGxDataset)
                        {
                            gxDataset = objs[k] as IGxDataset;
                            item      = gxDataset.Dataset;
                        }
                        else if (ilist_0[k] is IDataset)
                        {
                            item = objs[k] as IDataset;
                        }
                        if (item != null)
                        {
                            if (item is IGeoDataset)
                            {
                                flag = SpatialReferenctOperator.ValideFeatureClass(item as IGeoDataset);
                            }
                            if (item.Type == esriDatasetType.esriDTFeatureClass)
                            {
                                dataset = (IFeatureClass)item;
                                if ((gxDataset as IGxObject).Category.IndexOf("CAD") != -1)
                                {
                                    if (dataset.FeatureType != esriFeatureType.esriFTCoverageAnnotation)
                                    {
                                        cadFeatureLayerClass = new CadFeatureLayerClass();
                                    }
                                    else
                                    {
                                        cadFeatureLayerClass = new CadAnnotationLayerClass();
                                    }
                                    cadFeatureLayerClass.FeatureClass = dataset;
                                    cadFeatureLayerClass.Name         = dataset.AliasName;
                                }
                                else if (dataset.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                else if (dataset.FeatureType != esriFeatureType.esriFTDimension)
                                {
                                    cadFeatureLayerClass = new FeatureLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                else
                                {
                                    cadFeatureLayerClass = new DimensionLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                if (!flag)
                                {
                                    strs.Add(cadFeatureLayerClass.Name);
                                }
                                this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                            }
                            else if (item.Type == esriDatasetType.esriDTCadDrawing)
                            {
                                if ((gxDataset as IGxObject).Category != "CAD绘图")
                                {
                                    IEnumGxObject enumGxObject = (gxDataset as IGxObjectContainer).Children;
                                    enumGxObject.Reset();
                                    for (IGxDataset l = enumGxObject.Next() as IGxDataset; l != null; l = enumGxObject.Next() as IGxDataset)
                                    {
                                        dataset = l.Dataset as IFeatureClass;
                                        if (dataset != null)
                                        {
                                            if (dataset.FeatureType != esriFeatureType.esriFTAnnotation)
                                            {
                                                cadFeatureLayerClass = new CadFeatureLayerClass()
                                                {
                                                    FeatureClass = dataset,
                                                    Name         = dataset.AliasName
                                                };
                                            }
                                            else
                                            {
                                                cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                                {
                                                    FeatureClass = dataset,
                                                    Name         = dataset.AliasName
                                                };
                                            }
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag1 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag1;
                                                if (!flag1)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                    }
                                }
                                else
                                {
                                    ICadLayer cadLayerClass = new CadLayerClass()
                                    {
                                        CadDrawingDataset = gxDataset.Dataset as ICadDrawingDataset,
                                        Name = gxDataset.Dataset.Name
                                    };
                                    if (!flag)
                                    {
                                        strs.Add(cadLayerClass.Name);
                                    }
                                    this.AddLayer(map, cadLayerClass, ref envelope, flag);
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTFeatureDataset)
                            {
                                subsets = item.Subsets;
                                subsets.Reset();
                                for (j = subsets.Next(); j != null; j = subsets.Next())
                                {
                                    if (j.Type == esriDatasetType.esriDTFeatureClass)
                                    {
                                        dataset = j as IFeatureClass;
                                        if (dataset.FeatureType != esriFeatureType.esriFTAnnotation)
                                        {
                                            cadFeatureLayerClass = new FeatureLayerClass()
                                            {
                                                FeatureClass = dataset,
                                                Name         = dataset.AliasName
                                            };
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag2 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag2;
                                                if (!flag2)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                        else
                                        {
                                            cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                            {
                                                FeatureClass = dataset,
                                                Name         = dataset.AliasName
                                            };
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag3 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag3;
                                                if (!flag3)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                    }
                                    else if (j.Type == esriDatasetType.esriDTTopology)
                                    {
                                        topologyLayerClass = new TopologyLayerClass()
                                        {
                                            Topology = j as ITopology
                                        };
                                        (topologyLayerClass as ILayer).Name = j.Name;
                                        this.AddLayer(map, topologyLayerClass as ILayer, ref envelope, true);
                                    }
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTTopology)
                            {
                                if (MessageBox.Show(string.Concat("是否将参加拓扑-", item.Name, "-的所有要素添加到地图中"), "添加拓扑层", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                                {
                                    classes = (item as IFeatureClassContainer).Classes;
                                    classes.Reset();
                                    for (m = classes.Next(); m != null; m = classes.Next())
                                    {
                                        cadFeatureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = m,
                                            Name         = m.AliasName
                                        };
                                        flag = true;
                                        if (cadFeatureLayerClass is IGeoDataset)
                                        {
                                            bool flag4 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                            flag = flag4;
                                            if (!flag4)
                                            {
                                                strs.Add(cadFeatureLayerClass.Name);
                                            }
                                        }
                                        this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                    }
                                }
                                topologyLayerClass = new TopologyLayerClass()
                                {
                                    Topology = item as ITopology
                                };
                                (topologyLayerClass as ILayer).Name = item.Name;
                                this.AddLayer(map, topologyLayerClass as ILayer, ref envelope, true);
                            }
                            else if (item.Type == esriDatasetType.esriDTTin)
                            {
                                ITinLayer tinLayerClass = new TinLayerClass()
                                {
                                    Dataset = (ITin)item,
                                    Name    = item.Name
                                };
                                flag = true;
                                if (tinLayerClass is IGeoDataset)
                                {
                                    bool flag5 = SpatialReferenctOperator.ValideFeatureClass(tinLayerClass as IGeoDataset);
                                    flag = flag5;
                                    if (!flag5)
                                    {
                                        strs.Add(tinLayerClass.Name);
                                    }
                                }
                                this.AddLayer(map, tinLayerClass, ref envelope, flag);
                            }
                            else if (item.Type == esriDatasetType.esriDTRasterCatalog)
                            {
                                IGdbRasterCatalogLayer gdbRasterCatalogLayerClass = null;
                                gdbRasterCatalogLayerClass = new GdbRasterCatalogLayerClass();
                                if (gdbRasterCatalogLayerClass.Setup((ITable)(item as IRasterCatalog)))
                                {
                                    bool flag6 = SpatialReferenctOperator.ValideFeatureClass(gdbRasterCatalogLayerClass as IGeoDataset);
                                    flag = flag6;
                                    if (!flag6)
                                    {
                                        strs.Add((gdbRasterCatalogLayerClass as ILayer).Name);
                                    }
                                    this.AddLayer(map, gdbRasterCatalogLayerClass as ILayer, ref envelope, flag);
                                }
                            }
                            else if (!(item.Type == esriDatasetType.esriDTRasterDataset ? false : item.Type != esriDatasetType.esriDTRasterBand))
                            {
                                bool flag7 = true;
                                if (!((IRasterPyramid)item).Present)
                                {
                                    if (this.m_pApp.PyramidPromptType == PyramidPromptType.AlwaysBuildNoPrompt)
                                    {
                                        ((IRasterPyramid)item).Create();
                                    }
                                    else if (this.m_pApp.PyramidPromptType == PyramidPromptType.AlwaysPrompt)
                                    {
                                        DialogResult dialogResult = BuildPyramidSet.Show();
                                        if (dialogResult == DialogResult.Yes)
                                        {
                                            ((IRasterPyramid)item).Create();
                                        }
                                        else if (dialogResult == DialogResult.Cancel)
                                        {
                                            flag7 = false;
                                        }
                                    }
                                }
                                if (flag7)
                                {
                                    IRasterLayer rasterLayerClass = new RasterLayerClass()
                                    {
                                        Cached = true
                                    };
                                    rasterLayerClass.CreateFromDataset((IRasterDataset)item);
                                    rasterLayerClass.Name = item.Name;
                                    bool flag8 = SpatialReferenctOperator.ValideFeatureClass(rasterLayerClass as IGeoDataset);
                                    flag = flag8;
                                    if (!flag8)
                                    {
                                        strs.Add(rasterLayerClass.Name);
                                    }
                                    this.AddLayer(map, rasterLayerClass, ref envelope, flag);
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTTable)
                            {
                                try
                                {
                                    IStandaloneTableCollection standaloneTableCollection = this.GetMap() as IStandaloneTableCollection;
                                    IPropertySet connectionProperties = item.Workspace.ConnectionProperties;
                                    bool         flag9 = false;
                                    int          num   = 0;
                                    while (true)
                                    {
                                        if (num < standaloneTableCollection.StandaloneTableCount)
                                        {
                                            ITable table = standaloneTableCollection.StandaloneTable[num].Table;
                                            if (!connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) || !((table as IDataset).Name == item.Name))
                                            {
                                                num++;
                                            }
                                            else
                                            {
                                                flag9 = true;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    if (!flag9)
                                    {
                                        standaloneTableCollection.AddStandaloneTable(new StandaloneTableClass()
                                        {
                                            Table = item as ITable
                                        });
                                    }
                                }
                                catch (Exception exception)
                                {
                                    CErrorLog.writeErrorLog(this, exception, "");
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTGeometricNetwork)
                            {
                                IGeometricNetwork geometricNetwork = item as IGeometricNetwork;
                                if (geometricNetwork != null)
                                {
                                    IEnumFeatureClass classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleJunction];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexJunction];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleEdge];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexEdge];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTNetworkDataset)
                            {
                                INetworkLayer networkLayerClass = new NetworkLayerClass()
                                {
                                    NetworkDataset = item as INetworkDataset
                                };
                                this.AddLayer(map, networkLayerClass as ILayer, ref envelope, true);
                                if (MessageBox.Show(string.Concat("是否将参加网络要素集-", item.Name, "-的所有要素添加到地图中"), "添加拓扑层", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                                {
                                    classes = (item as IFeatureClassContainer).Classes;
                                    classes.Reset();
                                    for (m = classes.Next(); m != null; m = classes.Next())
                                    {
                                        cadFeatureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = m,
                                            Name         = m.AliasName
                                        };
                                        this.AddLayer(map, cadFeatureLayerClass, ref envelope, true);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        IMapServerLayer mapServerLayerClass = new MapServerLayerClass();
                        mapServerLayerClass.ServerConnect((objs[k] as IGxAGSObject).AGSServerObjectName, (objs[k] as IGxAGSObject).DefaultMapName);
                        this.AddLayer(map, mapServerLayerClass as ILayer, ref envelope, false);
                    }
                }
                processAssist.End();
                bool layerCount = this.GetMap().LayerCount > 0;
                if (strs.Count > 0)
                {
                    MessageBox.Show("警告:数据范围不一致。\r\n 一个或多个添加的图层范围与关联的空间坐标系范围不一致。请检查数据问题。存在问题图层信息请查看错误日志!", "管理平台", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (string str1 in strs)
                    {
                        if (stringBuilder.Length > 0)
                        {
                            stringBuilder.Append(",");
                        }
                        stringBuilder.Append(str1);
                    }
                    CErrorLog.writeErrorLog(stringBuilder, null, "图层范围不一致!");
                }
                foreach (ILayer list0 in this.list_0)
                {
                    list0.Visible = true;
                }
                if (layerCount && envelope != null)
                {
                    IMap map1 = this.GetMap();
                    ISpatialReference spatialReference = map1.SpatialReference;
                    if ((spatialReference is IUnknownCoordinateSystem || envelope.SpatialReference is IUnknownCoordinateSystem || envelope.SpatialReference == null ? false : spatialReference != null))
                    {
                        envelope.Project(spatialReference);
                    }
                    (map1 as IActiveView).Extent = envelope;
                    (map1 as IActiveView).Refresh();
                }
                if (this.m_pApp != null)
                {
                    this.m_pApp.MapDocumentChanged();
                }
                else if (ApplicationRef.Application != null)
                {
                    ApplicationRef.Application.MapDocumentChanged();
                }
            }
            catch (Exception exception1)
            {
                str = exception1.ToString();
            }
            if (this.onLoadCompleteHand_0 != null)
            {
                this.onLoadCompleteHand_0();
            }
        }
        /// <summary>
        /// Initialize the solver by calling the ArcGIS Network Analyst extension functions.
        /// </summary>
        private void Initialize()
        {
            IFeatureWorkspace featureWorkspace = null;
            INetworkDataset   networkDataset   = null;

            try
            {
                // Open Geodatabase and network dataset
                IWorkspace workspace = OpenWorkspace(Application.StartupPath + @"\..\..\..\..\..\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
            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)
                {
                    cboCostAttribute.Items.Add(networkAttribute.Name);
                }
            }
            cboCostAttribute.SelectedIndex = 0;

            txtTargetFacility.Text = "1";
            txtCutOff.Text         = "";

            // Load incidents from a feature class
            IFeatureClass inputFClass = featureWorkspace.OpenFeatureClass("Stores");

            LoadNANetworkLocations("Incidents", inputFClass, 500);

            // Load facilities from a feature class
            inputFClass = featureWorkspace.OpenFeatureClass("FireStations");
            LoadNANetworkLocations("Facilities", inputFClass, 500);

            //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>
        /// 最短路径分析
        /// </summary>
        /// <param name="mapControl">地图控件</param>
        /// <param name="gdbfileName">数据库文件</param>
        /// <param name="featureDatasetName">要素集名字</param>
        /// <param name="ndsName">网络数据集名字</param>
        /// <param name="featureClasses">参数要素类及其阈值,其中键值包括:Stops(路线经过结点),Barriers,PolylineBarriers,PolygonBarriers</param>
        /// <param name="isShowDataBase">是否显示网络数据集</param>
        ///  <param name="isShowNalayer">是否显示网络分析图层</param>
        ///  <param name="routeLayer">最近路线图层</param>
        public static bool Short_Path(AxMapControl mapControl, string gdbfileName, string featureDatasetName, string ndsName, IDictionary <string, DecorateRouteFeatureClass> featureClasses, bool isShowDataBase, bool isShowNalayer, ref ILayer routeLayer)
        {
            //首先判断输入的参数要素类是否合法
            if (!FeatureClassKeyIsRight(featureClasses))
            {
                throw new Exception("参数字典错误");
            }
            // mapControl.ClearLayers();
            //打开工作空间
            IFeatureWorkspace pFeatureWorkspace = OpenWorkspace(gdbfileName) as IFeatureWorkspace;

            if (pFeatureWorkspace == null)
            {
                return(false);
            }
            //获取网络数据集
            INetworkDataset pNetworkDataset = OpenNetworkDataset(pFeatureWorkspace as IWorkspace, featureDatasetName, ndsName);

            if (pNetworkDataset == null)
            {
                Debug.Print("无法获取网络数据集");
                return(false);
            }
            //获取网络分析上下文
            INAContext pNAContext = CreateNAContext(pNetworkDataset);
            //打开节点图层 一般和网络数据集放置在一起 名称是xxx_Junctions
            IFeatureClass pVertexFC = pFeatureWorkspace.OpenFeatureClass(ndsName + "_Junctions");
            ILayer        pLayer    = null;

            // 显示网络数据集图层
            if (isShowDataBase)
            {
                INetworkLayer pNetworkLayer = new NetworkLayerClass();
                pNetworkLayer.NetworkDataset = pNetworkDataset;
                pLayer      = pNetworkLayer as ILayer;
                pLayer.Name = "网络数据集";
                mapControl.AddLayer(pLayer, 0);
            }
            //创建网络分析图层
            INALayer naLayer = pNAContext.Solver.CreateLayer(pNAContext);

            //显示网络分析图层
            if (isShowNalayer)
            {
                pLayer                  = naLayer as ILayer;
                pLayer.Name             = pNAContext.Solver.DisplayName;
                pLayer.SpatialReference = mapControl.SpatialReference;
                mapControl.AddLayer(pLayer, 0);
                IActiveView        pActiveView        = mapControl.ActiveView;
                IMap               pMap               = pActiveView.FocusMap;
                IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
                mapControl.Refresh();
            }
            INASolver naSolver = pNAContext.Solver;

            //插入相关数据
            foreach (var value in featureClasses)
            {
                LoadNANetWorkLocations(pNAContext, value.Key, value.Value.FeatureClass, value.Value.SnapTolerance);
            }
            //插入经过点
            //LoadNANetWorkLocations(pNAContext,"Stops", stopFeatureClass, 30);
            //插入障碍点
            //    LoadNANetWorkLocations(pNAContext, "Barriers", barriesFeatureClass, 30);
            IGPMessages gpMessages = new GPMessagesClass();

            //  SetSolverSettings(pNAContext);
            //寻找最短路径
            try
            {
                pNAContext.Solver.Solve(pNAContext, gpMessages, new CancelTrackerClass());
                routeLayer = naLayer.get_LayerByNAClassName("Routes");
            }
            catch (Exception e)
            {
                Debug.Print("无法找到最短路径:" + e.Message);
                return(false);
            }
            mapControl.Refresh();
            if (gpMessages != null)
            {
                for (int i = 0; i < gpMessages.Count; i++)
                {
                    switch (gpMessages.GetMessage(i).Type)
                    {
                    case esriGPMessageType.esriGPMessageTypeError:
                        Debug.Print("错误 " + gpMessages.GetMessage(i).ErrorCode.ToString() + " " + gpMessages.GetMessage(i).Description);
                        break;

                    case esriGPMessageType.esriGPMessageTypeWarning:
                        Debug.Print("警告 " + gpMessages.GetMessage(i).Description);
                        break;

                    default:
                        Debug.Print("信息 " + gpMessages.GetMessage(i).Description);
                        break;
                    }
                }
            }
            return(true);
        }
		/// <summary>
		/// Initialize the solver by calling the ArcGIS Network Analyst extension functions.
		/// </summary>
		private void Initialize()
		{
			IFeatureWorkspace featureWorkspace = null;
			INetworkDataset networkDataset = null;

			try
			{
				// Open Geodatabase and network dataset
				IWorkspace workspace = OpenWorkspace(Application.StartupPath + @"\..\..\..\..\..\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; i++)
			{
				networkAttribute = networkDataset.get_Attribute(i);
				if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
				{
					string unitType = GetAttributeUnitType(networkAttribute.Units);
					if (unitType == "Time")
					{
						comboTimeAttribute.Items.Add(networkAttribute.Name);
					}
					else if (unitType == "Distance")
					{
						comboDistanceAttribute.Items.Add(networkAttribute.Name);
					}
				}
			}
			comboTimeAttribute.SelectedIndex = 0;
			comboDistanceAttribute.SelectedIndex = 0;

			// Populate time field unit in comboBox
			m_unitTimeList = new System.Collections.Hashtable();
			m_unitTimeList.Add("Seconds", esriNetworkAttributeUnits.esriNAUSeconds);
			m_unitTimeList.Add("Minutes", esriNetworkAttributeUnits.esriNAUMinutes);
			foreach (System.Collections.DictionaryEntry timeUnit in m_unitTimeList)
			{
				comboTimeUnits.Items.Add(timeUnit.Key.ToString());
			}
			comboTimeUnits.SelectedIndex = 1;

			// Populate distance field unit in comboBox
			m_unitDistList = new System.Collections.Hashtable();
			m_unitDistList.Add("Miles", esriNetworkAttributeUnits.esriNAUMiles);
			m_unitDistList.Add("Meters", esriNetworkAttributeUnits.esriNAUMeters);
			foreach (System.Collections.DictionaryEntry distUnit in m_unitDistList)
			{
				comboDistUnits.Items.Add(distUnit.Key.ToString());
			}
			comboDistUnits.SelectedIndex = 0;

			// Populate time window importance attribute in comboBox
			comboTWImportance.Items.Add("High");
			comboTWImportance.Items.Add("Medium");
			comboTWImportance.Items.Add("Low");
			comboTWImportance.SelectedIndex = 0;

			// Load locations 
			IFeatureClass inputFClass = featureWorkspace.OpenFeatureClass("Stores");
			LoadNANetworkLocations("Orders", inputFClass as ITable);
			inputFClass = featureWorkspace.OpenFeatureClass("DistributionCenter");
			LoadNANetworkLocations("Depots", inputFClass as ITable);
			inputFClass = featureWorkspace.OpenFeatureClass("Routes");
			LoadNANetworkLocations("Routes", inputFClass as ITable);
			ITable inputTable = featureWorkspace.OpenTable("Breaks");
			LoadNANetworkLocations("Breaks", inputTable);

			// Create layer for network dataset and add to ArcMap
			INetworkLayer networkLayer = new NetworkLayerClass();
			networkLayer.NetworkDataset = networkDataset;
			ILayer 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);
		}
Esempio n. 14
0
        /// <summary>
        /// ������������ӵ���ͼ��
        /// </summary>
        /// <param name="dataPath">��������·��</param>
        /// <param name="_mapControl">��ͼ�ؼ�</param>
        /// <param name="_pNAContext">INAContext</param>
        /// <param name="cmbCost">��ȡ�������ݼ�����Ĵ����ֶ�</param>
        /// <param name="isRoute">�Ƿ�ʹ��route</param>
        public void loadNetworkData(string dataPath,AxMapControl _mapControl,ref INAContext _pNAContext,ComboBox cmbCost,bool isRoute)
        {
            IFeatureWorkspace pFWorkspace;

            INetworkDataset pNetworkDataset;

            INetworkAttribute pNetworkAttribute;

            int i;

            IFeatureClass pInputFClass;

            //��workspace
            pFWorkspace=OpenWorkspace(dataPath) as IFeatureWorkspace;

            //��network Dataset

            pNetworkDataset=OpenNetworkDataset(pFWorkspace as IWorkspace,"Streets_nd");

            if(isRoute==false)
            _pNAContext=CreateSolverContext(pNetworkDataset);
            else
                _pNAContext=CreateRouteSolverContext(pNetworkDataset);

            // Get Cost Attributes
            for(i=0;i<pNetworkDataset.AttributeCount;i++)
            {

                //get the attribute of the network dataset

                pNetworkAttribute=pNetworkDataset.get_Attribute(i);
                //if it is a cost attribute,add it to combo box

                if(pNetworkAttribute.UsageType==esriNetworkAttributeUsageType.esriNAUTCost)
                {
                    cmbCost.Items.Add(pNetworkAttribute.Name);

                }

            }
            cmbCost.SelectedIndex=0;

            if(isRoute==false)
            {
                pInputFClass = pFWorkspace.OpenFeatureClass("BayAreaIncident");
                LoadNANetworkLocations("Incidents",pInputFClass, 100,ref _pNAContext);
            }
            else
            {

            }

            pInputFClass = pFWorkspace.OpenFeatureClass("BayAreaLocations");
            if(isRoute==false)
            {
                LoadNANetworkLocations("Facilities", pInputFClass, 100,ref _pNAContext);
            }
            else
            {
                LoadNANetworkLocations("Stops", pInputFClass, 100,ref _pNAContext);

            }

            //'Create Layer for Network Dataset and add to ArcMap

            ILayer pLayer;
            INetworkLayer pNetworkLayer=new NetworkLayerClass();

            pNetworkLayer.NetworkDataset = pNetworkDataset;

            pLayer = pNetworkLayer as ILayer;

            pLayer.Name = "Network Dataset";

            _mapControl.AddLayer(pLayer,0);

            //Create a Network Analysis Layer and add to ArcMap

            INALayer pNALayer=_pNAContext.Solver.CreateLayer(_pNAContext);
            pLayer = pNALayer as ILayer;
            pLayer.Name = _pNAContext.Solver.DisplayName;
            _mapControl.AddLayer(pLayer,0);
        }
Esempio n. 15
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add ShortPathSolveCommand.OnClick implementation
            string            name        = NetWorkAnalysClass.getPath(path) + "\\data\\Geodatabase.gdb";
            IFeatureWorkspace pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace;

            //"RouteNetwork", "BaseData"参数不可更改
            networkDataset = NetWorkAnalysClass.OpenPathNetworkDataset(pFWorkspace as IWorkspace, "RouteNetwork", "BaseData");
            m_NAContext    = NetWorkAnalysClass.CreatePathSolverContext(networkDataset);
            //通过网络数据集创建网络分析上下文
            //打开要素数据集
            inputFClass   = pFWorkspace.OpenFeatureClass("Stops");
            barriesFClass = pFWorkspace.OpenFeatureClass("Barries");
            if (IfLayerExist("NetworkDataset") == false)
            {
                ILayer        layer;
                INetworkLayer networkLayer;
                networkLayer = new NetworkLayerClass();
                networkLayer.NetworkDataset = networkDataset;
                layer      = networkLayer as ILayer;
                layer.Name = "NetworkDataset";
                m_hookHelper.ActiveView.FocusMap.AddLayer(layer);
                layer.Visible = false;
            }
            if (IfLayerExist(m_NAContext.Solver.DisplayName) == true)
            {
                for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++)
                {
                    if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName)
                    {
                        m_hookHelper.FocusMap.DeleteLayer(m_hookHelper.FocusMap.get_Layer(i));
                    }
                }
            }
            INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext);
            ILayer   pLayer  = naLayer as ILayer;

            pLayer.Name = m_NAContext.Solver.DisplayName;
            m_hookHelper.ActiveView.FocusMap.AddLayer(pLayer);
            if (inputFClass.FeatureCount(null) < 2)
            {
                MessageBox.Show("只有一个站点,不能进行路径分析!");
                return;
            }
            IGPMessages gpMessages = new GPMessagesClass();

            //加载站点要素,并设置容差
            NetWorkAnalysClass.LoadNANetworkLocations("Stops", inputFClass, m_NAContext, 80);
            //加载障碍点要素,并设置容差
            NetWorkAnalysClass.LoadNANetworkLocations("Barriers", barriesFClass, m_NAContext, 5);
            INASolver naSolver = m_NAContext.Solver;//创建网络分析对象

            try
            {
                naSolver.Solve(m_NAContext, gpMessages, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("未能找到有效路径" + ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }
            for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++)
            {
                if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName)
                {
                    ICompositeLayer pCompositeLayer = m_hookHelper.FocusMap.get_Layer(i) as ICompositeLayer;
                    {
                        for (int t = 0; t < pCompositeLayer.Count; t++)
                        {
                            ILayer pResultLayer = pCompositeLayer.get_Layer(t);
                            if (pResultLayer.Name == "Stops" || pResultLayer.Name == "Barriers")
                            {
                                pResultLayer.Visible = false;
                                continue;
                            }
                        }
                    }
                }
            }
            IGeoDataset geoDataset;
            IEnvelope   envelope;

            geoDataset = m_NAContext.NAClasses.get_ItemByName("Routes") as IGeoDataset;
            envelope   = geoDataset.Extent;
            if (!envelope.IsEmpty)
            {
                envelope.Expand(1.1, 1.1, true);
            }
            m_hookHelper.ActiveView.Extent = envelope;
            m_hookHelper.ActiveView.Refresh();
        }
		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;
		}
        /// <summary>
        /// 初始化,读取shp及网络数据集
        /// </summary>
        private void initialize()
        {
            axMapControl.ActiveView.Clear();
            axMapControl.ActiveView.Refresh();
            //获取当前应用程序的目录名称
            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            int    t;

            for (t = 0; t < path.Length; t++)
            {
                if (path.Substring(t, 7) == "TinyGIS")
                {
                    break;
                }
            }
            //根据目录名称获取数据存取路径
            string name = path.Substring(0, t - 1) + "\\data\\RouteQuery.mdb";

            //打开工作空间
            pFWorkspace = OpenWorkspace(name) as IFeatureWorkspace;
            //打开网络数据集
            networkDataset = OpenNetworkDataset(pFWorkspace as IWorkspace, "road_ND", "road");
            //创建网络分析上下文,建立一种解决关系
            m_NAContext = CreateSolverContext(networkDataset);
            //打开数据集
            inputFClass = pFWorkspace.OpenFeatureClass("stops");
            IFeatureCursor pFeatureCursor = inputFClass.Search(null, false);
            IFeature       pFeature       = pFeatureCursor.NextFeature();

            while (pFeature != null)
            {
                pFeature.Delete();
                pFeature = pFeatureCursor.NextFeature();
            }
            //road_ND_JUNCTIONS图层
            IFeatureLayer vertex = new FeatureLayerClass();

            vertex.FeatureClass = pFWorkspace.OpenFeatureClass("road_ND_Junctions");
            vertex.Name         = vertex.FeatureClass.AliasName;
            axMapControl.AddLayer(vertex, 0);
            //road图层
            IFeatureLayer road3;

            road3 = new FeatureLayerClass();
            road3.FeatureClass = pFWorkspace.OpenFeatureClass("road");
            road3.Name         = road3.FeatureClass.AliasName;
            axMapControl.AddLayer(road3, 0);
            //为networkdataset生成一个图层,并将该图层添加到axmapcontrol中
            ILayer        pLayer;//网络图层
            INetworkLayer pNetworkLayer;

            pNetworkLayer = new NetworkLayerClass();
            pNetworkLayer.NetworkDataset = networkDataset;
            pLayer      = pNetworkLayer as ILayer;
            pLayer.Name = "Network Dataset";
            axMapControl.AddLayer(pLayer, 0);
            //生成一个网络分析图层并添加到axmaptrol中
            ILayer   layer1;
            INALayer nalayer = m_NAContext.Solver.CreateLayer(m_NAContext);

            layer1      = nalayer as ILayer;
            layer1.Name = m_NAContext.Solver.DisplayName;
            axMapControl.AddLayer(layer1, 0);
            m_ipActiveView = axMapControl.ActiveView;
            m_ipMap        = m_ipActiveView.FocusMap;
            PGC            = m_ipMap as IGraphicsContainer;
        }
        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);
        }
        /// <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);
		}
Esempio n. 20
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            string            name        = NetWorkAnalysClass.getPath(path) + "\\data\\HuanbaoGeodatabase.gdb"; //得到数据库文件路径
            IFeatureWorkspace pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace;         //打开要素工作空间

            //"RouteNetwork","BaseData"参数不可更改
            networkDataset = NetWorkAnalysClass.OpenPathNetworkDataset(pFWorkspace as IWorkspace,
                                                                       "RouteNetwork", "BaseData"); //打开网络数据集
            m_NAContext = NetWorkAnalysClass.CreatePathSolverContext(networkDataset);               //通过网络数据集创建网络分析上下文


            inputFClass   = pFWorkspace.OpenFeatureClass("Stops");   //根据名字打开站点要素类
            barriesFClass = pFWorkspace.OpenFeatureClass("Barries"); //根据名字打开障碍点要素类
            if (IFLayerExist("NetworkDataset") == false)             //若不存在NetworkDataset图层就执行
            {
                //创建名为“NetworkDataset”的图层
                ILayer        layer;
                INetworkLayer networkLayer;
                networkLayer = new NetworkLayerClass();
                networkLayer.NetworkDataset = networkDataset;
                layer      = networkLayer as ILayer;
                layer.Name = "NetworkDataset";
                m_hookHelper.ActiveView.FocusMap.AddLayer(layer);
                layer.Visible = false;
            }
            //检查是否存在名为“Route”的图层。若存在则删除
            if (IFLayerExist(m_NAContext.Solver.DisplayName) == true)
            {
                for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++)
                {
                    if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName)
                    {
                        m_hookHelper.FocusMap.DeleteLayer(m_hookHelper.FocusMap.get_Layer(i));
                    }
                }
            }
            INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext);
            ILayer   pLayer  = naLayer as ILayer;

            pLayer.Name = m_NAContext.Solver.DisplayName;
            m_hookHelper.ActiveView.FocusMap.AddLayer(pLayer);//往当前地图中添加该图层


            int featureCount = inputFClass.FeatureCount(null); //得到站点要素类中要素的个数

            if (featureCount < 2)                              //若少于两个则不能进行分析
            {
                MessageBox.Show("只有一个站点,不能进行路径分析!");
                return;
            }
            IGPMessages gpMessages = new GPMessagesClass();//定义一个地理处理结果信息返回对象

            //加载站点要素,并设置容差
            NetWorkAnalysClass.LoadNANetworkLocations("Stops", inputFClass, m_NAContext, 80);
            //加载障碍点要素,并设置容差
            NetWorkAnalysClass.LoadNANetworkLocations("Barriers", barriesFClass, m_NAContext, 50);
            INASolver naSolver = m_NAContext.Solver;//创建网络分析对象

            try
            {
                naSolver.Solve(m_NAContext, gpMessages, null);//执行最短路径分析
            }
            catch (Exception ex)
            {
                MessageBox.Show("未能找到有效路径" + ex.Message, "提示",
                                MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }
            //将“Routes”图层组下的“Stops”、“Point Barriers”图层设为不可见
            for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++)
            {
                if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName)
                {
                    //ICompositeLayer Interface Provides access to members that work with a collection of layers that behaves like a single layer.
                    //CompositeLayer为图层组类型
                    ICompositeLayer pCompositeLayer = m_hookHelper.FocusMap.get_Layer(i) as ICompositeLayer;
                    for (int t = 0; t < pCompositeLayer.Count; t++)
                    {
                        ILayer pResultLayer = pCompositeLayer.get_Layer(t);
                        if (pResultLayer.Name == "Stops" || pResultLayer.Name == "Point Barriers")
                        {
                            pResultLayer.Visible = false;
                            continue;
                        }
                    }
                }
            }

            //接下来将地图的视图范围缩放至最短路径的显示范围
            IGeoDataset geoDataset; //地理数据集
            IEnvelope   envelope;   //最小边界矩形

            geoDataset = m_NAContext.NAClasses.get_ItemByName("Routes") as IGeoDataset;
            //The IGeoDataset::Extent property returns an envelope representing the maximum extent of data which has been stored in the dataset.
            envelope = geoDataset.Extent;
            if (!envelope.IsEmpty)
            {
                envelope.Expand(1.1, 1.1, true);
            }
            //将地图的显示的范围设置为“Routes”图层的数据范围
            m_hookHelper.ActiveView.Extent = envelope;
            //刷新视图
            m_hookHelper.ActiveView.Refresh();
            //获取最短路径“Routes”要素
            ITable  table  = m_NAContext.NAClasses.get_ItemByName("Routes") as ITable;
            ICursor cursor = table.Search(null, false);
            IRow    row    = cursor.NextRow();

            for (int i = 0; i < table.Fields.FieldCount; i++)
            {
                if (table.Fields.get_Field(i).AliasName == "Total_Shape_Length")
                {
                    //获取最短路径的总长度
                    total_Length_str = row.get_Value(i).ToString();
                }
            }
        }
Esempio n. 21
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");
        }
Esempio n. 22
0
        public override void OnClick()
        {
            // TODO: Add ShortPathSolveCommand.OnClick implementation
            //string name = NetWorkAnalysClass.getPath(path) + "\\data\\HuanbaoGeodatabase.gdb";
            IFeatureWorkspace pFWorkspace = NetWorkAnalysClass.OpenWorkspace(_name) as IFeatureWorkspace;

            //"RouteNetwork", "BaseData"�������ɸ���
            networkDataset = NetWorkAnalysClass.OpenPathNetworkDataset(pFWorkspace as IWorkspace, _networkDatasetName, _featureDatasetName);
            m_NAContext    = NetWorkAnalysClass.CreatePathSolverContext(networkDataset);
            //ͨ���������ݼ������������������
            //��Ҫ�����ݼ�
            inputFClass   = pFWorkspace.OpenFeatureClass("Stops");
            barriesFClass = pFWorkspace.OpenFeatureClass("Barries");
            if (IfLayerExist("NetworkDataset") == false)
            {
                ILayer        layer;
                INetworkLayer networkLayer;
                networkLayer = new NetworkLayerClass();
                networkLayer.NetworkDataset = networkDataset;
                layer      = networkLayer as ILayer;
                layer.Name = "NetworkDataset";
                m_hookHelper.ActiveView.FocusMap.AddLayer(layer);
                layer.Visible = false;
            }
            if (IfLayerExist(m_NAContext.Solver.DisplayName) == true)
            {
                for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++)
                {
                    if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName)
                    {
                        m_hookHelper.FocusMap.DeleteLayer(m_hookHelper.FocusMap.get_Layer(i));
                    }
                }
            }
            INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext);
            ILayer   pLayer  = naLayer as ILayer;

            pLayer.Name = m_NAContext.Solver.DisplayName;
            m_hookHelper.ActiveView.FocusMap.AddLayer(pLayer);
            if (inputFClass.FeatureCount(null) < 2)
            {
                MessageBox.Show("Only one point, can not execute !");
                return;
            }
            IGPMessages gpMessages = new GPMessagesClass();

            //����վ��Ҫ�أ��������ݲ�
            NetWorkAnalysClass.LoadNANetworkLocations("Stops", inputFClass, m_NAContext, 80);
            //�����ϰ���Ҫ�أ��������ݲ�
            NetWorkAnalysClass.LoadNANetworkLocations("Barriers", barriesFClass, m_NAContext, 5);
            INASolver naSolver = m_NAContext.Solver;//���������������

            try
            {
                naSolver.Solve(m_NAContext, gpMessages, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("δ���ҵ���Ч·��" + ex.Message, "��ʾ", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }
            for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++)
            {
                if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName)
                {
                    ICompositeLayer pCompositeLayer = m_hookHelper.FocusMap.get_Layer(i) as ICompositeLayer;
                    {
                        for (int t = 0; t < pCompositeLayer.Count; t++)
                        {
                            ILayer pResultLayer = pCompositeLayer.get_Layer(t);
                            if (pResultLayer.Name == "Stops" || pResultLayer.Name == "Barriers")
                            {
                                pResultLayer.Visible = false;
                                continue;
                            }
                        }
                    }
                }
            }
            IGeoDataset geoDataset;

            //IEnvelope envelope;
            geoDataset = m_NAContext.NAClasses.get_ItemByName("Routes") as IGeoDataset;
            var envelope = geoDataset.Extent;

            if (!envelope.IsEmpty)
            {
                envelope.Expand(1.1, 1.1, true);
            }
            m_hookHelper.ActiveView.Extent = envelope;
            m_hookHelper.ActiveView.Refresh();
        }
		//*********************************************************************************
		// Initialize the form, create a NA context, load some locations and draw the map
		//*********************************************************************************
		private void Initialize()
		{
			// Open Geodatabase and network dataset
			IFeatureWorkspace featureWorkspace = OpenWorkspace(Application.StartupPath + @"\..\..\..\..\..\Data\SanFrancisco\SanFrancisco.gdb") as IFeatureWorkspace;
			INetworkDataset networkDataset = OpenNetworkDataset(featureWorkspace as IWorkspace, "Transportation", "Streets_ND");

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

			// Get Cost Attributes and populate the combo drop down box
			INetworkAttribute networkAttribute;
			for (int i = 0; i < networkDataset.AttributeCount - 1; i++)
			{
				networkAttribute = networkDataset.get_Attribute(i);
				if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
				{
					cboCostAttribute.Items.Add(networkAttribute.Name);
					cboCostAttribute.SelectedIndex = 0;
				}
			}

			// Set the default number of facilities to solve for
			txtFacilitiesToLocate.Text = "1";

			// Set up the no cutoff for the Minimize Impedance case.
			// See the cboProblemType_SelectedIndexChanged routine for how this is managed for other problem types
			txtCutOff.Text = "<None>";

			// Populate combo box with Location-Allocation problem types
			cboProblemType.Items.Add("Minimize Impedance");
			cboProblemType.Items.Add("Maximize Coverage");
            cboProblemType.Items.Add("Maximize Capacitated Coverage");
            cboProblemType.Items.Add("Minimize Facilities");
			cboProblemType.Items.Add("Maximize Attendance");
			cboProblemType.Items.Add("Maximize Market Share");
			cboProblemType.Items.Add("Target Market Share");
			cboProblemType.Text = "Minimize Impedance";
			m_ProblemType = "Minimize Impedance";

			// Populate combo box with Impedance Transformation choices
			cboImpTransformation.Items.Add("Linear");
			cboImpTransformation.Items.Add("Power");
			cboImpTransformation.Items.Add("Exponential");
			cboImpTransformation.Text = "Linear";

			// Set the default impedance transformation parameter
			txtImpParameter.Text = "1.0";

			// Set up the default percentage for the Target Market Share problem type
			txtTargetMarketShare.Text = "10.0";

            // Set up the default capacity
            txtDefaultCapacity.Text = "1.0";

			// Load facility locations from feature class
			IFeatureClass inputFClass = featureWorkspace.OpenFeatureClass("CandidateStores");
			LoadNANetworkLocations("Facilities", inputFClass, 500);

			// Load demand point locations from feature class
			inputFClass = featureWorkspace.OpenFeatureClass("TractCentroids");
			LoadNANetworkLocations("DemandPoints", inputFClass, 500);

			// Create Layer for Network Dataset and add to Ax Map Control
			ILayer layer;
			INetworkLayer networkLayer;
			networkLayer = new NetworkLayerClass();
			networkLayer.NetworkDataset = networkDataset;
			layer = networkLayer as ILayer;
			layer.Name = "Network Dataset";
			axMapControl.AddLayer(layer, 0);

			// Create a Network Analysis Layer and add to Ax Map Control
			INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext);
			layer = naLayer as ILayer;
			layer.Name = m_NAContext.Solver.DisplayName;
			axMapControl.AddLayer(layer, 0);
		}
Esempio n. 24
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);
        }