您的位置:首页 > 数据库

从空间数据库中删除所有拓扑对象

2008-09-17 20:03 295 查看
/// <summary>

        /// //从空间数据库中删除所有拓扑对象

        /// </summary>

        /// <returns></returns>

        public bool DeleteALLTopolgyFromGISDB()

        {

            bool rbc = true;

            try

            {

                IWorkspace ws = this.DefaultWorkSpace;

                if (ws != null)

                {

                    //读取所有拓扑

                    IEnumDataset topEnumDataset = this.getEnumDataset(ws);

                    if (topEnumDataset != null)

                    {

                        topEnumDataset.Reset();

                        IDataset ds = topEnumDataset.Next();

                        while (ds != null)

                        {

                            switch (ds.Type)

                            {

                                case esriDatasetType.esriDTFeatureDataset:

                                    if (ds is ITopologyContainer)

                                    {

                                        ITopologyContainer topContainer = ds as ITopologyContainer;

                                        ISchemaLock schemaLock = (ISchemaLock)ds;

                                        try

                                        {

                                            schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                                            int tc = topContainer.TopologyCount;

                                            for (int i = tc - 1; i >= 0; i--)

                                            {

                                                ITopology top = topContainer.get_Topology(i);

                                                if (top != null && top is IDataset)

                                                {

                                                    //delete top's ITopologyRuleContainer 

                                                    ITopologyRuleContainer topruleList = top as ITopologyRuleContainer;

                                                    IEnumRule ER = topruleList.Rules;

                                                    ER.Reset();

                                                    IRule r = ER.Next();

                                                    while (r != null && r is ITopologyRule)

                                                    {

                                                        topruleList.DeleteRule(r as ITopologyRule);

                                                        r = ER.Next();

                                                    }

                                                    //delete top's featureclass

                                                    IFeatureClassContainer topFcList = top as IFeatureClassContainer;

                                                    for (int d = topFcList.ClassCount - 1; d >= 0; d--)

                                                    {

                                                        top.RemoveClass(topFcList.get_Class(d) as IClass);

                                                    }

                                                    //delete top object

                                                    (top as IDataset).Delete();

                                                    rbc = true;

                                                }

                                            }

                                        }

                                        catch (Exception ex)

                                        {

                                            AppLogErrWrite.WriteErrLog(ex.ToString());

                                        }

                                        finally 

                                        {

                                            schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);

                                        }

                                    }

                                    break;

                                case esriDatasetType.esriDTFeatureClass:

                                    break;

                            }

                            System.Runtime.InteropServices.Marshal.ReleaseComObject(ds);

                            ds = topEnumDataset.Next();

                        }

                        System.Runtime.InteropServices.Marshal.ReleaseComObject(topEnumDataset);

                    }//

                } //end ws!=null

            }

            catch (Exception ee)

            {

                rbc = false;

                AppLogErrWrite.WriteErrLog(ee.ToString());

            }

            return rbc;

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库 null class
相关文章推荐