ArcObjects Library Reference  

GeodesyMapControl

About the Geodesy MapControl Sample

[C#]

GeodesyMapControl.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.DefenseSolutions;

namespace GeodesyMapControl
{
    public partial class GeodesyMapControl : Form
    {

    private ESRI.ArcGIS.esriSystem.IAoInitialize m_pAOInitialize;
    private ESRI.ArcGIS.DefenseSolutions.IGeoEllipse m_pGeoEllipse;
    private ESRI.ArcGIS.DefenseSolutions.IMeasurementTool m_pMeasureTool;
    private ESRI.ArcGIS.Geometry.IPolygon m_pKeyPointPoly;
    private ESRI.ArcGIS.DefenseSolutions.IGeoPolygon m_pGeoPolygon;
    private ESRI.ArcGIS.Geometry.IPoint m_pOrigin;
    private ESRI.ArcGIS.DefenseSolutions.IGeoPolyline m_pGeoPolyline;
    private ESRI.ArcGIS.Geometry.IPolyline m_pPolyline;
    private ESRI.ArcGIS.Carto.IElement m_pKeyPointElement;
    private ESRI.ArcGIS.Carto.IElement m_pEllipseElement;
    private ESRI.ArcGIS.Carto.IElement m_pLineElement;
    private ESRI.ArcGIS.Controls.AxMapControl m_pMapControl;
    private ESRI.ArcGIS.Carto.IActiveView m_pActiveView;
    private ESRI.ArcGIS.Carto.IGraphicsContainer m_pGraphicsCont;

    const string con_strGeo = @"Geodesic";
    const string con_strGC = @"Great Circle";
    const string con_strRhumb = @"Rhumb Line";

        public GeodesyMapControl() 
        {
            InitializeComponent();

            m_pAOInitialize = new ESRI.ArcGIS.esriSystem.AoInitialize();
            ESRI.ArcGIS.esriSystem.esriLicenseStatus status;

            status = m_pAOInitialize.IsProductCodeAvailable(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);

            if (status != ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseAvailable)
                {
                System.Windows.Forms.MessageBox.Show(@"ERROR: license not available." + Environment.NewLine + status);
                this.Dispose();
                }
            else
                {
                status = m_pAOInitialize.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
                }
            
            m_pMapControl = (ESRI.ArcGIS.Controls.AxMapControl) this.MapControl1;
            m_pMapControl.AddLayerFromFile(GetSdkDataPath() + @"World\Continents.lyr");                   

            cboType.Items.Insert(0, con_strGeo);
            cboType.Items.Insert(1, con_strGeo);
            cboType.Items.Insert(2, con_strRhumb);
            cboType.Text = con_strGeo;

        }

        ~GeodesyMapControl()
        {
            m_pGeoEllipse = null;
            m_pMeasureTool = null;
            m_pKeyPointPoly = null;
            m_pOrigin = null;
            m_pGeoPolyline = null;
            m_pKeyPointElement = null;
            m_pLineElement = null;
            m_pMapControl = null;
            m_pActiveView = null;
            m_pGraphicsCont = null;
        }

        #region "Form Functions"

        private void cmdClearGraphics_Click(object sender, EventArgs e)
        {
            // Clear all graphic elements from the map control
            SetGraphicsContainer();
            m_pGraphicsCont.DeleteAllElements();
            m_pActiveView.Refresh();
        }

        private void cmdDrawLine_Click(object sender, EventArgs e)
        {
            try
            {

                // Create Geometry
                CreateGeoPolyline();

                if (m_pGeoPolyline == null)
                {
                    return;
                }

                // create the IElement to be rendered as a GeoPolylineElement and
                // set its geometry to the GeoPolyline geometry defined in the
                // CreateGeoPolyline subprocedure
                m_pLineElement = (IElement) new ESRI.ArcGIS.DefenseSolutions.GeoPolylineElement();
                m_pLineElement.Geometry = (IGeometry) m_pGeoPolyline;

                // QI to ILineElement to set the symbology of the GeoPolyline graphic
                ESRI.ArcGIS.Carto.ILineElement pLineElement;
                pLineElement = (ILineElement) m_pLineElement;
                pLineElement.Symbol = (ILineSymbol) GeoLineSymbol();

                // Define the graphics container and draw the GeoPolyline graphic. Display the
                // distance and azimuth of the GeoPolyline as calculated by the measurement tool.
                SetGraphicsContainer();
                m_pGraphicsCont.AddElement((IElement) pLineElement, 0);
                m_pActiveView.Refresh();
                double dDist = Math.Round((m_pMeasureTool.Distance / 1000), 6);
                double dAzim = Math.Round(m_pMeasureTool.Angle, 6);
                txtDistance.Text = dDist.ToString();
                txtAzimuth.Text = dAzim.ToString();
             }
            catch (Exception error)
            {
                System.Windows.Forms.MessageBox.Show(error.Message, "ERROR");
            }


        }

        private void cmdClearLineFields_Click(object sender, EventArgs e)
        {
            txtStartX.Text = "";
            txtStartY.Text = "";
            txtEndX.Text = "";
            txtEndY.Text = "";
            txtDistance.Text = "";
            txtAzimuth.Text = "";
        }

        private void cmdAddEllipse_Click(object sender, EventArgs e)
        {
            try
            {
                // create GeoEllipse geometry
                CreateGeoEllipse();

                if (m_pGeoEllipse == null)
                {
                    return;
                }

                // create the IElement to be rendered as a GeoEllipseElement and
                // set its geometry to the GeoEllipse geometry defined in the
                m_pEllipseElement = (IElement) new ESRI.ArcGIS.DefenseSolutions.GeoEllipseElement();
                m_pEllipseElement.Geometry = (IGeometry) m_pGeoEllipse;

                // outline color
                ESRI.ArcGIS.Display.IRgbColor pColor = new ESRI.ArcGIS.Display.RgbColor();
                pColor.Green = 255;

                // make fill color null
                ESRI.ArcGIS.Display.IColor pNullColor = new ESRI.ArcGIS.Display.RgbColor();
                pNullColor.NullColor = true;

                // create the line symbol for the polygon outline
                ESRI.ArcGIS.Display.ILineSymbol pLineSymbol= new ESRI.ArcGIS.Display.SimpleLineSymbol();
                pLineSymbol.Color = pColor;
                pLineSymbol.Width = 2;

                // create the fill symbol
                ESRI.ArcGIS.Display.IFillSymbol pFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbol();
                pFillSymbol.Outline = pLineSymbol;
                pFillSymbol.Color = pNullColor;

                // QI to IFillShapeElement to set the symbology of the GeoEllipse graphic
                ESRI.ArcGIS.Carto.IFillShapeElement pFillElement = (IFillShapeElement) m_pEllipseElement;
                pFillElement.Symbol = pFillSymbol;

                // define the graphics container and draw the GeoEllipse graphic
                SetGraphicsContainer();
                m_pGraphicsCont.AddElement((IElement) pFillElement, 0);
                m_pActiveView.Refresh();


            }
            catch (Exception error)
            {
                System.Windows.Forms.MessageBox.Show(error.Message, "ERROR");
            }
        }

        private void cmdKeyPoints_Click(object sender, EventArgs e)
        {
            try
            {

                // Run the CreateGeoEllipse subprocedure to get the geometry of the
                // key points polygon generated from the GeoEllipse.
                CreateGeoEllipse();
                if ((m_pGeoEllipse == null) || (m_pKeyPointPoly == null))
                {
                    return;
                }

                // outline color
                ESRI.ArcGIS.Display.IRgbColor pColor = new ESRI.ArcGIS.Display.RgbColor();
                pColor.Green = 255;

                // make fill color null
                ESRI.ArcGIS.Display.IColor pNullColor = new ESRI.ArcGIS.Display.RgbColor();
                pNullColor.NullColor = true;

                // create the outline symbol
                ESRI.ArcGIS.Display.ILineSymbol pLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol();
                pLineSymbol.Color = pColor;
                pLineSymbol.Width = 1.5;
                ESRI.ArcGIS.Display.IHashLineSymbol pHashLineSymbol = new ESRI.ArcGIS.Display.HashLineSymbol();
                pHashLineSymbol.HashSymbol = pLineSymbol;

                // create the fill symbol for the polygon
                ESRI.ArcGIS.Display.IFillSymbol pFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbol();
                pFillSymbol.Outline = pHashLineSymbol;
                pFillSymbol.Color = pNullColor;

                // create the IElement to be rendered as a PolygonElement and
                // set its geometry to the key points polygon geometry defined in the
                // CreateGeoEllipse subprocedure
                m_pKeyPointElement = new ESRI.ArcGIS.Carto.PolygonElement();
                m_pKeyPointElement.Geometry = m_pKeyPointPoly;

                // QI to IFillShapeElement to set the symbology of the key points polygon graphic
                ESRI.ArcGIS.Carto.IFillShapeElement pFillElement;
                pFillElement = (IFillShapeElement) m_pKeyPointElement;
                pFillElement.Symbol = pFillSymbol;

                // define the graphics container and draw the key points polygon graphic
                SetGraphicsContainer();
                m_pGraphicsCont.AddElement((IElement) pFillElement, 0);
                m_pActiveView.Refresh();
            }
            catch (Exception error)
            {
                System.Windows.Forms.MessageBox.Show(error.Message, "ERROR");
            }
        }

        private void cmdClearEllipseFields_Click(object sender, EventArgs e)
        {
            txtCenterX.Text = "";
            txtCenterY.Text = "";
            txtXAxis.Text = "";
            txtYAxis.Text = "";
            txtRotation.Text = "";
        }

        private void MapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            try
            {
                // On a right mouse button click use the TrackPolygon method on the map control
                // to define the vertices of an eventual GeoPolygon. Each right mouse button
                // click adds a vertex to the polygon; double-clicking the right mouse button
                // completes the polygon.
                ESRI.ArcGIS.Geometry.IPolygon pTrackPoly;
                ESRI.ArcGIS.Carto.IElement pTrackPolyElement;

                if (e.button == 2)
                {

                    // Create the polygon from the TrackPolygon method. This polygon will be
                    // the foundation for a GeoPolygon object.
                    pTrackPoly = (IPolygon)MapControl1.TrackPolygon();

                    // Define the GeoPolygon, QI to IGeoPolygon
                    m_pGeoPolygon = new ESRI.ArcGIS.DefenseSolutions.GeoPolygon();
                    m_pGeoPolygon.Polygon = pTrackPoly;

                    // Set the GeoPolyline type to form the segments of the GeoPolygon. In this case
                    // the segments will be Geodesic lines.
                    m_pGeoPolygon.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGeodesic;

                    // Set the GeoPolygon spatial reference.
                    m_pGeoPolygon.BaseSpatialReference = GetWGS84SpatialRef();

                    // outline color
                    ESRI.ArcGIS.Display.IRgbColor pColor = new ESRI.ArcGIS.Display.RgbColor();
                    pColor.Blue = 255;

                    // make fill color null
                    ESRI.ArcGIS.Display.IColor pNullColor = new ESRI.ArcGIS.Display.RgbColor();
                    pNullColor.NullColor = true;

                    // create the outline symbol
                    ESRI.ArcGIS.Display.ILineSymbol pLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol();
                    pLineSymbol.Color = pColor;
                    pLineSymbol.Width = 1.5;

                    // create the fill symbol for the GeoPolygon
                    ESRI.ArcGIS.Display.IFillSymbol pFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbol();
                    pFillSymbol.Outline = pLineSymbol;
                    pFillSymbol.Color = pNullColor;

                    // Create the IElement to be rendered as a GeoPolygonElement and
                    // set its geometry to the GeoPolygon geometry. When a GeoPolygonElement
                    // graphic is moved from one location to another in the map control
                    // the GeoPolygon geometry is automatically updated based on the
                    // geographic location and the graphic is updated accordingly.
                    pTrackPolyElement = (IElement)new ESRI.ArcGIS.DefenseSolutions.GeoPolygonElement();
                    pTrackPolyElement.Geometry = (IGeometry)m_pGeoPolygon;

                    // QI to IFillShapeElement to set the symbology of the GeoPolygon graphic
                    ESRI.ArcGIS.Carto.IFillShapeElement pFillElement;
                    pFillElement = (IFillShapeElement)pTrackPolyElement;
                    pFillElement.Symbol = pFillSymbol;

                    // define the graphics container and draw the key points polygon graphic
                    SetGraphicsContainer();
                    m_pGraphicsCont.AddElement((IElement)pFillElement, 0);
                    m_pActiveView.Refresh();

                }
                else
                {
                    pTrackPoly = null;
                }

            }
            catch (Exception error)
            {
                System.Windows.Forms.MessageBox.Show(error.Message, "ERROR");
            }

        }

        //private void MapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        //{
        //    try
        //    {
        //        // On a right mouse button click use the TrackPolygon method on the map control
        //        // to define the vertices of an eventual GeoPolygon. Each right mouse button
        //        // click adds a vertex to the polygon; double-clicking the right mouse button
        //        // completes the polygon.
        //        ESRI.ArcGIS.Geometry.IPolygon pTrackPoly;
        //        ESRI.ArcGIS.Carto.IElement pTrackPolyElement;

        //        if (e.button == 2)
        //        {

        //            // Create the polygon from the TrackPolygon method. This polygon will be
        //            // the foundation for a GeoPolygon object.
        //            pTrackPoly = (IPolygon)MapControl1.TrackPolygon();

        //            // Define the GeoPolygon, QI to IGeoPolygon
        //            m_pGeoPolygon = new ESRI.ArcGIS.DefenseSolutions.GeoPolygon();
        //            m_pGeoPolygon.Polygon = pTrackPoly;

        //            // Set the GeoPolyline type to form the segments of the GeoPolygon. In this case
        //            // the segments will be Geodesic lines.
        //            m_pGeoPolygon.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGeodesic;

        //            // Set the GeoPolygon spatial reference.
        //            m_pGeoPolygon.BaseSpatialReference = GetWGS84SpatialRef();

        //            // outline color
        //            ESRI.ArcGIS.Display.IRgbColor pColor = new ESRI.ArcGIS.Display.RgbColor();
        //            pColor.Blue = 255;

        //            // make fill color null
        //            ESRI.ArcGIS.Display.IColor pNullColor = new ESRI.ArcGIS.Display.RgbColor();
        //            pNullColor.NullColor = true;

        //            // create the outline symbol
        //            ESRI.ArcGIS.Display.ILineSymbol pLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol();
        //            pLineSymbol.Color = pColor;
        //            pLineSymbol.Width = 1.5;

        //            // create the fill symbol for the GeoPolygon
        //            ESRI.ArcGIS.Display.IFillSymbol pFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbol();
        //            pFillSymbol.Outline = pLineSymbol;
        //            pFillSymbol.Color = pNullColor;

        //            // Create the IElement to be rendered as a GeoPolygonElement and
        //            // set its geometry to the GeoPolygon geometry. When a GeoPolygonElement
        //            // graphic is moved from one location to another in the map control
        //            // the GeoPolygon geometry is automatically updated based on the
        //            // geographic location and the graphic is updated accordingly.
        //            pTrackPolyElement = (IElement)new ESRI.ArcGIS.DefenseSolutions.GeoPolygonElement();
        //            pTrackPolyElement.Geometry = (IGeometry)m_pGeoPolygon;

        //            // QI to IFillShapeElement to set the symbology of the GeoPolygon graphic
        //            ESRI.ArcGIS.Carto.IFillShapeElement pFillElement;
        //            pFillElement = (IFillShapeElement)pTrackPolyElement;
        //            pFillElement.Symbol = pFillSymbol;

        //            // define the graphics container and draw the key points polygon graphic
        //            SetGraphicsContainer();
        //            m_pGraphicsCont.AddElement((IElement)pFillElement, 0);
        //            m_pActiveView.Refresh();

        //        }
        //        else
        //        {
        //            pTrackPoly = null;
        //        }

        //    }
        //    catch (Exception error)
        //    {
        //        System.Windows.Forms.MessageBox.Show(error.Message, "ERROR");
        //    }
        //}


        #endregion

        #region "Helper Methods"

        public ESRI.ArcGIS.Geometry.ISpatialReference2 GetWGS84SpatialRef()
        {
            // Define the spatial reference to be used for geopolylines,
            // geoellipses, and geopolygons.
            ESRI.ArcGIS.Geometry.ISpatialReference2 pSpatRef; 
            ESRI.ArcGIS.Geometry.ISpatialReferenceFactory2 pSpatRefFact = (ISpatialReferenceFactory2) new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment();
            pSpatRef = (ISpatialReference2) pSpatRefFact.CreateSpatialReference((int) ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
            return pSpatRef;
        }

        public void SetGraphicsContainer()
        {
            //Define the graphics container to be the map control's active view
            m_pMapControl = (ESRI.ArcGIS.Controls.AxMapControl) MapControl1;
            m_pActiveView = m_pMapControl.ActiveView;
            m_pGraphicsCont = m_pActiveView.GraphicsContainer;
        }

        public void CreateGeoEllipse()
        {

            try
            {
                // reset the geoellipse and key point geometries
                m_pGeoEllipse = null;
                m_pKeyPointPoly = null;

                if (ValidateEllipseValues() == false)
                {
                    return;
                }

                // define the geoellipse
                m_pGeoEllipse = new ESRI.ArcGIS.DefenseSolutions.GeoEllipse();

                // define the geoellipse center point coordinates
                m_pOrigin = new ESRI.ArcGIS.Geometry.Point();
                double dX = System.Convert.ToDouble(txtCenterX.Text);
                double dY = System.Convert.ToDouble(txtCenterY.Text);
                m_pOrigin.PutCoords(dX, dY);

                // define the geoellipse spatial reference
                m_pGeoEllipse.BaseSpatialReference = GetWGS84SpatialRef();

                // set the lengths of the X and Y axes in kilometers
                m_pGeoEllipse.AxisX = (System.Convert.ToDouble(txtXAxis.Text) * 1000);
                m_pGeoEllipse.AxisY = (System.Convert.ToDouble(txtYAxis.Text) * 1000);

                // set the origin, or center point, of the geoellipse
                m_pGeoEllipse.Origin = m_pOrigin;


                // if the rotation is not given, use 0 as the default
                if (txtRotation.Text == "")
                {
                    txtRotation.Text = "0";
                }

                // define the amount of rotation, in degrees from
                // zero (north), of the geoellipse Y axis
                m_pGeoEllipse.Rotation = (System.Convert.ToDouble(txtRotation.Text) % 360);

                // set the number of vertices to be used in the creation
                // of the polygon representation of the geoellipse
                m_pGeoEllipse.GeoEllipsePointCount = 100;

                // define the key points polygon, which is a polygon connecting the end
                // points of the geoellipse X and Y axes
                m_pKeyPointPoly = m_pGeoEllipse.KeyPoints;

            }
            catch (Exception error)
            {
                System.Windows.Forms.MessageBox.Show(error.Message, "ERROR");
            }
        }

        public void CreateGeoPolyline()
        {
            try
            {
                // reset the polyline geometry
                m_pGeoPolyline = null;

                if (ValidatePolylineValues() == false)
                {
                    return;
                }

                // Set the measurement tool and the GeoPolyline. The measurement tool
                // will be used to calculate the distance and azimuth of the GeoPolyline
                // based on the start and end point coordinates of the line
                m_pGeoPolyline = new ESRI.ArcGIS.DefenseSolutions.GeoPolyline();
                m_pMeasureTool = new ESRI.ArcGIS.DefenseSolutions.MeasurementTool();

                // Get the GeoPolyline type from the Type dropdown list and set it as
                // the type for both the measurement tool and the GeoPolyline. The options
                // are Geodesic, Great Circle, and Rhumb Line.
                string strType;
                strType = cboType.SelectedItem.ToString();
                switch (strType)
                {
                    case con_strGeo:
                        m_pMeasureTool.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGeodesic;
                        m_pGeoPolyline.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGeodesic;
                        break;
                    case con_strGC:
                        m_pMeasureTool.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGreatCircle;
                        m_pGeoPolyline.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGreatCircle;
                        break;
                    case con_strRhumb:
                        m_pMeasureTool.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTRhumbLine;
                        m_pGeoPolyline.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTRhumbLine;
                        break;
                }

                // set the measurement tool spatial reference
                m_pMeasureTool.SpecialSpatialReference = GetWGS84SpatialRef();

                // Set start and end points for the measurement tool calculation
                // and the polyline from which the GeoPolyline is derived. The points
                // are created based on the decimal degree coordinates input into
                // the Start Point and End Point text boxes
                double dStartX = System.Convert.ToDouble(txtStartX.Text);
                double dStartY = System.Convert.ToDouble(txtStartY.Text);
                double dEndX = System.Convert.ToDouble(txtEndX.Text);
                double dEndY = System.Convert.ToDouble(txtEndY.Text);
                ESRI.ArcGIS.Geometry.IPoint pStartPoint = new ESRI.ArcGIS.Geometry.Point();
                ESRI.ArcGIS.Geometry.IPoint pEndPoint = new ESRI.ArcGIS.Geometry.Point();
                pStartPoint.PutCoords(dStartX, dStartY);
                pEndPoint.PutCoords(dEndX, dEndY);

                // Calculate the distance and azimuth of the GeoPolyline using the
                // ConstructByPoints method on the measurement tool. These values
                // will be displayed in the Distance and Azimuth text boxes
                m_pMeasureTool.ConstructByPoints(pStartPoint, pEndPoint);

                // Create the simple polyline which is the basis for the geometry of the GeoPolyline.
                m_pPolyline = new ESRI.ArcGIS.Geometry.PolylineClass();
                m_pPolyline.FromPoint = pStartPoint;
                m_pPolyline.ToPoint = pEndPoint;
                m_pPolyline.Project(GetWGS84SpatialRef());


                // QI to IGeoPolyLine to define the GeoPolyline. Set the base geometry of the
                // geopolyline to the polyline created from the start and end point coordinates
                // defined in the X and Y fields. Specify the number of vertices by which to densify
                // the GeoPolyline as a percentage of the total distance of the line. In this
                // case a vertex will be placed at every 1% of the line's total distance.
                m_pGeoPolyline.Polyline = m_pPolyline;
                m_pGeoPolyline.MaxPercent = 0.01;
                m_pGeoPolyline.UsePercent = true;

            }
            catch (Exception error)
            {
                System.Windows.Forms.MessageBox.Show(error.Message, "ERROR");
            }
        }

        public ESRI.ArcGIS.Display.ISymbol GeoLineSymbol()
        {
            try
            {
                // define the color for the line symbol
                ESRI.ArcGIS.Display.IRgbColor pRGB = new ESRI.ArcGIS.Display.RgbColorClass();
                pRGB.Red = 255;

                // define the properties of the character marker symbol and set it to the marker symbol
                ESRI.ArcGIS.Display.IMarkerSymbol pMarkSym;
                ESRI.ArcGIS.Display.ICharacterMarkerSymbol pCharMarkSym = new ESRI.ArcGIS.Display.CharacterMarkerSymbolClass();
                stdole.IFontDisp pFont;
                pFont = (stdole.IFontDisp)new stdole.StdFont();
                pFont.Name = @"ESRI Arrowhead";
                //  pFont.Size = 14
                pCharMarkSym.Color = pRGB;
                pCharMarkSym.XOffset = 1;
                pCharMarkSym.CharacterIndex = 36;
                pCharMarkSym.Font = pFont;
                pCharMarkSym.Size = 14;
                pMarkSym = pCharMarkSym;

                // define the simple line decoration element and add the marker symbol to it
                ESRI.ArcGIS.Display.ISimpleLineDecorationElement pSimpleLineDeco;
                pSimpleLineDeco = new ESRI.ArcGIS.Display.SimpleLineDecorationElement();
                pSimpleLineDeco.MarkerSymbol = pMarkSym;
                pSimpleLineDeco.AddPosition(1);

                // set the simple line decoration element to the line decoration element
                ESRI.ArcGIS.Display.ILineDecorationElement pLineDecoElem;
                pLineDecoElem = pSimpleLineDeco;

                // add the line decoration element to the line decoration
                ESRI.ArcGIS.Display.ILineDecoration pLineDeco;
                pLineDeco = new ESRI.ArcGIS.Display.LineDecoration();
                pLineDeco.AddElement(pLineDecoElem);

                // define the cartographic line symbol properties
                ESRI.ArcGIS.Display.ICartographicLineSymbol pCartoLineSym;
                pCartoLineSym = new ESRI.ArcGIS.Display.CartographicLineSymbol();
                pCartoLineSym.Color = pRGB;
                pCartoLineSym.Width = 1.5;

                // set the cartographic line symbol and the line decoration to the line properties
                ESRI.ArcGIS.Display.ILineProperties pLineProps;
                pLineProps = (ILineProperties) pCartoLineSym;
                pLineProps.LineDecoration = pLineDeco;

                return (ISymbol)pLineProps;

            }
            catch (Exception error)
            {
                System.Windows.Forms.MessageBox.Show(error.Message, "ERROR");
                return null;
            }
        }

        private bool ValidatePolylineValues()
        {

            // Make sure input text fields are not empty
            // or do not contain non-numeric values
            // Return false if an input value is invalid
            if (txtStartX.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("A start X value is required.", "Missing Value");
                return false;
            }
            if (Microsoft.VisualBasic.Information.IsNumeric(txtStartX.Text) == false)
            {
                System.Windows.Forms.MessageBox.Show("A numeric value is required for start X", "Missing Value");
                return false;
            }


            if (txtStartY.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("A start Y value is required","Missing Value");
                return false;
            }
            if (Microsoft.VisualBasic.Information.IsNumeric(txtStartY.Text) == false)
            {
                System.Windows.Forms.MessageBox.Show("A numeric value is required for start Y", "Missing Value");
                return false;
            }


            if (txtEndX.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("An end X value is required", "Missing Value");
                return false;
            }
            if (Microsoft.VisualBasic.Information.IsNumeric(txtEndX.Text) == false)
            {
                System.Windows.Forms.MessageBox.Show("A numeric value is required for end X", "Missing Value");
                return false;
            }


            if (txtEndY.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("An end Y value is required", "Missing Value");
                return false;
            }
            if (Microsoft.VisualBasic.Information.IsNumeric(txtEndY.Text) == false)
            {
                System.Windows.Forms.MessageBox.Show("A numeric value is required for end Y", "Missing Value");
                return false;
            }


            return true;
        }

        private bool ValidateEllipseValues()
        {

            // Make sure input text fields are not empty
            // or do not contain non-numeric values
            // Return false if an input value is invalid
            if (txtCenterX.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("A center point X value is required", "Missing Value");
                return false;
            }
            if (Microsoft.VisualBasic.Information.IsNumeric(txtCenterX.Text) == false)
            {
                System.Windows.Forms.MessageBox.Show("A numeric value is required for center point X", "Missing Value");
                return false;
            }


            if (txtCenterY.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("A center point Y value is required", "Missing Value");
                return false;
            }
            if (Microsoft.VisualBasic.Information.IsNumeric(txtCenterY.Text) == false)
            {
                System.Windows.Forms.MessageBox.Show("A numeric value is required for center point Y", "Missing Value");
                return false;
            }


            if (txtXAxis.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("An X axis value is required", "Missing Value");
                return false;
            }
            if (Microsoft.VisualBasic.Information.IsNumeric(txtXAxis.Text) == false)
            {
                System.Windows.Forms.MessageBox.Show("A numeric value is required for X axis", "Missing Value");
                return false;
            }


            if (txtYAxis.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("A Y axis value is required", "Missing Value");
                return false;
            }
            if (Microsoft.VisualBasic.Information.IsNumeric(txtYAxis.Text) == false)
            {
                System.Windows.Forms.MessageBox.Show("A numeric value is required for Y axis", "Missing Value");
                return false;
            }


            if (txtRotation.Text != "")
            {
                if (Microsoft.VisualBasic.Information.IsNumeric(txtRotation.Text) == false)
                {
                    System.Windows.Forms.MessageBox.Show("A numeric value is required for rotation", "Missing Value");
                    return false;
                }
            }

            return true;
        }

        private string GetSdkDataPath()
        {
            //get the ArcGIS path from the registry
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ESRI\ArcGIS_SXS_SDK");
            string path = Convert.ToString(key.GetValue("InstallDir"));

            //set the of the logo
            string str = System.IO.Path.Combine(path, @"Samples\data\");

            if (!System.IO.Directory.Exists(str))
            {
                MessageBox.Show("Path :" + str + " does not exist!");
                return string.Empty;
            }

            return str;
        }
	#endregion

        




    }
}
[Visual Basic .NET]

GeodesyMapControl.vb

Public Class frmGeodesyMapControl

    Private m_pAOInitialize As ESRI.ArcGIS.esriSystem.IAoInitialize
    Private m_pGeoEllipse As ESRI.ArcGIS.DefenseSolutions.IGeoEllipse
    Private m_pMeasureTool As ESRI.ArcGIS.DefenseSolutions.IMeasurementTool
    Private m_pEllipsePolygon As ESRI.ArcGIS.Geometry.IPolygon
    Private m_pKeyPointPoly As ESRI.ArcGIS.Geometry.IPolygon
    Private m_pGeoPolygon As ESRI.ArcGIS.DefenseSolutions.IGeoPolygon
    Private m_pTrackPoly As ESRI.ArcGIS.Geometry.IPolygon
    Private m_pOrigin As ESRI.ArcGIS.Geometry.IPoint
    Private m_pGeoPolyline As ESRI.ArcGIS.DefenseSolutions.IGeoPolyline
    Private m_pPolyline As ESRI.ArcGIS.Geometry.IPolyline
    Private m_pKeyPointElement As ESRI.ArcGIS.Carto.IElement
    Private m_pEllipseElement As ESRI.ArcGIS.Carto.IElement
    Private m_pLineElement As ESRI.ArcGIS.Carto.IElement
    Private m_pMapControl As ESRI.ArcGIS.Controls.IMapControl2
    Private m_pActiveView As ESRI.ArcGIS.Carto.IActiveView
    Private m_pActiveViewEvents As ESRI.ArcGIS.Carto.IMap
    Private m_pMap As ESRI.ArcGIS.Carto.IMap
    Private m_pGraphicsCont As ESRI.ArcGIS.Carto.IGraphicsContainer
    Private m_dXAxis As Double
    Private m_dYAxis As Double
    Private m_lPointCount As Long
    Private m_dRotation As Double

    Const con_strGeo As String = "Geodesic"
    Const con_strGC As String = "Great Circle"
    Const con_strRhumb As String = "Rhumb Line"

#Region "Form Functions"

    Public Sub New()
        ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine)
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.

        m_pAOInitialize = New ESRI.ArcGIS.esriSystem.AoInitialize
        Dim status As ESRI.ArcGIS.esriSystem.esriLicenseStatus

        status = m_pAOInitialize.IsProductCodeAvailable(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB)
        If (status <> ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseAvailable) Then
            MsgBox("ERROR: license not available." & vbCrLf & status)
            Me.Finalize()
        Else
            status = m_pAOInitialize.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB)
        End If

        m_pMapControl = MapControl1.Object
        m_pMapControl.AddLayerFromFile(GetSdkDataPath() + "World\Continents.lyr")

        cboType.Items.Insert(0, con_strGeo)
        cboType.Items.Insert(1, con_strGeo)
        cboType.Items.Insert(2, con_strRhumb)
        cboType.Text = con_strGeo

    End Sub

    Protected Overrides Sub Finalize()

        m_pGeoEllipse = Nothing
        m_pMeasureTool = Nothing
        m_pEllipsePolygon = Nothing
        m_pKeyPointPoly = Nothing
        m_pOrigin = Nothing
        m_pGeoPolyline = Nothing
        m_pKeyPointElement = Nothing
        m_pLineElement = Nothing
        m_pMapControl = Nothing
        m_pActiveView = Nothing
        m_pActiveViewEvents = Nothing
        m_pMap = Nothing
        m_pGraphicsCont = Nothing

        MyBase.Finalize()

    End Sub

    Private Sub cmdAddEllipse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddEllipse.Click

        On Error GoTo EH

        'create GeoEllipse geometry
        Call CreateGeoEllipse()
        If m_pGeoEllipse Is Nothing Then
            Exit Sub
        End If

        'create the IElement to be rendered as a GeoEllipseElement and
        'set its geometry to the GeoEllipse geometry defined in the
        m_pEllipseElement = New ESRI.ArcGIS.DefenseSolutions.GeoEllipseElement
        m_pEllipseElement.Geometry = m_pGeoEllipse

        'outline color
        Dim pColor As ESRI.ArcGIS.Display.IRgbColor
        pColor = New ESRI.ArcGIS.Display.RgbColor
        pColor.Green = 255

        'make fill color null
        Dim pNullColor As ESRI.ArcGIS.Display.IColor
        pNullColor = New ESRI.ArcGIS.Display.RgbColor
        pNullColor.NullColor = True

        'create the line symbol for the polygon outline
        Dim pLineSymbol As ESRI.ArcGIS.Display.ILineSymbol
        pLineSymbol = New ESRI.ArcGIS.Display.SimpleLineSymbol
        pLineSymbol.Color = pColor
        pLineSymbol.Width = 2

        'create the fill symbol
        Dim pFillSymbol As ESRI.ArcGIS.Display.IFillSymbol
        pFillSymbol = New ESRI.ArcGIS.Display.SimpleFillSymbol
        pFillSymbol.Outline = pLineSymbol
        pFillSymbol.Color = pNullColor

        'QI to IFillShapeElement to set the symbology of the GeoEllipse graphic
        Dim pFillElement As ESRI.ArcGIS.Carto.IFillShapeElement
        pFillElement = m_pEllipseElement
        pFillElement.Symbol = pFillSymbol

        'define the graphics container and draw the GeoEllipse graphic
        Call SetGraphicsContainer()
        m_pGraphicsCont.AddElement(pFillElement, 0)
        m_pActiveView.Refresh()

        Exit Sub

