English

How To: Convert geometry between integer and double values

Summary

Mobile ADF is manipulating its geometry, including coordinates, using integer value types. As a programmer, it may be necessary to frequently convert real-world coordinates, expressed in double coordinates, into integer coordinates. For instance, a Web Service may return a geocoded position to plot on the map. If the double coordinates are based on the Map Spatial Reference or on WGS84, convert them into integer map coordinates using the SpatialReference class.
This class is accessible from the MapCache class and allows transformation from double to integer for a given projection. It also allows transformation of Lat/Long into double or integer coordinates.
For example:

Code:
ServerCoordinate svrCoord = new ServerCoordinate(-117.234, 34.0453);
ServerCoordinate[] svrCoords = new ServerCoordinate[] { svrCoord };
CoordinateCollection coordCollection = map1.MapCache.SpatialReference.Wgs84ToMobileCoordinate(svrCoords);
map1.FlashGeometry(Pens.Black, new SolidBrush(Color.Red), 4, 3, coordCollection[0]);

The SpatialReference class can be also used to convert integer coordinates into real-world coordinates based on the map spatial reference or to WGS84.
For example:

Code:
private void map1_MouseMove(object sender, ESRI.ArcGIS.Mobile.MapMouseEventArgs e)
{
ServerCoordinate svrCoord = map1.MapCache.SpatialReference.MobileToServerGeometry(e.MapCoordinate);
ServerCoordinate[] svrCoords = new ServerCoordinate[] {svrCoord};
svrCoords = map1.MapCache.SpatialReference.ToWgs1984(svrCoords);
System.Console.WriteLine("Lat: {0}; Lon: {1}", svrCoords[0].Y, svrCoords[0].X);
}

Another useful class to use during conversion is the UnitConver class that allows transforming linear and square units.

Procedure