天天看點

基于C#的AE二次開發GP生成緩沖區分析

調用GP工具生成緩沖區分析

建立菜單欄或者按鈕,設定點選事件加載代碼即可,注意需要導入對應的動态連結庫(.dll)

/// GP工具調用,生成緩沖區
private void btnGPBuffer_Click(object sender, EventArgs e)
{
	try
	{
		//緩沖區分析-GP工具調用
		Geoprocessor gp = new Geoprocessor();
		gp.OverwriteOutput = true;//是否産生輸出檔案
		//調用緩沖區工具
		ESRI.ArcGIS.AnalysisTools.Buffer pBuffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
		//擷取緩沖區分析圖層
		ILayer pLayer = axMapControl1.get_Layer(0);
		IFeatureLayer featLayer = pLayer as IFeatureLayer;
		//輸入要緩沖的FeatureLayer
		pBuffer.in_features = featLayer;
		//如果路徑或檔案夾不存在會報錯
		string filepath = @"c:\dat\";
		//設定生成結果存儲路徑
		pBuffer.out_feature_class = filepath + "\\" + pLayer.Name + ".shp";
		//設定緩沖區距離_這裡設定為500米
		pBuffer.buffer_distance_or_field = "500 Meters";
		//生成的要素是否融合,這裡選擇ALL,也可以選擇None、List
		pBuffer.dissolve_option = "ALL";
		//執行緩沖區分析
		gp.Execute(pBuffer, null);
		//将生成結果添加到地圖中
		axMapControl1.AddShapeFile(filepath, pLayer.Name);
		axMapControl1.MoveLayerTo(0, 0);
	}
	catch {}
}