Select to view content in your preferred language

Zoom to selected features

2038
10
06-01-2010 12:26 AM
NehayaArabeiat
Emerging Contributor
Hi Everybody,

I build an ArcGIS Engine Application in vb.net language, I want to select a field in a feature layer and zoom to it, I try the following code but when I click the button it zooms to nothing and the map disappear, any help please??

Shared Sub SelectLayersFeatures(ByVal pFeatureLayer As IFeatureLayer, ByVal WhereClause As String, ByVal pActiveview As IActiveView, ByVal blockclass As IFeatureClass)
        Dim pFeatureSelection As IFeatureSelection = pFeatureLayer
        Dim pfeaturezoomlayer As IFeatureLayer

        If Not pFeatureSelection Is Nothing Then
            Dim pQueryFilter As IQueryFilter = New QueryFilterClass()
            pQueryFilter.WhereClause = WhereClause
            pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)

            pActiveview.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

            pfeaturezoomlayer = pFeatureSelection

            pfeaturezoomlayer.FeatureClass = BlockClass

            Dim pFSel As IFeatureSelection

            pFSel = pFeatureLayer

            Dim pSelSet As ISelectionSet
            pSelSet = pFSel.SelectionSet

            Dim pEnumGeom As IEnumGeometry
            Dim pEnumGeomBind As IEnumGeometryBind

            pEnumGeom = New EnumFeatureGeometry
            pEnumGeomBind = pEnumGeom
            pEnumGeomBind.BindGeometrySource(Nothing, pSelSet)

            Dim pGeomFactory As IGeometryFactory
            pGeomFactory = New GeometryEnvironment

            Dim pGeom As IGeometry
            pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom)

            pActiveview.Extent = pGeom.Envelope

          


        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim where As String
        where = "GeoCode2 = '" & Blocks_List.SelectedItem & "'"
        Dim pfeaturelayer As IFeatureLayer
        pfeaturelayer = New FeatureLayer
        pfeaturelayer.FeatureClass = BlockClass
        ' Dim blockclass2 As IFeatureClass
        Dim pActiveview As IActiveView = AxPageLayoutControl1.ActiveView

        'blockclass2 = pFeatureworkspace.OpenFeatureClass("Jerash_Blocks")
        'pfeaturelayer.FeatureClass = blockclass2

        SelectLayersFeatures(pfeaturelayer, where, pActiveview, BlockClass)

        '  AxMapControl1.ActiveView.Extent = pGeom.Envelope

        AxPageLayoutControl1.Refresh()
        AxMapControl1.Refresh()


    End Sub
0 Kudos
10 Replies
sapnas
by
Frequent Contributor
Can you try passing AxMapControl1.ActiveView as an input to "pActiveview" parameter?
0 Kudos