首页 > 其他 > 详细

ArcEngine开发:IElement.Geometry 值不在预期范围内 + 元素绘制代码

时间:2014-03-23 10:00:47      阅读:734      评论:0      收藏:0      [点我收藏+]

IElement pEle = pLineEle as IElement;

pEle.Geometry = pLn;

 

pLn为一个ILine对象,想当然的以为它是IGeometry对象,可以赋值,结果爆出异常值不在预期范围内。

解决方法是将ILine转换为IPolyline对象,涉及到一些Geometry的基本操作。贴出一些可用的绘制元素的代码

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#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       

ArcEngine开发:IElement.Geometry 值不在预期范围内 + 元素绘制代码,布布扣,bubuko.com

ArcEngine开发:IElement.Geometry 值不在预期范围内 + 元素绘制代码

原文:http://www.cnblogs.com/DayDreamEveryWhere/p/3617049.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!