How to convert labels to geodatabase annotation for a single layer


Converting labels to geodatabase annotation for a single layer

This document demonstrates how to use the ConvertLabelsToAnnotation class to change a label for a single layer to geodatabase annotation. The ConvertLabelsToAnnotation class is a coarse-grained object that encapsulates the logic needed to perform this conversion. This class works with maps labeled with Maplex or the standard label engine.
The following code examples contain a Boolean option for making the annotation feature linked. Feature-linked annotation can only be created with an ArcEditor or higher license level.
The map reference passed into the function must be activated on a window. Check the IsMapActivated property on IActiveView to determine if the map is activated. Typically the map is activated unless it is opened via MapDocument or MapReader.
[Java]
static void convertLabelsToGDBAnnotationEntireMap(IMap map, int layerIndex, boolean
    featureLinked)throws Exception{
    IConvertLabelsToAnnotation convertLabToAnno = new ConvertLabelsToAnnotation();
    ITrackCancel trackCancel = new CancelTracker();
    // Change global level options for the conversion by sending in
    // different parameters to the next line.
    convertLabToAnno.initialize(map,
        esriAnnotationStorageType.esriDatabaseAnnotation,
        esriLabelWhichFeatures.esriAllFeatures, true, trackCancel, null);

    ILayer layer = map.getLayer(layerIndex);
    IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)layer;
    if (geoFeatureLayer != null){
        IFeatureClass featureClass = geoFeatureLayer.getFeatureClass();
        IDataset dataset = new IDatasetProxy(featureClass);

        IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy
            (dataset.getWorkspace());
        // Add the layer information to the converter object. Specify the
        // parameters of the output annotation feature class here as well.
        convertLabToAnno.addFeatureLayer(geoFeatureLayer, geoFeatureLayer.getName() 
            + "_Anno", featureWorkspace, featureClass.getFeatureDataset(),
            featureLinked, false, false, true, true, "");

        // Do the conversion.
        convertLabToAnno.convertLabels();
        IEnumLayer enumLayer = convertLabToAnno.getAnnoLayers();
        // Turn off labeling for the layer converted.
        geoFeatureLayer.setDisplayAnnotation(false);

        // Add the result annotation layer to the map.
        map.addLayers(enumLayer, true);

        // Refresh the map to update the display.
        IActiveView activeView = (IActiveView)map;
        activeView.refresh();
    }
}






Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo
Engine Developer Kit Engine Runtime