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 am new to ArcGIS and want to implement the Zoom to Selected Features functionality available in Selection menu option (Selection-> Zoom to Selected Features), using C# API.

Is any API available in C# ?

share|improve this question
    
Are you using ArcObjects? –  blah238 Feb 14 '13 at 6:47
    
i am using ArcMap.Document –  DevRaj Feb 14 '13 at 10:09
2  
@DevRaj, This question/anwser is very common and can be found with a simple "arcobjects zoom to selected features c#" google search. What version of arcgis are you using? –  artwork21 Feb 14 '13 at 11:51
    
i am using arcGIS 10.1 –  DevRaj Feb 14 '13 at 12:38
    
So you are using ArcObjects. Please tag your questions appropriately in the future. I have done it for you this time. –  blah238 Feb 14 '13 at 15:31

2 Answers 2

To implement, I would suggest creating an Add-In (in C#) using ArcObjects API. Below are some helpful links to get you started:

At the minimum you will need to install Microsoft Visual Studio 2010 Express and ArcObjects .NET 10.1 SDK.

An alternative would be to develop a python Add-In. This option would entail less code, however you may be more limited on available GIS classes/objects.

As I stated in my comment, a web search should give you some source code to start off with.

share|improve this answer
    
Thnx for code sample –  DevRaj Feb 15 '13 at 6:03

Try this one:

void ZoomToSelectedFeature(IFeature feature)
{
    IGeometry geometry = feature.Shape;

    IActiveView activeView = ArcMap.Document.ActiveView;
    activeView.Extent = geometry.Envelope;
}

List<IFeature> GetSelectedFeatures(IFeatureLayer selectedFeature)
{
    IFeatureSelection featureSelection = selectedFeature as IFeatureSelection;
    ISelectionSet selectionSet = featureSelection.SelectionSet;
    ICursor cursor ;

    selectionSet.Search(null, false, out cursor);

    IFeatureCursor featureCursor = cursor as IFeatureCursor; 
    IFeature feature = featureCursor.NextFeature();
    List<IFeature> features = new List<IFeature>();
    while (feature != null)
    {
        features.Add(feature);  
        feature = featureCursor.NextFeature();
    }
    return features;
}
share|improve this answer

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.