SkylineGlobe 6.5 如何?簡單多邊形的動態繪製 C#範例程式碼

來源:互聯網
上載者:User

標籤:

在Skyline的TEPro軟體中,我們可以很容易地繪製出多邊形。

那麼,在二次開發過程中,該如何繪製一個簡單的多邊形呢?

通過下面的範例程式碼,我們可以很容易完成這一項工作。

其中,重點需要瞭解Geometry對象的定義和使用。

  1 using System;  2 using System.Collections.Generic;  3 using System.ComponentModel;  4 using System.Data;  5 using System.Drawing;  6 using System.Linq;  7 using System.Text;  8 using System.Windows.Forms;  9 using TerraExplorerX; 10  11 namespace HelloSkyline 12 { 13     public partial class CTerrainPolygon: Form 14     { 15         SGWorld65 sgworld = null; 16         String pbhander = "";         17         ITerrainPolygon65 pITPolygon = null; 18         List<double> ListVerticsArray = new List<double>(); 19  20         public CTerrainPolygon() 21         { 22             InitializeComponent(); 23  24             sgworld = new SGWorld65(); 25             sgworld.OnLButtonDown += new _ISGWorld65Events_OnLButtonDownEventHandler(sgworld_OnLButtonDown); 26             sgworld.OnRButtonDown += new _ISGWorld65Events_OnRButtonDownEventHandler(sgworld_OnRButtonDown); 27         } 28  29         bool sgworld_OnRButtonDown(int Flags, int X, int Y) 30         { 31             sgworld.Window.SetInputMode(MouseInputMode.MI_FREE_FLIGHT); 32             pbhander = ""; 33             pITPolygon = null;             34             return true; 35         } 36  37         bool sgworld_OnLButtonDown(int Flags, int X, int Y) 38         { 39             IWorldPointInfo65 pIWPInfo = sgworld.Window.PixelToWorld(X, Y, WorldPointType.WPT_TERRAIN); 40             IPosition65 pIPosition = sgworld.Navigate.GetPosition(AltitudeTypeCode.ATC_ON_TERRAIN); 41  42             if (pbhander == "TerrainPolygon") 43             { 44                 if (pITPolygon == null) 45                 { 46                     ILinearRing cRing = null; 47                     double[] cVerticesArray = null; 48                     cVerticesArray = new double[] { 49                         pIPosition.X,  pIPosition.Y,  0,  50                         pIWPInfo.Position.X,  pIWPInfo.Position.Y,  pIWPInfo.Position.Distance,   51                         pIWPInfo.Position.X,  pIWPInfo.Position.Y,  pIWPInfo.Position.Distance,                          52                             }; 53                     cRing = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray); 54                      55                     uint nLineColor = 0xFF00FF00; 56                     uint nFillColor = 0x7FFF0000; 57                     AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_ON_TERRAIN; 58                     string gid = CreateGroup("AnalysisTEMP"); 59                     pITPolygon = sgworld.Creator.CreatePolygon(cRing, nLineColor, nFillColor, eAltitudeTypeCode, gid, "Polygon"); 60  61                     IPolygon polygonGeometry = pITPolygon.Geometry as IPolygon; 62                     polygonGeometry.StartEdit(); 63                     foreach (ILinearRing ring in polygonGeometry.Rings) 64                     { 65                         double dx = pIWPInfo.Position.X; 66                         double dy = pIWPInfo.Position.Y; 67                         double dh = pIWPInfo.Position.Distance;                         68                         ring.Points.AddPoint(dx, dy, dh); 69                         ring.Points.DeletePoint(0); 70                     } 71                     IGeometry editedGeometry = polygonGeometry.EndEdit(); 72                     pITPolygon.Geometry = editedGeometry;                 73                 } 74                 else 75                 { 76                     IPolygon polygonGeometry = pITPolygon.Geometry as IPolygon; 77                     polygonGeometry.StartEdit(); 78                     foreach (ILinearRing ring in polygonGeometry.Rings) 79                     { 80                         double dx = pIWPInfo.Position.X; 81                         double dy = pIWPInfo.Position.Y; 82                         double dh = pIWPInfo.Position.Distance; 83                         ring.Points.AddPoint(dx, dy, dh); 84                     } 85                     IGeometry editedGeometry = polygonGeometry.EndEdit(); 86                     pITPolygon.Geometry = editedGeometry;                     87                 } 88             } 89             return false; 90         } 91  92         private void button1_Click(object sender, EventArgs e) 93         { 94             pbhander = "TerrainPolygon"; 95             sgworld.Window.SetInputMode(MouseInputMode.MI_COM_CLIENT); 96         } 97  98         private void button2_Click(object sender, EventArgs e) 99         {100             string gid = sgworld.ProjectTree.FindItem("AnalysisTEMP");101             if (gid != null && gid != "")102             {103                 sgworld.ProjectTree.DeleteItem(gid);104             }105         }106 107         private String CreateGroup(String GroupName)108         {109             string gid = sgworld.ProjectTree.FindItem(GroupName);110             if (gid != null && gid != "")111             {112                 return gid;113             }114             else115             {116                 return sgworld.ProjectTree.CreateLockedGroup(GroupName);117             }            118         }119     }120 }

 

SkylineGlobe 6.5 如何?簡單多邊形的動態繪製 C#範例程式碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.