Geodesy MapControl
.\GeodesyMapControl\GeodesyMapControl.cs
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

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

        




    }
}