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.

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. –  SpoiledTechie.com Oct 25 '10 at 16:14

1 Answer 1

up vote 3 down vote accepted

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

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

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;
doc.FocusMap.AddLayer(featLayer);
share|improve this answer
    
I added the code for feature layers. –  AndOne Oct 28 '10 at 10:11

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.