Exemple #1
0
 public void Delete(IEnumNameMapping ienumNameMapping_0, IName iname_0)
 {
     if (!(ienumNameMapping_0 is IMyEnumNameMapping))
     {
         (this.igeoDBDataTransfer_0 as IGeoDBDataTransfer2).Delete(ienumNameMapping_0, iname_0);
     }
 }
Exemple #2
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);
        }
Exemple #3
0
        public bool GenerateNameMapping(IEnumName ienumName_0, IName iname_0, out IEnumNameMapping ienumNameMapping_0)
        {
            bool flag;

            ienumNameMapping_0 = null;
            ienumName_0.Reset();
            IName name = ienumName_0.Next();

            if (!(name is IDatasetName) ||
                (name as IDatasetName).WorkspaceName.Type != esriWorkspaceType.esriFileSystemWorkspace)
            {
                ienumName_0.Reset();
                flag = this.igeoDBDataTransfer_0.GenerateNameMapping(ienumName_0, iname_0, out ienumNameMapping_0);
            }
            else
            {
                MyEnumNameMapping myEnumNameMapping = new MyEnumNameMapping();
                ienumNameMapping_0 = myEnumNameMapping;
                while (name != null)
                {
                    MyNameMapping myNameMapping = new MyNameMapping()
                    {
                        m_pSource = name
                    };
                    myNameMapping.ValidateTargetName(iname_0);
                    myEnumNameMapping.Add(myNameMapping);
                    name = ienumName_0.Next();
                }
                flag = true;
            }
            return(flag);
        }
Exemple #4
0
        public int NumberObjectsToTransfer(IEnumNameMapping ienumNameMapping_0)
        {
            int num;

            num = (!(ienumNameMapping_0 is IMyEnumNameMapping)
                ? this.igeoDBDataTransfer_0.NumberObjectsToTransfer(ienumNameMapping_0)
                : 0);
            return(num);
        }
        internal static void CopiaFeatureClass(IEnumName enumSourceName, IName targetName)
        {
            // Create the transfer object and a reference to a mapping enumerator.
            IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransfer();

            IEnumNameMapping[] enumNameMapping = new IEnumNameMapping[1];
            // See if the transfer can proceed with the datasets' existing names.
            _ = geoDBDataTransfer.GenerateNameMapping(enumSourceName, targetName, out enumNameMapping[0]);

            geoDBDataTransfer.Transfer(enumNameMapping[0], targetName);
        }
Exemple #6
0
        } // getFCNames

        public void doWork()
        {
            Log.p("doWork started...");
            String sdeconnfname = mSdeConnFileName; // "c:\\t\\test.sde";
            String tabnames     = mTabName;         // "T.TAB1,T.TAB2";

            Log.p("Open the source gdb");
            IWorkspaceFactory wspFact = new SdeWorkspaceFactoryClass();
            IWorkspace        wsp     = wspFact.OpenFromFile(sdeconnfname, 0);

            Log.p("Get FC names");
            IEnumNameEdit edtNames = getFCNames(wsp, tabnames);
            IEnumName     names    = (IEnumName)edtNames;

            Log.p("Create a scratch workspace factory");
            IScratchWorkspaceFactory scrWspFact = new ScratchWorkspaceFactoryClass();
            IWorkspace scrWsp     = scrWspFact.CreateNewScratchWorkspace();
            IDataset   dset       = (IDataset)scrWsp;
            IName      scrWspName = dset.FullName;

            Log.p("Create a Transfer object and a name mapping");
            IGeoDBDataTransfer trans        = new GeoDBDataTransferClass();
            IEnumNameMapping   nameMaps     = null;
            Boolean            hasConflicts = trans.GenerateNameMapping(
                names, scrWspName, out nameMaps);

            if (hasConflicts)
            {
                throw new ArgumentException("Name mapping has conflicts.");
            }

            bool          expData    = mNeedData;
            string        fname      = mExpFileName;
            bool          getMeta    = mNeedMeta;
            bool          compressed = false;
            bool          binaryGeom = true;
            IGdbXmlExport exp        = new GdbExporterClass();

            if (expData == false)
            {
                Log.p(String.Format("Export schema (u need sdeexport for data); file [{0}], metadata [{1}]",
                                    fname, getMeta));
                exp.ExportDatasetsSchema(nameMaps, fname, compressed, getMeta);
            }
            else
            {
                Log.p(String.Format("Export schema&data; file [{0}], metadata [{1}]",
                                    fname, getMeta));
                exp.ExportDatasets(nameMaps, fname, binaryGeom, compressed, getMeta);
            }

            Log.p("OK, xml writed.", "both");
        } // method doWork
