GP的功能非常强大,也是GIS建模的一个很重要的工具。在Arcengine中,实现Clip功能很多种方法,可以用IBasicGeoprocessor的clip方法,但是GP无疑是最简单的。
public Clip(
objectin_cover,
objectclip_cover,
objectout_cover
)
输入这三个参数,即可实现clip功能,第一个参数为输入要素,第二个为裁剪要素,最后为保存路径 string SavePath= @"F:\shiyan\最后的战役\ww2.shp";
//保存路径
string file= System.IO.Path.GetDirectoryName(SavePath);
//获取保存目录
string filename=System.IO.Path.GetFileName(SavePath);
//获取保存文件名
string name = System.IO.Path.GetFileNameWithoutExtension(SavePath); //获取不带后缀的文件名
Geoprocessor g = new Geoprocessor();
g.OverwriteOutput = true;
//ESRI.ArcGIS.AnalysisTools.Clip clip = new Clip(@"F:\shiyan\最后的战役\New_Shapefile(3).shp", @"F:\shiyan\最后的战役\New_Shapefile(4).shp", @"F:\shiyan\最后的战役\ww1.shp");
ESRI.ArcGIS.AnalysisTools.Clip clip = new Clip(featurelayer1, featurelayer2, SavePath); //两种方法皆可
IGeoProcessorResult result=(IGeoProcessorResult) g.Execute(clip, null);
if (result.Status == esriJobStatus.esriJobSucceeded) //运行状态
{
MessageBox.Show("成功!");
}
// 将得到的结果添加到图层
IWorkspaceFactory factory = new ShapefileWorkspaceFactoryClass();
IWorkspace workspace= factory.OpenFromFile(file,0);
IFeatureWorkspace featureworkspace = workspace as IFeatureWorkspace;
IFeatureClass featureclass= featureworkspace.OpenFeatureClass(filename);
IFeatureLayer layer = new FeatureLayerClass();
layer.FeatureClass = featureclass;
layer.Name = name;
axMapControl1.AddLayer(layer);
}