Beispiel #1
0
        private void ExportDatasetToXML(string fileGdbPath, string sourceFCName, string outputXmlFile)
        {
            // Open the source geodatabase and create a name object for it.
            IWorkspaceName sourceWorkspaceName = getWorkspaceName("esriDataSourcesGDB.FileGDBWorkspaceFactory", fileGdbPath);

            IFeatureClassName sourceFeatureClassName = getFeatureClassName(sourceWorkspaceName, sourceFCName);
            IName             sourceName             = (IName)sourceFeatureClassName;

            // Create a new names enumerator and add the feature dataset name.
            IEnumNameEdit enumNameEdit = new NamesEnumeratorClass();

            enumNameEdit.Add(sourceName);
            IEnumName enumName = (IEnumName)enumNameEdit;

            // Create a GeoDBDataTransfer object and create a name mapping.
            IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
            IEnumNameMapping   enumNameMapping   = null;

            geoDBDataTransfer.GenerateNameMapping(enumName, sourceWorkspaceName as IName, out enumNameMapping);

            // Create an exporter and export the dataset with binary geometry, not compressed,
            // and including metadata.
            IGdbXmlExport gdbXmlExport = new GdbExporterClass();

            gdbXmlExport.ExportDatasets(enumNameMapping, outputXmlFile, true, false, true);
        }
Beispiel #2
0
        public static void ExportToXml(IWorkspace sourceWorkspace, string targetPath,bool binaryGeometry,bool compressed,bool retriveMetadata)
        {
            // Open the source geodatabase and create a name object for it.
            IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
            //IWorkspace workspace = workspaceFactory.OpenFromFile(databaseName, 0);
            IDataset workspaceDataset = (IDataset)sourceWorkspace;
            IName workspaceName = workspaceDataset.FullName;

            // Retrieve the first feature dataset from the workspace.
            IEnumDatasetName enumDatasetName = sourceWorkspace.get_DatasetNames
              (esriDatasetType.esriDTFeatureDataset);
            enumDatasetName.Reset();
            IName featureDatasetName = (IName)enumDatasetName.Next();
            if (featureDatasetName == null)
            {
                throw new Exception(
                  "No feature datasets exist in the specified geodatabase.");
            }

            // Create a new names enumerator and add the feature dataset name.
            IEnumNameEdit enumNameEdit = new NamesEnumeratorClass();
            enumNameEdit.Add(featureDatasetName);
            IEnumName enumName = (IEnumName)enumNameEdit;

            // Create a GeoDBDataTransfer object and create a name mapping.
            IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
            IEnumNameMapping enumNameMapping = null;
            geoDBDataTransfer.GenerateNameMapping(enumName, workspaceName, out enumNameMapping);

            // Create an exporter and export the dataset with binary geometry, not compressed,
            // and including metadata.
            IGdbXmlExport gdbXmlExport = new GdbExporterClass();
            gdbXmlExport.ExportDatasets(enumNameMapping, targetPath, binaryGeometry, compressed, retriveMetadata);
        }
Beispiel #3
0
 private void KTreeView_DragDrop(object sender, DragEventArgs e)
 {
     if (this.bool_0)
     {
         IGxObject tag = this.treeNode_1.Tag as IGxObject;
         if (tag is IGxObjectContainer)
         {
             this.Expand(this.treeNode_1);
             IEnumNameEdit edit       = new NamesEnumeratorClass();
             IEnumerator   enumerator =
                 (e.Data.GetData("System.Collections.ArrayList") as ArrayList).GetEnumerator();
             enumerator.Reset();
             IGxObject current = null;
             while (enumerator.MoveNext())
             {
                 current = enumerator.Current as IGxObject;
                 if (current != null)
                 {
                     edit.Add(current.InternalObjectName);
                 }
             }
             if ((tag as IGxPasteTarget).Paste(edit as IEnumName, ref this.bool_1) && this.bool_1)
             {
                 enumerator.Reset();
                 while (enumerator.MoveNext())
                 {
                     current = enumerator.Current as IGxObject;
                     if (current is IGxDataset)
                     {
                         if ((current as IGxDataset).DatasetName.Type == esriDatasetType.esriDTFeatureDataset)
                         {
                             IEnumGxObject children = (current as IGxObjectContainer).Children;
                             children.Reset();
                             for (IGxObject obj5 = children.Next(); obj5 != null; obj5 = children.Next())
                             {
                                 obj5.Detach();
                             }
                         }
                         else
                         {
                             current.Detach();
                         }
                     }
                     else if (current != null)
                     {
                         current.Detach();
                     }
                 }
             }
             if (this.SelectNodeChanged != null)
             {
                 this.SelectNodeChanged(this);
             }
         }
     }
 }
