【039】Geometry 總結


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

●·● 目錄:

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個    ╠══════════════════════════════════════════════════╣
            ╚════════╝

·繪制幾何圖形 —— 橢圓

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM