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, ITerrainPolygon81, ICreator81 (CreatePolygon, GeometryCreator), IGeometryCreator (CreateLinearRingGeometry, CreatePolygonGeometry) INavigate81 (FlyTo), and IPosition81 (Copy, Pitch) properties and methods.

 

private void GeometryPolygon()

        {

            string tMsg = String.Empty;

            double[] cVerticesArray = null;

            ILinearRing cRing = null;

            IGeometry cPolygonGeometry = null;

            ITerrainPolygon81 cPolygon = null;

 

            try

            {

                //

                // A. Instantiate TerraExplorer Object

                //

                var SGWorld = newSGWorld81();

 

                //

                // B.  Create linear ring

                //

                {

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

                    cVerticesArray = newdouble[] {

                        -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

                    uintnLineColor = 0xFF00FF00; // Abgr value -> solid green

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

                    AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;

 

                    // D2. Create polygon

                    cPolygon = SGWorld.Creator.CreatePolygon(cPolygonGeometry, nLineColor, nFillColor, eAltitudeTypeCode, string.Empty, "Polygon");

                }

 

                //

                // E. FlyTo polygon

                //

                {

                    varcFlyToPos = 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);

            }

        }