代码改变世界

清除该图层上所有的图元

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

   private void ClearAllFeature(string tempLayerName)

{

         Catalog cat = MapInfo.Engine.Session.Current.Catalog;
            SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("");
            IResultSetFeatureCollection ifs;
            MapInfo.Data.Table Tm;
            Tm = cat.GetTable(tempLayerName);
            if (Tm != null) //Table exists close it
            {
                si = MapInfo.Data.SearchInfoFactory.SearchWhere("");
                ifs = MapInfo.Engine.Session.Current.Catalog.Search(tempLayerName, si);
                if (MessageBox.Show("确定清除所有的图元吗", "确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    foreach (Feature ft in ifs)
                    {
                        Tm.DeleteFeature(ft);//清除所有该图层上的图元
                    }
                }
                this.mapMainControl.Refresh(); //刷新地图
            }

}