首页
登录 | 注册

不同gdb,相同数据集合并

众所周知,数据处理是GIS中一项重要且繁琐的工作,处理数据的工具和方法也太多了,在做数据处理的时候,经常会遇到这样的问题:对存储在不同gdb中、并且数据集名称相同的数据进行合并处理:

如图:数据组织如下,每个gdb中都存储了一些列FeatureClass,(但gdb中的FeatureClass数量并不相同)

不同gdb,相同数据集合并

思路是:

1.先对每个gdb中的数据进行处理,使得每个gdb中的featureclass数量和名称相同。由于对Engine比较熟悉,这里我是用Engine进行处理的,具体代码如下:

private function Execute(){  //初始执行函数:
     string templatePath = @"F:\testout";
     DirectoryInfo directoryInfo = new DirectoryInfo(templatePath);
     DirectoryInfo[] dirInfo = directoryInfo.GetDirectories();
     string yy = dirInfo[0].Name;
     string FeatureClassName = "ROALK_arc";  //FeatureClass名称,这里可以设置一个数组,存储所有的FeatureClass
     for (int i = 0; i < dirInfo.Length; i++)
     {
         string gdbName = dirInfo[i].Name;
         //打开filegdb
         bool value = oper(@"F:\testout\" + gdbName, FeatureClassName);//判断FeatureClass是否存在
         string path = @"F:\testout\" + gdbName;
         if (value == false)
         {
             copyFeatureClass(path, FeatureClassName);
          }
               
    }
}
public bool oper(string filename,string featureClassName) //判断FeatureClass是否存在

        {

            IWorkspace2 workspace = null;
            IWorkspaceFactory2 workspaceFactory = new FileGDBWorkspaceFactoryClass();
            workspace = workspaceFactory.OpenFromFile(filename, 1) as IWorkspace2;

            IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

            bool flag = workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName);

            return flag;
            

        }
public bool oper(string filename,string featureClassName) //判断是gdb中是否存在某个FeatureClass

        {

            IWorkspace2 workspace = null;
            IWorkspaceFactory2 workspaceFactory = new FileGDBWorkspaceFactoryClass();
            workspace = workspaceFactory.OpenFromFile(filename, 1) as IWorkspace2;

            IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

            bool flag = workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName);

            return flag;
            

        }

//拷贝所有的FeatureClass到gdb,并删除里面的数据,保证每个featureclass为空,注:D:\Data\Shapefiles存储了所有的要合并的FeatureClass的空图层,便于拷贝。

 private void convert()
        {
                 IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass
                 {
                     WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory",
                     PathName = @"D:\Data\Shapefiles"
                 };
                 IName sourceWorkspaceIName = (IName)sourceWorkspaceName;
                 IWorkspace sourceWorkspace = (IWorkspace)sourceWorkspaceIName.Open();


                 // Create a name object for the target (file GDB) workspace and open it.
                 IWorkspaceName targetWorkspaceName = new WorkspaceNameClass
                 {
                     WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory",
                     PathName = @"D:\Data\Public.gdb"
                 };
                 IName targetWorkspaceIName = (IName)targetWorkspaceName;
                 IWorkspace targetWorkspace = (IWorkspace)targetWorkspaceIName.Open();



                 // Create a name object for the source dataset.
                 IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass();
                 IDatasetName sourceDatasetName = (IDatasetName)sourceFeatureClassName;
                 sourceDatasetName.Name = "BOUNT_arc";
                 sourceDatasetName.WorkspaceName = sourceWorkspaceName;


                 // Create a name object for the target dataset.
                 IFeatureClassName targetFeatureClassName = new FeatureClassNameClass();
                 IDatasetName targetDatasetName = (IDatasetName)targetFeatureClassName;
                 targetDatasetName.Name = "BOUNT_arc";
                 targetDatasetName.WorkspaceName = targetWorkspaceName;


                 // Open source feature class to get field definitions.
                 IName sourceName = (IName)sourceFeatureClassName;
                 IFeatureClass sourceFeatureClass = (IFeatureClass)sourceName.Open();


                 // Create the objects and references necessary for field validation.
                 IFieldChecker fieldChecker = new FieldCheckerClass();
                 IFields sourceFields = sourceFeatureClass.Fields;
                 IFields targetFields = null; 
                 IEnumFieldError enumFieldError = null;

                 // Set the required properties for the IFieldChecker interface.
                 fieldChecker.InputWorkspace = sourceWorkspace;
                 fieldChecker.ValidateWorkspace = targetWorkspace;


                 // Validate the fields and check for errors.
                 fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields);
                 if (enumFieldError != null)
                 {
                     // Handle the errors in a way appropriate to your application.
                     MessageBox.Show("Errors were encountered during field validation.");
                 }    // Find the shape field.

                 String shapeFieldName = sourceFeatureClass.ShapeFieldName;
                 int shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName);
                 IField shapeField = sourceFields.get_Field(shapeFieldIndex);


                 // Get the geometry definition from the shape field and clone it.
                 IGeometryDef geometryDef = shapeField.GeometryDef;
                 IClone geometryDefClone = (IClone)geometryDef;
                 IClone targetGeometryDefClone = geometryDefClone.Clone();
                 IGeometryDef targetGeometryDef = (IGeometryDef)targetGeometryDefClone;

                 // Cast the IGeometryDef to the IGeometryDefEdit interface.
                 IGeometryDefEdit targetGeometryDefEdit = (IGeometryDefEdit)targetGeometryDef;
                 // Set the IGeometryDefEdit properties.
                 targetGeometryDefEdit.GridCount_2 = 1;
                 targetGeometryDefEdit.set_GridSize(0, 0.75);

                 IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
                 IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertFeatureClass
                     (sourceFeatureClassName, null, null, targetFeatureClassName,
                     targetGeometryDef, targetFields, "", 1000, 0);    // Check for errors.
                 IInvalidObjectInfo invalidObjectInfo = null; enumInvalidObject.Reset();


        }

