public void CreateStandAloneAnnotationFeatureClass(Geodatabase geodatabase, SpatialReference spatialReference)
{
// Creating a Cities annotation feature class
// with following user defined fields
// Name
// GlobalID
// Annotation feature class name
string annotationFeatureClassName = "CitiesAnnotation";
// Create user defined attribute fields for annotation feature class
FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();
FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);
// Create a list of all field descriptions
List<FieldDescription> fieldDescriptions = new List<FieldDescription> { globalIDFieldDescription, nameFieldDescription };
// Create a ShapeDescription object
ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Polygon, spatialReference);
// Create general placement properties for Maplex engine
CIMMaplexGeneralPlacementProperties generalPlacementProperties =
new CIMMaplexGeneralPlacementProperties
{
AllowBorderOverlap = true,
PlacementQuality = MaplexQualityType.High,
DrawUnplacedLabels = true,
InvertedLabelTolerance = 1.0,
RotateLabelWithDisplay = true,
UnplacedLabelColor = new CIMRGBColor
{
R = 0,
G = 255,
B = 0,
Alpha = 0.5f // Green
}
};
// Create general placement properties for Standard engine
//CIMStandardGeneralPlacementProperties generalPlacementProperties =
// new CIMStandardGeneralPlacementProperties
// {
// DrawUnplacedLabels = true,
// InvertedLabelTolerance = 3.0,
// RotateLabelWithDisplay = true,
// UnplacedLabelColor = new CIMRGBColor
// {
// R = 255, G = 0, B = 0, Alpha = 0.5f // Red
// }
// };
// Create annotation label classes
// Green label
CIMLabelClass greenLabelClass = new CIMLabelClass
{
Name = "Green",
ExpressionTitle = "Expression-Green",
ExpressionEngine = LabelExpressionEngine.Arcade,
Expression = "$feature.OBJECTID",
ID = 1,
Priority = 0,
Visibility = true,
TextSymbol = new CIMSymbolReference
{
Symbol = new CIMTextSymbol()
{
Angle = 45,
FontType = FontType.Type1,
FontFamilyName = "Tahoma",
FontEffects = FontEffects.Normal,
HaloSize = 2.0,
Symbol = new CIMPolygonSymbol
{
SymbolLayers = new CIMSymbolLayer[]
{
new CIMSolidFill
{
Color = CIMColor.CreateRGBColor(0, 255, 0)
}
},
UseRealWorldSymbolSizes = true
}
},
MaxScale = 0,
MinScale = 0,
SymbolName = "TextSymbol-Green"
},
StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
{
AllowOverlappingLabels = true,
LineOffset = 1.0
},
MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
{
AlignLabelToLineDirection = true,
AvoidPolygonHoles = true
}
};
// Blue label
CIMLabelClass blueLabelClass = new CIMLabelClass
{
Name = "Blue",
ExpressionTitle = "Expression-Blue",
ExpressionEngine = LabelExpressionEngine.Arcade,
Expression = "$feature.OBJECTID",
ID = 2,
Priority = 0,
Visibility = true,
TextSymbol = new CIMSymbolReference
{
Symbol = new CIMTextSymbol()
{
Angle = 45,
FontType = FontType.Type1,
FontFamilyName = "Consolas",
FontEffects = FontEffects.Normal,
HaloSize = 2.0,
Symbol = new CIMPolygonSymbol
{
SymbolLayers = new CIMSymbolLayer[]
{
new CIMSolidFill
{
Color = CIMColor.CreateRGBColor(0, 0, 255)
}
},
UseRealWorldSymbolSizes = true
}
},
MaxScale = 0,
MinScale = 0,
SymbolName = "TextSymbol-Blue"
},
StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
{
AllowOverlappingLabels = true,
LineOffset = 1.0
},
MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
{
AlignLabelToLineDirection = true,
AvoidPolygonHoles = true
}
};
// Create a list of labels
List<CIMLabelClass> labelClasses = new List<CIMLabelClass> { greenLabelClass, blueLabelClass };
// Create an annotation feature class description object to describe the feature class to create
AnnotationFeatureClassDescription annotationFeatureClassDescription =
new AnnotationFeatureClassDescription(annotationFeatureClassName, fieldDescriptions, shapeDescription,
generalPlacementProperties, labelClasses)
{
IsAutoCreate = true,
IsSymbolIDRequired = false,
IsUpdatedOnShapeChange = true
};
// Create a SchemaBuilder object
SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
// Add the creation of the Cities annotation feature class to the list of DDL tasks
schemaBuilder.Create(annotationFeatureClassDescription);
// Execute the DDL
bool success = schemaBuilder.Build();
// Inspect error messages
if (!success)
{
IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
//etc.
}
}