Zoom to layer defined by CreateSelectionLayer

245
3
Jump to solution
05-08-2013 01:58 PM
Highlighted
New Contributor
Greetings,

I have several layers that have been created from a non-displayed "master layer" using IFeatureLayerDefinition2.CreateSelectionLayer to cut down on the number of feature classes stored in a file GeoDatabase (gdb).

This has worked fine adding the layers to the table of contents and only displaying the desired features.  However, when using the sample code to Zoom to a Layer (Displaying a TOCControl Context Menu sample), the extent sent via "ref layer" is the full extent of all features that were in the feature class up to that point.  For example Layer1 of Rectangle 1 zooms to just Rectangle 1.  Layer 3 created by querying for Rectangle 3 zooms to rectangles 1, 2 and 3.

How do I zoom only into the feature(s) that were part of the original query in the CreateSelectionLayer?

Thanks!

     -- Glenn
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor
I think you'll have to create your own extent. Call IGeoFeatureLayer::SearchDisplayFeatures on the layer, which will restrict the results to just those in the selection layer. Get the extent of each feature returned and union it with a "master" envelope. You'll have to build a SpatialFilter to pass to this function; you should only need the SHAPE field for this. You'll need to be comfortable working with geodatabase cursors.

View solution in original post

Reply
0 Kudos
3 Replies
Highlighted
Occasional Contributor
I think you'll have to create your own extent. Call IGeoFeatureLayer::SearchDisplayFeatures on the layer, which will restrict the results to just those in the selection layer. Get the extent of each feature returned and union it with a "master" envelope. You'll have to build a SpatialFilter to pass to this function; you should only need the SHAPE field for this. You'll need to be comfortable working with geodatabase cursors.

View solution in original post

Reply
0 Kudos
Highlighted
New Contributor
Pete,

Thanks for the quick reply!  I'll give it a try and let you know the results.

-- Glenn
Reply
0 Kudos
Highlighted
New Contributor
Pete,

There was no difference in my case between IGeoFeatureLayer.FeatureClass and DisplayFeatureClass properties-- both returned the correct feature count that I was expecting.

I did have to create a feature cursor and loop through the features and union the envelopes as you indicated, so that was the solution.  I just now need to go back and work in the case when a group layer is selected and have to drill down to each of the feature layers.

Thanks again for the quick response!

-- Glenn
Reply
0 Kudos