您的位置:首页 > 其它

AE调用GP工具(很好的ZZ)

2010-05-26 14:59 543 查看
引用

giszhouGeoprocessing调用ArcToolBox工具使用总结

Geoprocessing是ArcGIS提供的一个非常实用的工具,借由Geoprocessing工具可以方便的调用ArcToolBox中提供的各类工具,本文在ArcEngine9.2平台环境下总结了调用ArcToolBox工具的使用方法:

1、调用ArcToolBox工具方法

以ArcToolBox->Analysis Tools->Proximity->Buffer工具的调用为例,C#代码如下:

using ESRI.ArcGIS.AnalysisTools; //添加引用
using ESRI.ArcGIS.Geoprocessor;

Geoprocessor gp = new Geoprocessor(); //初始化Geoprocessor
gp.OverwriteOutput = true; //允许运算结果覆盖现有文件

ESRI.ArcGIS.AnalysisTools.Buffer pBuffer = new ESRI.ArcGIS.AnalysisTools.Buffer(); //定义Buffer工具
pBuffer.in_features = pVorLineLayer; //输入对象,既可是IFeatureLayer对象,也可是完整文件路径如“D:\\data.shp”
pBuffer.out_feature_class = pBuffer; //输出对象,一般是包含输出文件名的完整文件路径,如“D:\\buffer.shp”

//设置缓冲区的大小,即可是带单位的具体数值,如0.1 Decimal Degrees;也可是输入图层中的某个字段,如“BufferLeng”
pBuffer.buffer_distance_or_field = "BufferLeng";
pBuffer.dissolve_option = "ALL"; //支持融合缓冲区重叠交叉部分
gp.Execute(pBuffer, null); //执行缓冲区分析

ArcToolBox中各个工具调用时需添加的引用分别如下图所示:





参考网页:http://edndoc.esri.com/arcobjects/9.2/NET/c4ff8b68-0410-435f-b8e5-682d5cea47cf.htm

2、参数设置

在调用ArcToolBox执行具体的分析操作时,需要设置各类输入输出参数,简单概括起来说主要分为两类:对应于Environment Settings对话框的Geoprocessor对象设置、对应于具体操作窗口的方法设置。以ArcToolBox->Analysis Tools->Overlay->Intersect为例,C#代码如下:

Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true; //覆盖原有文件并重写

//Environment Settings对话框参数设置,具体名称参考操作界面Help中对应参数文档

object obj = gp.GetEnvironmentValue("Extent"); //设置Exten,大小写无关;

gp.SetEnvironmentValue("Extent", "MAXOF"); //或者"113.697050 115.074770 29.969986 31.362495"

obj = gp.GetEnvironmentValue("OutputZFlag"); //设置Output has Z Values
gp.SetEnvironmentValue("OutputZFlag", "DEFAULT");

obj = gp.GetEnvironmentValue("OutputMFlag"); //设置Output has M Values
gp.SetEnvironmentValue("OutputMFlag", "DEFAULT");

obj = gp.GetEnvironmentValue("OutputCoordinateSystem"); //设置Output Coordinate System
gp.SetEnvironmentValue("OutputCoordinateSystem", Application.StartupPath + "\\zhouyang.prj");

obj = gp.GetEnvironmentValue("QualifiedFieldNames"); //设置Maintain fully qualifid field names
gp.SetEnvironmentValue("QualifiedFieldNames", "QUALIFIED");

//关于Environment Settings的设置可以参考ArcMap操作界面提供的文档,如图所示:





Environment Settings设置





参数名称参考帮助,如上图所示为Extent,其取值有三种形式

//具体操作窗口的方法设置

Intersect pIntersect = new Intersect();
//多个对象的输入:用分号隔开包含完整路径的文件名
pIntersect.in_features = pInputFeature1 + ";" + pInputFeature2;

//多个对象的输入:使用IGpValueTableObject接口,该接口可以设置Rank(http://resources.esri.com/help/9.3/arcgisengine/dotnet/84349562-e062-44ee-8db0-9fcdcd64708b.htm

//object inputfeature1 = @"D:\周杨\贝贝\WuhanCity\ThiessenPolygons_Line_Buffer.shp";
//object inputfeature2 = @"D:\周杨\贝贝\wuhanCity_shp\poi Point.shp";
//IGpValueTableObject pObject = new GpValueTableObjectClass();
//pObject.SetColumns(2);
//pObject.AddRow(ref inputfeature1);
//pObject.AddRow(ref inputfeature2);
//pIntersect.in_features = pObject;
pIntersect.out_feature_class = pOutputFeature;
pIntersect.join_attributes = "All";
pIntersect.output_type = "POINT";

gp.Execute(pIntersect, null); //执行

//Intersect参数设置跟弹出的Intersect对话框对应,如图所示:





参考网页:http://edndoc.esri.com/arcobjects/9.2/NET/552ca115-f23b-4a74-a2c5-069c50d6cdcf.htm

3、运行结果对象提取

Geoprocessor对象通过Execute方法执行后将结果保存到指定输出路径下,通过也可以通过IGeoProcessorResult接口读取存储在内容中的结果对象,C#代码如下:

//执行图层求交运算
IGeoProcessorResult pResult = (IGeoProcessorResult)gp.Execute(pIntersect, null);

IGPUtilities pGPUtil = new GPUtilitiesClass();
IFeatureClass pFC;
IQueryFilter pQF;
pGPUtil.DecodeFeatureLayer(pResult.GetOutput(0),out pFC,out pQF);
int count = pFC.FeatureCount(null); //统计Feature对象个数
IFeatureCursor pCursor = pFC.Insert(true); //提取FeatureCursor对象
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFC;
m_mapControl.Map.AddLayer(pFeatureLayer); //加载图层对象

参考网页:http://edndoc.esri.com/arcobjects/9.2/NET/1b14f488-84de-4e7f-8009-cfe612f8dcbe.htm

其实总的说来,ESRI的官方帮助和各类在线帮助文档中都提供了相应的说明,可以很容易搞清楚一些内容,但是在具体的操作过程中,有时候经常得不到结果,这时候就需要关注下Environment Settings中的部分参数是否设置了,有可能没有像软件操作界面中那样进行默认设置。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: