I am working on an add-in for the ArcGIS Explorer Desktop mapping client and need to take
Lon/Lat coodinates and display them in an MGRS formatted string in a Note or MessageBox.
Ideally, Lon/Lat (0, 51.4791) would end up being displayed as MGRS 31UBT9168707373
I used sample code from the ArcGIS Resource Center, shown below, but when I do a ToString on the resulting point in the first code sample using the Geographic Coordinate System, I get:
resultString = "Point: X = 0 Y = 51.4791000009189" (obviously the original Lon/Lat)
In the second code sample using the Projected Coordinate System, I get:
resultString1 = "Point: X = -538880.521630103 Y = 5810593.60821005" (something entirely different, but not the final solution)
What do I need to do to end up with the string "31UBT9168707373"?
Thanks for any help!
First code sample:
// Create a Point at Greenwich, UK. By default new Geometries have the WGS 1984 geographical coordinate system.
ESRI.ArcGISExplorer.Geometry.Point projectPoint1 = new ESRI.ArcGISExplorer.Geometry.Point(0, 51.4791);
// Create an instance of the CoordinateSystem we want to project the Point into.
CoordinateSystem projectIntoHTRS96 = CoordinateSystem.GeographicCoordinateSystems.Europe.HTRS96;
// Retrieve suitable transformations between the two coordinate systems.
System.Collections.Generic.IList<GeographicTransformation> suitableTrans1 = GeographicTransformation.GetTransformations(projectPoint1.CoordinateSystem, projectIntoHTRS96);
ESRI.ArcGISExplorer.Geometry.Point outputPoint1 = null;
// For brevity here, simply pick the first suitable transformation.
GeographicTransformation geoT1 = suitableTrans1[0];
// Project the point using the selected transformation. Cast back to a Point - Project does
// not change the type of Geometry.
outputPoint1 = GeometryOperations.Project(projectPoint1, projectIntoHTRS96, geoT1) as ESRI.ArcGISExplorer.Geometry.Point;
String resultString = outputPoint1.ToString();
Second code sample:
// Create an instance of the CoordinateSystem we want to project the Point into.
CoordinateSystem projectIntoHTRS96Z = CoordinateSystem.ProjectedCoordinateSystems.UTM.Europe.HTRS96UTMZone33N;
// Retrieve suitable transformations between the two coordinate systems.
System.Collections.Generic.IList<GeographicTransformation> suitableTransZ = GeographicTransformation.GetTransformations(projectPoint1.CoordinateSystem, projectIntoHTRS96Z);
ESRI.ArcGISExplorer.Geometry.Point outputPointZ = null;
// For brevity here, simply pick the first suitable transformation.
GeographicTransformation geoTZ = suitableTransZ[0];
// Project the point using the selected transformation. Cast back to a Point - Project does
// not change the type of Geometry.
outputPointZ = GeometryOperations.Project(projectPoint1, projectIntoHTRS96Z, geoTZ) as ESRI.ArcGISExplorer.Geometry.Point;
String resultString1 = outputPointZ.ToString();
Other notes:
I was hoping for:
MGRS 31UBT9168707373
geoT1 and geoTZ are both = {HTRS96_To_WGS_1984_1}
_core = {ESRI.ArcGISExplorer.Internal.WrapperCore<ESRI::ArcGISExplorer::Geometry::GeographicTransformation>}
Name = "HTRS96_To_WGS_1984_1"
projectIntoHTRS96 = {GCS_HTRS96 (4761)}
resultString = "Point: X = 0 Y = 51.4791000009189"
projectIntoHTRS96Z = {HTRS96_UTM_Zone_33N (3767)}
resultString1 = "Point: X = -538880.521630103 Y = 5810593.60821005"