Пример #1
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add AddNetStopsTool.OnMouseDown implementation
            try
            {
                IPoint pStopsPoint = new PointClass();
                pStopsPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                IFeature newPointFeature = inputFClass.CreateFeature();
                try
                {
                    pStopsPoint.Z         = 0;
                    newPointFeature.Shape = pStopsPoint;
                    IZAware pZAware = pStopsPoint as IZAware;
                    IMAware pMAware = pStopsPoint as IMAware;
                    pZAware.ZAware = true;
                    pMAware.MAware = true;
                }
                catch
                {
                    IGeometry pGeo    = pStopsPoint;
                    IZAware   pZAware = pGeo as IZAware;
                    pZAware.ZAware = false;

                    newPointFeature.Shape = pGeo;
                }
                newPointFeature.Store();
                IGraphicsContainer pGrap = m_hookHelper.ActiveView as IGraphicsContainer;
                IColor             pColor;
                IRgbColor          pRgbColor = new RgbColorClass();
                pRgbColor.Red   = 255;
                pRgbColor.Green = 255;
                pRgbColor.Blue  = 255;
                pColor          = pRgbColor as IColor;
                IPictureMarkerSymbol pms = new PictureMarkerSymbolClass();
                pms.BitmapTransparencyColor = pColor;
                string picturePath = NetWorkAnalysClass.getPath(path) + "\\data\\Img\\stops.bmp";
                //添加自定义站点图片
                pms.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, picturePath);
                pms.Size = 18;
                IMarkerElement pMarkerEle = new MarkerElementClass();
                pMarkerEle.Symbol            = pms as IMarkerSymbol;
                pStopsPoint.SpatialReference = m_hookHelper.ActiveView.FocusMap.SpatialReference;
                IElement pEle = pMarkerEle as IElement;
                pEle.Geometry = pStopsPoint;
                pGrap.AddElement(pEle, 1);
                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
            catch
            {
                MessageBox.Show("添加站点失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
Пример #2
0
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add AddNetStopsTool.OnClick implementation
            string name = NetWorkAnalysClass.getPath(path) + "\\data\\Geodatabase.gdb";

            pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace;
            inputFClass = pFWorkspace.OpenFeatureClass("Stops");
            if (inputFClass.FeatureCount(null) > 0)
            {
                ITable pTable = inputFClass as ITable;
                pTable.DeleteSearchedRows(null);
            }
        }
 private void clearToolStripMenuItem_Click(object sender, EventArgs e)
 {
     axMapControl1.CurrentTool = null;
     try
     {
         string name = NetWorkAnalysClass.getPath(path) + "\\data\\Geodatabase.gdb";
         //打开工作空间
         pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace;
         IGraphicsContainer pGrap = this.axMapControl1.ActiveView as IGraphicsContainer;
         pGrap.DeleteAllElements();//删除所添加的图片要素
         IFeatureClass inputFClass = pFWorkspace.OpenFeatureClass("Stops");
         //删除站点要素
         if (inputFClass.FeatureCount(null) > 0)
         {
             ITable pTable = inputFClass as ITable;
             pTable.DeleteSearchedRows(null);
         }
         IFeatureClass barriesFClass = pFWorkspace.OpenFeatureClass("Barries");//删除障碍点要素
         if (barriesFClass.FeatureCount(null) > 0)
         {
             ITable pTable = barriesFClass as ITable;
             pTable.DeleteSearchedRows(null);
         }
         for (int i = 0; i < axMapControl1.LayerCount; i++)//删除分析结果
         {
             ILayer pLayer = axMapControl1.get_Layer(i);
             if (pLayer.Name == ShortPathSolveCommand.m_NAContext.Solver.DisplayName)
             {
                 axMapControl1.DeleteLayer(i);
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     this.axMapControl1.Refresh();
 }
Пример #4
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();
        }