AE中根据属性提取要素的功能

昨天帮一位朋友实现一个根据属性提取要素的功能,现记录如下,以备后用:

先看看效果图吧!

要素提取前

要素提取后

以下实现这个功能的关键代码:

//主程序的路径(这个是全局变量)
private string appPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

//设置环境
Geoprocessor gp = new Geoprocessor();
gp.SetEnvironmentValue("workspace",appPath+@"\data\");
gp.OverwriteOutput = true;
//获取要素图层
IFeatureLayer pLayer = this.axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IFeatureClass inputFeatures = pLayer.FeatureClass;
//使用Select工具
ESRI.ArcGIS.AnalysisTools.Select selectFeature = new Select();
selectFeature.in_features = inputFeatures;
selectFeature.out_feature_class = @"output\fgselect.shp";
selectFeature.where_clause = "GRIDCODE>=50";
//执行
gp.Execute(selectFeature,null);
// 将结果加载到当前地图
string pFolder = Path.GetDirectoryName(appPath+@"\data\output\fgselect.shp");
string pFileName = Path.GetFileName(appPath + @"\data\output\fgselect.shp");
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
IWorkspace shpWorksapce = pWorkspaceFactory.OpenFromFile(pFolder, 0);
IFeatureWorkspace pFeatureWorkspace=shpWorksapce as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName);
IFeatureLayer outputLayer = new FeatureLayerClass();
outputLayer.FeatureClass = pFeatureClass;
outputLayer.Name = pFeatureClass.AliasName;
this.axMapControl1.Map.AddLayer((ILayer)outputLayer);
this.axMapControl1.ActiveView.Refresh();


 


ArcGIS里面的GP真的是功能强大呀,借助它可以省不少事,看来以后还得多研究一下GP这东东。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值