0

I want to change Raster properties symbology using with Arcobjects. Unique Values change as per below attached snapshot.

Dim pWSFact As IWorkspaceFactory
Set pWSFact = New RasterWorkspaceFactory

'Getting Path
Dim pRWSpace As IRasterWorkspace
Set pRWSpace = pWSFact.OpenFromFile(strFolder, 0)

'Open Raster from path
Dim pRDSet As IRasterDataset
Set pRDSet = pRWSpace.OpenRasterDataset(DestFile)

'Convert RasterDataset to raster layer
Dim pRLyr As IRasterLayer
Set pRLyr = New RasterLayer
pRLyr.CreateFromDataset pRDSet
Dim pRReder As IRasterRenderer
Set pRReder = pRLyr.Renderer
Dim pBndCnt As Long
pBndCnt = pRLyr.BandCount
If (pBndCnt = 1) Then

'Document calling
Dim pmxdoc As IMxDocument
Set pmxdoc = ThisDocument

'Set map
Dim pmap As IMap
Set pmap = pmxdoc.FocusMap

'Add layer to Map
pmap.AddLayer pRLyr

Dim pRaster As IRaster
Set pRaster = pRLyr.Raster

Dim pRasterProps As IRasterProps
Set pRasterProps = pRaster

Dim pRSCRR As IRasterStretchColorRampRenderer
Set pRSCRR = New RasterStretchColorRampRenderer

Dim pRStch As IRasterStretch
Set pRStch = pRSCRR

enter image description here

  • what do you want to do? change from Uniquevalue to raster stretch or the other way round? – Ms. Smith Mar 10 '16 at 10:34
  • Hi chamiddor, After adding Raster in ArcMap, Raster Symbology default coming Stretched but i want Unique Values option could you please tell me how to set Unique Values through ArcObjects. – SATYA Mar 10 '16 at 12:18
  • Don't forget to take the Tour to learn about our focused Q&A format. Please use the edit button beneath your question to provide any requested clarifications. – PolyGeo Feb 13 '18 at 8:54
1

Look in the example here How to create a raster unique value renderer

This article shows how to create a raster unique value renderer.

0

I have solved my problem using this code:

Function unvrender(rstrdataset As IRasterDataset) As IRasterRenderer

    //get the raster attribute table and the size of the table
    Dim colorRamp As IRandomColorRamp
    Set colorRamp = New RandomColorRamp
    colorRamp.size = 2
    colorRamp.Seed = 1
    colorRamp.CreateRamp False


    //Create unique value renderer
    Dim uvRenderer As IRasterUniqueValueRenderer
    Set uvRenderer = New RasterUniqueValueRenderer

    Dim rasterRenderer As IRasterRenderer
    Set rasterRenderer = uvRenderer
    Set rasterRenderer.Raster = rstrdataset.CreateDefaultRaster
    rasterRenderer.Update

    uvRenderer.HeadingCount = 1
    uvRenderer.Heading(0) = "Band"
    uvRenderer.ClassCount(0) = 2
    uvRenderer.Field = "Value"

    Dim fillSymbol As ISimpleFillSymbol
    Dim i As Integer

    Dim col As IColor
    Set col = New RgbColor
    col.RGB = RGB(0, 0, 0)

    Dim col1 As IColor
    Set col1 = New RgbColor
    col1.RGB = RGB(255, 255, 255)

    uvRenderer.AddValue 0, 0, "0"
    uvRenderer.Label(0, 0) = "0"
    Set fillSymbol = New SimpleFillSymbol
    fillSymbol.Color = col
    uvRenderer.Symbol(0, 0) = fillSymbol


    uvRenderer.AddValue 0, 1, "1"
    uvRenderer.Label(0, 1) = "1"
    Set fillSymbol = New SimpleFillSymbol
    fillSymbol.Color = col1
    uvRenderer.Symbol(0, 1) = fillSymbol

 Set unvrender = rasterRenderer

End Function
  • Very nice, so the example at the link in my answer helped? I think it was really that what you were looking for. – Ms. Smith Mar 23 '16 at 8:33
  • Thanks you schmiddor your providing like very usefully for me. Actually i am working on Raster vectorization tool. before running that tool need to set raster unique values option other wise my not working. – SATYA Mar 23 '16 at 11:57
  • So if it was useful for you please mark it as answer or vote it at least. – Ms. Smith Mar 23 '16 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.