以下为解决办法:(下面两个方法为搜索结果,均未解决我的问题)
1、对 COM 组件的调用返回了错误 HRESULT E_FAIL
(1) 在控制面板--->管理工具--->服务中,开启Distributed Transaction Coordinator 服务。(2) 打开控制面板--->管理工具--->组件服务--->选择计算机--->我的电脑--->右击属性--->选择MSDTC--->选择安全配置勾选事务管理器通信中的允许出站、允许入站和不要求进行验证。
2、
clip方法裁剪图层的时候,提示COM组件调用错误解决办法
上一篇 / 下一篇 2011-11-26 17:15:07 / 个人分类:AE开发
查看( 421 ) / 评论( 0 ) / 评分( 0 / 0 )
问题代码:
public static ILayer clip(IFeatureLayer inputfeaturelayer, IFeatureLayer cliplayer)
{
try
{
Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
//gp.SetEnvironmentValue("workspace", "Database Connections\\Connection to wsz-nb-pc.sde"); //设置sde路径
//gp.SetEnvironmentValue("outputCoordinateSystem",
// @"C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\Gauss Kruger\CGCS 2000\Xian_1980_3_Degree_GK_CM_111E.prj");
IFeatureClass inputfeatureclass = inputfeaturelayer.FeatureClass;
IFeatureClass clipfeatureclass = cliplayer.FeatureClass;
IDataset dataset = inputfeatureclass as IDataset;
IWorkspace workspace = dataset.Workspace;
IFeatureWorkspace fworkspace = workspace as IFeatureWorkspace;
IFields utfields = inputfeatureclass.Fields;
IFeatureClass utfeatureclass = null;
try
{
utfeatureclass = fworkspace.OpenFeatureClass("ClipFile");
if (null != outfeatureclass)
{
//清空记录
IDataset pDataSet = (IDataset)outfeatureclass;
pDataSet.Delete();
}
}
catch (Exception err)
{
utfeatureclass = fworkspace.CreateFeatureClass("ClipFile", outfields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
}
ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip(inputfeatureclass, clipfeatureclass, outfeatureclass);
gp.Execute(clipTool, null);
IFeatureLayer utlayer = new FeatureLayerClass();
outlayer.FeatureClass = outfeatureclass;
outlayer.Name = outfeatureclass.AliasName;
return outlayer;
}catch(Exception err)
{
MessageBox.Show(string.Format("图层裁剪失败:【{0}】",err.Message), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}
该段代码在我的开发环境(xp + AE10 + SDE9.3 + ORACLE10G)中总是提示:
对COM组件的调用返回了错误 HRESULT E_FAIL的错误。
在确定了授权没问题,数据没问题后,将程序改后,成功解决:
public static void clip(IFeatureLayer inputfeaturelayer, IFeatureLayer cliplayer,string strOutShpPath,AxMapControl MapCtr)
{
try
{
Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
IFeatureClass inputfeatureclass = inputfeaturelayer.FeatureClass;
IFeatureClass clipfeatureclass = cliplayer.FeatureClass;
ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip();
clipTool.in_features = inputfeatureclass;
clipTool.clip_features = clipfeatureclass;
clipTool.out_feature_class = strOutShpPath;
GeoProcessorResult gpResult = new GeoProcessorResult();
gpResult = gp.Execute(clipTool, null) as GeoProcessorResult;
string strMsg = "";
for (int i = 0; i < gpResult.MessageCount; i++)
{
strMsg += gpResult.GetMessage(i)+"\n";
}
MessageBox.Show(strMsg);
string shpDir = System.IO.Path.GetDirectoryName(strOutShpPath);
string shpName = System.IO.Path.GetFileNameWithoutExtension(strOutShpPath);
MapCtr.AddShapeFile(shpDir, shpName);//"C:\\temp\\"
}
catch (Exception err)
{
MessageBox.Show(string.Format("图层裁剪失败:【{0}】", err.Message), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}