2.合并,在ArcGIS中采用Python:

   可以参考http://blog.csdn.net/esrichinacd/article/details/14146653

最后需要注意的地方是:在10.2的ArcMap中执行时会如下错误

  不同gdb,相同数据集合并

    我也是检查了好长时间,原因是10.2的ArcMap中执行结果会自动添加到ArcMap中,即使右键取消“添加至结果”也不行。(导致了第二次循环的时候合并的数据是结果集相同的数据的合并,所以会报上面错误) 

  不同gdb,相同数据集合并

所以这里,我们执行的时候可以到ArcCatalog中执行python脚本:

不同gdb,相同数据集合并


相关文章

  • 一.背景: 项目中有一些特殊的需求,如个别渠道继承腾讯bugly,个别渠道集成易观统计,不同的渠道集成不同的推送策略(如Oppo渠道优先Opush推送),不同的渠道拥有不同的第三方登录集成等等.这些需求本身,往往都与外部集成进来的功能有关, ...
  • LSTM实现中文文本情感分析
    1. 背景介绍 文本情感分析是在文本分析领域的典型任务,实用价值很高.本模型是第一个上手实现的深度学习模型,目的是对深度学习做一个初步的了解,并入门深度学习在文本分析领域的应用.在进行模型的上手实现之前,已学习了吴恩达的机器学习和深度学习的 ...
  • numpy C语言源代码调试(一)
    近期学习numpy,希望了解numpy内部实现机制,尝试调试numpy的源代码,特别是其中的C语言源码. 在numpy的官方网站上,有numpy的开发人员手册: https://docs.scipy.org/doc/numpy/dev/ 通 ...
  • 已迁移到我新博客,阅读体验更佳LDA && NCA: 降维与度量学习 代码实现放在我的github上:click me 一.Linear Discriminant Analysis(LDA) 1.1 Rationale    ...
  • TensorFlow之DNN(三):神经网络的正则化方法(Dropout、L2正则化、早停和数据增强)
    这一篇博客整理用TensorFlow实现神经网络正则化的内容. 深层神经网络往往具有数十万乃至数百万的参数,可以进行非常复杂的特征变换,具有强大的学习能力,因此容易在训练集上过拟合.缓解神经网络的过拟合问题,一般有两种思路,一种是用正则化方 ...
  • 基于mapreduce实现图的三角形计数
    源代码放在我的github上,想细致了解的可以访问:TriangleCount on github 一.实验要求 1.1 实验背景         图的三角形计数问题是一个基本的图计算问题,是很多复杂网络分析(比如社交网络分析)的基础.目前 ...

2020 cecdns.com webmaster#cecdns.com
12 q. 0.077 s.
京ICP备10005923号