1

kind of new to VB.NET.

Trying to set my label expression for a layer. Essentially a user picks a layer from a combo box, hits a button, expression is applied on the layer and then the single shp file is converted to annotation. my issue is it seems to work for 75%. I am labeling creeks and want to label the [TYPE] vs the [NAME]. It seems to label the Type for most but for whatever reason there are a few names being labeled as well. Did I screw up some where?

it seems to label the DEFAULT field as well as my expression when I just want it to label my expression.

Shared Sub ConvertLabelsToAnnotationSingleLayerMapAnno(ByVal pMap As IMap, ByVal layerIndex As Integer)
    Dim pConvertLabelsToAnnotation As IConvertLabelsToAnnotation = New ConvertLabelsToAnnotationClass()
    Dim pTrackCancel As ITrackCancel = New CancelTrackerClass()
    'Change global level options for the conversion by sending in different parameters to the next line.
    pConvertLabelsToAnnotation.Initialize(pMap, esriAnnotationStorageType.esriMapAnnotation, _
                                          esriLabelWhichFeatures.esriVisibleFeatures, True, _
                                          pTrackCancel, Nothing)
    Dim pLayer As ILayer = pMap.Layer(layerIndex)
    Dim pGeoFeatureLayer As IGeoFeatureLayer = pLayer

    If Not pGeoFeatureLayer Is Nothing Then
        Dim pAnnotateLPC As IAnnotateLayerPropertiesCollection
        pAnnotateLPC = pGeoFeatureLayer.AnnotationProperties
        Dim pAnnotateLP As IAnnotateLayerProperties
        pAnnotateLP = New LabelEngineLayerProperties
        Dim pLabelELP1 As ILabelEngineLayerProperties2
        pLabelELP1 = pAnnotateLP
        pLabelELP1.Expression = String.Format("[Type]")
        pAnnotateLPC.Add(pAnnotateLP)
        pGeoFeatureLayer.DisplayAnnotation = True

        Dim pFeatureClass As IFeatureClass = pGeoFeatureLayer.FeatureClass
        'Add the layer information to the converter object. Specify the parameters of the output annotation feature class here as well.
        pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer, pGeoFeatureLayer.Name + "_Anno", _
                                                   Nothing, Nothing, False, False, False, False, False, "")
        'Do the conversion.
        pConvertLabelsToAnnotation.ConvertLabels()
        'Turn off labeling for the layer converted.
        pGeoFeatureLayer.DisplayAnnotation = False
        'Refresh the map to update the display.
        Dim pActiveView As IActiveView = pMap
        pActiveView.Refresh()
    End If
End SubationSingleLayerMapAnno(pMap, cmbAOA.SelectedIndex)
  • If anyone comes across this geonet.esri.com/thread/40373 seems to have solved my issue. – unknownid Jun 13 '16 at 2:57
  • It might be better to 'answer' your own question and then accept it. It will archive as an answered question instead of an unanswered one. – Barrett Jun 13 '16 at 18:50
0

geonet.esri.com/thread/40373 has the working code here.

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.