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

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

思路是:

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[].Name;
string FeatureClassName = "ROALK_arc"; //FeatureClass名称,这里可以设置一个数组,存储所有的FeatureClass
for (int i = ; 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, ) 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, ) 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 = ;
targetGeometryDefEdit.set_GridSize(, 0.75); IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertFeatureClass
(sourceFeatureClassName, null, null, targetFeatureClassName,
targetGeometryDef, targetFields, "", , ); // Check for errors.
IInvalidObjectInfo invalidObjectInfo = null; enumInvalidObject.Reset(); }

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

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

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

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

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

不同gdb,相同数据集合并的更多相关文章

  1. R语言数据集合并、数据增减、不等长合并

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 数据选取与简单操作: which 返回一个向量 ...

  2. hadoop小文件合并

    1.背景 在实际项目中,输入数据往往是由许多小文件组成,这里的小文件是指小于HDFS系统Block大小的文件(默认128M), 然而每一个存储在HDFS中的文件.目录和块都映射为一个对象,存储在Nam ...

  3. R︱高效数据操作——data.table包(实战心得、dplyr对比、key灵活用法、数据合并)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 由于业务中接触的数据量很大,于是不得不转战开始 ...

  4. SAS︱数据索引、数据集常用操作(set、where、merge、append)

    代码部分大多来源于姚志勇老师的<SAS编程与数据挖掘商业案例>. 每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ ------------ ...

  5. Hadoop实战项目:小文件合并

    项目背景 在实际项目中,输入数据往往是由许多小文件组成,这里的小文件是指小于HDFS系统Block大小的文件(默认128M),早期的版本所定义的小文件是64M,这里的hadoop-2.2.0所定义的小 ...

  6. spark系列-2、Spark 核心数据结构:弹性分布式数据集 RDD

    一.RDD(弹性分布式数据集) RDD 是 Spark 最核心的数据结构,RDD(Resilient Distributed Dataset)全称为弹性分布式数据集,是 Spark 对数据的核心抽象, ...

  7. Atitit 数据存储视图的最佳实际best practice attilax总结

    Atitit 数据存储视图的最佳实际best practice attilax总结 1.1. 视图优点:可读性的提升1 1.2. 结论  本着可读性优先于性能的原则,面向人类编程优先于面向机器编程,应 ...

  8. Webform Application传值 ViewState

    Application:所有的会话共享一个Application空间,任何一个人改变Application的内容,其他人都会发现被改变了.Application中的内容不会被自动释放 存放位置:服务端 ...

  9. ASP.Net WebForm温故知新学习笔记:二、ViewState与UpdatePanel探秘

    开篇:经历了上一篇<aspx与服务器控件探秘>后,我们了解了aspx和服务器控件背后的故事.这篇我们开始走进WebForm状态保持的一大法宝—ViewState,对其刨根究底一下.然后,再 ...

随机推荐

  1. 生成读取相关连接的物理地址的lib(动态导入库)和dll(动态链接库)

    一.导出相关dll库 将原先的CmdInfoToPipe.h class后加入关键字 __declspec(dllexport) #ifndef NETINFO_CMDINFOTOPIPE_H_ #d ...

  2. javascript设计模式与开发实践阅读笔记(4)——单例模式

    定义 单例模式:保证一个类仅有一个实例,并提供一个访问它的全局访问点. 具体来说,就是保证有些对象有且只有一个,比如线程池.全局缓存.浏览器中的window 对象等.在js中单例模式用途很广,比如登录 ...

  3. Java Socket网络编程常见异常(转)

    1.java.net.SocketTimeoutException 这个异常比较常见,socket超时.一般有2个地方会抛出这个,一个是connect的时候,这个超时参数由connect(Socket ...

  4. HOWTO - Basic MSI安装包在安装运行过程中如何获取完整源路径

    有朋友问到如何在一个Windows Installer安装包中获取安装包源路径,就是在安装包运行过程中动态获取*.msi所在完整路径. 这个问题分两类,如果我们的安装包只是一个*.msi安装文件,那么 ...

  5. js for in对象key排序

    最近遇到一个比较奇葩的事情,for in 循环的时候,如果对象key 默认可以转化为整数,会把key转化为整数排序. code: 运行结果 大家看到data2的key默认顺序是"2" ...

  6. Android 实战之UI线程和Worker线程交互

    哈哈,博文取了个比较霸气的名字,大家不都喜欢这样忽悠人吗 呵呵! 好了,现在就是很简单的点击查询,然后这个查询有点花时间,不想见面出现假死现象,所以在另外的线程进行查询. 好了,代码在此: packa ...

  7. 第六章 - 图像变换 - 图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine)

    拉伸.收缩.扭曲.旋转是图像的几何变换,在三维视觉技术中大量应用到这些变换,又分为仿射变换和透视变换.仿射变换通常用单应性建模,利用cvWarpAffine解决密集映射,用cvTransform解决稀 ...

  8. Android TextUtils类介绍

    对于字符串处理Android为我们提供了一个简单实用的TextUtils类,如果处理比较简单的内容不用去思考正则表达式不妨试试这个在android.text.TextUtils的类,主要的功能如下: ...

  9. Service Station - An Introduction To RESTful Services With WCF

    Learning about REST An Abstract Example Why Should You Care about REST? WCF and REST WebGetAttribute ...

  10. OsmocomBB && Motorora C118

    OsmocomBB 编译安装: http://www.cnblogs.com/hangxin1940/p/3375216.html ##准备: C118 ![C118](http://images.c ...