This document is archived and information here might be outdated.  Recommended version.


How to create a raster layer (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with and configuring maps, layers, and graphics > Displaying raster data > How to create a raster layer (ArcObjects .NET 10.6 SDK)

How to create a raster layer


Creating a raster layer

Do the following steps to create a raster layer, set a raster renderer, and add it to a map to display:
  1. Create a raster layer from a raster dataset. You can also create a raster layer from a raster.
  2. Set the raster renderer. The default renderer is used if passing a null value.
  3. Add the layer to the map if the layer is valid.

    See the following code example:
[C#]
public static void AddRasterLayer(ESRI.ArcGIS.Carto.IActiveView activeView,
    ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset,
    ESRI.ArcGIS.Carto.IRasterRenderer rasterRenderer)
{
    //Create a raster layer from a raster dataset. You can also create a raster layer from a raster.
    ESRI.ArcGIS.Carto.IRasterLayer rasterLayer=new RasterLayerClass();
    rasterLayer.CreateFromDataset(rasterDataset);
    //Set the raster renderer. The default renderer will be used if passing a null value.
    if (rasterRenderer != null)
    {
        rasterLayer.Renderer=rasterRenderer;
    }
    //Add it to a map if the layer is valid.
    if (rasterLayer != null)
    {
        ESRI.ArcGIS.Carto.IMap map=activeView.FocusMap;
        map.AddLayer((ILayer)rasterLayer);
    }
}
[VB.NET]
Public Shared Sub AddRasterLayer(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal rasterDataset As ESRI.ArcGIS.GeodataMyBase.IRasterDataset, ByVal rasterRenderer As ESRI.ArcGIS.Carto.IRasterRenderer)
'Create a raster layer from a raster dataset. You can also create a raster layer from a raster.
Dim rasterLayer As ESRI.ArcGIS.Carto.IRasterLayer=New RasterLayerClass()
rasterLayer.CreateFromDataset(rasterDataset)

'Set the raster renderer. The default renderer will be used if passing a null value.
If Not rasterRenderer Is Nothing Then
    rasterLayer.Renderer=rasterRenderer
End If
'Add it to a map if the layer is valid.
If Not rasterLayer Is Nothing Then
    Dim map As ESRI.ArcGIS.Carto.IMap=activeView.FocusMap
    map.AddLayer(CType(rasterLayer, ILayer))
End If
End Sub


See Also:

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




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Basic ArcGIS Desktop Basic
Engine Developer Kit Engine