Beispiel #1
0
        /// <summary>
        /// To open the editor form, we need to first determine which barrier is
        ///  being edited, then pass that value to the form
        /// </summary>
        private void OpenBarrierEditorForm()
        {
            // get the barrier layer by using the category name to as the NAClassName
            INAWindowCategory activeCategory = GetActiveCategory();
            string            categoryName   = activeCategory.NAClass.ClassDefinition.Name;
            INALayer          naLayer        = GetActiveAnalysisLayer();
            ILayer            layer          = naLayer.get_LayerByNAClassName(categoryName);

            // get a selection count and popup a message if more or less than one item is selected
            IFeatureSelection fSel   = layer as IFeatureSelection;
            ISelectionSet     selSet = fSel.SelectionSet;

            if (selSet.Count != 1)
            {
                System.Windows.Forms.MessageBox.Show("Only one barrier in a category can be selected at a time for this command to execute", "Barrier Location Editor Warning");
            }
            else
            {
                // get the object IDs of the selected item
                int id = selSet.IDs.Next();

                // Get the barrier feature by using the selected ID
                IFeatureClass fClass         = naLayer.Context.NAClasses.get_ItemByName(categoryName) as IFeatureClass;
                IFeature      barrierFeature = fClass.GetFeature(id);

                // display the form for editing the barrier
                EditorForm form = new EditorForm(m_application, naLayer.Context, barrierFeature);
                form.ShowDialog();
                form = null;
            }
        }
Beispiel #2
0
        public static void GetClasses(INALayer layer, out NameValueCollection inputClasses,
                                      out NameValueCollection outputClasses)
        {
            INamedSet nAClasses = layer.Context.NAClasses;

            inputClasses  = new NameValueCollection();
            outputClasses = new NameValueCollection();
            for (int i = 0; i < nAClasses.Count; i++)
            {
                INAClass class2 = nAClasses.get_Item(i) as INAClass;
                string   name   = class2.ClassDefinition.Name;
                string   str2   = layer.get_LayerByNAClassName(name).Name;
                if (class2.ClassDefinition.IsInput)
                {
                    inputClasses.Add(str2, name);
                }
                else
                {
                    outputClasses.Add(str2, name);
                }
            }
        }
        /// <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);
        }