Esempio n. 1
0
        /// <summary>
        /// 移除图层右键菜单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void removeLayer_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IBasicMap          map           = null;
            ILayer             selectedLayer = null;
            object             unk           = null;
            object             data          = null;
            esriTOCControlItem item          = esriTOCControlItem.esriTOCControlItemNone;

            m_tocControl.GetSelectedItem(ref item, ref map, ref selectedLayer, ref unk, ref data);

            if (item == esriTOCControlItem.esriTOCControlItemLayer)
            {
                IDataLayer2 datalayer = selectedLayer as IDataLayer2;
                if (datalayer.DataSourceName.NameString != "")
                {
                    datalayer.Disconnect();
                }
                m_mapControl.Map.DeleteLayer(selectedLayer);
                if (m_attForm != null && selectedLayer is IFeatureLayer)
                {
                    m_attForm.att_removetable(selectedLayer as IFeatureLayer);
                }
            }
            this.Focus();
            m_mapControl.Focus();
        }
Esempio n. 2
0
        public override void OnDblClick()
        {
            IMapControl3 pMapCtrl = ClsGlobal.GetMapControl(m_hookHelper);

            if (pMapCtrl == null)
            {
                if (m_NewPolygonFeedback != null)
                {
                    m_NewPolygonFeedback.Stop();
                    m_NewPolygonFeedback = null;
                    return;
                }
            }
            IGeometry pGeometry = m_NewPolygonFeedback.Stop();

            m_NewPolygonFeedback = null;
            if (pGeometry == null)
            {
                return;
            }

            m_pClipPolygon = pGeometry as IPolygon;
            double dbNoDataValue = m_pFrmSetRasterNoDataValue.NoDataValue;

            //获取到无效值区域、无效值、栅格数据之后,开始设置
            ClsSetRasterRegionToDataValue pSetRasterToNoDataValue = new ClsSetRasterRegionToDataValue(m_pRasterLayer.Raster, m_pClipPolygon, dbNoDataValue);

            if (!pSetRasterToNoDataValue.SetRegionToNoDataValue())
            {
                MessageBox.Show("设置无效值出错!");
            }
            else
            {
                //MessageBox.Show("设置无效值成功!");
                //重新加载栅格数据
                try
                {
                    IRaster2        pSrcRaster2        = m_pRasterLayer.Raster as IRaster2;
                    IRasterDataset  pDstRasterDataset  = pSrcRaster2.RasterDataset;
                    IRasterPyramid3 pDstRasterPyramid3 = pDstRasterDataset as IRasterPyramid3;
                    if (pDstRasterPyramid3.Present)
                    {
                        IDataLayer2 pDataLayer = m_pRasterLayer as IDataLayer2;
                        pDataLayer.Disconnect();
                        pDstRasterPyramid3.DeletePyramid();
                        pDstRasterPyramid3.Create();
                        m_pRasterLayer.CreateFromDataset(pDstRasterDataset);
                    }

                    IMapControl3 pMapControl3 = ClsGlobal.GetMapControl(m_hookHelper);
                    pMapControl3.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            base.OnDblClick();
        }
Esempio n. 3
0
        /// <summary>
        /// 关闭主窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            //try
            //{

            //检查编辑状态
            if (pEngineEditor != null && pEngineEditor.HasEdits() == false)
            {
                pEngineEditor.StopEditing(false);
            }
            else
            {
                if (pEngineEditor != null)
                {
                    if (MessageBox.Show("Save Edits?", "Save Prompt", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        pEngineEditor.StopEditing(true);
                    }
                    else
                    {
                        pEngineEditor.StopEditing(false);
                    }
                }
            }
            //恢复光标
            ICommand t_editcommand = new ESRI.ArcGIS.Controls.ControlsEditingEditToolClass();

            t_editcommand.OnCreate(m_mapControl.Object);
            m_mapControl.CurrentTool = t_editcommand as ITool;
            t_editcommand.OnClick();

            m_editinglayer.Caption = "当前图层:";
            map_edittools.Visible  = false;

            //移除图层并解除图层锁
            for (int i = m_mapControl.Map.LayerCount - 1; i >= 0; i--)
            {
                IDataLayer2 datalayer = m_mapControl.get_Layer(i) as IDataLayer2;
                if (datalayer.DataSourceName.NameString != "")
                {
                    datalayer.Disconnect();
                }
                m_mapControl.DeleteLayer(i);
            }
            //}
            //catch (Exception err)
            //{

            //    MessageBox.Show(err.Message);
            //}
        }
Esempio n. 4
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdRasterTransZ.OnClick implementation
            IMapControl3 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl3;

            if (pMapCtr != null)
            {
                FrmRasterTransZ m_frmRasterTranZ = new FrmRasterTransZ();
                if (m_frmRasterTranZ.ShowDialog() == DialogResult.OK)
                {
                    if (m_frmRasterTranZ.istrue == true)
                    {
                        ClsRasterOp     pRasterOp      = new ClsRasterOp();
                        IRaster2        pRaster2       = pRasterLayer.Raster as IRaster2;
                        IRasterDataset2 pRasterDataset = pRaster2.RasterDataset as IRasterDataset2;
                        pRasterOp.ChangeRasterValue(pRasterDataset, m_frmRasterTranZ.a, m_frmRasterTranZ.b);
                        //此处要判断图层是否存在金字塔,如果存在则需要重新创建
                        IRasterPyramid3 pDstRasterPyramid3 = pRasterDataset as IRasterPyramid3;
                        if (pDstRasterPyramid3.Present)
                        {
                            IDataLayer2 pDataLayer = pRasterLayer as IDataLayer2;
                            pDataLayer.Disconnect();

                            pDstRasterPyramid3.DeletePyramid();
                            pDstRasterPyramid3.Create();

                            pRasterLayer.CreateFromDataset(pRasterDataset);
                        }
                        //更新图层渲染方式
                        ChangeStrechRender(pRasterLayer);
                        pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                        if (m_axTocControl != null)
                        {
                            m_axTocControl.SetBuddyControl(pMapCtr);
                            m_axTocControl.Update();
                            m_axTocControl.ActiveView.Refresh();
                        }
                    }
                }
            }
        }
Esempio n. 5
0
 private void LoopCloseAllLayer(ILayer layer)
 {
     if (layer is ICompositeLayer)
     {
         ICompositeLayer cplayer = layer as ICompositeLayer;
         for (int j = cplayer.Count - 1; j >= 0; j--)
         {
             LoopCloseAllLayer(cplayer.get_Layer(j));
         }
     }
     if (layer is IDataLayer2)
     {
         IDataLayer2 pDataLayer = (IDataLayer2)layer;
         pDataLayer.Disconnect();
     }
     if (layer is IFeatureLayer)
     {
         IFeatureClass fc = (layer as IFeatureLayer).FeatureClass;
         TokayWorkspace.ComRelease(fc);
         fc = null;
     }
     this.Map.DeleteLayer(layer);
 }
Esempio n. 6
0
        /// <summary>
        /// Called when the user clicks a command.
        /// </summary>
        /// <remarks>Note to inheritors: override OnClick and use this method to
        ///             perform the actual work of the custom command.</remarks>
        public override void OnClick()
        {
            try
            {
                ILayer currentLayer = CommandAPI.GetCurrentLayer(this.m_hookHelper);
                if (currentLayer != null)
                {
                    if (!(currentLayer is MapServerRESTLayer))
                    {
                        IDataLayer2 pDataLayer = currentLayer as IDataLayer2;
                        pDataLayer.Disconnect();
                    }

                    this.m_hookHelper.ActiveView.FocusMap.DeleteLayer(currentLayer);
                    (this.m_hookHelper.ActiveView.FocusMap as IActiveView).Refresh();
                    GFS.BLL.EnviVars.instance.TOCControl.Update();
                }
            }
            catch (Exception ex)
            {
                //logger.Log(LogLevel.Error, EventType.UserManagement, AppMessage.MSG0104, ex);
                GFS.BLL.Log.WriteLog(typeof(CmdRemoveLayer), ex);
            }
        }
Esempio n. 7
0
        public static bool SwitchSource(IDataLayer2 pDataLayer, IPropertySet pSDEConnectionProps, string newDatasetName)
        {
            bool retVal = false;
            try
            {
                IDatasetName pDatasetName;
                IWorkspaceName pWorkspaceName = new WorkspaceNameClass();
                pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory";

                pWorkspaceName.ConnectionProperties = pSDEConnectionProps;

                pDatasetName = (IDatasetName)pDataLayer.DataSourceName;
                pDatasetName.WorkspaceName = pWorkspaceName;

                pDatasetName.Name = newDatasetName; //e.g. //ISDUT.TA_XXXX;

                pDataLayer.Disconnect();
                pDataLayer.DataSourceName = (IName)pDatasetName;
                pDataLayer.Connect(null);
                retVal = true;
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);
            }
            return retVal;
        }