How to add a raster layer to a map


Summary The code example in this article shows the basic steps to create a raster layer, set a raster renderer, and add it to a map to display.

Adding a raster layer to a map

Use the following code example in your application:
[Java]
static void addRasterLayer(IActiveView activeView, IRasterDataset rasterDataset,
    IRasterRenderer rasterRenderer)throws Exception{
    //Create a raster layer from a raster dataset. You can also create a RasterLayer from a raster.
    IRasterLayer rasterLayer = new RasterLayer();
    rasterLayer.createFromDataset(rasterDataset);
    //Set the raster renderer. The default renderer will be used if passing a null value.
    if (rasterRenderer != null){
        rasterLayer.setRendererByRef(rasterRenderer);
    }
    //Add it to a map if the layer is valid.
    if (rasterLayer != null){
        IMap map = activeView.getFocusMap();
        map.addLayer((ILayer)rasterLayer);
    }
}


See Also:

How to create a raster classify renderer
How to create a raster stretch renderer
How to create a raster unique value renderer




Development licensing Deployment licensing
ArcInfo ArcInfo
ArcEditor ArcEditor
ArcView ArcView
Engine Developer Kit Engine Runtime