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

  1. /// <summary>
  2.         /// //从空间数据库中删除所有拓扑对象
  3.         /// </summary>
  4.         /// <returns></returns>
  5.         public bool DeleteALLTopolgyFromGISDB()
  6.         {
  7.             bool rbc = true;
  8.             try
  9.             {
  10.                 IWorkspace ws = this.DefaultWorkSpace;
  11.                 if (ws != null)
  12.                 {
  13.                     //读取所有拓扑
  14.                     IEnumDataset topEnumDataset = this.getEnumDataset(ws);
  15.                     if (topEnumDataset != null)
  16.                     {
  17.                         topEnumDataset.Reset();
  18.                         IDataset ds = topEnumDataset.Next();
  19.                         while (ds != null)
  20.                         {
  21.                             switch (ds.Type)
  22.                             {
  23.                                 case esriDatasetType.esriDTFeatureDataset:
  24.                                     if (ds is ITopologyContainer)
  25.                                     {
  26.                                         ITopologyContainer topContainer = ds as ITopologyContainer;
  27.                                         ISchemaLock schemaLock = (ISchemaLock)ds;
  28.                                         try
  29.                                         {
  30.                                             schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
  31.                                             int tc = topContainer.TopologyCount;
  32.                                             for (int i = tc - 1; i >= 0; i--)
  33.                                             {
  34.                                                 ITopology top = topContainer.get_Topology(i);
  35.                                                 if (top != null && top is IDataset)
  36.                                                 {
  37.                                                     //delete top's ITopologyRuleContainer 
  38.                                                     ITopologyRuleContainer topruleList = top as ITopologyRuleContainer;
  39.                                                     IEnumRule ER = topruleList.Rules;
  40.                                                     ER.Reset();
  41.                                                     IRule r = ER.Next();
  42.                                                     while (r != null && r is ITopologyRule)
  43.                                                     {
  44.                                                         topruleList.DeleteRule(r as ITopologyRule);
  45.                                                         r = ER.Next();
  46.                                                     }
  47.                                                     //delete top's featureclass
  48.                                                     IFeatureClassContainer topFcList = top as IFeatureClassContainer;
  49.                                                     for (int d = topFcList.ClassCount - 1; d >= 0; d--)
  50.                                                     {
  51.                                                         top.RemoveClass(topFcList.get_Class(d) as IClass);
  52.                                                     }
  53.                                                     //delete top object
  54.                                                     (top as IDataset).Delete();
  55.                                                     rbc = true;
  56.                                                 }
  57.                                             }
  58.                                         }
  59.                                         catch (Exception ex)
  60.                                         {
  61.                                             AppLogErrWrite.WriteErrLog(ex.ToString());
  62.                                         }
  63.                                         finally 
  64.                                         {
  65.                                             schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
  66.                                         }
  67.                                     }
  68.                                     break;
  69.                                 case esriDatasetType.esriDTFeatureClass:
  70.                                     break;
  71.                             }
  72.                             System.Runtime.InteropServices.Marshal.ReleaseComObject(ds);
  73.                             ds = topEnumDataset.Next();
  74.                         }
  75.                         System.Runtime.InteropServices.Marshal.ReleaseComObject(topEnumDataset);
  76.                     }//
  77.                 } //end ws!=null
  78.             }
  79.             catch (Exception ee)
  80.             {
  81.                 rbc = false;
  82.                 AppLogErrWrite.WriteErrLog(ee.ToString());
  83.             }
  84.             return rbc;
  85.         }
posted @ 2008-09-17 20:03  sqlite例子  阅读(167)  评论(0)    收藏  举报