EH:
        MsgBox(Err.Number & "  " & Err.Description, vbCritical, "Error")
    End Sub

    Private Sub cmdClearEllipseFields_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClearEllipseFields.Click
        txtCenterX.Text = ""
        txtCenterY.Text = ""
        txtXAxis.Text = ""
        txtYAxis.Text = ""
        txtRotation.Text = ""
    End Sub

    Private Sub cmdClearGraphics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClearGraphics.Click

        'Clear all graphic elements from the map control
        Call SetGraphicsContainer()
        m_pGraphicsCont.DeleteAllElements()
        m_pActiveView.Refresh()

    End Sub

    Private Sub cmdClearLineFields_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClearLineFields.Click

        txtStartX.Text = ""
        txtStartY.Text = ""
        txtEndX.Text = ""
        txtEndY.Text = ""
        txtDistance.Text = ""
        txtAzimuth.Text = ""

    End Sub

    Private Sub cmdDrawLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDrawLine.Click
        On Error GoTo EH

        'call CreateGeoPolyline subprocedure to create geometry
        Call CreateGeoPolyline()

        If m_pGeoPolyline Is Nothing Then
            Exit Sub
        End If

        'create the IElement to be rendered as a GeoPolylineElement and
        'set its geometry to the GeoPolyline geometry defined in the
        'CreateGeoPolyline subprocedure
        m_pLineElement = New ESRI.ArcGIS.DefenseSolutions.GeoPolylineElement
        m_pLineElement.Geometry = m_pGeoPolyline

        'QI to ILineElement to set the symbology of the GeoPolyline graphic
        Dim pLineElement As ESRI.ArcGIS.Carto.ILineElement
        pLineElement = m_pLineElement
        pLineElement.Symbol = GeoLineSymbol()

        'Define the graphics container and draw the GeoPolyline graphic. Display the
        'distance and azimuth of the GeoPolyline as calculated by the measurement tool.
        Call SetGraphicsContainer()
        m_pGraphicsCont.AddElement(pLineElement, 0)
        m_pActiveView.Refresh()
        txtDistance.Text = Math.Round((m_pMeasureTool.Distance / 1000), 6)
        txtAzimuth.Text = Math.Round(m_pMeasureTool.Angle, 6)
        Exit Sub

