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

Just as the title says, I want to save the Raster to the table of contents.

I have a Raster displaying on the ArcMap IDisplay, but I can't figure out how to save it to the Table of Contents in ArcMap. The save to TOC will come after a button is pressed in ArcMap.

Looking for code here. C# of VB.NET will be fine!

Thanks all!

share|improve this question
By "save", do you mean you want to create a raster layer, point it to your data, and add this layer to the TOC? – Petr Krebs Oct 25 '10 at 15:43
yep, you got that right. – Oct 25 '10 at 16:14
up vote 3 down vote accepted

Assuming you already have a raster object available in your code:

RasterLayer rlayer = new RasterLayerClass();
rlayer.Name = "My new raster Layer";
IMxDocument doc = m_application.Document as IMxDocument;
IMap map = doc.FocusMap;

m_application is of type IApplication and is a reference to your ArcMap instance. It works quite similar for any feature class. Just create an object of the corrensping layer type, set the feature class to display and add the layer object to the map:

FeatureLayer featLayer = new FeatureLayerClass();
featLayer.FeatureClass = myFeatureClass;
featLayer.Name = "My new feature layer";
IMxDocument doc = m_application.Document as IMxDocument;
share|improve this answer
I added the code for feature layers. – AndOne Oct 28 '10 at 10:11

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.