比较有用,我要用唯一值的渲染,已经实现,用的是C#的代码,一会分享。
不同方式渲染rasterlayer,包括唯一值、分级、rgb、Stretch等
''' <summary>
''' Stretch渲染raster
''' </summary>
''' <param name="pRLayer">raster图层</param>
''' <remarks></remarks>
Sub UsingRasterStretchColorRampRender(ByVal pRLayer As IRasterLayer)
' Get Map
Dim pRaster As IRaster
pRaster = pRLayer.Raster
' Create renderer and QI RasterRenderer
Dim pStretchRen As IRasterStretchColorRampRenderer
pStretchRen = New RasterStretchColorRampRenderer
Dim pRasRen As IRasterRenderer
pRasRen = pStretchRen
' Set raster for the renderer and update
pRasRen.Raster = pRaster
pRasRen.Update()
' Define two colors
Dim pFromColor As IColor
Dim pToColor As IColor
pFromColor = New RgbColor
pFromColor.RGB = RGB(255, 0, 0)
pToColor = New RgbColor
pToColor.RGB = RGB(0, 255, 0)
' Create color ramp
Dim pRamp As IAlgorithmicColorRamp
pRamp = New AlgorithmicColorRamp
pRamp.Size = 255
pRamp.FromColor = pFromColor
pRamp.ToColor = pToColor
pRamp.CreateRamp(True)
' Plug this colorramp into renderer and select a band
pStretchRen.BandIndex = 0
pStretchRen.ColorRamp = pRamp
' Update the renderer with new settings and plug into layer
pRasRen.Update()
pRLayer.Renderer = pStretchRen
'Release memeory
pRLayer = Nothing
pRaster = Nothing
pStretchRen = Nothing
pRasRen = Nothing
pRamp = Nothing
pToColor = Nothing
pFromColor = Nothing
End Sub
''' <summary>
''' RGB渲染raster
''' </summary>
''' <param name="pRLayer">raster图层</param>
''' <remarks></remarks>
Sub ChangeRGBRenderer(ByVal pRLayer As IRasterLayer)
Dim pRaster As IRaster
pRaster = pRLayer.Raster
Dim pBandCol As IRasterBandCollection
pBandCol = pRaster
If pBandCol.Count < 3 Then Exit Sub
' Create UniqueValue renderer and QI RasterRenderer
Dim pRGBRen As IRasterRGBRenderer
pRGBRen = New RasterRGBRenderer
Dim pRasRen As IRasterRenderer
pRasRen = pRGBRen
' Connect the renderer and the raster
pRasRen.Raster = pRaster
pRasRen.Update()
pRGBRen.RedBandIndex = 2
pRGBRen.GreenBandIndex = 1
pRGBRen.BlueBandIndex = 0
'Update render and refresh layer
pRasRen.Update()
pRLayer.Renderer = pRGBRen
End Sub
''' <summary>
''' 分级渲染raster
''' </summary>
''' <param name="NumOfClass">级别数</param>
''' <param name="pLayer">raster图层</param>
''' <param name="pA">当前view</param>
''' <remarks></remarks>
Sub UsingRasterClassifyRendered(ByVal NumOfClass As Integer, ByVal pLayer As IRasterLayer, ByVal pA As IActiveView)
Dim pRaster As IRaster
pRaster = pLayer.Raster
' Create classfy renderer and QI RasterRenderer interface
Dim pClassRen As IRasterClassifyColorRampRenderer
pClassRen = New RasterClassifyColorRampRenderer
Dim pRasRen As IRasterRenderer
pRasRen = pClassRen
' Set raster for the render and update
pRasRen.Raster = pRaster
pClassRen.ClassCount = NumOfClass
pRasRen.Update()
' Create a color ramp to use
Dim pRamp As IAlgorithmicColorRamp
pRamp = New AlgorithmicColorRamp
pRamp.Size = NumOfClass
pRamp.CreateRamp(True)
' Create symbol for the classes
Dim pFSymbol As IFillSymbol
pFSymbol = New SimpleFillSymbol
' loop through the classes and apply the color and label
Dim I As Integer
pClassRen.Break(0) = 228
pClassRen.Break(1) = 229
pFSymbol.Color = pRamp.Color(I)
pClassRen.Symbol(0) = pFSymbol
For I = 0 To pClassRen.ClassCount - 1
pFSymbol.Color = pRamp.Color(I)
pClassRen.Symbol(I) = pFSymbol
pClassRen.Label(I) = "Class" & CStr(I)
Next I
' Update the renderer and plug into layer
pRasRen.Update()
pLayer.Renderer = pClassRen
pLayer.Draw(esriDrawPhase.esriDPGeography, pA.ScreenDisplay, Nothing)
' Release memeory
pRaster = Nothing
pRasRen = Nothing
pClassRen = Nothing
pRamp = Nothing
pFSymbol = Nothing
End Sub
''' <summary>
''' 唯一值渲染Raster
''' </summary>
''' <param name="pLayer">raster图层</param>
''' <remarks></remarks>
Sub ChangeRenderToUVRenderer(ByVal pLayer As IRasterLayer)
' Get raster input from layer
Dim pRLayer As IRasterLayer
pRLayer = pLayer
Dim pRaster As IRaster
pRaster = pRLayer.Raster
' Get the number of rows from raster table
Dim pTable As ITable
Dim pBand As IRasterBand
Dim pBandCol As IRasterBandCollection
pBandCol = pRaster
pBand = pBandCol.Item(0)
Dim TableExist As Boolean
pBand.HasTable(TableExist)
If Not TableExist Then Exit Sub
pTable = pBand.AttributeTable
Dim NumOfValues As Integer
NumOfValues = pTable.RowCount(Nothing)
' Specified a field and get the field index for the specified field to be rendered.
Dim FieldIndex As Integer
Dim FieldName As String
FieldName = "Value" 'Value is the default field, you can specify other field here.
FieldIndex = pTable.FindField(FieldName)
' Create random color
Dim pRamp As IRandomColorRamp
pRamp = New RandomColorRamp
pRamp.Size = NumOfValues
pRamp.Seed = 100
pRamp.CreateRamp(True)
Dim pFSymbol As ISimpleFillSymbol
' Create UniqueValue renderer and QI RasterRenderer
Dim pUVRen As IRasterUniqueValueRenderer
pUVRen = New RasterUniqueValueRenderer
Dim pRasRen As IRasterRenderer
pRasRen = pUVRen
' Connect renderer and raster
pRasRen.Raster = pRaster
pRasRen.Update()
' Set UniqueValue renerer
pUVRen.HeadingCount = 1 ' Use one heading
pUVRen.Heading(0) = "All Data Values"
pUVRen.ClassCount(0) = NumOfValues
pUVRen.Field = FieldName
Dim I As Long
Dim pRow As IRow
Dim LabelValue As Object
For I = 0 To NumOfValues - 1
pRow = pTable.GetRow(I) 'Get a row from the table
LabelValue = pRow.Value(FieldIndex) ' Get value of the given index
pUVRen.AddValue(0, I, LabelValue) 'Set value for the renderer
pUVRen.Label(0, I) = CStr(LabelValue) 'Set label
pFSymbol = New SimpleFillSymbol
pFSymbol.Color = pRamp.Color(I)
pUVRen.Symbol(0, I) = pFSymbol 'Set symbol
Next I
' Update render and refresh layer
pRasRen.Update()
pRLayer.Renderer = pUVRen
pRLayer = Nothing
pUVRen = Nothing
pRasRen = Nothing
pRamp = Nothing
pFSymbol = Nothing
pRaster = Nothing
pRLayer = Nothing
pBand = Nothing
pBandCol = Nothing
pTable = Nothing
pRow = Nothing
End Sub
http://blog.sina.com.cn/s/blog_53fc3ca10100ihyy.html