HOW TO

Convert geometry between integer and double values

Last Published: April 25, 2020

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



    Article ID: 000009040

    Software:
    • ArcGIS Server

    Receive notifications and find solutions for new or common issues

    Get summarized answers and video solutions from our new AI chatbot.

    Download the Esri Support App

    Discover more on this topic

    Get help from ArcGIS experts

    Contact technical support

    Download the Esri Support App

    Go to download options