现在的位置: 首页 > 综合 > 正文

在各个图层中查找选择的要素

2013年10月09日 ⁄ 综合 ⁄ 共 1349字 ⁄ 字号 评论关闭
面是在各个图层中查找选择的要素,你可以只在你要的图层里找,下面是例子的代码

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

 

抱歉!评论已关闭.