在各個圖層中查找選擇的要素


面是在各個圖層中查找選擇的要素,你可以只在你要的圖層里找,下面是例子的代碼

Public Sub QuerySelectedFeatures()
  Dim pMxDoc As IMxDocument
  Dim pEnumLayer As IEnumLayer
  Dim pFeature As IFeature
  Dim pFeatureCursor As IFeatureCursor
  Dim pFeatureLayer As IFeatureLayer
  Dim pFeatureSelection As IFeatureSelection
  Dim pMap As IMap
  Dim pSelectionSet As ISelectionSet
  Dim pUID As IUID

'the UID specifies the interface identifier (GUID)
'that represents the type of layer you want returned.
'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
 

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com