This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ESRI.ArcGIS.Snippets > Snippets > Statements - Convert Coordinates MGRS to LatLong, DMS and UTM Snippet (ArcObjects .NET 10.4 SDK) |
Use the ICoordinateTool.Convert to convert from MGRS to Lat/Long, DMS and UTM.
//<-- Snippet Start --> // DESCRIPTION: // Use the ICoordinateTool.Convert to convert from MGRS to LatLong, DMS and UTM. // Set the following parameters to be used in the conversion. // value: The input coordinates (example: "18VWL9439643654") // format: The format of the input IPoint coordinates (example: 4), // Where 1=Decimal Degrees, 2=DMS, 3=UTM, 4=MGRS // fromDatum: The datum of the input coordinates (example: "WGS 1984 (WGS84)") // toDatum: The datum of the output coordinates (example: "WGS 1984 (WGS84)") System.Object value="a_coordinate_string"; // Note: the variable is a string. System.Int32 format="an_integer"; // Note: the variable is an integer. System.Object fromDatum="a_datum_string"; // Note: the variable is a string. Syste.Object toDatum="a_datum_string"; // Note: the variable is a string. 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); string message="In X=" + System.Convert.ToString(WGSPoint.X) + "\n" + "In Y=" + System.Convert.ToString(WGSPoint.Y) + "\n" + "Out X=" + System.Convert.ToString(outPoint.X) + "\n" + "Out Y=" + System.Convert.ToString(outPoint.Y) + "\n" + "DMS=" + DMS + "\n" + "UTM=" + UTM + "\n" + "MGRS=" + MGRS; System.Windows.Forms.MessageBox.Show(message); //<-- Snippet End -->
'<-- Snippet Start --> ' DESCRIPTION: ' Use the ICoordinateTool.Convert to convert from MGRS to Lat/Long, DMS and UTM. ' ' Set the following parameters to be used in the conversion. ' value: The input coordinates (example: "18VWL9439643654") ' format: The format of the input IPoint coordinates (example: 4), ' Where 1=Decimal Degrees, 2=DMS, 3=UTM, 4=MGRS ' fromDatum: The datum of the input coordinates (example: "WGS 1984 (WGS84)") ' toDatum: The datum of the output coordinates (example: "WGS 1984 (WGS84)") Dim value As System.Object="a_coordinate_string" 'Note: the variable is a string. Dim format As System.Int32="an_integer" 'Note: the variable is an integer. Dim fromDatum As System.Object="a_datum_string" 'Note: the variable is a string. Dim toDatum As System.Object="a_datum_string" 'Note: the variable is a string. 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) '<-- Snippet End -->