许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  AE GP工具类:封装与使用

AE GP工具类:封装与使用

阅读数 15
点赞 0
article_banner

1、联合

      //gp联合

           public IFeatureClass gpUnion(List<IFeatureClass> features, string tempName)

           {

               IGeoProcessorResult result = null;

               IFeatureClass pFeatureClass = null;

               try

               {

                   Geoprocessor geoprocessor = new Geoprocessor();

                   geoprocessor.OverwriteOutput = true;//允许覆盖现有文件

                   geoprocessor.AddOutputsToMap = false;

                   ESRI.ArcGIS.AnalysisTools.Union union = new ESRI.ArcGIS.AnalysisTools.Union();

                   IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();//对两个要素 类  进行相交运算

                   gpValueTableObject.SetColumns(2);
foreach (IFeatureClass featureClass in features)

                   {

                       object o1 = featureClass;//输入IFeatureClass 1

                       gpValueTableObject.AddRow(ref o1);

                   }

               union.in_features = gpValueTableObject;

                   union.join_attributes = "ONLY_FID";

                   union.out_feature_class = dw_ArchiveOutput_Cls.CurWorkProject.projectPath + @"\耕地\分析 数据库  .gdb\" + tempName;

                   result = (IGeoProcessorResult)geoprocessor.Execute(union, null);

                   pFeatureClass = (IFeatureClass)geoprocessor.Open(result.ReturnValue);

               }

               catch (Exception)

               {

                   throw;

               }

               finally

               {

           }
return pFeatureClass;

           }

2、擦除

//gp擦除

           public IFeatureClass gpErase(IFeatureClass infeature,IFeatureClass efeature,string tempName)

           {

               IGeoProcessorResult result = null;

               IFeatureClass pFeatureClass = null;

               Geoprocessor geoprocessor=null;

               try

               {

                   geoprocessor = new Geoprocessor();

                   geoprocessor.OverwriteOutput = true;//允许覆盖现有文件

                   geoprocessor.AddOutputsToMap = false;

                   ESRI.ArcGIS.AnalysisTools.Erase erase = new ESRI.ArcGIS.AnalysisTools.Erase();

                   IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();//对两个要素类进行相交运算

                   gpValueTableObject.SetColumns(2);

                   //foreach (IFeatureClass featureClass in features)

                   //{

                   //    object o1 = featureClass;//输入IFeatureClass 1

                   //    gpValueTableObject.AddRow(ref o1);

                   //}

               erase.in_features = infeature;

                   erase.erase_features = efeature;

                   erase.out_feature_class = dw_ArchiveOutput_Cls.CurWorkProject.projectPath + @"\耕地\分析数据库.gdb\" + tempName;

                   result = (IGeoProcessorResult)geoprocessor.Execute(erase, null);

                   pFeatureClass = (IFeatureClass)geoprocessor.Open(result.ReturnValue);

               }

               catch (Exception)

               {

                   throw;

               }

               finally

               {

                   //ReleaseComObject.releaseComObject(geoprocessor);

                   //ReleaseComObject.releaseComObject(result);

               }

               return pFeatureClass;

           }

3、识别

//gp Identity

           public IFeatureClass gpIdentity(IFeatureClass in_features, IFeatureClass identity_features,string tempName)

           {

               //identity操作;

               ESRI.ArcGIS.AnalysisTools.Identity pIdentity = null;

               IGeoProcessorResult result = null;

               IFeatureClass pFeatureClass = null;

               try

               {

                   Geoprocessor gp = new Geoprocessor();

                   gp.OverwriteOutput = true;//允许覆盖现有文件

                   gp.AddOutputsToMap = false;

               pIdentity = new ESRI.ArcGIS.AnalysisTools.Identity();

                   pIdentity.in_features = in_features;//形状

                   pIdentity.identity_features = identity_features;//获取属性

                   //    pIdentity.out_feature_class = @"https://www.gofarlic.com\ code \TESTSHP\identity.shp";

                   pIdentity.out_feature_class = dw_ArchiveOutput_Cls.CurWorkProject.projectPath + @"\耕地\分析数据库.gdb\" + tempName;

                   result = (IGeoProcessorResult)gp.Execute(pIdentity, null);

                   pFeatureClass = (IFeatureClass)gp.Open(result.ReturnValue);

               }

               catch (Exception)

               {

                   throw;

               }

               finally

               {

               }

               return pFeatureClass;

           }

4、相交

