bhavanisankarnimmala

Place Annotation in Annotation feature class

Blog Post created by bhavanisankarnimmala on May 14, 2018

// Main Line of Code

IFeature annoFeat = PlaceAnnotation(landTextObj.landTextAnno, Globals.annoFclass, pt, featureID, pColor, fontsize, TextOrientation, isItalicFont, angle);

 

//Sub Method of Code

public static IFeature PlaceAnnotation(string sampleText, IFeatureClass pFClass, IPoint pt, int featureID, IRgbColor pColor, int fontsize, string TextOrientation, bool isItalicFont, double angle)

{

IFeature pFeature = null;

try

{

IFeatureCursor pFCursor = pFClass.Insert(true);

IFeatureBuffer pFeatBuffer = pFClass.CreateFeatureBuffer();

pFeature = pFeatBuffer as IFeature;

//IElement pElement = null;

//ITextElement pTextElement = new TextElementClass();

IElement pElement = new TextElement();

ITextElement pTextElement = pElement as ITextElement;

IFormattedTextSymbol pTextSymbol = new TextSymbol();

stdole.IFontDisp fnt = (stdole.IFontDisp)new stdole.StdFont();

fnt.Name = "Arial";

fnt.Size = fontsize;

fnt.Weight = 400;

fnt.Italic = isItalicFont;

fnt.Underline = false;

fnt.Strikethrough = false;

fnt.Bold = true;

 

pTextSymbol.Font = fnt;

pTextSymbol.Size = fontsize;

//pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline;

pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;

pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;

//if (TextOrientation.ToUpper() == "H")

//{

// pTextSymbol.Angle = 0;

//}

//else if (TextOrientation.ToUpper() == "V")

//{

// pTextSymbol.Angle = 90;

//}

pTextSymbol.Angle = angle;

//IRgbColor pColor = GetRGBColor(0, 0, 0);

pColor.Transparency = 255;

pTextSymbol.Color = pColor;

pTextSymbol.CharacterWidth = 70;

pTextElement.Symbol = pTextSymbol;

pTextElement.Text = sampleText;

pElement = pTextElement as IElement;

pElement.Geometry = pt;

IAnnotationFeature pAnnoFeat = pFeature as IAnnotationFeature;

pAnnoFeat.Annotation = pElement;

pFeature = pAnnoFeat as IFeature;

pFeature.set_Value(pFeature.Fields.FindField("FeatureID"), featureID);

pFeature.set_Value(pFeature.Fields.FindField("Status"), 0);

pFCursor.InsertFeature(pFeature as IFeatureBuffer);

pFCursor.Flush();

}

catch (Exception ex)

{

Globals.logging(ex.Message, false, "FATAL");

Globals.logging(ex.StackTrace, false, "FATAL");

Globals.logging("ERROR in " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Method.", false, "FATAL");

pFeature = null;

}

finally

{

GC.Collect();

}

return pFeature;

}

 

Outcomes