EH:
        MsgBox(Err.Number & "  " & Err.Description, vbCritical, "Error")

    End Sub

    Private Sub cmdKeyPoints_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdKeyPoints.Click
        On Error GoTo EH

        'Run the CreateGeoEllipse subprocedure to get the geometry of the
        'key points polygon generated from the GeoEllipse.
        Call CreateGeoEllipse()
        If m_pGeoEllipse Is Nothing Then
            Exit Sub
        End If
        If m_pKeyPointPoly Is Nothing Then
            Exit Sub
        End If

        'outline color
        Dim pColor As ESRI.ArcGIS.Display.IRgbColor
        pColor = New ESRI.ArcGIS.Display.RgbColor
        pColor.Green = 255

        'make fill color null
        Dim pNullColor As ESRI.ArcGIS.Display.IColor
        pNullColor = New ESRI.ArcGIS.Display.RgbColor
        pNullColor.NullColor = True

        'create the outline symbol
        Dim pLineSymbol As ESRI.ArcGIS.Display.ILineSymbol
        pLineSymbol = New ESRI.ArcGIS.Display.SimpleLineSymbol
        pLineSymbol.Color = pColor
        pLineSymbol.Width = 1.5
        Dim pHashLineSymbol As ESRI.ArcGIS.Display.IHashLineSymbol
        pHashLineSymbol = New ESRI.ArcGIS.Display.HashLineSymbol
        pHashLineSymbol.HashSymbol = pLineSymbol

        'create the fill symbol for the polygon
        Dim pFillSymbol As ESRI.ArcGIS.Display.IFillSymbol
        pFillSymbol = New ESRI.ArcGIS.Display.SimpleFillSymbol
        pFillSymbol.Outline = pHashLineSymbol
        pFillSymbol.Color = pNullColor

        'create the IElement to be rendered as a PolygonElement and
        'set its geometry to the key points polygon geometry defined in the
        'CreateGeoEllipse subprocedure
        m_pKeyPointElement = New ESRI.ArcGIS.Carto.PolygonElement
        m_pKeyPointElement.Geometry = m_pKeyPointPoly

        'QI to IFillShapeElement to set the symbology of the key points polygon graphic
        Dim pFillElement As ESRI.ArcGIS.Carto.IFillShapeElement
        pFillElement = m_pKeyPointElement
        pFillElement.Symbol = pFillSymbol

        'define the graphics container and draw the key points polygon graphic
        Call SetGraphicsContainer()
        m_pGraphicsCont.AddElement(pFillElement, 0)
        m_pActiveView.Refresh()

        Exit Sub
