Zooming to layer with definition query in a nested group

532
2
03-31-2011 06:03 PM
AdrianFitzgerald
New Contributor
I am trying to create a button on a toolbar that will add a layer files that contain layers that have definition queries and are in a nested group. Using some code snippets I found I was able to find my layer in the nested group and then have it zoom to the layer's extent with the definition query.

I am very new to programming and arcobjects so I don't think I am referencing the layer correctly in  the code snippet that zooms to the layer's extent with the definition query.

below is the code i have so far. The following is a link where I got the function to get the layer in the nested group:

http://forums.esri.com/Thread.asp?c=93&f=992&t=99138

When I execute the code it still zooms to the full extent of the layer and not the extent based on the definition query.

Does anyone know what I am doing wrong?


    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap
    Dim LayerName As String
    LayerName = "Rooms"
    Dim pLayer As ILayer

'this is the function I am using to get the layer i want in the nested group
    Set pLayer = GetLayerByName(pMap, LayerName, True)
   
'I think there is where I am referencing the layer incorrectly
    Dim featureLayer As IFeatureLayer
    Set featureLayer = pLayer
   

    Dim geoDataset As IGeoDataset
    Set geoDataset = featureLayer
    Dim activeView As IActiveView
    Set activeView = pMxDoc.FocusMap
    Dim geoFeatureLayer As IGeoFeatureLayer
    Set geoFeatureLayer = featureLayer
    Dim enumGeometryBind As IEnumGeometryBind
    Set enumGeometryBind = New EnumFeatureGeometry
    enumGeometryBind.BindGeometrySource Nothing, geoFeatureLayer.DisplayFeatureClass
    Dim geoFactory As IGeometryFactory
    Set geoFactory = New GeometryEnvironment
    Dim geometry As IGeometry
    Set geometry = geoFactory.CreateGeometryFromEnumerator(enumGeometryBind)
    activeView.Extent = geometry.Envelope
    activeView.Refresh
0 Kudos
2 Replies
JeffMatson
Occasional Contributor III
You could create a selection from the GeoFeatureLayer:

 
Dim geoFeatureLayer As IGeoFeatureLayer
    Set geoFeatureLayer = featureLayer
    
    Dim featCur As IFeatureCursor
    Set featCur = geoFeatureLayer.Search(Nothing, True)
    Dim feat As IFeature
    Set feat = featCur.NextFeature
    
    Dim featSel As IFeatureSelection
    Set featSel = featureLayer
    If featSel.SelectionSet.Count > 0 Then
        featSel.Clear
    End If
    
    Do Until feat Is Nothing
        featSel.Add feat
        Set feat = featCur.NextFeature
    Loop
    
    Dim ss As ISelectionSet
    Set ss = featSel.SelectionSet
    
    Dim pEnumGeom As IEnumGeometry
    Dim pEnumGeomBind As IEnumGeometryBind
    Set pEnumGeom = New EnumFeatureGeometry
    Set pEnumGeomBind = pEnumGeom
    ''pEnumGeomBind.BindGeometrySource Nothing, featCur
    pEnumGeomBind.BindGeometrySource Nothing, ss
    
    Dim pGeomFactory As IGeometryFactory
    Set pGeomFactory = New GeometryEnvironment
    
    Dim pGeom As IGeometry
    Set pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom)
    
    activeView.Extent = pGeom.Envelope
    activeView.Refresh
0 Kudos
AdrianFitzgerald
New Contributor
That work great. Thanks for your help.

-Adrian
0 Kudos