This document is archived and information here might be outdated. Recommended version. |
Use the ICoordinateTool.Convert to convert from MGRS to Lat/Long, DMS and UTM and display in a MessageBox.
///<summary>Use the ICoordinateTool.Convert to convert from MGRS to Lat/Long, DMS and UTM and display in a MessageBox.</summary> /// ///<param name="value">A System.Object that is the input coordinates. Ex: "18VWL9439643654"</param> ///<param name="format">A System.Int32 that is the format of the input IPoint coordinates. Valid values are: 1=Decimal Degrees, 2=DMS, 3=UTM, 4=MGRS. Ex: 4</param> ///<param name="fromDatum">A System.Object that is the datum of the input coordinates. Ex: "WGS 1984 (WGS84)"</param> ///<param name="toDatum">A System.Object that is the datum of the output coordinates. Ex: "WGS 1984 (WGS84)"</param> /// ///<remarks></remarks> public void DisplayLatLongDMSAndUTMFromMGRS(object value, System.Int32 format, object fromDatum, object toDatum) { ESRI.ArcGIS.Geometry.IPoint WGSPoint=new ESRI.ArcGIS.Geometry.PointClass(); ESRI.ArcGIS.Geometry.IPoint outPoint=new ESRI.ArcGIS.Geometry.PointClass(); System.String DMS=""; //Note: an empty string is initialized. Because it will be populated by the .ConvertLocation Method System.String UTM=""; //Note: an empty string is initialized. Because it will be populated by the .ConvertLocation Method System.String MGRS=""; //Note: an empty string is initialized. Because it will be populated by the .ConvertLocation Method ESRI.ArcGIS.DefenseSolutions.ICoordinateTool coordinateTool=new ESRI.ArcGIS.DefenseSolutions.CoordinateToolClass(); //Convert the coordinates coordinateTool.ConvertLocation(value, format, fromDatum, toDatum, ref WGSPoint, ref outPoint, ref DMS, ref UTM, ref MGRS); System.String message="In X=" + System.Convert.ToString(WGSPoint.X) + System.Environment.NewLine + "In Y=" + System.Convert.ToString(WGSPoint.Y) + System.Environment.NewLine + "Out X=" + System.Convert.ToString(outPoint.X) + System.Environment.NewLine + "Out Y=" + System.Convert.ToString(outPoint.Y) + System.Environment.NewLine + "DMS=" + DMS + System.Environment.NewLine + "UTM=" + UTM + System.Environment.NewLine + "MGRS=" + MGRS + System.Environment.NewLine; System.Windows.Forms.MessageBox.Show(message); }
'''<summary>Use the ICoordinateTool.Convert to convert from MGRS to Lat/Long, DMS and UTM and display in a MessageBox.</summary> ''' '''<param name="value">A System.Object that is the input coordinates. Ex: "18VWL9439643654"</param> '''<param name="format">A System.Int32 that is the format of the input IPoint coordinates. Valid values are: 1=Decimal Degrees, 2=DMS, 3=UTM, 4=MGRS. Ex: 4</param> '''<param name="fromDatum">A System.Object that is the datum of the input coordinates. Ex: "WGS 1984 (WGS84)"</param> '''<param name="toDatum">A System.Object that is the datum of the output coordinates. Ex: "WGS 1984 (WGS84)"</param> ''' '''<remarks></remarks> Public Sub DisplayLatLongDMSAndUTMFromMGRS(ByVal value As System.Object, ByVal format As System.Int32, ByVal fromDatum As System.Object, ByVal toDatum As System.Object) Dim WGSPoint As ESRI.ArcGIS.Geometry.IPoint=New ESRI.ArcGIS.Geometry.PointClass Dim outPoint As ESRI.ArcGIS.Geometry.IPoint=New ESRI.ArcGIS.Geometry.PointClass Dim DMS As System.String="" 'Note: an empty string is initialized. Because it will be populated by the .ConvertLocation Method Dim UTM As System.String="" 'Note: an empty string is initialized. Because it will be populated by the .ConvertLocation Method Dim MGRS As System.String="" 'Note: an empty string is initialized. Because it will be populated by the .ConvertLocation Method Dim coordinateTool As ESRI.ArcGIS.DefenseSolutions.ICoordinateTool=New ESRI.ArcGIS.DefenseSolutions.CoordinateToolClass 'Convert the coordinates coordinateTool.ConvertLocation(value, format, fromDatum, toDatum, WGSPoint, outPoint, DMS, UTM, MGRS) Dim message As String=_ "In X=" & CStr(WGSPoint.X) & vbCrLf & _ "In Y=" & CStr(WGSPoint.Y) & vbCrLf & _ "Out X=" & CStr(outPoint.X) & vbCrLf & _ "Out Y=" & CStr(outPoint.Y) & vbCrLf & _ "DMS=" & DMS & vbCrLf & _ "UTM=" & UTM & vbCrLf & _ "MGRS=" & MGRS & vbCrLf System.Windows.Forms.MessageBox.Show(message) End Sub