Пример #1
0
        private void method_13(object sender, ValueChangedEventArgs e)
        {
            ListViewItem item = this.listView1.Items[e.Row];

            if (item.Tag is INameMapping)
            {
                INameMapping tag = item.Tag as INameMapping;
                if (tag.TargetName != e.NewValue.ToString())
                {
                    tag.TargetName = e.NewValue.ToString();
                }
            }
        }
Пример #2
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);
        }
Пример #3
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);
         }
     }
 }
Пример #4
0
 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;
 }
Пример #5
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
        }
Пример #6
0
 public void Add(INameMapping inameMapping_0)
 {
     this.ilist_0.Add(inameMapping_0);
 }
Пример #7
0
        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();
            }
        }
Пример #8
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);
        }
Пример #9
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);
            }
        }