ArcEngine 개발: Ielement.Geometry 값이 예상 범위 내에 있지 않음 + 요소 그리기 코드

6349 단어 ArcEngine
IElement pEle = pLineEle as IElement;
pEle.Geometry = pLn;
 
pLn은 ILINe 대상입니다. 당연히 IGeometry 대상이라고 생각하고 값을 부여할 수 있습니다. 그 결과 이상 값이 예상 범위 내에 있지 않다는 것이 밝혀졌습니다.
해결 방법은 ILINe을 IPolyline 객체로 변환하는 것으로, Geometry의 기본 작업과 관련됩니다.그림% 1개의 캡션을 편집했습니다.
 
#region   RgbColor

        /// <summary>

        ///   RgbColor    

        /// </summary>

        /// <param name="r"></param>

        /// <param name="g"></param>

        /// <param name="b"></param>

        /// <param name="alpa">    ,   .0    </param>

        /// <returns></returns>

        public static IRgbColor getRgbColor(int r, int g, int b, byte alpa = 255)

        {

            IRgbColor pColor = new RgbColorClass();

            pColor.Red = r;

            pColor.Green = g;

            pColor.Blue = b;

            pColor.Transparency = alpa;



            return pColor;

        }

        #endregion



        #region       

        /// <summary>

        ///       

        /// </summary>

        /// <returns></returns>

        public static IRgbColor getRandColor()

        {

            Random rd = new Random();

            IRgbColor myColor = new RgbColorClass();

            myColor.Red = rd.Next(0, 255);

            myColor.Blue = rd.Next(0, 255);

            myColor.Green = rd.Next(0, 255);



            return myColor;

        }

        #endregion



        #region    

        /// <summary>

        ///    

        /// </summary>

        /// <param name="pLine"></param>

        /// <param name="pMapCtrl"></param>

        /// <param name="pLineSymbol">   </param>

        /// <param name="refresh">  </param>

        public static void DrawLine(ILine pLine, IMapControl2 pMapCtrl, ISimpleLineSymbol pLineSymbol

            , bool refresh)

        {

            ILineElement pLineEle = new LineElementClass();

            pLineEle.Symbol = pLineSymbol;

            IGeometryCollection pPolyline = new PolylineClass();

            ISegmentCollection pPath = new PathClass();

            object m1 = Type.Missing;

            object m2 = Type.Missing;

            pPath.AddSegment(pLine as ISegment, ref m1, ref m2);

            pPolyline.AddGeometry(pPath as IGeometry, ref m1, ref m2);

            IElement pEle = pLineEle as IElement;

            pEle.Geometry = pPolyline as IGeometry;

            IGraphicsContainer pGC = pMapCtrl.Map as IGraphicsContainer;

            pGC.AddElement(pEle, 0);

            if (refresh)

            {

                IActiveView pAv = pMapCtrl.ActiveView;

                pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            }

        }

        #endregion



        #region       

        /// <summary>

        ///     

        /// </summary>

        /// <param name="pnt"></param>

        /// <param name="value"></param>

        /// <param name="ptxtSym"></param>

        /// <param name="pMapCtrl"></param>

        /// <param name="refresh"></param>

        public static void DrawTextEle(IPoint pnt, string strvalue, ITextSymbol ptxtSym,

            IMapControl2 pMapCtrl, bool refresh)

        {

            ITextElement pTextEle = new TextElementClass();

            pTextEle.Text = strvalue;

            pTextEle.Symbol = ptxtSym;



            IElement pEle = pTextEle as IElement;

            pEle.Geometry = pnt;

            IGraphicsContainer pGc = pMapCtrl.Map as IGraphicsContainer;

            pGc.AddElement(pEle, 0);

            if (refresh)

            {

                IActiveView pAv = pMapCtrl.ActiveView;

                pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            }

        }

        #endregion



        #region   polyline

        /// <summary>

        /// 

        /// </summary>

        /// <param name="pPolyline"></param>

        /// <param name="pLineSym"></param>

        /// <param name="pMapCtrl"></param>

        /// <param name="refresh"></param>

        public static void DrawPolyline(IPolyline pPolyline, ISimpleLineSymbol pLineSym, IMapControl2 pMapCtrl,

            bool refresh)

        {

            ILineElement pLineEle = new LineElementClass();

            IElement pEle = pLineEle as IElement;

            pLineEle.Symbol = pLineSym;

            pEle.Geometry = pPolyline;



            IGraphicsContainer pGc = pMapCtrl.Map as IGraphicsContainer;

            pGc.AddElement(pEle, 0);

            if (refresh)

            {

                IActiveView pAv = pMapCtrl.ActiveView;

                pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            }

        }

        #endregion



        #region    

        /// <summary>

        ///    

        /// </summary>

        /// <param name="pnt"></param>

        /// <param name="pMapCtrl"></param>

        /// <param name="pColor">  </param>

        /// <param name="refresh">    </param>

        public static void DrawPoint(IPoint pnt, IMapControl2 pMapCtrl, IRgbColor pColor, bool refresh)

        {

            ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass();



            pMarkerSymbol.Color = pColor;

            pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

            pMarkerSymbol.Size = 3;

            IElement pEle;

            IMarkerElement pMe = new MarkerElementClass();

            pMe.Symbol = pMarkerSymbol;

            pEle = pMe as IElement;

            pEle.Geometry = pnt;



            IActiveView pav = pMapCtrl.ActiveView;

            IGraphicsContainer pGc = pMapCtrl.Map as IGraphicsContainer;

            pGc.AddElement(pEle, 0);

            if (refresh)

                pav.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

        }

        #endregion        


 
 

좋은 웹페이지 즐겨찾기