Beispiel #4
0
        private IEnumNameEdit getFCNames(IWorkspace wsp, String tabnames)
        {
            Log.p("get featureclass list...");
            IEnumNameEdit edtNames = new NamesEnumeratorClass();

            String[]         tabs      = tabnames.Split(',');
            int              numItems  = 0;
            IEnumDatasetName dsetNames = wsp.get_DatasetNames(
                esriDatasetType.esriDTFeatureClass);
            //esriDatasetType.esriDTFeatureDataset);

            IDatasetName dsetName = null;

            foreach (String t in tabs)
            {
                Log.p(String.Format("    tabname is [{0}]", t));
                dsetNames.Reset();
                while (true)
                {
                    dsetName = dsetNames.Next();
                    if (dsetName == null)
                    {
                        break;
                    }
                    //Log.p(String.Format("    check feature class name [{0}]", dsetName.Name));
                    if (t.ToUpper() == dsetName.Name.ToUpper())
                    {
                        Log.p(String.Format("    add feature class name [{0}]", dsetName.Name));
                        edtNames.Add((IName)dsetName);
                        numItems += 1;
                        break;
                    }
                }
                if (dsetName == null)
                {
                    Log.p(String.Format("Error, tabname [{0}] will not exported", t), "both");
                }
            }

            if (numItems != tabs.GetLength(0))
            {
                throw new ArgumentException("Can't find all of tables in gdb.");
            }
            return(edtNames);
        } // getFCNames
Beispiel #5
0
 private void KTreeView_DragOver(object sender, DragEventArgs e)
 {
     System.Drawing.Point p = new System.Drawing.Point(e.X, e.Y);
     p = base.PointToClient(p);
     this.treeNode_1 = base.GetNodeAt(p);
     this.bool_0     = false;
     if ((this.treeNode_1 != null) && (this.treeNode_1.Tag is IGxPasteTarget))
     {
         IEnumerator enumerator = (e.Data.GetData("System.Collections.ArrayList") as ArrayList).GetEnumerator();
         enumerator.Reset();
         IEnumNameEdit edit    = new NamesEnumeratorClass();
         IGxObject     current = null;
         while (enumerator.MoveNext())
         {
             current = enumerator.Current as IGxObject;
             if (current != null)
             {
                 edit.Add(current.InternalObjectName);
             }
         }
         this.bool_0 = (this.treeNode_1.Tag as IGxPasteTarget).CanPaste(edit as IEnumName, ref this.bool_1);
     }
     if (this.bool_0)
     {
         if (this.bool_1)
         {
             e.Effect = DragDropEffects.Move;
         }
         else
         {
             e.Effect = DragDropEffects.Copy;
         }
     }
     else
     {
         e.Effect = DragDropEffects.None;
     }
 }