Exemple #7
0
        private void ImportXmlWorkspaceDocument(string inputXmlFile)
        {
            IWorkspaceName targetWorkspaceName = getWorkspaceName("esriDataSourcesGDB.SdeWorkspaceFactory", sdePath);
            IName          targetName          = (IName)targetWorkspaceName;
            IWorkspace     targetWorkspace     = (IWorkspace)targetName.Open();

            IGdbXmlImport    gdbXmlImport    = new GdbImporterClass();
            IEnumNameMapping enumNameMapping = null;

            Boolean conflictsFound = gdbXmlImport.GenerateNameMapping(inputXmlFile, targetWorkspace, out enumNameMapping);

            // Check for conflicts.
            if (conflictsFound)
            {
                // Iterate through each name mapping.
                INameMapping nameMapping = null;
                enumNameMapping.Reset();
                while ((nameMapping = enumNameMapping.Next()) != null)
                {
                    // Resolve the mapping's conflict (if there is one).
                    if (nameMapping.NameConflicts)
                    {
                        nameMapping.TargetName = nameMapping.GetSuggestedName(targetName);
                    }

                    // See if the mapping's children have conflicts.
                    IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                    if (childEnumNameMapping != null)
                    {
                        childEnumNameMapping.Reset();

                        // Iterate through each child mapping.
                        INameMapping childNameMapping = null;
                        while ((childNameMapping = childEnumNameMapping.Next()) != null)
                        {
                            if (childNameMapping.NameConflicts)
                            {
                                childNameMapping.TargetName =
                                    childNameMapping.GetSuggestedName(targetName);
                            }
                        }
                    }
                }
            }

            // Import the workspace document, including both schema and data.
            gdbXmlImport.ImportWorkspace(inputXmlFile, enumNameMapping, targetWorkspace, false);
        }
Exemple #8
0
        //导入xml工作空间
        private void ImportWS(string dbPath, string pGDB, string XmlFile)
        {
            IWorkspaceFactory pWSF  = new AccessWorkspaceFactory();
            IWorkspaceName    pWSN  = pWSF.Create(dbPath, pGDB, null, 0);
            IName             pName = (IName)pWSN;
            IWorkspace        pWS   = (IWorkspace)pName.Open();

            //导入库结构
            IGdbXmlImport    pImporter = new GdbImporter();
            IEnumNameMapping pEnumName = null;

            pImporter.GenerateNameMapping(XmlFile, pWS, out pEnumName);
            pImporter.ImportWorkspace(XmlFile, pEnumName, pWS, true);

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pWS);
        }
