Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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? :)

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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