EH:
        MsgBox(Err.Number & "  " & Err.Description, vbCritical, "Error")

    End Sub

    Private Sub MapControl1_OnMouseDown(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent) Handles MapControl1.OnMouseDown
        On Error GoTo EH
        'On a right mouse button click use the TrackPolygon method on the map control
        'to define the vertices of an eventual GeoPolygon. Each right mouse button
        'click adds a vertex to the polygon; double-clicking the right mouse button
        'completes the polygon.
        Dim pTrackPoly As ESRI.ArcGIS.Geometry.IPolygon
        Dim pTrackPolyElement As ESRI.ArcGIS.Carto.IElement

        If e.button = 2 Then

            'Create the polygon from the TrackPolygon method. This polygon will be
            'the foundation for a GeoPolygon object.
            pTrackPoly = MapControl1.TrackPolygon

            'Define the GeoPolygon, QI to IGeoPolygon
            m_pGeoPolygon = New ESRI.ArcGIS.DefenseSolutions.GeoPolygon
            m_pGeoPolygon.Polygon = pTrackPoly

            'Set the GeoPolyline type to form the segments of the GeoPolygon. In this case
            'the segments will be Geodesic lines.
            m_pGeoPolygon.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGeodesic

            'Set the GeoPolygon spatial reference.
            m_pGeoPolygon.BaseSpatialReference = GetWGS84SpatialRef()

            'outline color
            Dim pColor As ESRI.ArcGIS.Display.IRgbColor
            pColor = New ESRI.ArcGIS.Display.RgbColor
            pColor.Blue = 255

            'make fill color null
            Dim pNullColor As ESRI.ArcGIS.Display.IColor
            pNullColor = New ESRI.ArcGIS.Display.RgbColor
            pNullColor.NullColor = True

            'create the outline symbol
            Dim pLineSymbol As ESRI.ArcGIS.Display.ILineSymbol
            pLineSymbol = New ESRI.ArcGIS.Display.SimpleLineSymbol
            pLineSymbol.Color = pColor
            pLineSymbol.Width = 1.5

            'create the fill symbol for the GeoPolygon
            Dim pFillSymbol As ESRI.ArcGIS.Display.IFillSymbol
            pFillSymbol = New ESRI.ArcGIS.Display.SimpleFillSymbol
            pFillSymbol.Outline = pLineSymbol
            pFillSymbol.Color = pNullColor

            'Create the IElement to be rendered as a GeoPolygonElement and
            'set its geometry to the GeoPolygon geometry. When a GeoPolygonElement
            'graphic is moved from one location to another in the map control
            'the GeoPolygon geometry is automatically updated based on the
            'geographic location and the graphic is updated accordingly.
            pTrackPolyElement = New ESRI.ArcGIS.DefenseSolutions.GeoPolygonElement
            pTrackPolyElement.Geometry = m_pGeoPolygon

            'QI to IFillShapeElement to set the symbology of the GeoPolygon graphic
            Dim pFillElement As ESRI.ArcGIS.Carto.IFillShapeElement
            pFillElement = pTrackPolyElement
            pFillElement.Symbol = pFillSymbol

            'define the graphics container and draw the key points polygon graphic
            Call SetGraphicsContainer()
            m_pGraphicsCont.AddElement(pFillElement, 0)
            m_pActiveView.Refresh()
        Else
            pTrackPoly = Nothing
        End If

        Exit Sub

