arcgis engine 按照属性选择要素

arcgis engine 按照属性选择要素

前言
条件过滤主要用到IQueryFilter接口,其SubFields属性用于过滤指定的字段;WhereClause用于过滤指定的sql语句;
一、按照属性选择要素主要步骤:
1、由ILayer获取图层名;
2、由指定的图层名,获取图层要素IFeatureLayer
3、由指定的字段名设置IQueryFilter
4、由IFeatureLayer获取IFeatureClass,进而获得该图层属性表中的所有字段IFields以及IFeatureCursor
5、由字段名获取属性表中一个字段IField
6、由IFeatureCursor获得IDataStatistics
7、由IDataStatistics的UniqueValues属性得到IEnumerator
8、由IEnumerator得到字段的所有值
9、根据以上步骤获得属性过滤条件,字段=字段值
10、根据属性过滤条件设置IQueryFilter
11、根据IFeatureSelection选择指定属性过滤条件的要素。

二、下面代码是根据过滤条件,选择要素的方法:

 private void SelectFeatureByFilter()
        {
            IFeatureSelection pFeatureSelection = currentFeatureLayer as IFeatureSelection;
            IQueryFilter pQueryFilter = new QueryFilterClass();
            pQueryFilter.WhereClause = txtSelectResult.Text;//过滤条件,查询表达式
            IActiveView pActiveView = currentMap as IActiveView;
            switch (comBoxSelectMethod.SelectedIndex)
            {
                case 0:
                    currentMap.ClearSelection();
                    pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew,false);
                    break;
                case 1:
                     currentMap.ClearSelection();
                    pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd,false);
                    break;
                case 2:
                     currentMap.ClearSelection();
                    pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultSubtract,false);
                    break;
                case 3:
                    currentMap.ClearSelection();
                    pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAnd,false);
                    break;
                default:
                     currentMap.ClearSelection();
                    pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew,false);
                    break;

            }
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);
        }

三、运行界面及结果
arcgis engine 按照属性选择要素_第1张图片
参考:
http://blog.sciencenet.cn/blog-3373120-1110830.html
Arcgis官方构建查询表达式方法:
https://resources.arcgis.com/zh-cn/help/main/10.2/index.html#/na/00s50000002t000000/

你可能感兴趣的:(Arcgis,engine)