simalaya
路人甲
路人甲
  • 注册日期2003-11-19
  • 发帖数46
  • QQ
  • 铜币286枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1759回复:2

在地图上选择图元后,如何在代码里获得指定的某个图层上被选择的图元

楼主#
更多 发布于:2007-06-05 10:39
<P>才开始用engine。现在有这样的一个功能请大家帮我看看代码,如何实现。</P>
<P>我在mapcontrol上显示了一个地图,里面有10多个图层,第一个叫ycbase,...。在toolbar control组件中放了一个select feature。提供给客户选择图元用。客户用它在地图上一拉,把从第一个图层到最底下的图层中拉选范围的图元都选择出来了。我这个时候通过代码得到了这些图元。但是我只关心想得到第一个图层上(或者某个图层上)的被选择的图元,那我怎么能得到呢?我下面的代码只能实现得到全部图层被选择的图元。请大家帮我看看怎么得到某个图层上的图元。</P>
<P>  try{<BR>      <BR> com.esri.arcgis.carto.MapSelection selection = new com.esri.arcgis.carto.MapSelection(mapBean1.getActiveView().getSelection()); <BR> com.esri.arcgis.geodatabase.IEnumFeature enumFeature = (com.esri.arcgis.geodatabase.IEnumFeature)selection;<BR> com.esri.arcgis.geodatabase.IFeature feature = null;<BR>  <BR>       // Add the selected features geometry to the array<BR> enumFeature.reset();<BR> feature = enumFeature.next();<BR> while(feature != null){<BR>                System.out.println("OID:" + feature.getOID());<BR>  feature = enumFeature.next();<BR>       }<BR> }<BR>       catch(Exception e){<BR>     e.printStackTrace();<BR>         }</P><img src="images/post/smile/dvbbs/em08.gif" />
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2007-06-09 11:27
<P>下面是在各个图层中查找选择的要素,你可以只在你要的图层里找,下面是例子的代码</P>
<P>Public Sub QuerySelectedFeatures()<BR>  Dim pMxDoc As IMxDocument<BR>  Dim pEnumLayer As IEnumLayer<BR>  Dim pFeature As IFeature<BR>  Dim pFeatureCursor As IFeatureCursor<BR>  Dim pFeatureLayer As IFeatureLayer<BR>  Dim pFeatureSelection As IFeatureSelection<BR>  Dim pMap As IMap<BR>  Dim pSelectionSet As ISelectionSet<BR>  Dim pUID As IUID<BR></P><PRE>'the UID<EM> </EM>specifies the interface identifier (GUID)<BR>'that represents the type of layer you want returned.<BR>'in this case we want an EnumLayer containing all the FeatureLayer objects  
  Set pUID = New UID
  pUID = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" ' Identifies FeatureLayer objects
  Set pMxDoc = Application.Document
  Set pMap = pMxDoc.FocusMap
  
  'Loop through all feature layers in the map
  Set pEnumLayer = pMap.Layers(pUID, True)
  pEnumLayer.Reset
  Set pFeatureLayer = pEnumLayer.Next
  Do While Not pFeatureLayer Is Nothing
    'Loop through the selected features per layer
    Set pFeatureSelection = pFeatureLayer 'QI
    Set pSelectionSet = pFeatureSelection.SelectionSet
    'Can use Nothing keyword if you don't want to draw them,
    'otherwise, the spatial reference might not match the Map's
    pSelectionSet.Search Nothing, False, pFeatureCursor
    Set pFeature = pFeatureCursor.NextFeature
    Do While Not pFeature Is Nothing
      'Do something with the feature
      Debug.Print pFeature.Value(pFeature.Fields.FindField("Name"))
      Set pFeature = pFeatureCursor.NextFeature
    Loop
    Set pFeatureLayer = pEnumLayer.Next
  Loop
  
End Sub
</PRE>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
gzstyxb
路人甲
路人甲
  • 注册日期2004-09-22
  • 发帖数358
  • QQ
  • 铜币1045枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2007-06-11 09:48
其实,你不需要知道选择的IFeature属于哪个图层,也可以照样对它进行操作的嘛。如果需要绘制 新图形的话,就需要先确定在哪个图层上绘制了。
由爱故生忧, 由爱故生怖. 若离于爱者, 无忧亦无怖.
举报 回复(0) 喜欢(0)     评分
游客

返回顶部