2

I created labels for layer in according with this example They display coded value description from domain, but I need value itself. I can resolve it manually by unchecking this option

"Layer's Properties -> Labels -> Expression... -> Display coded value description"

"Layer's Properties -> Labels -> Expression... -> Display coded value description"

How can I do that programmatically with ArcObjects 10+?

  • Just clarify you want to display in the label the value not the coded description? – Hornbydd Jul 25 '18 at 9:38
  • @Hornbydd Yes, I want to. – Филипп Кольцов Jul 25 '18 at 9:48
3

Below is some VBA code to show you how to do this, key Interface is ICodedValueAttributes

Public Sub TurnONOFFCodedDescription()
    ' Get Document
    Dim pMXD As IMxDocument
    Set pMXD = ThisDocument

    ' Get map
    Dim pMap As IMap
    Set pMap = pMXD.FocusMap

    ' Get first layer and cast into IGeoFeatureLayer
    Dim pLayer As ILayer
    Set pLayer = pMap.Layer(0)
    Dim pGeoFL As IGeoFeatureLayer
    Set pGeoFL = pLayer

    ' Get annotation layer properties for this layer
    Dim pAnnotationPropertiesColl As IAnnotateLayerPropertiesCollection
    Set pAnnotationPropertiesColl = pGeoFL.AnnotationProperties
    Dim unplacedEle As IElementCollection
    Set unplacedEle = New ElementCollection
    Dim placedEle As IElementCollection
    Set placedEle = New ElementCollection
    Dim pAnnotateLayerProperties As IAnnotateLayerProperties
    pAnnotationPropertiesColl.QueryItem 0, pAnnotateLayerProperties, placedEle, unplacedEle

    ' Get label engine
    Dim pLabelEngineLayerProperties As ILabelEngineLayerProperties2
    Set pLabelEngineLayerProperties = pAnnotateLayerProperties
    Dim pAnnotationExpressionEngine As IAnnotationExpressionEngine
    Set pAnnotationExpressionEngine = pLabelEngineLayerProperties.ExpressionParser

    ' Set Coded value to be false (same as unchecking on GUI)
    Dim pCodedValueAttributes As ICodedValueAttributes
    Set pCodedValueAttributes = pAnnotationExpressionEngine
    pCodedValueAttributes.UseCodedValue = False
End Sub

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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