现在的位置: 首页 > 综合 > 正文

【039】Geometry 总结

2012年05月13日 ⁄ 综合 ⁄ 共 9524字 ⁄ 字号 评论关闭

---------------------------------------------------------------------------------------------------------

●·● 目录:

A1 ………… Geometry 总结
A2 ………… 绘制几何图形 —— 圆
A3 ………… 绘制几何图形 —— 椭圆
A4 ………… 绘制几何图形 —— 圆弧
A5 ………… 绘制几何图形 —— 椭圆弧
A6 ………… VS2008打开VS2010项目
A7 ………… Visual Studio 2008“分析 EntityName 时出错。 行 2,位置 81。”报错解决!
A8 ………… 类、接口等的引用传递的理解
A9 ………… DrawShape 与 AddElement 显示图形的区别

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣    第A1个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

·Geometry 总结

  1. Polyline:是 Path 的集合,可以实现 IGeometryCollection 接口,用于添加几何图形!

  2. Path:由 Segment 组成,可以实现 ISegmentCollection 接口,用于添加 Segment!
  3. Polygon:是 Ring 的集合,可以实现 IGeometryCollection 接口,用于添加几何图形!
  4. Ring:由 Segment 组成,可以实现 ISegmentCollection 接口,用于添加 Segment!
  5. Segment:包括 Line、CircularArc、EllipticArc、BezierCurve 四个!

---------------------------------------------------------------------------------------------------------

            ╔════════╗
╠════╣    第A2个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

·绘制几何图形 —— 圆

  1. 构造圆心点,IPoint。

  2. 构造圆弧,IConstructCircularArc,通过此接口,利用圆心和半径来确定圆弧。
  3. 构造线段,ISegment,将圆弧转为线段接口,用于添加到下面的线段集合中。
  4. 构造线段集合,ISegmentCollection,将上面的线段添加进来。
  5. 构造环,IRing,将线段集合转为环接口,用于实现图形的 Close 。
  6. 构造几何图形集合: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个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

·绘制几何图形 —— 椭圆

  1. 构造两个点,IPoint。

  2. 构造包络线也就是矩形,IEnvelope,通过上面的两个点。
  3. 构造圆弧,IConstructEllipticArc,通过此接口,利用矩形来确定椭圆弧。
  4. 构造线段,ISegment,将椭圆弧转为线段接口,用于添加到下面的线段集合中。
  5. 构造线段集合,ISegmentCollection,将上面的线段添加进来。
  6. 构造环,IRing,将线段集合转为环接口,用于实现图形的 Close 。
  7. 构造几何图形集合: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个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

·绘制几何图形 —— 圆弧

  1. 构造圆心点,IPoint。
  2. 构造圆弧,IConstructCircularArc,通过此接口,利用圆心、半径、起始角度,中心角来确定圆弧。
  3. 构造线段,ISegment,将圆弧转为线段接口,用于添加到下面的线段集合中。
  4. 构造线段集合,ISegmentCollection,将上面的线段添加进来。
  5. 构造环或者路径,IRing or IPath,将线段集合转为环接口或是路径接口 。
  6. 构造几何图形集合: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个    ╠══════════════════════════════════════════════════╣
            ╚════════╝

·绘制几何图形 —— 椭圆

 

 

抱歉!评论已关闭.