You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

Label - Define classes of features and labe...   Indra Nitz Nov 17, 2003
Re: Label - Define classes of features and...   Olivier Damanet Nov 17, 2003
Re: Label - Define classes of features and...   Indra Nitz Nov 17, 2003
Re: Label - Define classes of features and...   Olivier Damanet Nov 17, 2003
Re: Label - Define classes of features and...   Indra Nitz Nov 24, 2003
Re: Label - Define classes of features and...   Olivier Damanet Nov 24, 2003
Re: Label - Define classes of features and...   Indra Nitz Nov 24, 2003
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Label - Define classes of features and label each class differently 
Author Indra Nitz 
Date Nov 17, 2003 
Message How can I change the option 'Label all features the same way' to 'Define classes of features and label each class differently' by VBA code? And then how can I get all the available symbol classes or create a new label class?
I know that this is possible in the layer's properties dialog (labels tab), but how can I do this with VBA?

I want to use the following code after this: 
 
Sub LabelClasses()
    Dim pDoc As IMxDocument
    Dim pGeoLayer As IGeoFeatureLayer
    Set pDoc = ThisDocument
    Set pGeoLayer = GetGeoLayerByName("TA", "POIATTR")
    
    Dim pAnnoPropsColl As IAnnotateLayerPropertiesCollection
    Set pAnnoPropsColl = pGeoLayer.AnnotationProperties
    Dim pAnnoProp As IAnnotateLayerProperties
    
    For lloop = 0 To pAnnoPropsColl.Count - 1
       pAnnoPropsColl.QueryItem lloop, pAnnoProp
        Select Case pAnnoProp.Class
        Case "Andere POIs"
           pAnnoProp.DisplayAnnotation = False
        Case "Theatre"
           pAnnoProp.DisplayAnnotation = True
        Case "Cinema"
           pAnnoProp.DisplayAnnotation = False
        Case "Museum"
           pAnnoProp.DisplayAnnotation = False
       End Select
    Next lloop
    pGeoLayer.DisplayAnnotation = True
    pDoc.ActiveView.Refresh
End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label - Define classes of features and label each class differently 
Author Olivier Damanet 
Date Nov 17, 2003 
Message see http://forums.esri.com/Thread.asp?c=93&f=992&t=110952&mc=4

the 'Label all features the same way' (1 class) and 'Define classes of features and label each class differently' (>1 class) are automatically set with respect to the IAnnotateLayerPropertiesCollection.Count
 
  Olivier. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label - Define classes of features and label each class differently 
Author Indra Nitz 
Date Nov 17, 2003 
Message Okay, now I know how to add classes but I have a problem with a special class.
I have a unique value renderer and I named the symbol class 'all other values' 'Andere POIs'. If I try to add 'Andere POIs' as class to the IAnnotateLayerPropertiesCollection it is not possible.
If I get all the available symbol classes over the properties dialog the name of this class is 'Andere POIs'. What can I do? 
 
Sub LabelClasses()
    Dim pDoc As IMxDocument
    Dim pGeoLayer As IGeoFeatureLayer
    Set pDoc = ThisDocument
    Set pGeoLayer = GetGeoLayerByName("TA", "POIATTR")
    
    Dim pAnnoPropsColl2 As IAnnotateLayerPropertiesCollection
    Set pAnnoPropsColl2 = pGeoLayer.AnnotationProperties
    Dim pAnnoProp2 As IAnnotateLayerProperties
    
    pAnnoPropsColl2.QueryItem 0, pAnnoProp2, Nothing, Nothing
    pAnnoProp2.LabelWhichFeatures = esriVisibleFeatures

    pAnnoPropsColl2.Clear
    pAnnoProp2.Class = "Andere POIs"
    pAnnoPropsColl2.Add pAnnoProp2
    pAnnoProp2.Class = "Restaurant"
    pAnnoPropsColl2.Add pAnnoProp2

    For lloop = 0 To pAnnoPropsColl2.Count - 1
       pAnnoPropsColl2.QueryItem lloop, pAnnoProp2
        Select Case pAnnoProp2.Class
        Case "Andere POIs"
           pAnnoProp2.DisplayAnnotation = False
        Case Else
            pAnnoProp2.DisplayAnnotation = True
       End Select
    Next lloop
    
    pGeoLayer.DisplayAnnotation = True
    pDoc.ActiveView.Refresh
End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label - Define classes of features and label each class differently 
Author Olivier Damanet 
Date Nov 17, 2003 
Message Where is pAnnoProp2 set? Since you cleared the AnnotateLayerPropertiesCollection, you should Set it explicitely to a New LabelEngineLayerProperties for each new label class. 
 
pAnnoPropsColl2.Clear
    Set pAnnoProp2 = New LabelEngineLayerProperties
    pAnnoProp2.Class = "Andere POIs"
    pAnnoPropsColl2.Add pAnnoProp2
    Set pAnnoProp2 = New LabelEngineLayerProperties
    pAnnoProp2.Class = "Restaurant"
    pAnnoPropsColl2.Add pAnnoProp2
 
  Olivier. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label - Define classes of features and label each class differently 
Author Indra Nitz 
Date Nov 24, 2003 
Message Thanks for your help. It was very useful for me.

But now I got another problem. Everything works fine using the code except that the labels would not displayed unless i open and apply the LabelPlacementOptions in "Layer Properties - Labels" manually. Did I need any refresh method?

And another question, how can I delete one of these classes (I want to delete the "Default" class)?

Thanks, Indra 
 
Sub LabelPOI(pGFLayer As IGeoFeatureLayer, sLabelField As String, ScaleRange As Long, pRed As Long, pGreen As Long, pBlue As Long, Size As Long)

    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    
    'Get the label properties
    Dim pLabelProps As ILabelEngineLayerProperties
    Dim pAnnoPropsColl As IAnnotateLayerPropertiesCollection
    Set pAnnoPropsColl = pGFLayer.AnnotationProperties
    pAnnoPropsColl.QueryItem 0, pLabelProps
    
    'get the (first) AnnotateLayerProperties property set in the collection
    Dim pAnnoLayerProps As IAnnotateLayerProperties
    pAnnoPropsColl.QueryItem 0, pAnnoLayerProps, Nothing, Nothing
    
    'Set the label expression
    pLabelProps.IsExpressionSimple = False
    pLabelProps.Expression = "[" & sLabelField & "]"
    
    pAnnoLayerProps.AnnotationMinimumScale = ScaleRange
    pAnnoLayerProps.LabelWhichFeatures = esriVisibleFeatures 'geht nicht so wie ich will...
    
    Dim pSym As ITextSymbol
    Set pSym = New TextSymbol
    pSym.Color = BuildRGB(pRed, pGreen, pBlue)
    pSym.Size = Size
    
    'Text maskieren (damit man ihn besser lesen kann...)
    Dim pMask As IMask
    Set pMask = pSym
    pMask.MaskStyle = esriMSHalo
    pMask.MaskSize = 1.5
    Set pMask.MaskSymbol = MakeFillSym(MakeColor(vbWhite))
    
    'Set the label symbol
    Set pLabelProps.Symbol = pSym
    
    'Build label classes
    Dim pAnnoProp As IAnnotateLayerProperties
    pAnnoPropsColl.QueryItem 0, pAnnoProp, Nothing, Nothing
    
    Set pAnnoProp = New LabelEngineLayerProperties
    pAnnoProp.Class = "Restaurant"
    pAnnoProp.WhereClause = "(""PoiTyp"" = 15)"
    pAnnoPropsColl.Add pAnnoProp
    Set pAnnoProp = New LabelEngineLayerProperties
    pAnnoProp.Class = "Andere POIs"
    pAnnoProp.WhereClause = "Not((""PoiTyp"" = 15))"
    pAnnoPropsColl.Add pAnnoProp
    
    For lloop = 0 To pAnnoPropsColl.Count - 1
        pAnnoPropsColl.QueryItem lloop, pAnnoProp
        Select Case pAnnoProp.Class
        Case "Andere POIs"
            pAnnoProp.DisplayAnnotation = False
        Case "Default"
            pAnnoProp.DisplayAnnotation = False
        Case Else
            pAnnoProp.DisplayAnnotation = True
        End Select
    Next lloop
              
    'On/Off the labels
    pGFLayer.DisplayAnnotation = Not pGFLayer.DisplayAnnotation
    
End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label - Define classes of features and label each class differently 
Author Olivier Damanet 
Date Nov 24, 2003 
Message The refresh method is IMxDocument.ActiveView.Refresh: you don't call it in the last code you posted (though you did in the previous one).
I adapted your code as to remove the 'default' class: 
 
For lloop = 0 To pAnnoPropsColl.Count - 1
        pAnnoPropsColl.QueryItem lloop, pAnnoProp
        Select Case pAnnoProp.Class
        Case "Andere POIs"
            pAnnoProp.DisplayAnnotation = False
        Case "Default"
            pAnnoPropsColl.Remove pAnnoProp
        Case Else
            pAnnoProp.DisplayAnnotation = True
        End Select
    Next lloop
 
  Olivier. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label - Define classes of features and label each class differently 
Author Indra Nitz 
Date Nov 24, 2003 
Message Yes, I forgot to call the MxDocument.ActiveView.Refresh method...

But now I have add this method and I still have the same problem, the labels would not displayed unless i open and apply the LabelPlacementOptions in "Layer Properties - Labels" manually.