EH:
        MsgBox(Err.Number & "  " & Err.Description, vbCritical, "Error")

    End Sub

#End Region

#Region "Helper Methods"


    Public Sub SetGraphicsContainer()

        'Define the graphics container to be the map control's active view
        m_pMapControl = MapControl1.Object
        m_pActiveView = m_pMapControl.ActiveView
        m_pGraphicsCont = m_pActiveView.GraphicsContainer

    End Sub

    Public Sub CreateGeoEllipse()
        On Error GoTo EH

        'reset geoellipse and key point geometries
        m_pGeoEllipse = Nothing
        m_pKeyPointPoly = Nothing

        If ValidateEllipseValues() = False Then
            Exit Sub
        End If

        'define the geoellipse
        m_pGeoEllipse = New ESRI.ArcGIS.DefenseSolutions.GeoEllipse

        'define the geoellipse center point coordinates
        m_pOrigin = New ESRI.ArcGIS.Geometry.Point
        Dim dX As Double
        Dim dY As Double
        dX = txtCenterX.Text
        dY = txtCenterY.Text
        m_pOrigin.PutCoords(dX, dY)

        'define the geoellipse spatial reference
        m_pGeoEllipse.BaseSpatialReference = GetWGS84SpatialRef()

        'set the lengths of the X and Y axes in kilometers
        m_pGeoEllipse.AxisX = CDbl(txtXAxis.Text) * 1000
        m_pGeoEllipse.AxisY = CDbl(txtYAxis.Text) * 1000

        'set the origin, or center point, of the geoellipse
        m_pGeoEllipse.Origin = m_pOrigin

        'if the rotation is not given, use 0 as default
        If txtRotation.Text = "" Then
            txtRotation.Text = "0"
        End If

        'define the amount of rotation, in degrees from
        'zero (north), of the geoellipse Y axis
        m_pGeoEllipse.Rotation = CDbl(txtRotation.Text) Mod 360

        'set the number of vertices to be used in the creation
        'of the polygon representation of the geoellipse
        m_pGeoEllipse.GeoEllipsePointCount = 100

        'define the key points polygon, which is a polygon connecting the end
        'points of the geoellipse X and Y axes
        m_pKeyPointPoly = m_pGeoEllipse.KeyPoints


        Exit Sub
EH:
        MsgBox(Err.Number & "  " & Err.Description, vbCritical, "Error")
    End Sub

    Public Sub CreateGeoPolyline()
        On Error GoTo EH

        'reset the polyline geometry
        m_pGeoPolyline = Nothing

        If ValidatePolylineValues() = False Then
            Exit Sub
        End If

        'Set the measurement tool and the GeoPolyline. The measurement tool
        'will be used to calculate the distance and azimuth of the GeoPolyline
        'based on the start and end point coordinates of the line
        m_pGeoPolyline = New ESRI.ArcGIS.DefenseSolutions.GeoPolyline
        m_pMeasureTool = New ESRI.ArcGIS.DefenseSolutions.MeasurementTool

        'Get the GeoPolyline type from the Type dropdown list and set it as
        'the type for both the measurement tool and the GeoPolyline. The options
        'are Geodesic, Great Circle, and Rhumb Line.
        Dim strType As String
        strType = cboType.Items(cboType.SelectedIndex).ToString
        If strType = con_strGeo Then
            m_pMeasureTool.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGeodesic
            m_pGeoPolyline.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGeodesic
        ElseIf strType = con_strGC Then
            m_pMeasureTool.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGreatCircle
            m_pGeoPolyline.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTGreatCircle
        ElseIf strType = con_strRhumb Then
            m_pMeasureTool.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTRhumbLine
            m_pGeoPolyline.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTRhumbLine
        End If

        'set the measurement tool spatial reference
        m_pMeasureTool.SpecialSpatialReference = GetWGS84SpatialRef()

        'Set start and end points for the measurement tool calculation
        'and the polyline from which the GeoPolyline is derived. The points
        'are created based on the decimal degree coordinates input into
        'the Start Point and End Point text boxes
        Dim dStartX As Double
        Dim dStartY As Double
        Dim dEndX As Double
        Dim dEndY As Double
        Dim pStartPoint As ESRI.ArcGIS.Geometry.IPoint
        Dim pEndPoint As ESRI.ArcGIS.Geometry.IPoint
        dStartX = txtStartX.Text
        dStartY = txtStartY.Text
        pStartPoint = New ESRI.ArcGIS.Geometry.Point
        pStartPoint.PutCoords(dStartX, dStartY)
        dEndX = txtEndX.Text
        dEndY = txtEndY.Text
        pEndPoint = New ESRI.ArcGIS.Geometry.Point
        pEndPoint.PutCoords(dEndX, dEndY)

        'Calculate the distance and azimuth of the GeoPolyline using the
        'ConstructByPoints method on the measurement tool. These values
        'will be displayed in the Distance and Azimuth text boxes
        m_pMeasureTool.ConstructByPoints(pStartPoint, pEndPoint)

        'Create the simple polyline which is the basis for the geometry of the GeoPolyline.
        m_pPolyline = New ESRI.ArcGIS.Geometry.Polyline
        m_pPolyline.FromPoint = pStartPoint
        m_pPolyline.ToPoint = pEndPoint
        m_pPolyline.Project(GetWGS84SpatialRef)

        'QI to IGeoPolyLine to define the GeoPolyline. Set the base geometry of the
        'geopolyline to the polyline created from the start and end point coordinates
        'defined in the X and Y fields. Specify the number of vertices by which to densify
        'the GeoPolyline as a percentage of the total distance of the line. In this
        'case a vertex will be placed at every 1% of the line's total distance.
        m_pGeoPolyline.Polyline = m_pPolyline
        m_pGeoPolyline.MaxPercent = 0.01
        m_pGeoPolyline.UsePercent = True

        Exit Sub

