创建注记图层C# IFeatureWorkspaceAnno

http://blog.csdn.net/mydriverc/article/details/1675613

    //IFeatureWorkspaceAnno Example

    //The following example show how to use the CreateAnnotationClass on IFeatureWorkspaceAnno
    //to create a new feature-linked annotation class. In this function, the annotation class is
    //feature-linked to the feature class that is supplied as an argument and is created in the
    //same feature dataset as the feature class it is linked to.

    //The label expression is a simple expression of the values in the field called
    //DESCRIPTION in the feature class it is linked to. A text symbol for the feature-linked
    //annotation is red with a font of "Courier New".

    //e.g., nameOfFeatureClass = "States";
    //on ArcSDE use ISqlSyntax::QualifyTableName for fully qualified table names.
    public IFeatureClass IFeatureWorkspaceAnno_Example(IFeatureClass featureClass)
    {
        IDataset dataset = (IDataset)featureClass;
        //cast for the feature workspace from the workspace
        IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)dataset.Workspace;
        IFeatureWorkspaceAnno featureWorkspaceAnno = (IFeatureWorkspaceAnno)dataset.Workspace;
        //set up the reference scale
        ESRI.ArcGIS.Carto.IGraphicsLayerScale graphicLayerScale =
            new ESRI.ArcGIS.Carto.GraphicsLayerScaleClass();
        IGeoDataset geoDataset = (IGeoDataset)dataset;
        graphicLayerScale.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
        graphicLayerScale.ReferenceScale = 2000;
        //set up symbol collection
        ESRI.ArcGIS.Display.ISymbolCollection symbolCollection =
            new ESRI.ArcGIS.Display.SymbolCollectionClass();

        #region "MakeText"
        ESRI.ArcGIS.Display.IFormattedTextSymbol myTextSymbol =
            new ESRI.ArcGIS.Display.TextSymbolClass();
        //set the font for myTextSymbol
        stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
        myFont.Name = "Courier New";
        myFont.Size = 9;
        myTextSymbol.Font = myFont;
        //set the Color for myTextSymbol to be Dark Red
        ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
        rgbColor.Red = 150;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        myTextSymbol.Color = (ESRI.ArcGIS.Display.IColor)rgbColor;
        //Set other properties for myTextSymbol
        myTextSymbol.Angle = 0;
        myTextSymbol.RightToLeft = false;
        myTextSymbol.VerticalAlignment = ESRI.ArcGIS.Display.esriTextVerticalAlignment.esriTVABaseline;
        myTextSymbol.HorizontalAlignment = ESRI.ArcGIS.Display.esriTextHorizontalAlignment.esriTHAFull;
        myTextSymbol.CharacterSpacing = 200;
        myTextSymbol.Case = ESRI.ArcGIS.Display.esriTextCase.esriTCNormal;
        #endregion

        symbolCollection.set_Symbol(0, (ESRI.ArcGIS.Display.ISymbol)myTextSymbol);
        //set up the annotation labeling properties including the expression
        ESRI.ArcGIS.Carto.IAnnotateLayerProperties annoProps = new
            ESRI.ArcGIS.Carto.LabelEngineLayerPropertiesClass();
        annoProps.FeatureLinked = true;
        annoProps.AddUnplacedToGraphicsContainer = false;
        annoProps.CreateUnplacedElements = true;
        annoProps.DisplayAnnotation = true;
        annoProps.UseOutput = true;

        ESRI.ArcGIS.Carto.ILabelEngineLayerProperties layerEngineLayerProps =
            (ESRI.ArcGIS.Carto.ILabelEngineLayerProperties)annoProps;
        ESRI.ArcGIS.Carto.IAnnotationExpressionEngine annoExpressionEngine =
            new ESRI.ArcGIS.Carto.AnnotationVBScriptEngineClass();
        layerEngineLayerProps.ExpressionParser = annoExpressionEngine;
        layerEngineLayerProps.Expression = "[DESCRIPTION]";
        layerEngineLayerProps.IsExpressionSimple = true;
        layerEngineLayerProps.Offset = 0;
        layerEngineLayerProps.SymbolID = 0;
        layerEngineLayerProps.Symbol = myTextSymbol;

        ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties annoLayerTransProp =
            (ESRI.ArcGIS.Carto.IAnnotateLayerTransformationProperties)annoProps;
        annoLayerTransProp.ReferenceScale = graphicLayerScale.ReferenceScale;
        annoLayerTransProp.Units = graphicLayerScale.Units;
        annoLayerTransProp.ScaleRatio = 1;

        ESRI.ArcGIS.Carto.IAnnotateLayerPropertiesCollection annoPropsColl =
            new ESRI.ArcGIS.Carto.AnnotateLayerPropertiesCollectionClass();
        annoPropsColl.Add(annoProps);
        //use the AnnotationFeatureClassDescription to get the list of required
        //fields and the default name of the shape field
        IObjectClassDescription oCDesc = new ESRI.ArcGIS.Carto.AnnotationFeatureClassDescriptionClass();
        IFeatureClassDescription fCDesc = (IFeatureClassDescription)oCDesc;
       
        //create the new class
        return featureWorkspaceAnno.CreateAnnotationClass("AnnoTest",
            oCDesc.RequiredFields, oCDesc.InstanceCLSID, oCDesc.ClassExtensionCLSID,
            fCDesc.ShapeFieldName, "", featureClass.FeatureDataset, featureClass,
            annoPropsColl, graphicLayerScale, symbolCollection, true);
    }

posted @ 2014-06-25 10:19  adodo1  Views(610)  Comments(0Edit  收藏  举报