首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

c#+AE中TextElement标注不显示,该如何解决

2013-01-02 
c#+AE中TextElement标注不显示在看兰小机和刘德儿两位老师编著的ArcObjects GIS应用开发这本书的时候,在做

c#+AE中TextElement标注不显示
在看兰小机和刘德儿两位老师编著的ArcObjects GIS应用开发这本书的时候,在做到TextElement标注时运行时并没有显示,但是我的代码和书上都是一样的,不知道是怎么回事,请高手帮助分析一下,谢谢。
代码:


 private void btnTextElementLabel_Click(object sender, EventArgs e)
        {
            IMap pMap;
            IFeatureLayer pFeatureLyr;
            IFeatureClass pFeatureClass;
            string pFieldName = "原村名";
            pMap = axMapControl1.Map;
            pFeatureLyr = pMap.get_Layer(0) as IFeatureLayer;
            pFeatureClass = pFeatureLyr.FeatureClass;
            TextElementLabel(pMap, pFeatureClass, pFieldName);
           
        }


 private void TextElementLabel(IMap pMap, IFeatureClass pFeatureClass, string strName)
        {
            //查询条件
            //IQueryFilter pQueryFilter = new QueryFilterClass();
            //pQueryFilter.WhereClause = "OBJECTID>";
             //获取要素查询后的要素有表对象
            IFeatureCursor pFeatCursor;
            pFeatCursor = pFeatureClass.Search(null,true);//全部地物
            IFeature pFeature;
            pFeature = pFeatCursor.NextFeature();
            while (pFeature != null)
            {
                IFields pFields = pFeature.Fields;
                int i;
                //找出标注字段的索引号
                i = pFields.FindField(strName);
                //得到要素的Envelope
                IEnvelope pEnve = pFeature.Extent;
                IPoint pPoint = new PointClass();
                pPoint.PutCoords(pEnve.XMin + pEnve.Width / 2, pEnve.YMin + pEnve.Height / 2);
                //新建字体对象


                stdole.IFontDisp pFont;
                pFont = new stdole.StdFontClass() as stdole.IFontDisp;
                pFont.Name = "arial";
                //新建rgb对象
                IRgbColor pRGB = new RgbColorClass();
                pRGB.Red = 110;
                pRGB.Green = 60; 
                pRGB.Blue = 200;
                //产生一个文本符号
                ITextSymbol pTextSymbol = new TextSymbolClass();
                //设置文本符号的大小
                pTextSymbol.Size = 3;
                pTextSymbol.Font = pFont;
                pTextSymbol.Color = pRGB;
                //产生一个文本对象
                ITextElement pTextEle = new TextElementClass();
                pTextEle.Text = pFeature.get_Value(i).ToString();
                pTextEle.ScaleText = true;
                pTextEle.Symbol = pTextSymbol;
                IElement pEle = pTextEle as IElement;
                pEle.Geometry = pPoint;
                IActiveView pActiveView = pMap as IActiveView;
                IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
                //添加元素
                pGraphicsContainer.AddElement(pEle, 0);
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);
                pPoint = null;
                pEle = null;
                pFeature = pFeatCursor.NextFeature();


            }
        }


[解决办法]
错在这里
 //得到要素的Envelope
IEnvelope pEnve = pFeature.Extent;
IPoint pPoint = new PointClass();
pPoint.PutCoords(pEnve.XMin + pEnve.Width / 2, pEnve.YMin + pEnve.Height / 2);

你的点没有空间参考,用这段代码吧。
IEnvelope pEnve = pFeature.Extent;
IPoint pPoint = (pEnve as IArea).CentraPoint;

热点排行