Creating a raster unique value renderer
See the following code example:
[Java]
static IRasterRenderer uniqueValueRenderer(IRasterDataset rasterDataset)throws
Exception{
//get the raster attribute table and the size of the table
IRaster2 raster = new IRaster2Proxy(rasterDataset.createDefaultRaster());
ITable rasterTable = raster.getAttributeTable();
if (rasterTable == null){
return null;
}
int tableRows = rasterTable.rowCount(null);
//create colors for each unique value
IRandomColorRamp colorRamp = new RandomColorRamp();
colorRamp.setSize(tableRows);
colorRamp.setSeed(100);
boolean createColorRamp[] = {
false
};
colorRamp.createRamp(createColorRamp);
if (createColorRamp[0] == false){
return null;
}
//Create unique value renderer
IRasterUniqueValueRenderer uvRenderer = new RasterUniqueValueRenderer();
IRasterRenderer rasterRenderer = (IRasterRenderer)uvRenderer;
rasterRenderer.setRasterByRef(rasterDataset.createDefaultRaster());
rasterRenderer.update();
//set renderer properties
uvRenderer.setHeadingCount(1);
uvRenderer.setHeading(0, "All Data Value");
uvRenderer.setClassCount(0, tableRows);
uvRenderer.setField("Value"); //or any other field in the table
IRow row;
ISimpleFillSymbol fillSymbol;
for (int i = 0; i < tableRows; i++){
row = rasterTable.getRow(i);
uvRenderer.addValue(0, i, row.getValue(i)); // assuming the raster is 8 bit
uvRenderer.setLabel(0, i, row.getValue(0).toString());
fillSymbol = new SimpleFillSymbol();
fillSymbol.setColor(colorRamp.getColor(i));
uvRenderer.setSymbol(0, i, (ISymbol)fillSymbol);
}
return rasterRenderer;
}
See Also:
How to add a raster layer to a mapDevelopment licensing | Deployment licensing |
---|---|
ArcEditor | ArcInfo |
ArcEditor | ArcEditor |
ArcView | ArcView |
Engine Developer Kit | Engine Runtime |