I want to get all features in the current extent of my PageLayoutControl's ActiveView. I got it working for a MapControl as described here.

With my PageLayoutControl it seems that I don't get the correct extent. When I fill the found features it looks like this:

Here is how I get the features:

Dictionary<String, IFeatureCursor> featureCursors = new Dictionary<String, IFeatureCursor>();
IMap map = this._pageLayoutControl.ActiveView.FocusMap;

// Get ActiveView from MapFrame
IActiveView tmpActiveView = null;
IGraphicsContainer graphicsContainer = (IGraphicsContainer)_pageLayoutControl.PageLayout;
IElement element = graphicsContainer.Next();
while (element != null)
  if (element is IMapFrame)
    IMapFrame mapFrame = (IMapFrame)element;
    tmpActiveView = (IActiveView)mapFrame.Map;
  element = graphicsContainer.Next();
if (tmpActiveView == null)
  return featureCursors;

IEnvelope envelope = this._pageLayoutControl.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds; // FittedBounds;
// PageLayout has no SpatialReference. So use the View of the MapFrame 
IPoint pointMax = tmpActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint((System.Int32)envelope.XMax, (System.Int32)envelope.YMax);
IPoint pointMin = tmpActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint((System.Int32)envelope.XMin, (System.Int32)envelope.YMin);
envelope.XMax = pointMax.X;
envelope.YMax = pointMax.Y;
envelope.XMin = pointMin.X;
envelope.YMin = pointMin.Y;

// Get Features in all layers
for (int iFeatLayer = 0; iFeatLayer < _pageLayoutControl.ActiveView.FocusMap.LayerCount; iFeatLayer++)
  ILayer thisLayer = _pageLayoutControl.ActiveView.FocusMap.Layer[iFeatLayer];
  IGeoFeatureLayer featLayer = thisLayer as IGeoFeatureLayer;
  if (featLayer != null)
    IFeatureClass featureClass = featLayer.FeatureClass;
    System.String shapeFieldName = featureClass.ShapeFieldName;

    // Create a new spatial filter and use the new envelope as the geometry
    ISpatialFilter spatialFilter = new SpatialFilterClass();
    spatialFilter.Geometry = envelope;
    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
    spatialFilter.set_OutputSpatialReference(shapeFieldName, map.SpatialReference);
    spatialFilter.GeometryField = shapeFieldName;

    // Do the search
    IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
    featureCursors.Add(thisLayer.Name, featureCursor);
return featureCursors;

What did I miss? :)

1 Answer 1


Finally figured it out: The IEnvelope I got was the wrong one. The Extent of the MapFrame's ActiveView is the one I needed. So that part should look like this:

IEnvelope envelope = tmpActiveView.Extent;

The IEnvelope already has the spatial reference, so the 'translation' via ToMapPoint is no longer needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.