【039】Geometry 总结
---------------------------------------------------------------------------------------------------------
●·● 目录:
A1 ………… Geometry 总结
A2 ………… 绘制几何图形 —— 圆
A3 ………… 绘制几何图形 —— 椭圆
A4 ………… 绘制几何图形 —— 圆弧
A5 ………… 绘制几何图形 —— 椭圆弧
A6 ………… VS2008打开VS2010项目
A7 ………… Visual Studio 2008“分析 EntityName 时出错。 行 2,位置 81。”报错解决!
A8 ………… 类、接口等的引用传递的理解
A9 ………… DrawShape 与 AddElement 显示图形的区别
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A1个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Geometry 总结:
- Polyline:是 Path 的集合,可以实现 IGeometryCollection 接口,用于添加几何图形!
- Path:由 Segment 组成,可以实现 ISegmentCollection 接口,用于添加 Segment!
- Polygon:是 Ring 的集合,可以实现 IGeometryCollection 接口,用于添加几何图形!
- Ring:由 Segment 组成,可以实现 ISegmentCollection 接口,用于添加 Segment!
- Segment:包括 Line、CircularArc、EllipticArc、BezierCurve 四个!
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A2个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● 绘制几何图形 —— 圆:
- 构造圆心点,IPoint。
- 构造圆弧,IConstructCircularArc,通过此接口,利用圆心和半径来确定圆弧。
- 构造线段,ISegment,将圆弧转为线段接口,用于添加到下面的线段集合中。
- 构造线段集合,ISegmentCollection,将上面的线段添加进来。
- 构造环,IRing,将线段集合转为环接口,用于实现图形的 Close 。
- 构造几何图形集合:IGeometryCollection,将上面的环添加到几何图形集合中,然后就可以用了。
有填充颜色的:
IPoint pPoint = new PointClass(); pPoint.X = 110; pPoint.Y = 40; //构建圆对象 IConstructCircularArc pConstructCircularArc = new CircularArcClass(); pConstructCircularArc.ConstructCircle(pPoint, 20, false); ICircularArc pArc = pConstructCircularArc as ICircularArc; //不必要 ISegment pSegment1 = pArc as ISegment; //通过ISegmentCollection构建Ring对象 ISegmentCollection pSegCollection = new RingClass(); object o = Type.Missing; //添加Segement对象即圆 pSegCollection.AddSegment(pSegment1, ref o, ref o); //QI到IRing接口封闭Ring对象,使其有效 IRing pRing = pSegCollection as IRing; pRing.Close(); //通过Ring对象使用IGeometryCollection构建Polygon对象 IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); //构建一个CircleElement对象 IElement pElement = new CircleElementClass(); pElement.Geometry = pGeometryColl as IGeometry; IGraphicsContainer pGC = this.axMapControl1.ActiveView.GraphicsContainer; pGC.AddElement(pElement, 0); this.axMapControl1.Refresh();
没有填充颜色的,只需加入下面一句,使其为透明颜色即可!
pColor.Transparency = 0;
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A3个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● 绘制几何图形 —— 椭圆:
- 构造两个点,IPoint。
- 构造包络线也就是矩形,IEnvelope,通过上面的两个点。
- 构造圆弧,IConstructEllipticArc,通过此接口,利用矩形来确定椭圆弧。
- 构造线段,ISegment,将椭圆弧转为线段接口,用于添加到下面的线段集合中。
- 构造线段集合,ISegmentCollection,将上面的线段添加进来。
- 构造环,IRing,将线段集合转为环接口,用于实现图形的 Close 。
- 构造几何图形集合:IGeometryCollection,将上面的环添加到几何图形集合中,然后就可以用了。
有填充颜色的:
IPoint pPoint1 = new PointClass(); pPoint1.PutCoords(80, 20); IPoint pPoint2 = new PointClass(); pPoint2.PutCoords(130, 50); IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.LowerLeft = pPoint1; pEnvelope.UpperRight = pPoint2; IConstructEllipticArc pConstructEllipticArc = new EllipticArcClass(); pConstructEllipticArc.ConstructEnvelope(pEnvelope); IEllipticArc pEllipticArc = pConstructEllipticArc as IEllipticArc; //不必要 ISegment pSegment = pEllipticArc as ISegment; ISegmentCollection pSegmentCollection = new RingClass(); object o = Type.Missing; pSegmentCollection.AddSegment(pSegment, ref o, ref o); IRing pRing = pSegmentCollection as IRing; pRing.Close(); IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); ISimpleLineSymbol pSimpleLineSym = new SimpleLineSymbol(); pSimpleLineSym.Color = GetColor(0, 0, 0); pSimpleLineSym.Width = 2; ISimpleFillSymbol pSimpleFillSym = new SimpleFillSymbol(); IRgbColor pColor = new RgbColor(); pColor.Red = 255; pColor.Green = 255; pSimpleFillSym.Color = pColor; pSimpleFillSym.Outline = pSimpleLineSym; IElement pElement = new EllipseElementClass(); pElement.Geometry = pGeometryColl as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSym; IGraphicsContainer pGC = axMapControl1.ActiveView.GraphicsContainer; pGC.AddElement(pElement, 0); axMapControl1.Refresh();
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A4个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● 绘制几何图形 —— 圆弧:
- 构造圆心点,IPoint。
- 构造圆弧,IConstructCircularArc,通过此接口,利用圆心、半径、起始角度,中心角来确定圆弧。
- 构造线段,ISegment,将圆弧转为线段接口,用于添加到下面的线段集合中。
- 构造线段集合,ISegmentCollection,将上面的线段添加进来。
- 构造环或者路径,IRing or IPath,将线段集合转为环接口或是路径接口 。
- 构造几何图形集合:IGeometryCollection,将上面的环添加到几何图形集合中,然后就可以用了。
IPoint pPoint = new PointClass(); pPoint.X = 80; pPoint.Y = 40; IConstructCircularArc pConstructCircularArc = new CircularArcClass(); pConstructCircularArc.ConstructBearingRadiusAngle(pPoint, 0, false, 20, Math.PI*4/3); ICircularArc pArc = pConstructCircularArc as ICircularArc; //不必要 ISegment pSegment1 = pArc as ISegment; ISegmentCollection pSegCollection = new RingClass(); object o = Type.Missing; pSegCollection.AddSegment(pSegment1, ref o, ref o); IRing pRing = pSegCollection as IRing; //IPath pRing = pSegCollection as IPath; //也可以的 IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); ISimpleLineSymbol pSimpleLineSym = new SimpleLineSymbol(); pSimpleLineSym.Color = GetColor(0, 0, 0); pSimpleLineSym.Width = 2; ISimpleFillSymbol pSimpleFillSym = new SimpleFillSymbol(); IRgbColor pColor = new RgbColor(); pColor.RGB = 255; //pColor.Transparency = 0; //透明填充 pSimpleFillSym.Color = pColor; pSimpleFillSym.Outline = pSimpleLineSym; IElement pElement = new CircleElementClass(); IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; pFillShapeEle.Symbol = pSimpleFillSym; pElement.Geometry = pGeometryColl as IGeometry; IGraphicsContainer pGC = this.axMapControl1.ActiveView.GraphicsContainer; pGC.AddElement(pElement, 0); this.axMapControl1.Refresh();
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A5个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● 绘制几何图形 —— 椭圆弧:
1. 实现画¼圆弧:Construct an elliptic arc that starts at fromPoint, goes to toPoint, and spans an angle of pi/2. The rotation of the ellipse will be either 0 or pi/2.
IPoint pPoint1 = new PointClass(); pPoint1.PutCoords(105, 20); IPoint pPoint2 = new PointClass(); pPoint2.PutCoords(130, 35); IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.LowerLeft = pPoint1; pEnvelope.UpperRight = pPoint2; IConstructEllipticArc pConstructEllipticArc = new EllipticArcClass(); pConstructEllipticArc.ConstructQuarterEllipse(pPoint1, pPoint2, true); //第三个参数决定顺逆时针! ISegment pSegment = pConstructEllipticArc as ISegment; ISegmentCollection pSegmentCollection = new RingClass(); object o = Type.Missing; pSegmentCollection.AddSegment(pSegment, ref o, ref o); IRing pRing = pSegmentCollection as IRing; IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); ISimpleLineSymbol pSimpleLineSym = new SimpleLineSymbol(); pSimpleLineSym.Color = GetColor(0, 0, 0); pSimpleLineSym.Width = 2; ISimpleFillSymbol pSimpleFillSym = new SimpleFillSymbol(); IRgbColor pColor = new RgbColor(); pColor.Red = 255; pSimpleFillSym.Color = pColor; pSimpleFillSym.Outline = pSimpleLineSym; IElement pElement = new EllipseElementClass(); pElement.Geometry = pGeometryColl as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSym; IGraphicsContainer pGC = axMapControl1.ActiveView.GraphicsContainer; pGC.AddElement(pElement, 0); axMapControl1.Refresh();
2. 实现根据起始点,以及限制在一个矩形中:Construct an elliptic arc that starts at fromPoint, goes to toPoint, and tries to have the embedded ellipse inscribed in the suggestedEnvelope. The result will have rotation of 0 or pi/2.
IPoint pPoint1 = new PointClass(); pPoint1.PutCoords(80, 20); IPoint pPoint2 = new PointClass(); pPoint2.PutCoords(130, 50); IPoint pPoint3 = new PointClass(); pPoint3.PutCoords(50, 20); IPoint pPoint4 = new PointClass(); pPoint4.PutCoords(140, 60); IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.LowerLeft = pPoint3; pEnvelope.UpperRight = pPoint4; IConstructEllipticArc pConstructEllipticArc = new EllipticArcClass(); pConstructEllipticArc.ConstructTwoPointsEnvelope(pPoint1, pPoint2, pEnvelope, esriArcOrientation.esriArcMajor); ISegment pSegment = pConstructEllipticArc as ISegment; ISegmentCollection pSegmentCollection = new RingClass(); object o = Type.Missing; pSegmentCollection.AddSegment(pSegment, ref o, ref o); IRing pRing = pSegmentCollection as IRing; IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); ISimpleLineSymbol pSimpleLineSym = new SimpleLineSymbol(); pSimpleLineSym.Color = GetColor(0, 0, 0); pSimpleLineSym.Width = 2; ISimpleFillSymbol pSimpleFillSym = new SimpleFillSymbol(); IRgbColor pColor = new RgbColor(); pColor.Red = 255; pColor.Transparency = 0; pSimpleFillSym.Color = pColor; pSimpleFillSym.Outline = pSimpleLineSym; IElement pElement2 = new RectangleElementClass(); pElement2.Geometry = pEnvelope; IFillShapeElement pFillShapeElement2 = pElement2 as IFillShapeElement; pFillShapeElement2.Symbol = pSimpleFillSym; IElement pElement = new EllipseElementClass(); pElement.Geometry = pGeometryColl as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pColor.Transparency = 1; pSimpleFillSym.Color = pColor; pFillShapeElement.Symbol = pSimpleFillSym; IGraphicsContainer pGC = axMapControl1.ActiveView.GraphicsContainer; pGC.AddElement(pElement, 0); pGC.AddElement(pElement2, 0); axMapControl1.Refresh();
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A6个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● 绘制几何图形 —— 椭圆:
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A7个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● 绘制几何图形 —— 椭圆:
posted on 2012-05-03 14:38 McDelfino 阅读(2192) 评论(6) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)