转自:http://blog.csdn.net/qinyilang/article/details/6321079
属性查询是在当前map的layer中获取符合条件的feature的集合,实现过程是获取featurelayer的featureclass。然后定义过滤条件。在featureclass中执行search函数。获取查询结果。主要代码:
ILayer layer = axMapControl1.get_Layer(0);
IFeatureLayer featureLayer = layer as IFeatureLayer;
//获取featureLayer的featureClass
IFeatureClass featureClass = featureLayer.FeatureClass;
IFeature feature = null;
IQueryFilter queryFilter = new QueryFilterClass();
IFeatureCursor featureCusor;
queryFilter.WhereClause = "name = '" + searchName + "'";
featureCusor = featureClass.Search(queryFilter, true);
//search的参数第一个为过滤条件,第二个为是否重复执行。
feature = featureCusor.NextFeature();
if (feature != null)
{
axMapControl1.Map.SelectFeature(axMapControl1.get_Layer(0), feature);
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
空间查询实现起来比较简单,使用arcgis封装好的函数即可,主要是获取选取的geometry对象:
axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;
IGeometry geometry = null;
switch (actionFlag)
{
case flag.POINTSELECT://点选
ESRI.ArcGIS.Geometry.Point pt = new ESRI.ArcGIS.Geometry.Point();
pt.X = e.mapX;
pt.Y = e.mapY;
geometry = pt as IGeometry;
break;
case flag.CIRCLESELECT://圆选
geometry = axMapControl1.TrackCircle();
break;
case flag.RECTSELECT://长方形选取
geometry = axMapControl1.TrackRectangle();
break;
case flag.POLYGONSELECT://多边形选取
geometry = axMapControl1.TrackPolygon();
break;
}
axMapControl1.Map.SelectByShape(geometry, null, false);
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
from:http://blog.csdn.net/zzjiadw/article/details/7669382