Adding or removing a color map from a raster dataset
This topic shows how to add or remove a color map from a raster dataset. The raster dataset has to be a single-band dataset to apply a color map. Raster color maps can be removed from the raster dataset using the Remove Colormap Geoprocessing tool.
Do the following steps to programmatically add or remove color maps:
- Cast to IRasterDatasetEdit for the color map operation.
- To add a color map, get the color map from the color map raster dataset through the raster band object and use the AlterColormap method on IRasterDatasetEdit.
- To remove a color map, call the DeleteColormap method on IRasterDatasetEdit.
See the following code example:
static void AddRemoveColormap(IRasterDataset rasterDataset, IRasterDataset
colormapDataset)
{
//If the colormapDataset is null, it will remove the color map.
//If the colormapDataset is not null, it will add the color map of the colormapDataset to the input raster.
//Cast to IRasterDatasetEdit for the color map operation.
IRasterDatasetEdit rasterDatasetEdit = (IRasterDatasetEdit)rasterDataset;
//Add a color map from a given raster dataset.
if (colormapDataset != null)
{
//Get the raster color map from the given raster dataset.
IRasterBandCollection rasterBandCollection = (IRasterBandCollection)
colormapDataset;
IRasterBand rasterBand = rasterBandCollection.Item(0);
IRasterColormap rasterColormap = rasterBand.Colormap;
if (rasterColormap != null)
{
rasterDatasetEdit.AlterColormap(rasterColormap);
}
}
else
{
//Remove the raster color map.
rasterDatasetEdit.DeleteColormap();
}
}
[VB.NET]
Public Sub AddRemoveColormap(ByVal rasterDataset As IRasterDataset, ByVal colormapDataset As IRasterDataset)
'If the colormapDataset is null, it will remove the color map.
'If the colormapDataset is not null, it will add the color map of the colormapDataset to the input raster.
'Cast to IRasterDatasetEdit for the color map operation.
Dim rasterDatasetEdit As IRasterDatasetEdit = CType(rasterDataset, IRasterDatasetEdit)
'Add a color map from a given raster dataset.
If Not colormapDataset Is Nothing Then
'Get the raster color map from the given raster dataset.
Dim rasterBandCollection As IRasterBandCollection = CType(colormapDataset, IRasterBandCollection)
Dim rasterBand As IRasterBand = rasterBandCollection.Item(0)
Dim rasterColormap As IRasterColormap = rasterBand.Colormap
If Not rasterColormap Is Nothing Then
rasterDatasetEdit.AlterColormap(rasterColormap)
End If
Else
'Remove the raster color map.
rasterDatasetEdit.DeleteColormap()
End If
End Sub
See Also:
How to access a raster datasetTo 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.DataSourcesRaster ESRI.ArcGIS.Geodatabase ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |
Engine Developer Kit | Engine |