基于AE的个人地理数据库(MDB格式)导入到企业级数据库(SDE数据库中)中(C#)

基于AE的个人地理数据库(mdb格式)导入到企业级数据库(sde数据库中,采用Oracle数据库)中(C#).

个人地理数据库有数据集,导入到企业级数据库后没有数据集,只有要素类。

private void btnPGD2EGD_Click(object sender, EventArgs e)
        {
            try
            {
                string pWorkspaceName = strName;
                string sdeUser = pSDEwsp.ConnectionProperties.GetProperty("USER").ToString();
                IWorkspaceFactory pMDBwspf = new AccessWorkspaceFactoryClass();
                pMDBwsp = pMDBwspf.OpenFromFile(pWorkspaceName, 0);
                Cursor = Cursors.WaitCursor;
                if (pSDEwsp != null)
                {
                    //progressBar.Visible = true;
                    DataVonverter(ref pMDBwsp, ref pSDEwsp, sdeUser);//数据导入
                    progressBar.Visible = false;
                }

                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            MessageBox.Show("mdb数据上传SDE库成功!", "数据导入", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
            
        }


  public void DataVonverter(ref IWorkspace FromWorkspace, ref IWorkspace ToWorkspace,string SDEUser)
        {
            if (SDEUser == "") return;
            IFeatureWorkspace pOutFeatureWorkspace;
            IFeatureWorkspace pInFeatureWorkspace;
            IFeatureClass pFeatureClass;
            IFeatureClass pOutFeatureClass;
            IWorkspace2 pWorkspace2;
            IEnumDataset pEnumDataset;
            IDataset pOutDataset;

            IFeatureDataset pOutFeatureDataset;
            IEnumFeatureClass pEnumFeatureClass;
            IFeatureClassContainer pFeatureclassContainer;

            pOutFeatureWorkspace = (IFeatureWorkspace)ToWorkspace;
            pInFeatureWorkspace = (IFeatureWorkspace)FromWorkspace;
            pWorkspace2 = (IWorkspace2)ToWorkspace;

            pEnumDataset = (IEnumDataset)FromWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);//获得MDB端的所有数据集
            pOutDataset = (IDataset)pEnumDataset.Next();

            while (pOutDataset != null)//遍历数据集
            {
                pOutFeatureDataset = (IFeatureDataset)pOutDataset;
                if (pOutFeatureDataset != null)
                {
                    pFeatureclassContainer = (IFeatureClassContainer)pOutFeatureDataset; 
                    pEnumFeatureClass = (IEnumFeatureClass)pFeatureclassContainer.Classes;
                    pFeatureClass = (IFeatureClass)pEnumFeatureClass.Next();
                    while (pFeatureClass != null)//在每一个数据集中遍历数据层IFeatureClass
                    {
                        if (!pFeatureClass.AliasName.Contains("UnClassfied"))
                        {
                            if (pWorkspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, SDEUser + "." + pFeatureClass.AliasName))
                            {
                                pOutFeatureClass = pOutFeatureWorkspace.OpenFeatureClass(SDEUser + "." + pFeatureClass.AliasName);
                                fc2fc(ref pFeatureClass, ref pOutFeatureClass);
                            }
                            else
                            {
                                fc2fc(ref pFeatureClass, ref ToWorkspace);
                            }
                        }
                        pFeatureClass = (IFeatureClass)pEnumFeatureClass.Next();
                    }
                }
                pOutDataset = (IDataset)pEnumDataset.Next();
            }

            ITable pInTable;
            pInTable = pInFeatureWorkspace.OpenTable("AIndexInfo");
            //如果SDE数据库中已经有AIndexInfo表,则将新的记录追加进去
            if (pWorkspace2.get_NameExists(esriDatasetType.esriDTTable, SDEUser + "." + "AIndexInfo"))
            {
                ITable pOutTable = pOutFeatureWorkspace.OpenTable("AIndexInfo");
                FusedIndexTable(ref pInTable, ref pOutTable);
            }
            else//如果SDE数据库中没有AIndexInfo表,则重新生成和来源端一样的AIndexInfo表
            {
                FusedIndexTable(ref pInTable, ref ToWorkspace);
            }
        }

posted @ 2012-05-23 17:14  LinHugh  阅读(630)  评论(0编辑  收藏  举报