Select to view content in your preferred language

Problem using OpenFeatureQuery

2379
7
04-07-2010 12:19 PM
GéomatiqueSopfeu
Emerging Contributor
Hi !

When I do an OpenFeatureQuery to seach by attribute in a lake dataset it result a featurelayer where the extend is the same as Lake. I mean that if I only have 1 lake resulting from my query def, zoom to layer won't bring me to that lake it zoom out to the dataset extend. My code works fine and the result looks great too but I'd like to set the extend of the resulting feature layer to an envelope that would fit the selection.

Any help would be appreciated. Thanks !

AcrGIS Engine 9.3.1; vb.net 2008; SDE 9.3.1 (arcGIS Server basic).
0 Kudos
7 Replies
KirkKuykendall
Deactivated User
Not sure how to change the extent of this layer.  You might consider using IFeatureLayerDefinition.CreateSelectionLayer instead - the resulting layer has an extent based on features that it contains.

Option Explicit
Sub Test()
    Dim pWSF As IWorkspaceFactory
    Set pWSF = New FileGDBWorkspaceFactory
    
    Dim pFWS As IFeatureWorkspace
    Set pFWS = pWSF.OpenFromFile("D:\Projects\SAWS\data\EncinoPark.gdb", 0)
    
    Dim pFLayer As IFeatureLayer
    Set pFLayer = New FeatureLayer
    Set pFLayer.FeatureClass = pFWS.OpenFeatureClass("EARZ_ZONES2")
    pFLayer.Name = "mylayer"
    
    Dim pQF As IQueryFilter
    Set pQF = New QueryFilter
    pQF.WhereClause = """EARZ_ZONE"" = 'AREA 5'"
    
    Dim pFSel As IFeatureSelection
    Set pFSel = pFLayer
    pFSel.SelectFeatures pQF, esriSelectionResultNew, False
    
    Dim pFLD As IFeatureLayerDefinition
    Set pFLD = pFSel
    
    Dim pLayer As ILayer
    Set pLayer = pFLD.CreateSelectionLayer("mylayer", True, "", "")
    
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    pMxDoc.FocusMap.AddLayer pLayer
    
       
End Sub
0 Kudos
GéomatiqueSopfeu
Emerging Contributor
Thanks Kirk... I really tried your code but some problems : 1) if I open then attribute table, it will contains the 73000 records even if only 66 records were selected (and 66 are displayed) and 2) Unfortunatly, the zoom to extend doesn't work either. I tried to play around with the code without any success. What am I doing wrong ???
0 Kudos
KirkKuykendall
Deactivated User
When I run the code above with a path to the data in the attached file gdb, and open the attribute window, I only see one row.

Right clicking on the layer and choosing zoom to extent will zoom to whatever features are present in the layer (created using code posted previously).

However, I see that IGeoDataset.Extent for the layer is still the full extent of the layer, so  I guess zoom to layer uses some other method.  I wouldn't think it would loop through each feature to build an envelope, but I don't see what else it would use.  Setting ILayer2.AreaOfInterest doesn't change the behavior of zoom to extent.

9.3.1 sp 1 Vista64
0 Kudos
GéomatiqueSopfeu
Emerging Contributor
Finally, funny facts !

I tried with a filegeo in Engine : it did'nt work better. Cannot zoom to extend and all features are in the attribute table.

BUT, I tried in arcMap VBA : Tada ! Everyting works fine !!! I can zoom to layer and only the selected features are in the attribute table.

So I guess it is a problem with arcEngine OR the way to proceed is a bit different (but undocumented, of course).
0 Kudos
KirkKuykendall
Deactivated User
How are you populating your attribute window?

You should cast the featurelayer to an IDisplayTable, then load rows into your datagrid (or whatever) by looping through rows returned by the ICursor returned from IDisplayTable.SearchDisplayTable.
0 Kudos
GéomatiqueSopfeu
Emerging Contributor
It is true that using OpenFeatureClass, I would have to specify my query to correctly set my iDisplayTable; but as OpenFetaureQuery works fine with it, I'd like to keep my open attribute table function as general as I can. Otherwise, I would have know, for each featureLayer in my table of content if there's a query to apply or not and so on...

So I now hope that ESRI can figure it out. Thank you for your precious help.
0 Kudos
KirkKuykendall
Deactivated User
Using IDisplayTable for any featurelayer (regardless of whether it was created as a selection layer) should return the rows that you see when you display the layer attribute window in arcmap.
0 Kudos