//gp相交

           public IFeatureClass gpIntsect(List<IFeatureClass> features,string tempName)

           {

               IGeoProcessorResult result = null;

               IFeatureClass pFeatureClass=null;

               Geoprocessor geoprocessor = null;

               try

               {

                   geoprocessor = new Geoprocessor();

                   geoprocessor.OverwriteOutput = true;//允许覆盖现有文件

                   geoprocessor.AddOutputsToMap = false;

                   ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();

                   IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();//对两个要素类进行相交运算

                   gpValueTableObject.SetColumns(2);

                   foreach(IFeatureClass featureClass in features){

                       object o1 = featureClass;//输入IFeatureClass 1

                       gpValueTableObject.AddRow(ref o1);

                   }


                   intersect.in_features = gpValueTableObject;

                   //intersect.out_feature_class = dw_ArchiveOutput_Cls.CurWorkProject.projectPath + @"\耕地\" + tempName + ".shp";

                   //打开gdb

                   //IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();

                   //IWorkspace workspace = workspaceFactory.OpenFromFile(dw_ArchiveOutput_Cls.CurWorkProject.projectPath + @"\耕地\\分析数据库.gdb", 0);

                   //IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

                   //IFeatureClass pBY = featureWorkspace.OpenFeatureClass("GDFX");

               intersect.out_feature_class = dw_ArchiveOutput_Cls.CurWorkProject.projectPath + @"\耕地\分析数据库.gdb\" + tempName;

                   result=(IGeoProcessorResult)geoprocessor.Execute(intersect, null);

                   pFeatureClass = (IFeatureClass)geoprocessor.Open(result.ReturnValue);

               }

               catch (Exception)

               {

                   throw;

               }

               finally

               {

                   //ReleaseComObject.releaseComObject(geoprocessor);

                   //ReleaseComObject.releaseComObject(result);

                   //Marshal.FinalReleaseComObject(geoprocessor);

                   //Marshal.FinalReleaseComObject(result);

               }

               return pFeatureClass;

           }

5、

//gp dissolve

           public IFeatureClass gpDissolve(IFeatureClass pInFeatureClass, string tempName)

           {

               IGeoProcessorResult result = null;

               IFeatureClass pFeatureClass = null;

               try

               {

                   Geoprocessor geoprocessor = new Geoprocessor();

                   geoprocessor.OverwriteOutput = true;//允许覆盖现有文件

                   geoprocessor.AddOutputsToMap = false;

                   ESRI.ArcGIS.DataManagementTools.Dissolve dissolve = new ESRI.ArcGIS.DataManagementTools.Dissolve();

                   //  IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();//对两个要素类进行联合运算

               //gpValueTableObject.SetColumns(num);

                   //foreach (IFeatureClass featureClass in features)

                   //{

                   //    object o1 = featureClass;//输入IFeatureClass 1

                   //    gpValueTableObject.AddRow(ref o1);

                   //}

               dissolve.in_features = pInFeatureClass;

                   dissolve.out_feature_class = dw_ArchiveOutput_Cls.CurWorkProject.projectPath + @"\耕地\分析数据库.gdb\" + tempName;

                   result = (IGeoProcessorResult)geoprocessor.Execute(dissolve, null);

                   pFeatureClass = (IFeatureClass)geoprocessor.Open(result.ReturnValue);

               }

               catch (Exception)

               {

                   throw;

               }

               finally

               {

           }

               return pFeatureClass;

           }

6、删除

//gp删除

           public IFeatureClass gpDelete(IFeatureClass infeature)

           {

               IGeoProcessorResult result = null;

               IFeatureClass pFeatureClass = null;

               Geoprocessor geoprocessor = null;

               try

               {

                   geoprocessor = new Geoprocessor();

                   geoprocessor.OverwriteOutput = true;//允许覆盖现有文件

                   geoprocessor.AddOutputsToMap = false;

                   ESRI.ArcGIS.DataManagementTools.DeleteFeatures dissolve = new ESRI.ArcGIS.DataManagementTools.DeleteFeatures();

               dissolve.in_features = infeature;

                   geoprocessor.Execute(dissolve, null);

               }

               catch (Exception)

               {

                   throw;

               }

               finally

               {

                   //ReleaseComObject.releaseComObject(geoprocessor);

                   //ReleaseComObject.releaseComObject(result);

               }

               return pFeatureClass;

           }

7、字段计算器

      //gp 计算椭球面积

           public IFeatureClass gpTuo(ITable table)

           {

               IGeoProcessorResult result = null;

               IFeatureClass pFeatureClass = null;

               Geoprocessor geoprocessor = null;

               try

               {

               Geoprocessor gp = new Geoprocessor();

                   gp.OverwriteOutput = true;

                   ESRI.ArcGIS.DataManagementTools.CalculateField calc = new ESRI.ArcGIS.DataManagementTools.CalculateField();

                   calc.in_table = table;

                   calc.field = "Shape_Area";

                   calc.expression = "!shape.geodesicArea!";

                   calc.expression_type = "PYTHON";

                   //或者calc.expression_type = "PYTHON3";

               gp.Execute(calc, null);

               }

               catch (Exception)

               {

                   throw;

               }

               finally

               {

                   //ReleaseComObject.releaseComObject(geoprocessor);

                   //ReleaseComObject.releaseComObject(result);

               }

               return pFeatureClass;

           }


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空