AE调用gp服务
2014-03-27 14:29
776 查看
参考:http://www.cnblogs.com/zhangjun1130/archive/2010/05/26/1744472.html
Geoprocessing是ArcGIS提供的一个非常实用的工具,借由Geoprocessing工具可以方便的调用ArcToolBox中提供的各类工具,本文在ArcEngine9.2平台环境下总结了调用ArcToolBox工具的使用方法:
1、调用ArcToolBox工具方法
以ArcToolBox->AnalysisTools->Proximity->Buffer工具的调用为例,C#代码如下:
usingESRI.ArcGIS.AnalysisTools;//添加引用
usingESRI.ArcGIS.Geoprocessor;
Geoprocessorgp=newGeoprocessor();//初始化Geoprocessor
gp.OverwriteOutput=true;//允许运算结果覆盖现有文件
ESRI.ArcGIS.AnalysisTools.BufferpBuffer=newESRI.ArcGIS.AnalysisTools.Buffer();//定义Buffer工具
pBuffer.in_features=pVorLineLayer;//输入对象,既可是IFeatureLayer对象,也可是完整文件路径如“D:\\data.shp”
pBuffer.out_feature_class=pBuffer;//输出对象,一般是包含输出文件名的完整文件路径,如“D:\\buffer.shp”
//设置缓冲区的大小,即可是带单位的具体数值,如0.1DecimalDegrees;也可是输入图层中的某个字段,如“BufferLeng”
pBuffer.buffer_distance_or_field="BufferLeng";
pBuffer.dissolve_option="ALL";//支持融合缓冲区重叠交叉部分
gp.Execute(pBuffer,null);//执行缓冲区分析
2、参数设置
在调用ArcToolBox执行具体的分析操作时,需要设置各类输入输出参数,简单概括起来说主要分为两类:对应于EnvironmentSettings对话框的Geoprocessor对象设置、对应于具体操作窗口的方法设置。以ArcToolBox->AnalysisTools->Overlay->Intersect为例,C#代码如下:
Geoprocessorgp=newGeoprocessor();
gp.OverwriteOutput=true;//覆盖原有文件并重写
//EnvironmentSettings对话框参数设置,具体名称参考操作界面Help中对应参数文档
objectobj=gp.GetEnvironmentValue("Extent");//设置Exten,大小写无关;
gp.SetEnvironmentValue("Extent","MAXOF");//或者"113.697050115.07477029.96998631.362495"
obj=gp.GetEnvironmentValue("OutputZFlag");//设置OutputhasZValues
gp.SetEnvironmentValue("OutputZFlag","DEFAULT");
obj=gp.GetEnvironmentValue("OutputMFlag");//设置OutputhasMValues
gp.SetEnvironmentValue("OutputMFlag","DEFAULT");
obj=gp.GetEnvironmentValue("OutputCoordinateSystem");//设置OutputCoordinateSystem
gp.SetEnvironmentValue("OutputCoordinateSystem",Application.StartupPath+"\\zhouyang.prj");
obj=gp.GetEnvironmentValue("QualifiedFieldNames");//设置Maintainfullyqualifidfieldnames
gp.SetEnvironmentValue("QualifiedFieldNames","QUALIFIED");
//具体操作窗口的方法设置
IntersectpIntersect=newIntersect();
//多个对象的输入:用分号隔开包含完整路径的文件名
pIntersect.in_features=pInputFeature1+";"+pInputFeature2;
//多个对象的输入:使用IGpValueTableObject接口,该接口可以设置Rank(http://resources.esri.com/help/9.3/arcgisengine/dotnet/84349562-e062-44ee-8db0-9fcdcd64708b.htm)
//objectinputfeature1=@"D:\周杨\贝贝\WuhanCity\ThiessenPolygons_Line_Buffer.shp";
//objectinputfeature2=@"D:\周杨\贝贝\wuhanCity_shp\poiPoint.shp";
//IGpValueTableObjectpObject=newGpValueTableObjectClass();
//pObject.SetColumns(2);
//pObject.AddRow(refinputfeature1);
//pObject.AddRow(refinputfeature2);
//pIntersect.in_features=pObject;
pIntersect.out_feature_class=pOutputFeature;
pIntersect.join_attributes="All";
pIntersect.output_type="POINT";
gp.Execute(pIntersect,null);//执行
3、运行结果对象提取
Geoprocessor对象通过Execute方法执行后将结果保存到指定输出路径下,通过也可以通过IGeoProcessorResult接口读取存储在内容中的结果对象,C#代码如下:
//执行图层求交运算
IGeoProcessorResultpResult=(IGeoProcessorResult)gp.Execute(pIntersect,null);
IGPUtilitiespGPUtil=newGPUtilitiesClass();
IFeatureClasspFC;
IQueryFilterpQF;
pGPUtil.DecodeFeatureLayer(pResult.GetOutput(0),outpFC,outpQF);
intcount=pFC.FeatureCount(null);//统计Feature对象个数
IFeatureCursorpCursor=pFC.Insert(true);//提取FeatureCursor对象
IFeatureLayerpFeatureLayer=newFeatureLayerClass();
pFeatureLayer.FeatureClass=pFC;
m_mapControl.Map.AddLayer(pFeatureLayer);//加载图层对象
ArcGISToolboxReference对话框。
下面是一个执行计算最优路径模型的工具,它位于BestPath工具箱中:
工具箱能够发布在局域网(LAN)或者作为一个Web服务发布在Internet上。要想使用geoprocessing服务工具,你必须添加工具箱。下面的示例代码显示了如何使用AddToolbox方法添加发布在ArcGISServer的工具。
其中在arccatalog中添加GISServer时hostName同arcgisservermanager打开时的网址中的内容如:
则添加工具代码为:
如果无端口号信息则:
Geoprocessing是ArcGIS提供的一个非常实用的工具,借由Geoprocessing工具可以方便的调用ArcToolBox中提供的各类工具,本文在ArcEngine9.2平台环境下总结了调用ArcToolBox工具的使用方法:
1、调用ArcToolBox工具方法
以ArcToolBox->AnalysisTools->Proximity->Buffer工具的调用为例,C#代码如下:
usingESRI.ArcGIS.AnalysisTools;//添加引用
usingESRI.ArcGIS.Geoprocessor;
Geoprocessorgp=newGeoprocessor();//初始化Geoprocessor
gp.OverwriteOutput=true;//允许运算结果覆盖现有文件
ESRI.ArcGIS.AnalysisTools.BufferpBuffer=newESRI.ArcGIS.AnalysisTools.Buffer();//定义Buffer工具
pBuffer.in_features=pVorLineLayer;//输入对象,既可是IFeatureLayer对象,也可是完整文件路径如“D:\\data.shp”
pBuffer.out_feature_class=pBuffer;//输出对象,一般是包含输出文件名的完整文件路径,如“D:\\buffer.shp”
//设置缓冲区的大小,即可是带单位的具体数值,如0.1DecimalDegrees;也可是输入图层中的某个字段,如“BufferLeng”
pBuffer.buffer_distance_or_field="BufferLeng";
pBuffer.dissolve_option="ALL";//支持融合缓冲区重叠交叉部分
gp.Execute(pBuffer,null);//执行缓冲区分析
2、参数设置
在调用ArcToolBox执行具体的分析操作时,需要设置各类输入输出参数,简单概括起来说主要分为两类:对应于EnvironmentSettings对话框的Geoprocessor对象设置、对应于具体操作窗口的方法设置。以ArcToolBox->AnalysisTools->Overlay->Intersect为例,C#代码如下:
Geoprocessorgp=newGeoprocessor();
gp.OverwriteOutput=true;//覆盖原有文件并重写
//EnvironmentSettings对话框参数设置,具体名称参考操作界面Help中对应参数文档
objectobj=gp.GetEnvironmentValue("Extent");//设置Exten,大小写无关;
gp.SetEnvironmentValue("Extent","MAXOF");//或者"113.697050115.07477029.96998631.362495"
obj=gp.GetEnvironmentValue("OutputZFlag");//设置OutputhasZValues
gp.SetEnvironmentValue("OutputZFlag","DEFAULT");
obj=gp.GetEnvironmentValue("OutputMFlag");//设置OutputhasMValues
gp.SetEnvironmentValue("OutputMFlag","DEFAULT");
obj=gp.GetEnvironmentValue("OutputCoordinateSystem");//设置OutputCoordinateSystem
gp.SetEnvironmentValue("OutputCoordinateSystem",Application.StartupPath+"
obj=gp.GetEnvironmentValue("QualifiedFieldNames");//设置Maintainfullyqualifidfieldnames
gp.SetEnvironmentValue("QualifiedFieldNames","QUALIFIED");
//具体操作窗口的方法设置
IntersectpIntersect=newIntersect();
//多个对象的输入:用分号隔开包含完整路径的文件名
pIntersect.in_features=pInputFeature1+";"+pInputFeature2;
//多个对象的输入:使用IGpValueTableObject接口,该接口可以设置Rank(
//objectinputfeature1=@"D:\周杨\贝贝\WuhanCity\ThiessenPolygons_Line_Buffer.shp";
//objectinputfeature2=@"D:\周杨\贝贝\wuhanCity_shp\poiPoint.shp";
//IGpValueTableObjectpObject=newGpValueTableObjectClass();
//pObject.SetColumns(2);
//pObject.AddRow(refinputfeature1);
//pObject.AddRow(refinputfeature2);
//pIntersect.in_features=pObject;
pIntersect.out_feature_class=pOutputFeature;
pIntersect.join_attributes="All";
pIntersect.output_type="POINT";
gp.Execute(pIntersect,null);//执行
3、运行结果对象提取
Geoprocessor对象通过Execute方法执行后将结果保存到指定输出路径下,通过也可以通过IGeoProcessorResult接口读取存储在内容中的结果对象,C#代码如下:
//执行图层求交运算
IGeoProcessorResultpResult=(IGeoProcessorResult)gp.Execute(pIntersect,null);
IGPUtilitiespGPUtil=newGPUtilitiesClass();
IFeatureClasspFC;
IQueryFilterpQF;
pGPUtil.DecodeFeatureLayer(pResult.GetOutput(0),outpFC,outpQF);
intcount=pFC.FeatureCount(null);//统计Feature对象个数
IFeatureCursorpCursor=pFC.Insert(true);//提取FeatureCursor对象
IFeatureLayerpFeatureLayer=newFeatureLayerClass();
pFeatureLayer.FeatureClass=pFC;
m_mapControl.Map.AddLayer(pFeatureLayer);//加载图层对象
运行自定义的geoprocessing工具
除了使用现有的工具和ESRI提供的工具箱,也可以执行你自定义的工具,比如modeltools(模型工具)和scripttools(脚本工具),他们存在于自定义工具箱中。使用集成开发环境(IDE)框架嵌入在VisualStudio.NET中,你可以生成geoprocessing程序集用来重现任何自定义工具箱。这样做,使用引用名称执行工具
声明你的自定义工具箱并不是生成geoprocessing程序集的先决条件。这里有另外一种使用geoprocessor的方式来使用Execute方法。Execute方法已经被重载和附加,允许您通过指定工具的名称、工具的参数和ITrackCancel接口来执行工具。下面是一个执行计算最优路径模型的工具,它位于BestPath工具箱中:
usingESRI.ArcGIS.Geoprocessor; usingESRI.ArcGIS.esriSystem; publicvoidSampleCalculateBestPathTool() { //Initializethegeoprocessor. GeoprocessorGP=newGeoprocessor(); //AddtheBestPathtoolbox. GP.AddToolbox(@"C:\SanDiego\BestPath.tbx"); //Generatethearrayofparameters. IVariantArrayparameters=newVarArrayClass(); parameters.Add(@"C:\SanDiego\source.shp"); parameters.Add(@"C:\SanDiego\destination.shp"); parameters.Add(@"C:\SanDiego\bestpath.shp"); //Executethemodeltoolbyname. GP.Execute("CalculateBestPath",parameters,null); }
执行geoprocessingserver工具
通过ArcGISDesktop和ArcGISEngine(9.2及以上版本),你可以执行发布在ArcGISServer上的geoprocessing工具。Server工具能通过像自定义工具一样执行。首先你必须添加工具箱,这个工具箱是生成一个geoprocessingtoolboxassembly来表示或使用 AddToolbox方法添加自定义的。
工具箱能够发布在局域网(LAN)或者作为一个Web服务发布在Internet上。要想使用geoprocessing服务工具,你必须添加工具箱。下面的示例代码显示了如何使用AddToolbox方法添加发布在ArcGISServer的工具。
usingESRI.ArcGIS.Geoprocessor; publicvoidSampleGeoprocessingServerTool(GeoprocessorGP) { //AddtheBestPathtoolboxpublishedonaLAN. //Enteredasservername;folder/toolbox. GP.AddToolbox(@"flame7;SanDiego/BestPath"); //AddtheBestPathtoolboxpublishedasageoprocessingWebservice. //EnteredasWebservice;folder/toolbox. GP.AddToolbox(@"http://flame7/arcgis/services;SanDiego/BestPath"); //TODO:Addyourcodehere...
其中在arccatalog中添加GISServer时hostName同arcgisservermanager打开时的网址中的内容如:
则添加工具代码为:
GP.AddToolbox(@"http://192.168.0.200:8399/arcgis/services;tt/tbx");
如果无端口号信息则:
则添加工具代码为:
GP.AddToolbox(@"http://temp-pc/arcgis/services;tt/tbx");
相关文章推荐
- AE调用GP
- (八)ArcGIS API For Javascript调用GP服务
- [置顶] ArcGIS 10.2以上GP服务调用
- (十)ArcGIS JS GP服务异步调用
- 基于ArcGIS API For JavaScript调用GP服务实现动态插值分析实现
- Silverlight 调用GP服务第一篇之发布GP服务(Geoprocessing Service)
- 解决AE中GP工具错误 对 COM 组件的调用返回了错误 HRESULT E_FAIL
- C#中winform下利用ArcEngine调用ArcGIS Server发布的服务 AE 10
- Silverlight 调用GP服务第一篇之发布GP服务(Geoprocessing Service)
- JAVA基于AE调用GP实现泰森多边形
- ArcGIS API for javascript开发笔记(四)——GP服务调用之GP模型的规范化制作详解
- ArcGIS for Android示例解析之GP服务调用-----ViewShed
- 学习笔记之ArcGIS Engine调用自定义GP服务(二)
- ArcGIS API for Javascript和GP服务调用
- ArcGIS API for JavaScript开发笔记(二)GP服务REST调用
- AE调用GP工具“对COM组件的调用返回了错误 HRESULTE_FAIL”解决
- (十一)ArcGIS JS GP服务同步调用
- ArcGIS Server Flex API 调用GP服务
- Silverlight调用GP服务第二篇之调用GP服务(Geoprocessing Service)过程详解
- AE调用影像服务