gkmorales

[HELP] IUniqueValueRenderer

Discussion created by gkmorales on Mar 6, 2012
Latest reply on Mar 7, 2012 by gkmorales
need help...

i am trying to use 2 field in IUniqueValueRenderer...

i get results in the TOC but the layer is invisible...

here's my code... the idea is to check if there's a Building.PIN first... if it is blank then it will symbolize as No PIN... but if the Building.PIN is not blank then it will check the Table.Tag value...

Try
            Dim pMxDoc As IMxDocument = DirectCast(m_application.Document, IMxDocument)
            Dim pMap As IMap = pMxDoc.FocusMap

            Dim pGFLayer As IGeoFeatureLayer = Nothing

            Dim LyrCnt As Integer
            For LyrCnt = 0 To pMap.LayerCount - 1
                If pMap.Layer(LyrCnt).Name = "Building" Then
                    pGFLayer = pMap.Layer(LyrCnt)
                    Exit For
                End If
            Next LyrCnt

            Dim pFClass As IFeatureClass = pGFLayer.FeatureClass
            Dim pFields As IFields = pFClass.Fields

            Dim strnamefield as string = "Table.Tag"
            Dim strnamefieldPIN as string = "Building.PIN"

            Dim pTable As ITable = pGFLayer
            Dim fieldNumber As Long = pTable.FindField(strnamefield)
            Dim fieldNumberPIN As Long = pTable.FindField(strnamefieldPIN)

            Dim pUniqueValueRenderer As IUniqueValueRenderer = New UniqueValueRenderer
            pUniqueValueRenderer.FieldCount = 2
            pUniqueValueRenderer.Field(0) = strnamefieldPIN
            pUniqueValueRenderer.Field(1) = strnamefield

            Dim pColorRamp As IRandomColorRamp = New RandomColorRamp
            With pColorRamp
                .StartHue = 0
                .MinValue = 99
                .MinSaturation = 15
                .EndHue = 360
                .MaxValue = 100
                .MaxSaturation = 30
                .Size = 100
                .CreateRamp(True)
                Dim pEnumRamp As IEnumColors = .Colors
            End With

            Dim pNextUniqueColor As IRgbColor = Nothing

            Dim pQueryFilter As IQueryFilter = New QueryFilter
            pQueryFilter.SubFields = ""
            pQueryFilter.AddField(strnamefield)
            pQueryFilter.AddField(strnamefieldPIN)

            Dim pCursor As ICursor = pTable.Search(pQueryFilter, True)
            Dim pNextRow As IRow = pCursor.NextRow

            Dim countNull As Integer = 0
            Dim countZero As Integer = 0
            Dim countOne As Integer = 0
            Dim countPIN As Integer = 0

            Do While Not pNextRow Is Nothing
                Dim pNextRowBuffer As IRowBuffer = pNextRow
                Dim codeValue As Object = pNextRowBuffer.Value(fieldNumber)
                Dim codeValuePIN As Object = pNextRowBuffer.Value(fieldNumberPIN)

                Dim strColor As IRgbColor = New RgbColor
                strColor.Red = 138
                strColor.Green = 43
                strColor.Blue = 226
                Dim strLabel As String = "No PIN"

                If IsDBNull(codeValuePIN) Then codeValuePIN = ""
                If IsDBNull(codeValue) Then codeValue = ""

                If codeValuePIN <> "" Then

                    If Trim(codeValue) = "0" Then
                        strColor.Red = 175
                        strColor.Green = 255
                        strColor.Blue = 0
                    ElseIf Trim(codeValue) = "1" Then
                        strColor.Red = 255
                        strColor.Green = 0
                        strColor.Blue = 0
                    Else
                        strColor.Red = 0
                        strColor.Green = 0
                        strColor.Blue = 255
                    End If

                    pNextUniqueColor = strColor

                    Dim pSym As IFillSymbol = New SimpleFillSymbol
                    pSym.Color = pNextUniqueColor

                    If Trim(codeValue) = "0" Then
                        pUniqueValueRenderer.AddValue(codeValue, "", pSym)
                        pUniqueValueRenderer.Label(codeValue) = strLabel1 & " - " & countZero
                        countZero += 1
                    ElseIf Trim(codeValue) = "1" Then
                        pUniqueValueRenderer.AddValue(codeValue, "", pSym)
                        pUniqueValueRenderer.Label(codeValue) = strLabel2 & " - " & countOne
                        countOne += 1
                    Else
                        pUniqueValueRenderer.AddValue("<Null>", "", pSym)
                        pUniqueValueRenderer.Label("<Null>") = "No Business Record" & " - " & countNull
                        countNull += 1
                    End If

                Else

                    strColor.Red = 138
                    strColor.Green = 43
                    strColor.Blue = 226

                    pNextUniqueColor = strColor

                    Dim pSym As IFillSymbol = New SimpleFillSymbol
                    pSym.Color = pNextUniqueColor

                    pUniqueValueRenderer.AddValue(codeValuePIN, "", pSym)
                    pUniqueValueRenderer.Label(codeValuePIN) = strLabel & " - " & countPIN
                    countPIN += 1

                End If

                pNextRow = pCursor.NextRow
            Loop

            pGFLayer.Renderer = pUniqueValueRenderer
            Dim pEnvelope As IEnvelope
            pEnvelope = pMxDoc.ActiveView.Extent

            pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, Nothing, Nothing) 'nothingpEnvelope
            pMxDoc.UpdateContents()
        Catch ex As Exception
            MsgBox(ex.Message, , "ExportToMap")
        End Try

Outcomes