ArcObjects Library Reference

Decimal Degree Angle Radian Example Snippet

Display sample values in Decimal Degree, Angle and Radian formats.

[C#]
/// <summary>
/// Display sample values in Decimal Degree, Angle and Radian formats.
/// </summary>
/// <remarks></remarks>
public void DecimalDegreeAngleRadianExample()
{

  // Create an AngleFormat object and set AngleFormat options through the IAngleFormat interface
  ESRI.ArcGIS.esriSystem.IAngleFormat angleFormat = new ESRI.ArcGIS.esriSystem.AngleFormatClass();
  angleFormat.AngleInDegrees = true; //Input values are in degrees
  angleFormat.DisplayDegrees = true; //Display formatted numbers in degrees

  // Set NumericFormat options through the INumericFormat interface. This step is not necessary 
  // unless you want to change the  INumericFormat default properties.  Comment this block of 
  // code out to see how it changes the format!
  ESRI.ArcGIS.esriSystem.INumericFormat numericFormat = (ESRI.ArcGIS.esriSystem.INumericFormat)angleFormat;
  numericFormat.AlignmentOption = ESRI.ArcGIS.esriSystem.esriNumericAlignmentEnum.esriAlignRight;
  numericFormat.RoundingOption = ESRI.ArcGIS.esriSystem.esriRoundingOptionEnum.esriRoundNumberOfDecimals;
  numericFormat.AlignmentWidth = 16;
  numericFormat.RoundingValue = 5;
  numericFormat.ShowPlusSign = true;
  numericFormat.UseSeparator = false;
  numericFormat.ZeroPad = false;

  // The ValueToString & StringToValue methods are in the INumberFormat interface.  
  ESRI.ArcGIS.esriSystem.INumberFormat numberFormat = (ESRI.ArcGIS.esriSystem.INumberFormat)angleFormat; //= pNumericFormat could be used here as well

  // Format some angular numbers in degree format
  System.Double double_DecimalDegree = 0;
  System.String string_ValueToString = null;
  System.Double double_StringToValue = 0;

  for (double_DecimalDegree = -180; double_DecimalDegree <= 180; double_DecimalDegree += 90)
  {
    string_ValueToString = numberFormat.ValueToString(double_DecimalDegree);
    double_StringToValue = numberFormat.StringToValue(string_ValueToString);
    System.Windows.Forms.MessageBox.Show("ValueToString(" + double_DecimalDegree.ToString() + ") = '" + string_ValueToString + "'" + System.Environment.NewLine + "StringToValue('" + string_ValueToString + "') = " + double_StringToValue.ToString(), "AngleFormat - Degree Format");
  }

  // Display radian values. A degree-to-radian conversion takes place in the ValueToString 
  //method, and a radian-to-degree conversion takes place in the StringToValue method.
  angleFormat.DisplayDegrees = false;
  for (double_DecimalDegree = -180; double_DecimalDegree <= 180; double_DecimalDegree += 90)
  {
    string_ValueToString = numberFormat.ValueToString(double_DecimalDegree);
    double_StringToValue = numberFormat.StringToValue(string_ValueToString);
    System.Windows.Forms.MessageBox.Show("ValueToString(" + double_DecimalDegree.ToString() + ") = '" + string_ValueToString + "'" + System.Environment.NewLine + "StringToValue('" + string_ValueToString + "') = " + double_StringToValue.ToString(), "AngleFormat - Radian Format");
  }

}
[Visual Basic .NET]
''' <summary>
''' Display sample values in Decimal Degree, Angle and Radian formats.
''' </summary>
''' <remarks></remarks>
Public Sub DecimalDegreeAngleRadianExample()

  ' Create an AngleFormat object and set AngleFormat options through the IAngleFormat interface
  Dim angleFormat As ESRI.ArcGIS.esriSystem.IAngleFormat = New ESRI.ArcGIS.esriSystem.AngleFormatClass
  angleFormat.AngleInDegrees = True 'Input values are in degrees
  angleFormat.DisplayDegrees = True 'Display formatted numbers in degrees

  ' Set NumericFormat options through the INumericFormat interface. This step is not necessary 
  ' unless you want to change the  INumericFormat default properties.  Comment this block of 
  ' code out to see how it changes the format!
  Dim numericFormat As ESRI.ArcGIS.esriSystem.INumericFormat = CType(angleFormat, ESRI.ArcGIS.esriSystem.INumericFormat)
  numericFormat.AlignmentOption = ESRI.ArcGIS.esriSystem.esriNumericAlignmentEnum.esriAlignRight
  numericFormat.RoundingOption = ESRI.ArcGIS.esriSystem.esriRoundingOptionEnum.esriRoundNumberOfDecimals
  numericFormat.AlignmentWidth = 16
  numericFormat.RoundingValue = 5
  numericFormat.ShowPlusSign = True
  numericFormat.UseSeparator = False
  numericFormat.ZeroPad = False

  ' The ValueToString & StringToValue methods are in the INumberFormat interface.  
  Dim numberFormat As ESRI.ArcGIS.esriSystem.INumberFormat = CType(angleFormat, ESRI.ArcGIS.esriSystem.INumberFormat)  '= pNumericFormat could be used here as well

  ' Format some angular numbers in degree format
  Dim double_DecimalDegree As System.Double
  Dim string_ValueToString As System.String
  Dim double_StringToValue As System.Double

  For double_DecimalDegree = -180 To 180 Step 90
    string_ValueToString = numberFormat.ValueToString(double_DecimalDegree)
    double_StringToValue = numberFormat.StringToValue(string_ValueToString)
    System.Windows.Forms.MessageBox.Show("ValueToString(" + double_DecimalDegree.ToString + ") = '" + string_ValueToString + "'" + System.Environment.NewLine + _
             "StringToValue('" + string_ValueToString + "') = " + double_StringToValue.ToString, _
             "AngleFormat - Degree Format")
  Next

  ' Display radian values. A degree-to-radian conversion takes place in the ValueToString 
  ' method, and a radian-to-degree conversion takes place in the StringToValue method.
  angleFormat.DisplayDegrees = False
  For double_DecimalDegree = -180 To 180 Step 90
    string_ValueToString = numberFormat.ValueToString(double_DecimalDegree)
    double_StringToValue = numberFormat.StringToValue(string_ValueToString)
    System.Windows.Forms.MessageBox.Show("ValueToString(" + double_DecimalDegree.ToString + ") = '" + string_ValueToString & "'" + System.Environment.NewLine + _
             "StringToValue('" + string_ValueToString + "') = " + double_StringToValue.ToString, _
             "AngleFormat - Radian Format")
  Next

End Sub


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.System
  • System
  • System.Windows.Forms