• ArcEngine将Shp文件导入到GeoDatabase中


    第一种:使用IFeatureDataConverter.ConvertFeatureClass方法

            /// <summary>
            ///使用IFeatureDataConverter.ConvertFeatureClass方法
            /// </summary>
            /// <param name="pFeatureClass"></param>
            /// <param name="pQueryFilter"></param>
            /// <param name="outWorkspace"></param>
            /// <returns></returns>
            public int ImportFeatureClassToNewWorkSpace(IFeatureClass pFeatureClass, IQueryFilter pQueryFilter, IWorkspace outWorkspace, string outName)
            {
                try
                {
                    //输入的要素类空间
                    IDataset inDataSet = pFeatureClass as IDataset;
                    IFeatureClassName inFCName = inDataSet.FullName as IFeatureClassName;
                    IWorkspace inWorkspace = inDataSet.Workspace;
    
                    //输出的shapfile文件的工作空间
                    IDataset outDataSet = outWorkspace as IDataset;
                    IWorkspaceName outWorkspaceName = outDataSet.FullName as IWorkspaceName;
                    IFeatureClassName outFCName = new FeatureClassNameClass();
                    IDatasetName dataSetName = outFCName as IDatasetName;
    
                    dataSetName.WorkspaceName = outWorkspaceName;
                    //dataSetName.Name = pFeatureClass.AliasName.ToString();
                    dataSetName.Name = outName;
    
                    //检查字段的有效性
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    fieldChecker.InputWorkspace = inWorkspace;
                    fieldChecker.ValidateWorkspace = outWorkspace;
    
                    IFields fields = pFeatureClass.Fields;
                    IFields outFields = null;
                    IEnumFieldError enumFieldError = null;
                    fieldChecker.Validate(fields, out enumFieldError, out outFields);
    
                    //调用IFeatureDataConverter接口进行数据转换
                    IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
                    featureDataConverter.ConvertFeatureClass(inFCName, pQueryFilter, null, outFCName, null, outFields, "", 1000, 0);
                }
                catch
                {
                    return 0;
                }
                return 1;
    
            }

    调用:

                    //将shp数据转换成GDB
                    string fileName = GetVectorFileName(subDir[0]);
                    string folder = subDir[0];
                    IFeatureClass shpFeatureClass = m_GisHelp.GetFeatureClass(folder, fileName);
                    IWorkspace outWorkspace=m_GisHelp.Get_Workspace(gdbPath);
                    int success = m_GisHelp.ImportFeatureClassToNewWorkSpace(shpFeatureClass, null, outWorkspace, "parcel");

    第二种:通过GP工具,FeatureClassToGeodatabase

          public void FeatureClassToGDB(string shpRoot, string outGDBPath)
            {
                string shapes = GetShapes(shpRoot);
                ESRI.ArcGIS.ConversionTools.FeatureClassToGeodatabase featureClassToGeodatabase = new ESRI.ArcGIS.ConversionTools.FeatureClassToGeodatabase();
                featureClassToGeodatabase.Input_Features = shapes;
                featureClassToGeodatabase.Output_Geodatabase = outGDBPath;
                featureClassToGeodatabase.Derived_Geodatabase = "";
                Geoprocessor geoprocessor = new Geoprocessor();
                geoprocessor.OverwriteOutput = true;
                try
                {
                    geoprocessor.Execute(featureClassToGeodatabase, null);
                }
                catch (Exception ex)
                {
                    //string mess = null;
                    //for (int k = 0; k < geoprocessor.MessageCount; k++)
                    //{
                    //    mess += geoprocessor.GetMessage(k) + "
    ";
                    //}
                    throw ex;
                }
            }

    作者:ldy

    出处:https://www.cnblogs.com/ParanoiaApe/

    你所做的一切努力并不会立即给你想要的一切,但可以让你逐渐成为你想成为的那一种人!

    本文版权归作者所有,欢迎转载,但请保留该声明。

  • 相关阅读:
    今天是周日,一如既往的在加班
    懒出来的框架
    把Visio文档中形状信息导出到XML文件的VBA代码
    DataGridView多线程更新数据的问题的解决办法
    为VS定制一个自己的代码生成器
    安装VS2012之后自己开发的自定义工具没法使用问题的解决办法
    通过RSA进行私钥加密公钥解密算法的进一步改进
    程序员在职场 该反思了吗?
    图片与字节数组相互转换的方法
    jQuery Ajax 方法调用 Asp.Net WebService 的详细例子
  • 原文地址:https://www.cnblogs.com/ParanoiaApe/p/10876634.html
Copyright © 2020-2023  润新知