Beispiel #6
0
        /// <summary>
        /// 签出数据
        /// </summary>
        /// <param name="pMasterWorkspace">源工作空间</param>
        /// <param name="featureClassName">要素类的名字</param>
        /// <param name="featureDatasetName">数据集的名字</param>
        /// <param name="checkoutName">版本名称</param>
        /// <param name="onlySchema">是否只签出结构</param>
        /// <param name="reuseSchema">是否重用已有的结构</param>
        /// <param name="fileName">文件名</param>
        /// <param name="dataExtractionType">数据提取的类型(checkout或只导出数据)</param>
        /// <param name="replicaModelType">简单图层或与源工作空间结构相同</param>
        public void CheckOut(IWorkspace pMasterWorkspace,
                             string[] featureClassName,   //要素类类的名字
                             string[] featureDatasetName, //数据集的名字
                             string checkoutName,
                             bool onlySchema,
                             bool reuseSchema,
                             string fileName,
                             esriDataExtractionType dataExtractionType,
                             esriReplicaModelType replicaModelType)
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            bool             hasVersion       = false;
            string           versionName      = System.IO.Path.GetFileNameWithoutExtension(fileName);
            IEnumVersionInfo pEnumVersionInfo = (pMasterWorkspace as IVersionedWorkspace).Versions;

            if (pEnumVersionInfo != null)
            {
                pEnumVersionInfo.Reset();
                IVersionInfo pVersionInfo = pEnumVersionInfo.Next();
                while (pVersionInfo != null)
                {
                    if (pVersionInfo.VersionName == "SDE." + checkoutName)
                    {
                        hasVersion = true;
                        break;
                    }
                    pVersionInfo = pEnumVersionInfo.Next();
                }
            }
            if (hasVersion)
            {
                IVersion pVersion = (pMasterWorkspace as IVersionedWorkspace).FindVersion(versionName);
                if (pVersion != null)
                {
                    pVersion.Delete();
                }
            }

            IPropertySet pCheckOutPropSet = new PropertySetClass();

            pCheckOutPropSet.SetProperty("Database", fileName);
            IWorkspaceFactory pCheckOutWorkFact = new AccessWorkspaceFactoryClass();
            string            path = System.IO.Path.GetDirectoryName(fileName);
            IWorkspaceName    pCheckOutWorkspaceName = pCheckOutWorkFact.Create(path, checkoutName, pCheckOutPropSet, 0);
            IName             pName = pCheckOutWorkspaceName as IName;
            IWorkspace        pCheckOutWorkspace = pName.Open() as IWorkspace;

            if (pCheckOutWorkspace != null)
            {
                IFeatureWorkspace   pMasterFeaWorkspace = pMasterWorkspace as IFeatureWorkspace;
                IFeatureClass       pFeaClass;
                IFeatureDataset     pFeatureDataset;
                IDataset            pDS;
                IEnumNameEdit       pEnumNameEdit = new NamesEnumeratorClass();
                IEnumName           pEnumName;
                IReplicaDescription pRepDescription = new ReplicaDescriptionClass();

                for (int i = 0; i < featureClassName.Length; i++)
                {
                    pFeaClass = pMasterFeaWorkspace.OpenFeatureClass(featureClassName[i]);
                    pDS       = pFeaClass as IDataset;
                    pEnumNameEdit.Add(pDS.FullName as IName);
                }

                for (int i = 0; i < featureDatasetName.Length; i++)
                {
                    pFeatureDataset = pMasterFeaWorkspace.OpenFeatureDataset(featureDatasetName[i]);
                    pDS             = pFeatureDataset as IDataset;
                    pEnumNameEdit.Add(pDS.FullName as IName);
                }

                pEnumName = pEnumNameEdit as IEnumName;
                pRepDescription.Init(pEnumName, pCheckOutWorkspaceName, false, dataExtractionType);
                pRepDescription.ReplicaModelType = replicaModelType;//简单图层类型或与SDE数据库一样
                ICheckOut pCheckOut = new CheckOutClass();
                try
                {
                    pCheckOut.CheckOutData(pRepDescription, true, checkoutName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("可能是备份的SDE数据没有注册为版本,或者是由于该文件名上次已经作为一个版本号存在数据库中。" + ex.ToString());
                }
                pCheckOutWorkspace = null;
                GC.Collect();
            }
        }
