Geodesy MapControl
.\GeodesyMapControl\GeodesyMapControl.vb
' 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.
' 

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