Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I currently have a basic shapefile that's a map of the United States. It has the name of the states, populations, and other pieces of information that I can get the names of via the following code:

IFeatureLayer myFeatureLayer = myLayer as IFeatureLayer;
IFeatureClass myFeatureClass = myFeatureLayer.FeatureClass;

For(int I = 0; I < myFeatureClass.Fields.FieldCount; i++)
{
IField field = myFeatureClass.Fields.get_Field(i);
Console.writeLine(field.Name);
}

The first field in the featureClass (after FID and the shape) is STATE_NAME which obviously is the name of each state.

If I do the following:

IGeoFeatureLayer geoLayer = myLayer as IGeoFeatureLayer;
geoLayer.displayAnnotation = true;

The states are now labeled; however, what I'd like is the ability to show different labels. I know from my looping through the featureclass Field count there are properties such as population and elevation. How do I change the AnnotationProperties to have it display that information instead of the default?

share|improve this question
    
need to change title to reflect question (as shown in bold). –  Kirk Kuykendall Feb 16 '11 at 21:51

1 Answer 1

up vote 3 down vote accepted

its set in properties.Expression ...

public void annotateLayer(ILayer thisLayer, String geocode, double minScale, double maxScale, bool annotationsOn, bool showMapTips, RgbColor annotationLabelColor)
{
   IGeoFeatureLayer geoLayer = thisLayer as IGeoFeatureLayer;
   if (geoLayer != null)
   {
        geoLayer.DisplayAnnotation = annotationsOn;
        IAnnotateLayerPropertiesCollection propertiesColl = geoLayer.AnnotationProperties;
        IAnnotateLayerProperties labelEngineProperties = new LabelEngineLayerProperties() as IAnnotateLayerProperties;
        IElementCollection placedElements = new ElementCollectionClass();
        IElementCollection unplacedElements = new ElementCollectionClass();
        propertiesColl.QueryItem(0, out labelEngineProperties, out placedElements, out unplacedElements);
        ILabelEngineLayerProperties lpLabelEngine = labelEngineProperties as ILabelEngineLayerProperties;
        lpLabelEngine.Expression = geocode;
        lpLabelEngine.Symbol.Color = annotationLabelColor; 
        labelEngineProperties.AnnotationMinimumScale = minScale;
        labelEngineProperties.AnnotationMaximumScale = maxScale; 
        IFeatureLayer thisFeatureLayer = thisLayer as IFeatureLayer;
        IDisplayString displayString = thisFeatureLayer as IDisplayString;
        IDisplayExpressionProperties properties = displayString.ExpressionProperties;
        properties.Expression = geocode; //example: "[OWNER_NAME] & vbnewline & \"$\" & [TAX_VALUE]";
        thisFeatureLayer.ShowTips = showMapTips;
}
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.