desertoasis
路人甲
路人甲
  • 注册日期2005-07-17
  • 发帖数15
  • QQ
  • 铜币190枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1550回复:4

SelectionSet.RemoveList()方法 求助

楼主#
更多 发布于:2006-08-18 11:51
<P>各位大虾,偶遇到一个问题,请大伙帮我出出主意:现在要把符合条件的要素从选择集里剔除,为什么执行到这一句时就跳出程序了?谢谢!</P>
<P>            int    ln_SelCount =0 ,ln_UnSelCount =0;</P>
<P>            IQueryFilter lip_QuFilter = new QueryFilterClass();<BR>            lip_QuFilter.WhereClause = "SubStr("+ls_FieldUnit + ",1,"+ls_Dwbm.Length+") <> '"+ls_Dwbm+"'";           </P>
<P>            ICursor lip_Cur = null;</P>
<P>  for (int Index = 0; Index < m_ipMapControl3.LayerCount; Index++)<BR>            {<BR>                ILayer lip_Lay = m_ipMapControl3.get_Layer(Index);<BR>                IFeatureSelection lip_FeaSel = lip_Lay as IFeatureSelection;<BR>                if (lip_FeaSel == null)<BR>                    continue;</P>
<P>                ln_SelCount += lip_FeaSel.SelectionSet.Count; //累加被选择的元素数目</P>
<P>                IFeatureLayer lip_FeaLay = lip_Lay as IFeatureLayer;<BR>                lip_Cur = null;<BR>                lip_FeaSel.SelectionSet.Search(lip_QuFilter, false, out lip_Cur); //选择符合条件的记录</P>
<P>                IFeatureCursor lip_FeaCur = (IFeatureCursor)lip_Cur;<BR>                IFeature lip_Feature = lip_FeaCur.NextFeature();<BR>                while( lip_Feature != null)<BR>                {<BR>                    int ln_OID = lip_Feature.OID;<BR>                    <FONT color=#ff0000>lip_FeaSel.SelectionSet.RemoveList(1, ref ln_OID); //从选择中剔出  (执行到此处自动跳出?????)</FONT>                 <BR>                    ln_UnSelCount++;</P>
<P>                    lip_Feature = lip_FeaCur.NextFeature();<BR>                }<BR>               <BR>                lip_FeaCur = null; //关闭游标(但SDE9有Bug,不能关闭)<BR>            }<BR></P>
喜欢0 评分0
hsghxm
路人甲
路人甲
  • 注册日期2004-10-27
  • 发帖数517
  • QQ4604052
  • 铜币1枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-08-18 12:01
<FONT color=#ff0000>ln_OID 的类型错误,须为一个整型<FONT color=#74bb44>数组</FONT> !</FONT><img src="images/post/smile/dvbbs/em02.gif" />
MSN:hsghxm@163.com QQ:4604052 (很少用,最好别加) Email:hsghxm@163.com 我的BOLG:http://www.gisempire.com/blog/user1/864/index.htm
举报 回复(0) 喜欢(0)     评分
desertoasis
路人甲
路人甲
  • 注册日期2005-07-17
  • 发帖数15
  • QQ
  • 铜币190枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2006-08-18 12:10
<P>哦,非常感谢!一会试试</P><img src="images/post/smile/dvbbs/em12.gif" /><img src="images/post/smile/dvbbs/em03.gif" />
举报 回复(0) 喜欢(0)     评分
desertoasis
路人甲
路人甲
  • 注册日期2005-07-17
  • 发帖数15
  • QQ
  • 铜币190枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-08-19 16:41
<P>感谢 <FONT size=4>hsghxm<STRONG>,</STRONG></FONT><FONT size=3>我把程序改成了这样:</FONT></P>
<P> while( lip_Feature != null)<BR> {<BR>  int ln_OID = lip_Feature.OID;               <BR>  int[] ln_OidList = new int[1];<BR>  ln_OidList[0] = ln_OID;<BR>  lip_FeaSel.SelectionSet.RemoveList(1, ref ln_OidList[0]); //将其他单位的要素,从选择中剔出                  </P>
<P>   ln_UnSelCount++;</P>
<P>  lip_Feature = lip_FeaCur.NextFeature();<BR>  }</P>
<P><FONT size=3>跟踪程序发现还是不执行这句,跳出了程序,没有报任何异常。不知道是什么原因,难道是ESRI 的Bug。</FONT></P>
举报 回复(0) 喜欢(0)     评分
desertoasis
路人甲
路人甲
  • 注册日期2005-07-17
  • 发帖数15
  • QQ
  • 铜币190枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2006-08-23 18:16
问题解决了。
<P>终于找到了原因:从选择集里Remove掉要素,用上面的代码是没有问题的。但是如果是SDE图层,就会抱错:Error whlie reading or writing logfile,这是因为SDE不允许更新SelectionSet,所以必须创建一个SelectionSet:</P>
<P> IWorkspace lip_Wks = lip_FeaLay.FeatureClass.FeatureDataset.Workspace;//工作空间,selectionset容器</P>
<P>  ISelectionSet lp_SelSet = lip_FeaSel.SelectionSet.Select(lip_QuFilter, esriSelectionType.esriSelectionTypeSnapshot,<BR>                    esriSelectionOption.esriSelectionOptionNormal, lip_Wks);</P>
<P> lp_SelSet.Search(lip_QuFilter, false, out lip_Cur); //选择符合条件的记录</P>
<P>然后就可以 lip_FeaSel.SelectionSet.RemoveList(1, ref ln_OID); </P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部