【029】获取选择要素的属性

本文介绍了使用ArcGIS Engine进行地图要素操作的方法,包括获取选择要素的属性值、闪烁显示选择要素及取消选择要素等实用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

---------------------------------------------------------------------------------------------------------

●·● 目录:

第一部分:获取选择要素的属性值:

第二部分:闪烁显示选择要素:

第三部分:取消选择的要素:

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣    第A1个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

第一部分:获取选择要素的属性值:

通过 IEnumFeature 即可存储 pMap.FeatureSelection,但这个时候只能获取属性的字段的前两列,也是最没用的两列,要想获取其他的字段属性,则要引入 IEnumFeatureSetup,将属性 AllFields 设置为 true 才可!

IMap pMap = axMapControl1.Map;
ISelection pSelection = pMap.FeatureSelection; //获取选择集
IEnumFeatureSetup pEnumFeatureSetup = pSelection as IEnumFeatureSetup; //将其转为setup
pEnumFeatureSetup.AllFields = true; //设置所有字段显示
IEnumFeature pEnumFeature = pEnumFeatureSetup as IEnumFeature; //将其转为 pEnumFeature
pEnumFeature.Reset(); //从头开始,不是必要的!
IFeature pFeature = pEnumFeature.Next(); //下一个要素
string str = "";
while (pFeature != null)
{
str += pFeature.get_Value(pFeature.Fields.FindField("Name")).ToString() + "\n";
pFeature = pEnumFeature.Next();
}
MessageBox.Show(str);

参考:http://huangdingjun.blog.163.com/blog/static/3110639201108112823953/

---------------------------------------------------------------------------------------------------------

●·● Geodatabase 命名空间

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣    第G1个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

●·● IEnumFeatureSetup 接口

Provides access to members that define behavior of IEnumFeature.

Product Availability
Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.
Members
   Description
Read/write propertyAllFieldsIndicates if returned features will contain all fields.
Read/write propertyRecyclingIndicates if returned features recycle.

CoClasses that implement IEnumFeatureSetup
CoClasses and Classes Description
MapSelection (esriCarto)Maintains the map's feature selection.

 

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣    第G2个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

●·● IEnumFeature 接口

Provides access to members that hand out enumerated features and reset the enumeration.

Product Availability
Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.
Members
   Description
MethodNextRetrieves the next Feature in the enumeration sequence.
MethodResetResets the enumeration sequence to the beginning.

CoClasses that implement IEnumFeature
CoClasses and Classes Description
EditSelection (esriEditor)Enumerates the editable selected features.
MapSelection (esriCarto)Maintains the map's feature selection.

 

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣    第A2个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

第二部分:闪烁显示选择要素:

第一步是建立筛选条件,这个时候要用到 IQueryFilter 接口,通过其 WhereClause 属性可以建立 SQL 语句进行筛选,然后循环!

第二步是建立闪烁,建立闪烁通过 axMapControl 的 FlashShape 方法即可实现,如下所示:

IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = "Area > 20";
IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pQueryFilter, false); //建立查询
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null) //循环查询要素
{
ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol(); //建立闪烁样式
IRgbColor pColor = new RgbColor();
pColor.Red = 255;
pSimpleFillSymbol.Color = pColor;

IPolygon pPolygon = pFeature.Shape as IPolygon; //闪烁几何体
axMapControl1.FlashShape(pPolygon, 3, 20, pSimpleFillSymbol); //闪烁几何体
object symbol = pSimpleFillSymbol as object; //后面要用到ref,这里要转为 object 类型!
axMapControl1.DrawShape(pPolygon, ref symbol); //在绘制此要素几何!
pFeature = pFeatureCursor.NextFeature(); //循环下一个要素
}

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣    第A3个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

第三部分:取消选择的要素:

此方法在 IMap 接口中实现的,即 ClearSelection 方法!

IMap pMap = axMapControl1.Map;
pMap.ClearSelection();
axMapControl1.ActiveView.Refresh();



 

 



转载于:https://www.cnblogs.com/alex-bn-lee/archive/2012/04/07/2436484.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值