AnsweredAssumed Answered

Labels to Annotation in another databse

Question asked by sibghatullah86 on Dec 9, 2017
Latest reply on Dec 14, 2017 by CRowland-Simms-esristaff

I am trying to convert labels to annotation by using following code.It is working fine and creating annotation in the feature layers database but i want to store in other Geodatabase.

I have tried by adding string path of my geodatabase as a workspace but it is not working.Convert Annotation

 

string fgdb= folderPath + "\\Test.gdb;

IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(fgdb, 0);

 

 

 

static void ConvertLabelsToGDBAnnotationEntireMap(IMap pMap, bool featureLinked)
{
    IConvertLabelsToAnnotation pConvertLabelsToAnnotation = new
        ConvertLabelsToAnnotationClass();
    ITrackCancel pTrackCancel = new CancelTrackerClass();
    //Change global level options for the conversion by sending in different parameters to the next line.
    pConvertLabelsToAnnotation.Initialize(pMap,
        esriAnnotationStorageType.esriDatabaseAnnotation,
        esriLabelWhichFeatures.esriVisibleFeatures, true, pTrackCancel, null);
    IUID pUID = new UIDClass();
    pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
        //IGeoFeatureLayer interface ID.
    IMapLayers pMapLayers = pMap as IMapLayers;
    IEnumLayer pEnumLayer = pMapLayers.get_Layers(pUID as UIDClass, true);
    pEnumLayer.Reset();
    IGeoFeatureLayer pGeoFeatureLayer = pEnumLayer.Next()as IGeoFeatureLayer;

    while (pGeoFeatureLayer != null)
    {
        if (pGeoFeatureLayer.Valid == true)
        {
            if (pMapLayers.IsLayerVisible(pGeoFeatureLayer as ILayer))
            //Takes scale and groups layers into account.
            {
                if (pGeoFeatureLayer.DisplayAnnotation == true)
                {
                    IFeatureClass pFeatureClass = pGeoFeatureLayer.FeatureClass;
                    IDataset pDataset = pFeatureClass as IDataset;
                    IFeatureWorkspace pFeatureWorkspace = pDataset.Workspace as
                        IFeatureWorkspace;

                    //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", pFeatureWorkspace,
                        pFeatureClass.FeatureDataset, featureLinked, false, false,
                        true, true, "");
                }
            }
        }
        pGeoFeatureLayer = pEnumLayer.Next()as IGeoFeatureLayer;
    }
    //Do the conversion.
    pConvertLabelsToAnnotation.ConvertLabels();
    IEnumLayer pAnnoEnumLayer = pConvertLabelsToAnnotation.AnnoLayers;
    //Turn off labeling for the layers converted.
    pEnumLayer.Reset();
    pGeoFeatureLayer = pEnumLayer.Next()as IGeoFeatureLayer;
    while (pGeoFeatureLayer != null)
    {
        if (pGeoFeatureLayer.Valid == true)
        {
            if (pMapLayers.IsLayerVisible(pGeoFeatureLayer as ILayer))
            //Takes scale and groups layers into account.
            {
                if (pGeoFeatureLayer.DisplayAnnotation == true)
                    pGeoFeatureLayer.DisplayAnnotation = false;
            }
        }
        pGeoFeatureLayer = pEnumLayer.Next()as IGeoFeatureLayer;
    }
    //Add the result annotation layer to the map.
    pMap.AddLayers(pAnnoEnumLayer, true);
    //Refresh the map to update the display.
    IActiveView pActiveView = pMap as IActiveView;
    pActiveView.Refresh();
}

Outcomes