EH:
        MsgBox(Err.Number & "  " & Err.Description, vbCritical, "Error")

    End Sub

    Public Function GeoLineSymbol() As ESRI.ArcGIS.Display.ISymbol

        On Error GoTo EH
        'define the color for the line symbol
        Dim pRGB As ESRI.ArcGIS.Display.IRgbColor
        pRGB = New ESRI.ArcGIS.Display.RgbColor
        pRGB.Red = 255

        'define the properties of the character marker symbol and set it to the marker symbol
        Dim pMarkSym As ESRI.ArcGIS.Display.IMarkerSymbol
        Dim pCharMarkSym As ESRI.ArcGIS.Display.ICharacterMarkerSymbol
        pCharMarkSym = New ESRI.ArcGIS.Display.CharacterMarkerSymbol
        Dim pFont As stdole.IFontDisp
        pFont = New stdole.StdFont
        pFont.Name = "ESRI Arrowhead"
        '  pFont.Size = 14
        With pCharMarkSym
            .Color = pRGB
            .XOffset = 1
            .CharacterIndex = 36
            .Font = pFont
            .Size = 14
        End With
        pMarkSym = pCharMarkSym

        'define the simple line decoration element and add the marker symbol to it
        Dim pSimpleLineDeco As ESRI.ArcGIS.Display.ISimpleLineDecorationElement
        pSimpleLineDeco = New ESRI.ArcGIS.Display.SimpleLineDecorationElement
        pSimpleLineDeco.MarkerSymbol = pMarkSym
        pSimpleLineDeco.AddPosition(1)

        'set the simple line decoration element to the line decoration element
        Dim pLineDecoElem As ESRI.ArcGIS.Display.ILineDecorationElement
        pLineDecoElem = pSimpleLineDeco

        'add the line decoration element to the line decoration
        Dim pLineDeco As ESRI.ArcGIS.Display.ILineDecoration
        pLineDeco = New ESRI.ArcGIS.Display.LineDecoration
        pLineDeco.AddElement(pLineDecoElem)

        'define the cartographic line symbol properties
        Dim pCartoLineSym As ESRI.ArcGIS.Display.ICartographicLineSymbol
        pCartoLineSym = New ESRI.ArcGIS.Display.CartographicLineSymbol
        pCartoLineSym.Color = pRGB
        pCartoLineSym.Width = 1.5

        'set the cartographic line symbol and the line decoration to the line properties
        Dim pLineProps As ESRI.ArcGIS.Display.ILineProperties
        pLineProps = pCartoLineSym
        pLineProps.LineDecoration = pLineDeco

        'set the line properties to the symbol
        GeoLineSymbol = pLineProps

        Exit Function
