Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I like to add text information to each feature in the shown map extent in my MapControl/PageLayoutControl. Adding the text is not a problem, but I couldn't find a way on how to get the features.

Is there a way to get all features in a layer that are in the current map extent?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Have you looked at:

Dim pEnv As IEnvelope
 pEnv = pAv.ScreenDisplay.DisplayTransformation.VisibleBounds

Setting the envelope = to the activeview visible bounds. You will then have to define a spatial filter, find the specific feature class, and set that to a featurecursor to grab all the features.

share|improve this answer
    
Thanks artwork21. Thats the trick. See my answer for implementation details. –  gumo Oct 20 '11 at 13:17

Thanks to artwork21 I could solve this like this:

IMap map = this._mapControl.ActiveView.FocusMap;
IEnvelope envelope = _mapControl.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds;

IGeoFeatureLayer featLayer = myLayer 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);
return featureCursor;
share|improve this answer
1  
Won't the envelope be larger than what is visible if IDisplayTransformation.Rotation is not zero? –  Kirk Kuykendall Apr 3 '13 at 14:02

Your Answer

 
discard

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.