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 am trying to load different shp files in ArcObjects progromatically. Currently I can load lines,polylines, polygons and ellipses (even though that's just a fancy polygon as far as ArcObjects is concerned).

However, I'm having a problem loading Text. Basically it's a point on a map with some text above it.

This is how I'm trying to load the shape File. Note this is basically the same thing I do for polygons, polylines,and ellipses. The only notable difference is ITextSymbol as opposed to ISimpleFillSymbol for Polygons or ISimpleLineSymbol for Lines

IFeatureLayer featureLayer = new FeatureLayerrClass();
featureLayer.FeatureClass = myFeatureClass //Loaded from the featureWorkspace
featureLayer.Name = featureClass.AliasName;
featureLayer.Visibile = true;

IGeoFeatureLayer layer = featureLayer as IGeoFeatureLayer;

IRgbColor textColor = new RgbColorClass();
textColor.Red = 255;
textColor.Blue = 0;
textColor.Green =0;

ITextSymbol textSymbol = new TextSymbolClass();
textSymbol.Color = textColor;
textSymbol.Font = (stdole.IFontDisp)OLE.GetIFontDispFromFont(new Font("Arial", 12 , FontStyle.Bold);
textSymbol.Size = 12;
textSymbol.Text = myText;

ISimpleRenderer simpleRenderer = new SimpleRendererClass();
simpleRenderer.Symbol = textSymbol as ISymbol;
geoFeatureLayer.Renderer = simpleRenderer;

myAxMap.AddLayer(geoFeatureLayer as ILayer);
Invalidate();
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Text symbols cannot be used as renderer symbols. You will need to set up labeling for your layer instead.

A good start for setting layer's labeling properties is IGeoFeatureLayer.AnnotationProperties.

share|improve this answer
    
I do labeling already with other shape files that have labels i.e rivers/lakes/ and just use the ILabelEngineLayerProperties and IAnnotateLayerProperties so I guess it's the same logic –  PSU_Kardi Mar 24 '11 at 18:19
    
That being said, should I be using IPoint as my shape? Or is there a better ESRI.ArcGIS.Geometry that I should be using. It was straight forward with Polygon/Polyline/Ellipse –  PSU_Kardi Mar 24 '11 at 18:26
    
But I guess you did not display any text for the polygon/polyline/ellipse cases, did you? Points are the obvious choice for text labels, but once you get into labeling, you can pretty much place the labels on top of anything (be it point, line or polygon). –  Petr Krebs Mar 24 '11 at 18:30
add comment

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.