代码改变世界

删除选中的图元

2012-03-27 16:18  枫桥夜泊日  阅读(200)  评论(0编辑  收藏  举报

        /// <summary>
        /// 删除选中的图元
        /// </summary>

private void ClearFeature(string tempLayerNames)
        {
            try
            {
                cat = MapInfo.Engine.Session.Current.Catalog;
                MapInfo.Data.Table Tm = cat.GetTable(tempLayerName);
                FeatureLayer lyr = mapMainControl.Map.Layers[tempLayerName] as FeatureLayer;
                if (MapInfo.Engine.Session.Current.Selections.DefaultSelection[0] != null)
                {
                    if (MessageBox.Show("确定要删除所选择的图元吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        IResultSetFeatureCollection irfc = (IResultSetFeatureCollection)MapInfo.Engine.Session.Current.Selections.DefaultSelection[0];
                        foreach (Feature l in irfc)
                        {
                            Tm.DeleteFeature(l);//删除该图层上选中的图元
                        }
                    }
                }
                else
                {
                    CommonMethod.ShowInfoMsg("请选中要删除的图元!");
                }
            }
            catch (Exception e)
            {
                CommonMethod.ShowInfoMsg(e.Message);
            }

            this.mapMainControl.Refresh(); //刷新地图
        }