This document is archived and information here might be outdated.  Recommended version.


How to get map coordinates from screen coordinates (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with the map display > Working with the map display > How to get map coordinates from screen coordinates (ArcObjects .NET 10.6 SDK)

How to get map coordinates from screen coordinates


Summary
This topic summarizes how to obtain real-world (map) coordinates from device (screen) coordinates.

Getting map coordinates from screen coordinates

Call IDisplayTransformation.ToMapPoint by passing in an x,y of IPoint that contains coordinate values from the device (screen) in your Windows application and IActiveView. The IPoint interface containing real-world (map) coordinates is returned by the method. See the following steps and code examples:
  1. Obtain an IScreenDisplay reference to the ScreenDisplay object from IActiveView.ScreenDisplay. See the following code example:
[VB.NET]
Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay=activeView.ScreenDisplay
[C#]
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay=activeView.ScreenDisplay;
  1. Obtain an IDisplayTransformation reference to the DisplayTransformation object from IScreenDisplay.DisplayTransformation. See the following code example:
[VB.NET]
Dim displayTransformation As ESRI.ArcGIS.Display.IDisplayTransformation=screenDisplay.DisplayTransformation
[C#]
ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation =
    screenDisplay.DisplayTransformation
  1. Call the IDisplayTransformation.ToMapPoint method to convert x,y device (screen) coordinates to real-world (map) coordinates. The IPoint interface that contains real-world (map) coordinates is returned by the method. See the following code example:
[VB.NET]
displayTransformation.ToMapPoint(CInt(Fix(screenPoint.X)), CInt(Fix(screenPoint.Y)))
[C#]
displayTransformation.ToMapPoint((System.Int32)screenPoint.X, (System.Int32)
    screenPoint
See the following code example that shows the GetMapCoordinatesFromScreenCoordinates function that takes point in device (screen coordinates) and returns point in real-world (map) coordinates:
[VB.NET]
Public Function GetMapCoordinatesFromScreenCoordinates(ByVal screenPoint As ESRI.ArcGIS.Geometry.IPoint, ByVal activeView As ESRI.ArcGIS.Carto.IActiveView) As ESRI.ArcGIS.Geometry.IPoint
    
    If screenPoint Is Nothing OrElse screenPoint.IsEmpty OrElse activeView Is Nothing Then
        Return Nothing
    End If
    
    Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay=activeView.ScreenDisplay
    Dim displayTransformation As ESRI.ArcGIS.Display.IDisplayTransformation=screenDisplay.DisplayTransformation
    
    Return displayTransformation.ToMapPoint(CInt(Fix(screenPoint.X)), CInt(Fix(screenPoint.Y)))
    
End Function
[C#]
public ESRI.ArcGIS.Geometry.IPoint GetMapCoordinatesFromScreenCoordinates
    (ESRI.ArcGIS.Geometry.IPoint screenPoint, ESRI.ArcGIS.Carto.IActiveView
    activeView)
{

    if (screenPoint == null || screenPoint.IsEmpty || activeView == null)
    {
        return null;
    }

    ESRI.ArcGIS.Display.IScreenDisplay screenDisplay=activeView.ScreenDisplay;
    ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation =
        screenDisplay.DisplayTransformation;

    return displayTransformation.ToMapPoint((System.Int32)screenPoint.X, 
        (System.Int32)screenPoint.Y); // Explicit cast.
}


See Also:

How to get screen coordinates from map coordinates
Snippet: Get geographic coordinates in globe
Snippet: Get map coordinates from screen coordinates




Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine