Select to view content in your preferred language

Label with LXP file

3111
2
04-30-2010 12:10 PM
CraigGraham
Occasional Contributor
Good Afternoon,
I have a sub to symbolize a working layer from a saved layer file.  (see below)  I was hoping to be able to do some labeling in the same way.  Or in a worst case scenerio grab the needed values from the feature, build a string and pass it to some sort of label object that way. 

Any leads greatly appreciated.

Take care,
Craig

Here's the symbology sub:
Public Sub subSymbolizeByLayerFile(sLayer As String, sLayerFilePath As String)
    Dim pDoc As IMxDocument, pMap As IMap, pFLayer As IFeatureLayer, pGxLayer As IGxLayer, pGxFile As IGxFile
    Dim pSymLayer As ILayer, pLyr As IGeoFeatureLayer, pGeoSymLyr As IGeoFeatureLayer, pLayer As ILayer
    Dim pLayer1 As ILayer, pLayers As IEnumLayer
    Dim i As Integer
    Dim pFSO As FileSystemObject
    Set pDoc = g_App.Document
    Set pMap = pDoc.FocusMap
    Set pLayers = pMap.Layers
    Set pLayer1 = pLayers.Next
    Do While Not pLayer1 Is Nothing
        If pLayer1.Name = sLayer Then
            Set pLayer = pLayer1
            Exit Do
        End If
        Set pLayer1 = pLayers.Next
    Loop
    If pLayer Is Nothing Then Exit Sub
    Set pFSO = New FileSystemObject
    If pFSO.FileExists(sLayerFilePath) = False Then Exit Sub
    Set pFLayer = pLayer
    Set pGxLayer = New GxLayer
    Set pGxFile = pGxLayer
    pGxFile.Path = sLayerFilePath
    Set pSymLayer = pGxLayer.Layer
    Set pLyr = pFLayer
    Set pGeoSymLyr = pSymLayer
    Set pLyr.Renderer = pGeoSymLyr.Renderer
    pDoc.ActiveView.Refresh
    pDoc.UpdateContents
End Sub


Here is the contents of the label expression file:
Function FindLabel ( [POLYID], [POLYTYPE], [FORMOD], [DEVSTAGE], [OSPCOMP], [USPCOMP], [VERT], [PRI_ECO], [SEC_ECO] )
  Dim Str
  Str = [POLYID] & " - " & [POLYTYPE]  
  If [POLYTYPE] = "FOR" Then
    Str = Str & vbNewLine & "FORMOD = " & [FORMOD]  & vbNewLine & "DEVSTAGE = " & [DEVSTAGE]  & vbNewLine & "OSC = " & [OSPCOMP] 
  End If
  FindLabel = Str
0 Kudos
2 Replies
JohnHauck
Frequent Contributor
IGeoFeatureLayer also provides access to the label information. IGeoFeatureLayer::AnnotationProperties. Each item in the collection is an IAnnotateLayerProperties object that represents a label class.

Public Sub subSymbolizeByLayerFile()
    Dim sLayerFilePath As String
    sLayerFilePath = "C:\fromFC.lyr"

    Dim pDoc As IMxDocument, pMap As IMap, pFLayer As IFeatureLayer, pGxLayer As IGxLayer, pGxFile As IGxFile
    Dim pSymLayer As ILayer, pLyr As IGeoFeatureLayer, pGeoSymLyr As IGeoFeatureLayer, pLayer As ILayer
    Dim pLayer1 As ILayer, pLayers As IEnumLayer
    Dim i As Integer

    Set pDoc = ThisDocument
    Set pMap = pDoc.FocusMap

    Set pLayer1 = pMap.Layer(0)

    Set pFLayer = pLayer1
    Set pGxLayer = New GxLayer
    Set pGxFile = pGxLayer
    pGxFile.Path = sLayerFilePath
    Set pSymLayer = pGxLayer.Layer
    Set pLyr = pFLayer
    Set pGeoSymLyr = pSymLayer

    Set pLyr.Renderer = pGeoSymLyr.Renderer
    
    
    '''''added
    Dim pAnnoLyrProps As IAnnotateLayerProperties
    Dim id As Long
    Dim pAnnoLyrPropsColl2 As IAnnotateLayerPropertiesCollection2
    Set pAnnoLyrPropsColl2 = pGeoSymLyr.AnnotationProperties
    
    pLyr.AnnotationProperties.Clear
    
    For i = 0 To pAnnoLyrPropsColl2.Count - 1
        pAnnoLyrPropsColl2.QueryItem i, pAnnoLyrProps, id
        pLyr.AnnotationProperties.Add pAnnoLyrProps
    Next i
    
    If pGeoSymLyr.DisplayAnnotation Then
        pLyr.DisplayAnnotation = True
    End If
    '''''end added
    
    pDoc.ActiveView.Refresh
    pDoc.UpdateContents
End Sub

0 Kudos
CraigGraham
Occasional Contributor
Thanks for the tips.  Much appreciated.  Aside: anyone know why the forum didnt email me telling me I had a reply?  🙂
0 Kudos