Creating a Polygon

This example demonstrates how to create a polygon using an array of vertices and set basic properties. This example uses the ILinearRing, IGeometry, ITerrainPolygon61, ICreator61 (CreatePolygon, GeometryCreator), IGeometryCreator (CreateLinearRingGeometry, CreatePolygonGeometry) INavigate61 (FlyTo), and IPosition61 (Copy, Pitch) properties and methods.

 

privatevoid GeometryPolygon()

        {

            string tMsg = String.Empty;

            double[] cVerticesArray = null;

            ILinearRing cRing = null;

            IGeometry cPolygonGeometry = null;

            ITerrainPolygon61 cPolygon = null;

           

            try

            {

                //

                // A. Instantiate Terra Explorer Globe

                //

                SGWorld61 sgworld = new SGWorld61();

 

                //

                // B.  Create linear ring

                //

                {

                    //B1. Create vertices double array, each point in format x,y,z

                    cVerticesArray = new double[] {

                        -122.415025,  37.76059,  10, 

                        -122.415868,  37.760546, 11, 

                        -122.415922,  37.761244, 12, 

                        -122.415592,  37.761254, 13, 

                        -122.415557,  37.760973, 14, 

                        -122.415081,  37.76099,  15, 

                    };

 

 

                    // B2. Create linear ring using vertices

                    {

                        cRing = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray);

                    }

                }

 

                //

                // C. Create polygon geometry using linear ring

                //

                {

                    cPolygonGeometry = sgworld.Creator.GeometryCreator.CreatePolygonGeometry(cRing, null);

                }

 

                //

                // D. Create polygon using polygon geometry

                //

                {

                    // D1. Set polygon input params

                    uint nLineColor = 0xFF00FF00; // Abgr value -> solid green

                    uint nFillColor = 0x7FFF0000; // Abgr value -> 50% transparent blue

                    AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;

 

                    // D2. Create polygon

                    cPolygon = sgworld.Creator.CreatePolygon(cPolygonGeometry, nLineColor, nFillColor, eAltitudeTypeCode, 0, "Polygon");

                }

 

                //

                // E. FlyTo polygon

                //

                {

                    IPosition61 cFlyToPos = cPolygon.Position.Copy();

                    cFlyToPos.Pitch = -89.0; // Set camera to look downward on polygon

                    sgworld.Navigate.FlyTo(cFlyToPos, ActionCode.AC_FLYTO);

                }

            }

            catch (Exception ex)

            {

                tMsg = String.Format("GeometryPolygon_Click Exception: {0}", ex.Message);

                MessageBox.Show(tMsg);

            }

        }