Exemple #9
0
        /// <summary>
        /// 依据Workspace.xml文件创建要素类
        /// </summary>
        /// <param name="space">目标工作空间</param>
        /// <param name="xmlpath">workspace类型的xmlw文件</param>
        /// <param name="IsContainsData">创建时,是否导入xml文件中的要素数据</param>
        /// <returns></returns>
        public bool ImportWorkspaceXML(IWorkspace space, string xmlpath, bool IsContainsData = false)
        {
            bool result = false;

            try
            {
                IEnumNameMapping namemapping = null;
                GdbImporter      importer    = new GdbImporter();
                importer.GenerateNameMapping(xmlpath, space, out namemapping);
                importer.ImportWorkspace(xmlpath, namemapping, space, !IsContainsData);
                result = true;
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
            return(result);
        }
Exemple #10
0
 public void Transfer(IEnumNameMapping ienumNameMapping_0, IName iname_0)
 {
     if (!(ienumNameMapping_0 is IMyEnumNameMapping))
     {
         this.bool_0 = false;
         this.igeoDBDataTransfer_0.Transfer(ienumNameMapping_0, iname_0);
     }
     else
     {
         this.bool_0 = true;
         Dataloaders dataloader = new Dataloaders();
         ienumNameMapping_0.Reset();
         for (INameMapping i = ienumNameMapping_0.Next(); i != null; i = ienumNameMapping_0.Next())
         {
             this.method_1((i.SourceObject as IDatasetName).Name);
             dataloader.ConvertData(i.SourceObject as IDatasetName, iname_0, i.TargetName, null);
         }
     }
 }
Exemple #11
0
        public static ESRI.ArcGIS.Geodatabase.IWorkspace GetWorkspace(string inXMLFile)
        {
            IWorkspaceFactory inMemoryWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
            IWorkspaceName    workspaceName            = inMemoryWorkspaceFactory.Create("", "InMemory", null, 0);
            IName             name      = workspaceName as IName;
            IWorkspace        workspace = (IWorkspace)name.Open();

            //Create a GDB importer
            IGdbXmlImport xmlImport = new GdbImporterClass();

            // Read schema section from the XML file.
            // Note: enumNameMapping is initialized to nothing and its value is set 'by ref' with a call to the GenerateNameMapping method.
            IEnumNameMapping eNameMapping = null;

            xmlImport.GenerateNameMapping(inXMLFile, workspace, out eNameMapping);

            //Create the workspace schema and load the data
            xmlImport.ImportWorkspace(inXMLFile, eNameMapping, workspace, false);

            return(workspace);
        }
 private void method_7()
 {
     this.ienumNameMapping_0.Reset();
     for (INameMapping mapping = this.ienumNameMapping_0.Next();
          mapping != null;
          mapping = this.ienumNameMapping_0.Next())
     {
         if (mapping.SourceObject is IName)
         {
             IName sourceObject = mapping.SourceObject as IName;
             if (sourceObject is IFeatureClassName)
             {
                 this.int_0++;
             }
             else if (sourceObject is ITableName)
             {
                 this.int_0++;
             }
             IEnumNameMapping children = mapping.Children;
             if (children != null)
             {
                 children.Reset();
                 for (INameMapping mapping3 = children.Next(); mapping3 != null; mapping3 = children.Next())
                 {
                     sourceObject = mapping3.SourceObject as IName;
                     if (sourceObject is IFeatureClassName)
                     {
                         this.int_0++;
                     }
                     else if (sourceObject is ITableName)
                     {
                         this.int_0++;
                     }
                 }
             }
         }
     }
     this.progressBarObjectClass.Minimum = 0;
     this.progressBarObjectClass.Maximum = this.int_0;
 }
        public List <string> CheckDataSchema(string template, string dbpath)
        {
            List <string> msgs = new List <string>();

            try
            {
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");
                IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
                                                         (factoryType);

                IFeatureWorkspace source_fws = workspaceFactory.OpenFromFile(dbpath, 0) as IFeatureWorkspace;

                IScratchWorkspaceFactory target_wsf = new FileGDBScratchWorkspaceFactoryClass();
                IWorkspace target_ws = target_wsf.CreateNewScratchWorkspace();

                IGdbXmlImport    importer   = new GdbImporterClass();
                IEnumNameMapping mapping    = null;
                bool             isConflict = false;
                isConflict = importer.GenerateNameMapping(template, target_ws, out mapping);
                importer.ImportWorkspace(template, mapping, target_ws, true);

                IDataset      ds      = target_ws as IDataset;
                List <String> fcNames = new List <string>();
                Util.GetAllFeatureClassNames(ds, ref fcNames);

                IFeatureWorkspace target_fws = target_ws as IFeatureWorkspace;
                IWorkspace2       source_ws  = source_fws as IWorkspace2;
                foreach (string fcName in fcNames)
                {
                    if (!source_ws.get_NameExists(esriDatasetType.esriDTFeatureClass, fcName))
                    {
                        msgs.Add(string.Format("数据源中丢失图层:{0}", fcName));
                        continue;
                    }
                    IFeatureClass source_fc = source_fws.OpenFeatureClass(fcName);
                    IFeatureClass target_fc = target_fws.OpenFeatureClass(fcName);
                    for (int i = 0; i < target_fc.Fields.FieldCount; i++)
                    {
                        IField fld = target_fc.Fields.get_Field(i);
                        if (fcName == target_fc.OIDFieldName)
                        {
                            continue;
                        }
                        int source_fld_idx = source_fc.FindField(fld.Name);
                        if (source_fld_idx == -1)
                        {
                            msgs.Add(string.Format("数据源中丢失字段{0}", fld.Name));
                        }
                        else
                        {
                            IField source_fld = source_fc.Fields.get_Field(source_fld_idx);
                            if (source_fld.Type != fld.Type)
                            {
                                msgs.Add(string.Format("数据源中字段{0}类型不正确", fld.Name));
                            }
                            if (source_fld.Length != fld.Length)
                            {
                                msgs.Add(string.Format("数据源中字段{0}长度不正确", fld.Name));
                            }
                            if (source_fld.Precision != fld.Precision)
                            {
                                msgs.Add(string.Format("数据源中字段{0}精度不正确", fld.Name));
                            }
                        }
                    }
                    if (source_fc.FindField("SyncID") == -1)
                    {
                        msgs.Add(@"数据源中丢失系统字段SyncID");
                    }
                    if (source_fc.FindField("SyncTimeStamp") == -1)
                    {
                        msgs.Add(@"数据源中丢失系统字段SyncTimeStamp");
                    }
                    if (source_fc.FindField("SyncStatus") == -1)
                    {
                        msgs.Add(@"数据源中丢失系统字段SyncStatus");
                    }
                    if (source_fc.FindField("SyncEditable") == -1)
                    {
                        msgs.Add(@"数据源中丢失系统字段SyncEditable");
                    }
                }
            }
            catch
            { }
            return(msgs);
        }
        public bool CheckOut(IWorkspace source, string dir, string dbname, string template, IPolygon area, string taskName, string dept)
        {
            m_message = "";
            //检查文件是否已经存在
            string mdbpath = dir + @"\" + dbname + ".mdb";
            bool   isExist = File.Exists(mdbpath);

            if (isExist)
            {
                File.Delete(mdbpath);
            }

            Type factoryType = Type.GetTypeFromProgID(
                "esriDataSourcesGDB.AccessWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
                                                     (factoryType);

            IWorkspaceName workspaceName = workspaceFactory.Create(dir, dbname,
                                                                   null, 0);

            IWorkspace workspace = workspaceFactory.OpenFromFile(mdbpath, 0);

            //导入库结构
            IGdbXmlImport    importer   = new GdbImporterClass();
            IEnumNameMapping mapping    = null;
            bool             isConflict = false;

            isConflict = importer.GenerateNameMapping(template, workspace, out mapping);
            importer.ImportWorkspace(template, mapping, workspace, true);


            IDataset      ds      = workspace as IDataset;
            List <String> fcNames = new List <string>();

            Util.GetAllFeatureClassNames(ds, ref fcNames);

            IFeatureWorkspace source_ws = source as IFeatureWorkspace;
            IFeatureWorkspace target_ws = workspace as IFeatureWorkspace;
            IWorkspaceEdit    wse       = target_ws as IWorkspaceEdit;

            foreach (string fcname in fcNames)
            {
                IWorkspace2 source_ws2 = source_ws as IWorkspace2;
                if (!source_ws2.get_NameExists(esriDatasetType.esriDTFeatureClass, fcname))
                {
                    continue;
                }
                IFeatureClass source_fc = source_ws.OpenFeatureClass(fcname);
                IFeatureClass target_fc = target_ws.OpenFeatureClass(fcname);
                AddSyncFields(target_fc);

                ISpatialFilter filter = new SpatialFilterClass();
                filter.Geometry   = area as IGeometry;
                filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                wse.StartEditing(false);
                IFeatureCursor target_cur = target_fc.Insert(true);
                IFeatureBuffer buffer     = target_fc.CreateFeatureBuffer();
                IFeatureCursor source_cur = source_fc.Search(filter, true);
                IFeature       source_fea = source_cur.NextFeature();
                while (source_fea != null)
                {
                    buffer.set_Value(target_fc.FindField("SyncID"), source_fea.OID);
                    for (int i = 0; i < source_fc.Fields.FieldCount; i++)
                    {
                        IField source_field = source_fc.Fields.get_Field(i);
                        if (source_field.Name != source_fc.OIDFieldName)
                        {
                            int target_field_index = target_fc.FindField(source_field.Name);
                            if (target_field_index != -1)
                            {
                                object source_value = source_fea.get_Value(source_fc.FindField(source_field.Name));
                                buffer.set_Value(target_field_index, source_value);
                            }
                        }
                    }
                    target_cur.InsertFeature(buffer);
                    source_fea = source_cur.NextFeature();
                }
                target_cur.Flush();
                wse.StopEditing(true);
            }

            IFeatureClass log_fc = source_ws.OpenFeatureClass("TaskLog");

            IWorkspaceEdit source_wse = source_ws as IWorkspaceEdit;

            source_wse.StartEditing(false);
            IFeature log_fea = log_fc.CreateFeature();

            log_fea.set_Value(log_fc.FindField("CheckOutDate"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            log_fea.set_Value(log_fc.FindField("TaskName"), taskName);
            log_fea.set_Value(log_fc.FindField("Dept"), dept);
            log_fea.set_Value(log_fc.FindField("Status"), Task.TaskManager.CHECKOUT_STATUS);
            log_fea.Shape = area;
            log_fea.Store();
            source_wse.StopEditing(true);

            return(true);
        }
Exemple #15
0
        public static void ExportDatabase(IWorkspace theWorkspace)
        {
            // Try and make sure the user understands what they're doing
            MessageBox.Show("You must first browse to a previously generated, empty geodatabase.", "NCGMP Tools");

            // Browse for a file, personal or SDE geodatabase
            IWorkspaceFactory wsFact          = null;
            IWorkspace        openedWorkspace = null;

            IGxObjectFilter objectFilter = new GxFilterWorkspaces();
            IGxObject       openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an empty database");

            if (openedObject == null)
            {
                return;
            }

            // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory
            string pathToOpen = null;

            switch (openedObject.Category)
            {
            case "Personal Geodatabase":
                wsFact     = new AccessWorkspaceFactoryClass();
                pathToOpen = openedObject.FullName;
                break;

            case "File Geodatabase":
                wsFact     = new FileGDBWorkspaceFactoryClass();
                pathToOpen = openedObject.FullName;
                break;

            case "Spatial Database Connection":
                wsFact = new SdeWorkspaceFactoryClass();
                IGxRemoteDatabaseFolder remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                pathToOpen = remoteDatabaseFolder.Path + openedObject.Name;
                break;

            default:
                break;
            }
            openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0);

            // Okay, now export the current database to an XML doc
            string tempFilePath = System.IO.Path.GetTempFileName();

            tempFilePath += ".xml";

            IGdbXmlExport xmlExporter = new GdbExporterClass();

            xmlExporter.ExportWorkspace(theWorkspace, tempFilePath, true, false, false);

            // Import to the new database
            // Use the temp file to perform the import
            IGdbXmlImport    xmlImporter     = new GdbImporterClass();
            IEnumNameMapping enumNameMapping = null;
            bool             conflictsFound  = xmlImporter.GenerateNameMapping(tempFilePath, openedWorkspace, out enumNameMapping);

            try
            {
                // Deal with conflicts (lifted wholesale from http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/00010000011m000000.htm)
                if (conflictsFound)
                {
                    IName workspaceName = ((IDataset)openedWorkspace).FullName;

                    // Iterate through each name mapping.
                    INameMapping nameMapping = null;
                    enumNameMapping.Reset();
                    while ((nameMapping = enumNameMapping.Next()) != null)
                    {
                        // Resolve the mapping's conflict (if there is one).
                        if (nameMapping.NameConflicts)
                        {
                            nameMapping.TargetName = nameMapping.GetSuggestedName(workspaceName);
                        }
                        // See if the mapping's children have conflicts.
                        IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                        if (childEnumNameMapping != null)
                        {
                            childEnumNameMapping.Reset();
                            // Iterate through each child mapping.
                            INameMapping childNameMapping = null;
                            while ((childNameMapping = childEnumNameMapping.Next()) != null)
                            {
                                if (childNameMapping.NameConflicts)
                                {
                                    childNameMapping.TargetName = nameMapping.GetSuggestedName
                                                                      (workspaceName);
                                }
                            }
                        }
                    }
                }

                // Perform the import
                xmlImporter.ImportWorkspace(tempFilePath, enumNameMapping, openedWorkspace, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine + "XML Workspace Doc written to: " + tempFilePath);
            }


            // Perhaps, strip the SysInfo table
        }
        private void method_1()
        {
            this.listView1.Items.Clear();
            this.ienumNameMapping_0.Reset();
            INameMapping mapping = this.ienumNameMapping_0.Next();

            string[] items = new string[3];
            while (mapping != null)
            {
                ListViewItem item;
                if (mapping.SourceObject is IDomain)
                {
                    IDomain sourceObject = mapping.SourceObject as IDomain;
                    if (sourceObject.Type == esriDomainType.esriDTCodedValue)
                    {
                        items[0] = "CV域";
                    }
                    else
                    {
                        items[0] = "范围域";
                    }
                    items[1] = sourceObject.Name;
                    if (mapping.NameConflicts)
                    {
                        mapping.TargetName = mapping.GetSuggestedName(this.iname_0);
                    }
                    items[2] = mapping.TargetName;
                    item     = new ListViewItem(items)
                    {
                        Tag = mapping
                    };
                    this.listView1.Items.Add(item);
                }
                else if (mapping.SourceObject is IName)
                {
                    IName name = mapping.SourceObject as IName;
                    items[0] = this.method_0(name);
                    items[1] = (name as IDatasetName).Name;
                    if (mapping.NameConflicts)
                    {
                        mapping.TargetName = mapping.GetSuggestedName(this.iname_0);
                    }
                    items[2] = mapping.TargetName;
                    item     = new ListViewItem(items)
                    {
                        Tag = mapping
                    };
                    this.listView1.Items.Add(item);
                    IEnumNameMapping children = mapping.Children;
                    if (children != null)
                    {
                        children.Reset();
                        for (INameMapping mapping3 = children.Next(); mapping3 != null; mapping3 = children.Next())
                        {
                            name     = mapping3.SourceObject as IName;
                            items[0] = "  " + this.method_0(name);
                            items[1] = (name as IDatasetName).Name;
                            if (mapping3.NameConflicts)
                            {
                                mapping3.TargetName = mapping3.GetSuggestedName(this.iname_0);
                            }
                            items[2] = mapping3.TargetName;
                            item     = new ListViewItem(items)
                            {
                                Tag = mapping3
                            };
                            this.listView1.Items.Add(item);
                        }
                    }
                }
                mapping = this.ienumNameMapping_0.Next();
            }
        }
Exemple #17
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //首先进行坐标系x,y变换
            //string fileExpTran;//进行x,y做表转换后输出的tiff文件存储路径,用这一文件在进行后期的Z转换
            //fileExpTran = System.IO.Path.GetDirectoryName(LayerExpName) +"\\"+ System.IO.Path.GetFileNameWithoutExtension(LayerExpName)+"XY.tif";
            //try
            //{
            //    if (NorthEastToEastNorth(pRasterLayer, LayerExpName))
            //    {
            //        RasterLayerClass rasterlayer = new RasterLayerClass();
            //        rasterlayer.CreateFromFilePath(LayerExpName);
            //        IRaster2 pRaster2 = rasterlayer.Raster as IRaster2;
            //        IRasterDataset2 pRasterDataset = pRaster2.RasterDataset as IRasterDataset2;
            //        ChangeRasterValue(pRasterDataset, -1, 0);
            //        pMapControl.AddLayer(rasterlayer as ILayer);
            //        this.Close();
            //    }
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}

            try
            {
                IFeatureClass    pFC        = pFeatureLayer.FeatureClass;
                IDataset         pDS        = pFC as IDataset;
                IWorkspace       pWS        = pDS.Workspace;
                string           filedir    = pWS.PathName;
                string           fdestname  = System.IO.Path.GetFileNameWithoutExtension(txtFeatureName.Text);
                ClsGDBDataCommon CGD        = new ClsGDBDataCommon();
                IWorkspace       pTargetWS  = CGD.OpenFromShapefile(txtLayerExp.Text);
                IWorkspace2      workspace2 = pTargetWS as IWorkspace2;

                if (workspace2.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, fdestname))
                {
                    MessageBox.Show("目标文件已存在!");
                    return;
                }
                //shape文件直接拷贝后再修改
                if (pDS.CanCopy() == true)
                {
                    pDS.Copy(txtFeatureName.Text, pTargetWS);
                    IFeatureWorkspace pFW = pTargetWS as IFeatureWorkspace;
                    pTargetFeatureClass = pFW.OpenFeatureClass(txtFeatureName.Text);
                    TransCoordiante(pFW as IWorkspace, pTargetFeatureClass);
                }
                //表示为gdb的feature,只能往gdb拷贝
                else
                {
                    // Create workspace name objects.
                    IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass();
                    IWorkspaceName targetWorkspaceName = new WorkspaceNameClass();
                    IName          targetName          = (IName)targetWorkspaceName;

                    // Set the workspace name properties.
                    sourceWorkspaceName.PathName = pWS.PathName;
                    sourceWorkspaceName.WorkspaceFactoryProgID =
                        "esriDataSourcesGDB.FileGDBWorkspaceFactory";
                    // targetWorkspaceName.PathName = @"PartialMontgomery.gdb";
                    targetWorkspaceName.PathName = txtLayerExp.Text;
                    targetWorkspaceName.WorkspaceFactoryProgID =
                        "esriDataSourcesGDB.FileGDBWorkspaceFactory";

                    //if (txtLayerExp.Text.Length>4 && txtLayerExp.Text.Substring(txtLayerExp.Text.Length-4,4) == ".gdb")
                    //{
                    //    targetWorkspaceName.WorkspaceFactoryProgID =
                    //      "esriDataSourcesGDB.FileGDBWorkspaceFactory";
                    //}
                    //else
                    //{
                    //    targetWorkspaceName.WorkspaceFactoryProgID =
                    //     "esriDataSourcesFile.ShapefileWorkspaceFactory";
                    //}

                    // Create a name object for the source feature class.
                    IFeatureClassName featureClassName = new FeatureClassNameClass();

                    // Set the featureClassName properties.
                    IDatasetName sourceDatasetName = (IDatasetName)featureClassName;
                    sourceDatasetName.WorkspaceName = sourceWorkspaceName;
                    sourceDatasetName.Name          = pDS.BrowseName;
                    IName sourceName = (IName)sourceDatasetName;


                    // Create an enumerator for source datasets.
                    IEnumName     sourceEnumName     = new NamesEnumeratorClass();
                    IEnumNameEdit sourceEnumNameEdit = (IEnumNameEdit)sourceEnumName;

                    // Add the name object for the source class to the enumerator.
                    sourceEnumNameEdit.Add(sourceName);

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

                    // Use the data transfer object to create a name mapping enumerator.
                    Boolean conflictsFound = geoDBDataTransfer.GenerateNameMapping(sourceEnumName,
                                                                                   targetName, out enumNameMapping);
                    enumNameMapping.Reset();
                    //修改拷贝的文件名
                    INameMapping nameMapping = enumNameMapping.Next();
                    if ((nameMapping != null))
                    {
                        nameMapping.TargetName = txtFeatureName.Text;
                    }

                    // Check for conflicts.
                    //if (conflictsFound)
                    //{
                    //    // Iterate through each name mapping.
                    //    INameMapping nameMapping = null;
                    //    while ((nameMapping = enumNameMapping.Next()) != null)
                    //    {
                    //        // Resolve the mapping's conflict (if there is one).
                    //        if (nameMapping.NameConflicts)
                    //        {
                    //            nameMapping.TargetName = nameMapping.GetSuggestedName(targetName);
                    //        }

                    //        // See if the mapping's children have conflicts.
                    //        IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                    //        if (childEnumNameMapping != null)
                    //        {
                    //            childEnumNameMapping.Reset();

                    //            // Iterate through each child mapping.
                    //            INameMapping childNameMapping = null;
                    //            while ((childNameMapping = childEnumNameMapping.Next()) != null)
                    //            {
                    //                if (childNameMapping.NameConflicts)
                    //                {
                    //                    childNameMapping.TargetName = childNameMapping.GetSuggestedName
                    //                        (targetName);
                    //                }
                    //            }
                    //        }
                    //    }
                    //}

                    // Start the transfer.
                    geoDBDataTransfer.Transfer(enumNameMapping, targetName);
                    IFeatureWorkspace pFW = CGD.OpenFromFileGDB(txtLayerExp.Text) as IFeatureWorkspace;
                    pTargetFeatureClass = pFW.OpenFeatureClass(txtFeatureName.Text);
                    TransCoordiante(pFW as IWorkspace, pTargetFeatureClass);
                }

                if (pTargetFeatureClass != null)
                {
                    //添加到图层中
                    IFeatureLayer featureLayer = new FeatureLayerClass();
                    featureLayer.FeatureClass = pTargetFeatureClass;
                    featureLayer.Name         = fdestname;
                    pMapControl.AddLayer(featureLayer as ILayer);
                    pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #18
0
        public void TansferFileGDBToSDE(string fileGDBPath, string sourceFCName)
        {
            // Create workspace name objects.
            IWorkspaceName sourceWorkspaceName = getWorkspaceName("esriDataSourcesGDB.FileGDBWorkspaceFactory", fileGDBPath);

            // Create a name object for the target (SDE) workspace and open it.
            IWorkspaceName targetWorkspaceName = getWorkspaceName("esriDataSourcesGDB.SdeWorkspaceFactory", sdePath);

            IName targetName = (IName)targetWorkspaceName;

            // Create a name object for the source dataset.
            IFeatureClassName sourceFeatureClassName = getFeatureClassName(sourceWorkspaceName, sourceFCName);
            IName             sourceName             = (IName)sourceFeatureClassName;

            // Create an enumerator for source datasets.
            IEnumName     sourceEnumName     = new NamesEnumeratorClass();
            IEnumNameEdit sourceEnumNameEdit = (IEnumNameEdit)sourceEnumName;

            // Add the name object for the source class to the enumerator.
            sourceEnumNameEdit.Add(sourceName);

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

            // Use the data transfer object to create a name mapping enumerator.
            Boolean conflictsFound = geoDBDataTransfer.GenerateNameMapping(sourceEnumName,
                                                                           targetName, out enumNameMapping);

            enumNameMapping.Reset();

            // Check for conflicts.
            if (conflictsFound)
            {
                // Iterate through each name mapping.
                INameMapping nameMapping = null;
                while ((nameMapping = enumNameMapping.Next()) != null)
                {
                    // Resolve the mapping's conflict (if there is one).
                    if (nameMapping.NameConflicts)
                    {
                        nameMapping.TargetName = nameMapping.GetSuggestedName(targetName);
                    }

                    // See if the mapping's children have conflicts.
                    IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                    if (childEnumNameMapping != null)
                    {
                        childEnumNameMapping.Reset();

                        // Iterate through each child mapping.
                        INameMapping childNameMapping = null;
                        while ((childNameMapping = childEnumNameMapping.Next()) != null)
                        {
                            if (childNameMapping.NameConflicts)
                            {
                                childNameMapping.TargetName = childNameMapping.GetSuggestedName(targetName);
                            }
                        }
                    }
                }
            }

            // Start the transfer.
            geoDBDataTransfer.Transfer(enumNameMapping, targetName);
        }
Exemple #19
0
        /// <summary>
        ///     Transfers the feature class (and all relationships) to the specified workspace, while preserving the OBJECTID
        ///     values.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="name">The name feature class in the transfer.</param>
        /// <param name="workspace">The workspace.</param>
        /// <param name="conflicts">if set to <c>true</c> has conflicts with the export.</param>
        /// <param name="enumNameMapping">The enum name mapping.</param>
        /// <returns>
        ///     Returns a <see cref="IFeatureClass" /> representing the feature class in the target workspace.
        /// </returns>
        public static IFeatureClass Transfer(this IFeatureClass source, string name, IWorkspace workspace, out bool conflicts, out IEnumNameMapping enumNameMapping)
        {
            IDataset ds       = (IDataset)source;
            IName    fromName = ds.Workspace.Define(ds.Name, new FeatureClassNameClass());

            IEnumName     fromNames = new NamesEnumeratorClass();
            IEnumNameEdit edit      = (IEnumNameEdit)fromNames;

            edit.Add(fromName);

            ds.Workspace.Transfer(workspace, fromNames, out conflicts, out enumNameMapping);

            if (!conflicts)
            {
                return(workspace.GetFeatureClass(name));
            }

            return(null);
        }