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'm writing a program using ArcGIS Engine, and need to zoom & pan into the map to show the selected content.

Loading and displaying the map does work using something like this:

AxMapControl _mapControl;

// in constructor:
_mapControl = new AxMapControl();

// in loading

Afterwards I select some objects and want to zoom into them, but I can't find a way to get the selected extent - any pointers to achieve this?

share|improve this question
up vote 4 down vote accepted

suppose you have just one Layer, with the selected features & you want to zoom to the extent of all the selected features, here is how I would do it:

IMapControl2 MapControl= (ImapControl2)_mapControl;
IfeatureLayer FeatureLayer=MapControl.Layer[0];

IFeatureSelection FeatureSelection= (IFeatureSelection)FeatureLayer;

ISelectionSet SelectionSet=FeatureSelection.selectionSet;

ICursor cursor;
SelectionSet.Search(Null, true, out cursor);

IFeatureCursor featureCursor = (IFeatureCursor)cursor; 

IFeature feature;
IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();

while ((feature = featureCursor.NextFeature()) != null)
        IGeometry geometry = feature.Shape;
        IEnvelope featureExtent = geometry.Envelope;

share|improve this answer
Yes, great, this is the GetGeometries-part I was missing in fencliffs example! Thanks!! – Sam Feb 28 '11 at 15:04

You could try this:

List<IGeometry> geometries = GetGeometries() // However you retrieve your geometries
double margin = 1.2; 
IEnvelope envelope = null;
foreach (IGeometry g in geometries)
    if (envelope == null)
        envelope = g.Envelope;
envelope.Expand(margin , margin , true);
_mapControl.ActiveView.Extent = envelope;

You can retrieve the geometry of a feature from IFeature.Shape.

share|improve this answer
I'm not yet sure how to get from AxMapControl to GetGeometries (which usually is my main problem with ArcGis: not knowing how to get from where to there). – Sam Feb 28 '11 at 14:38
But at least your example looks like my old avenue code - except for the black magic part, where in avenue I used GetThemes > GetFTab > GetSelection to get the selected items. – Sam Feb 28 '11 at 14:42
@Sam GetGeometries() is just an placeholder for place your retrieval code here, not from my codebase :) I'll try to get back to you later when I have time, unless someone else has answered by then. – fencliff Feb 28 '11 at 14:49
Aah, ok, so I need to get my selected features into a list of IGeometries - I'll try my very best, thanks for your pointers!! – Sam Feb 28 '11 at 14:52

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.