alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

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

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

●·● 目录:

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

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

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

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

            ╔════════╗
╠════╣    第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 property AllFields Indicates if returned features will contain all fields.
Read/write property Recycling Indicates 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
Method Next Retrieves the next Feature in the enumeration sequence.
Method Reset Resets 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();



 

 



posted on   McDelfino  阅读(1415)  评论(1编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示