Beispiel #7
0
 private void frmCheckInWizard_Load(object sender, EventArgs e)
 {
     if (this.iarray_0.Count == 0)
     {
         MessageBox.Show("没有检入的数据!");
         base.Close();
     }
     else if (this.iarray_0.Count == 1)
     {
         CheckInOutWorkspaceInfo info = this.iarray_0.get_Element(0) as CheckInOutWorkspaceInfo;
         CheckInHelper.m_pHelper = new CheckInHelper();
         IWorkspaceName fullName = (info.Workspace as IDataset).FullName as IWorkspaceName;
         if (fullName.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
         {
             CheckInHelper.m_pHelper.MasterWorkspaceName   = fullName;
             CheckInHelper.m_pHelper.CheckoutWorkspaceName = null;
         }
         else
         {
             CheckInHelper.m_pHelper.CheckoutWorkspaceName = fullName;
             CheckInHelper.m_pHelper.MasterWorkspaceName   = null;
         }
         IEnumNameEdit edit     = new NamesEnumeratorClass();
         IEnumName     enumName = info.EnumName;
         enumName.Reset();
         IName name  = enumName.Next();
         IList list  = new ArrayList();
         IList list2 = new ArrayList();
         while (name != null)
         {
             string str;
             if (name is IFeatureClassName)
             {
                 if ((name as IFeatureClassName).FeatureDatasetName != null)
                 {
                     IDatasetName featureDatasetName = (name as IFeatureClassName).FeatureDatasetName;
                     str = featureDatasetName.Name;
                     if (list.IndexOf(str) == -1)
                     {
                         list.Add(str);
                         edit.Add(featureDatasetName as IName);
                     }
                 }
                 else
                 {
                     str = (name as IDatasetName).Name;
                     if (list2.IndexOf(str) == -1)
                     {
                         list2.Add(str);
                         edit.Add(name);
                     }
                 }
             }
             else if (name is IFeatureDatasetName)
             {
                 str = (name as IDatasetName).Name;
                 if (list.IndexOf(str) == -1)
                 {
                     list.Add(str);
                     edit.Add(name);
                 }
             }
             else
             {
                 str = (name as IDatasetName).Name;
                 if (list2.IndexOf(str) == -1)
                 {
                     list2.Add(str);
                     edit.Add(name);
                 }
             }
             name = enumName.Next();
         }
         this.checkInSetupCtrl_0.Visible = true;
         this.btnNext.Text = "完成";
     }
     else
     {
         CheckInHelper.m_pHelper = new CheckInHelper();
         this.selectCheckOutWorkspaceCtrl_0.WorkspaceArray = this.iarray_0;
         this.selectCheckOutWorkspaceCtrl_0.Visible        = true;
     }
 }
Beispiel #8
0
 private void frmExtractionDataWizard_Load(object sender, EventArgs e)
 {
     if (this.iarray_0.Count == 0)
     {
         MessageBox.Show("没有可用于提取的数据!");
         base.Close();
     }
     else if (this.iarray_0.Count == 1)
     {
         CheckInOutWorkspaceInfo info = this.iarray_0.get_Element(0) as CheckInOutWorkspaceInfo;
         ExtractionDataHelper.m_pHelper = new ExtractionDataHelper();
         ExtractionDataHelper.m_pHelper.MasterWorkspaceName =
             (info.Workspace as IDataset).FullName as IWorkspaceName;
         IEnumNameEdit edit     = new NamesEnumeratorClass();
         IEnumName     enumName = info.EnumName;
         enumName.Reset();
         IName name  = enumName.Next();
         IList list  = new ArrayList();
         IList list2 = new ArrayList();
         while (name != null)
         {
             string str;
             if (name is IFeatureClassName)
             {
                 if ((name as IFeatureClassName).FeatureDatasetName != null)
                 {
                     IDatasetName featureDatasetName = (name as IFeatureClassName).FeatureDatasetName;
                     str = featureDatasetName.Name;
                     if (list.IndexOf(str) == -1)
                     {
                         list.Add(str);
                         edit.Add(featureDatasetName as IName);
                     }
                 }
                 else
                 {
                     str = (name as IDatasetName).Name;
                     if (list2.IndexOf(str) == -1)
                     {
                         list2.Add(str);
                         edit.Add(name);
                     }
                 }
             }
             else if (name is IFeatureDatasetName)
             {
                 str = (name as IDatasetName).Name;
                 if (list.IndexOf(str) == -1)
                 {
                     list.Add(str);
                     edit.Add(name);
                 }
             }
             else
             {
                 str = (name as IDatasetName).Name;
                 if (list2.IndexOf(str) == -1)
                 {
                     list2.Add(str);
                     edit.Add(name);
                 }
             }
             name = enumName.Next();
         }
         ExtractionDataHelper.m_pHelper.EnumName = edit as IEnumName;
         this.extractionDataSetupCtrl_0.Visible  = true;
     }
     else
     {
         ExtractionDataHelper.m_pHelper = new ExtractionDataHelper();
         this.selectCheckOutWorkspaceCtrl_0.WorkspaceArray = this.iarray_0;
         this.selectCheckOutWorkspaceCtrl_0.Visible        = true;
     }
 }
        public bool Do()
        {
            IEnumNameEdit edit;
            IEnumName     enumName;
            IName         name2;
            IList         list;
            IList         list2;
            IDatasetName  featureDatasetName;
            string        name;

            if (this.EditWorkspacelist.SelectedItems.Count == 0)
            {
                return(false);
            }
            CheckInOutWorkspaceInfo tag = this.EditWorkspacelist.SelectedItems[0].Tag as CheckInOutWorkspaceInfo;

            if (this.int_0 == 0)
            {
                CheckOutHelper.m_pHelper.MasterWorkspaceName = (tag.Workspace as IDataset).FullName as IWorkspaceName;
                edit     = new NamesEnumeratorClass();
                enumName = tag.EnumName;
                enumName.Reset();
                name2 = enumName.Next();
                list  = new ArrayList();
                list2 = new ArrayList();
                while (name2 != null)
                {
                    if (name2 is IFeatureClassName)
                    {
                        if ((name2 as IFeatureClassName).FeatureDatasetName != null)
                        {
                            featureDatasetName = (name2 as IFeatureClassName).FeatureDatasetName;
                            name = featureDatasetName.Name;
                            if (list.IndexOf(name) == -1)
                            {
                                list.Add(name);
                                edit.Add(featureDatasetName as IName);
                            }
                        }
                        else
                        {
                            name = (name2 as IDatasetName).Name;
                            if (list2.IndexOf(name) == -1)
                            {
                                list2.Add(name);
                                edit.Add(name2);
                            }
                        }
                    }
                    else if (name2 is IFeatureDatasetName)
                    {
                        name = (name2 as IDatasetName).Name;
                        if (list.IndexOf(name) == -1)
                        {
                            list.Add(name);
                            edit.Add(name2);
                        }
                    }
                    else
                    {
                        name = (name2 as IDatasetName).Name;
                        if (list2.IndexOf(name) == -1)
                        {
                            list2.Add(name);
                            edit.Add(name2);
                        }
                    }
                    name2 = enumName.Next();
                }
                CheckOutHelper.m_pHelper.EnumName = edit as IEnumName;
            }
            else if (this.int_0 == 1)
            {
                IWorkspaceName fullName = (tag.Workspace as IDataset).FullName as IWorkspaceName;
                if (fullName.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                {
                    CheckInHelper.m_pHelper.MasterWorkspaceName   = fullName;
                    CheckInHelper.m_pHelper.CheckoutWorkspaceName = null;
                }
                else
                {
                    CheckInHelper.m_pHelper.MasterWorkspaceName   = null;
                    CheckInHelper.m_pHelper.CheckoutWorkspaceName = fullName;
                }
            }
            else if (this.int_0 == 2)
            {
                ExtractionDataHelper.m_pHelper.MasterWorkspaceName =
                    (tag.Workspace as IDataset).FullName as IWorkspaceName;
                edit     = new NamesEnumeratorClass();
                enumName = tag.EnumName;
                enumName.Reset();
                name2 = enumName.Next();
                list  = new ArrayList();
                list2 = new ArrayList();
                while (name2 != null)
                {
                    if (name2 is IFeatureClassName)
                    {
                        if ((name2 as IFeatureClassName).FeatureDatasetName != null)
                        {
                            featureDatasetName = (name2 as IFeatureClassName).FeatureDatasetName;
                            name = featureDatasetName.Name;
                            if (list.IndexOf(name) == -1)
                            {
                                list.Add(name);
                                edit.Add(featureDatasetName as IName);
                            }
                        }
                        else
                        {
                            name = (name2 as IDatasetName).Name;
                            if (list2.IndexOf(name) == -1)
                            {
                                list2.Add(name);
                                edit.Add(name2);
                            }
                        }
                    }
                    else if (name2 is IFeatureDatasetName)
                    {
                        name = (name2 as IDatasetName).Name;
                        if (list.IndexOf(name) == -1)
                        {
                            list.Add(name);
                            edit.Add(name2);
                        }
                    }
                    else
                    {
                        name = (name2 as IDatasetName).Name;
                        if (list2.IndexOf(name) == -1)
                        {
                            list2.Add(name);
                            edit.Add(name2);
                        }
                    }
                    name2 = enumName.Next();
                }
                ExtractionDataHelper.m_pHelper.EnumName = edit as IEnumName;
            }
            else if (this.int_0 == 3)
            {
                ExportChangesHelper.m_pHelper.CheckoutWorkspaceName =
                    (tag.Workspace as IDataset).FullName as IWorkspaceName;
            }
            return(true);
        }