EH:
        GeoLineSymbol = Nothing

    End Function

    Private Function ValidatePolylineValues() As Boolean

        'Make sure input text fields are not empty
        'or do not contain non-numeric values
        'Return false if an input value is invalid
        If txtStartX.Text = "" Then
            MsgBox("A start X value is required", vbCritical, "Missing Value")
            ValidatePolylineValues = False
            Exit Function
        End If

        If Not IsNumeric(txtStartX.Text) Then
            MsgBox("A numeric value is required for start X", vbCritical, "Missing Value")
            ValidatePolylineValues = False
            Exit Function
        End If

        If txtStartY.Text = "" Then
            MsgBox("A start Y value is required", vbCritical, "Missing Value")
            ValidatePolylineValues = False
            Exit Function
        End If

        If Not IsNumeric(txtStartY.Text) Then
            MsgBox("A numeric value is required for start Y", vbCritical, "Missing Value")
            ValidatePolylineValues = False
            Exit Function
        End If

        If txtEndX.Text = "" Then
            MsgBox("An end X value is required", vbCritical, "Missing Value")
            ValidatePolylineValues = False
            Exit Function
        End If

        If Not IsNumeric(txtEndX.Text) Then
            MsgBox("A numeric value is required for end X", vbCritical, "Missing Value")
            ValidatePolylineValues = False
            Exit Function
        End If

        If txtEndY.Text = "" Then
            MsgBox("An end Y value is required", vbCritical, "Missing Value")
            ValidatePolylineValues = False
            Exit Function
        End If

        If Not IsNumeric(txtEndY.Text) Then
            MsgBox("A numeric value is required for end Y", vbCritical, "Missing Value")
            ValidatePolylineValues = False
            Exit Function
        End If

        ValidatePolylineValues = True
    End Function

    Private Function ValidateEllipseValues() As Boolean

        'Make sure input text fields are not empty
        'or do not contain non-numeric values
        'Return false if an input value is invalid

        If txtCenterX.Text = "" Then
            MsgBox("A center point X value is required", vbCritical, "Missing Value")
            ValidateEllipseValues = False
            Exit Function
        End If

        If Not IsNumeric(txtCenterX.Text) Then
            MsgBox("A numeric value is required for center point X", vbCritical, "Missing Value")
            ValidateEllipseValues = False
            Exit Function
        End If

        If txtCenterY.Text = "" Then
            MsgBox("A center point Y value is required", vbCritical, "Missing Value")
            ValidateEllipseValues = False
            Exit Function
        End If

        If Not IsNumeric(txtCenterY.Text) Then
            MsgBox("A numeric value is required for center point Y", vbCritical, "Missing Value")
            ValidateEllipseValues = False
            Exit Function
        End If

        If txtXAxis.Text = "" Then
            MsgBox("An X axis value is required", vbCritical, "Missing Value")
            ValidateEllipseValues = False
            Exit Function
        End If

        If Not IsNumeric(txtXAxis.Text) Then
            MsgBox("A numeric value is required for X axis", vbCritical, "Missing Value")
            ValidateEllipseValues = False
            Exit Function
        End If

        If txtYAxis.Text = "" Then
            MsgBox("A Y axis value is required", vbCritical, "Missing Value")
            ValidateEllipseValues = False
            Exit Function
        End If

        If Not IsNumeric(txtYAxis.Text) Then
            MsgBox("A numeric value is required for Y axis", vbCritical, "Missing Value")
            ValidateEllipseValues = False
            Exit Function
        End If

        If Not txtRotation.Text = "" Then
            If Not IsNumeric(txtRotation.Text) Then
                MsgBox("A numeric value is required for rotation", vbCritical, "Missing Value")
                ValidateEllipseValues = False
                Exit Function
            End If
        End If

        ValidateEllipseValues = True

    End Function

    Private Function GetWGS84SpatialRef() As ESRI.ArcGIS.Geometry.ISpatialReference2

        'Define the spatial reference to be used for geopolylines,
        'geoellipses, and geopolygons.
        Dim pSpatRef As ESRI.ArcGIS.Geometry.ISpatialReference2
        Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory2
        pSpatRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment
        pSpatRef = pSpatRefFact.CreateSpatialReference(ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984)
        GetWGS84SpatialRef = pSpatRef

    End Function

    Private Function GetSdkDataPath() As String
        'get the ArcGIS path from the registry
        Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ESRI\ArcGIS_SXS_SDK")
        Dim path As String = Convert.ToString(key.GetValue("InstallDir"))

        'set the of the logo
        Dim str As String = System.IO.Path.Combine(path, "Samples\data\")
        If (Not System.IO.Directory.Exists(str)) Then
            MessageBox.Show("Path :" & str & " does not exist!")
            Return String.Empty
        End If

        Return str
    End Function

#End Region


End Class