• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
bobird的学习笔记
博客园    首页    新随笔    联系   管理    订阅  订阅
如何判断MapControl中某一图层的一个Feature是否被选中

如题,在MapControl中有一系列的Feature被选中并高亮显示 然后,我想实现点选MapControl获得点选到的Feature,如果之前Feature已经被选中则修改它,设置它为不选择状态;如果Feature没被选中则设置它被选中状态
问题就是:我现在怎么判断一个Feature在MapControl或者是FeatureLayers中是否被选择上???

anthony_f005 发表于 2008-11-4 16:33

自己先顶一个,高手指点啊

OASIS 发表于 2008-11-4 17:24

IFeatureSelection pFeaSel = mFeatLyr as IFeatureSelection;
if (pFeaSel.SelectionSet.Count == 0) { MessageBox.Show("没有选中任何要素!"); return; } IEnumIDs ln_SelOids = lip_FeaSel.SelectionSet.IDs; int id = ln_SelOids.Next();//记录选中要素的Oid号
ArrayList lc_Array = new ArrayList();//记录选中要素的Oid号 while (id != -1) { lc_Array.Add(id); id = ln_SelOids.Next(); }
for (int Index = 0; Index < lc_Array.Count; Index++) {
IFeature lip_Feature = mFeatLyr.FeatureClass.GetFeature((int)lc_Array[Index]); } ......

anthony_f005 发表于 2008-11-4 18:14

通过循环SelectionSet.IDs我也想过 不过我担心如果IFeatureSelection.Count 过大 会不会影响运行的效率
不知道有没有直接的方法或接口能判断Feature被选中
我之前想的 private bool isSelect(IFeatureLayer mFeatLyr ,IFeature p) { bool result = false; int IDS = p.IDS; IFeatureSelection pFeaSel = mFeatLyr as IFeatureSelection; IEnumIDs ln_SelOids = lip_FeaSel.SelectionSet.IDs; int id = ln_SelOids.Next(); while (id != -1) { if (IDS == id) { result = true; return result; } id = ln_SelOids.Next(); } return result; }

OASIS 发表于 2008-11-4 19:01

是的,循环会影响效率。不知道有没有直接判断要素是否被选择的属性,你再找找看吧

blade.xu 发表于 2008-11-4 19:05

用哈希表可以提高速度: private bool isSelect(IFeatureLayer mFeatLyr ,IFeature p) { bool result = false; int IDS = p.IDS; IFeatureSelection pFeaSel = mFeatLyr as IFeatureSelection; IEnumIDs ln_SelOids = lip_FeaSel.SelectionSet.IDs; HashTable table=new HashTable; int id = ln_SelOids.Next(); while (id != -1) { table.Add(id,id); id = ln_SelOids.Next(); } result =table.ContainsKey(IDS ); return result; }

posted on 2013-06-27 10:17  bobird  阅读(362)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3