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:
- Create a raster layer from a raster dataset. You can also create a raster layer from a raster.
- Set the raster renderer. The default renderer is used if passing a null value.
- Add the layer to the map if the layer is valid.
See the following code example:
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 rendererHow 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):
ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)ESRI.ArcGIS.Display ESRI.ArcGIS.Geometry ESRI.ArcGIS.DataSourcesGDB ESRI.ArcGIS.Geodatabase ESRI.ArcGIS.DataSourcesRaster ESRI.ArcGIS.Carto
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
Engine Developer Kit | Engine |