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


Get Map Coordinates from Screen Coordinates Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Get Map Coordinates from Screen Coordinates Snippet

Obtain the real world (map) coordinates from the device (screen) coordinates.

[C#]
///<summary>Obtain the real world (map) coordinates from the device (screen) coordinates.</summary>
/// 
///<param name="screenPoint">An IPoint interface that contains the X,Y values from the device (screen) in your Windows application.</param>
///<param name="activeView">An IActiveView interface</param>
///  
///<returns>An IPoint interface containing the real world (map) coordinates is returned.</returns>
///  
///<remarks></remarks>
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
}
[Visual Basic .NET]
'''<summary>Obtain the real world (map) coordinates from the device (screen) coordinates.</summary>
''' 
'''<param name="screenPoint">An IPoint interface that contains the X,Y values from the device (screen) in your Windows application.</param>
'''<param name="activeView">An IActiveView interface</param>
'''  
'''<returns>An IPoint interface containing the real world (map) coordinates is returned.</returns>
'''  
'''<remarks></remarks>
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(screenPoint.X), CInt(screenPoint.Y))

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.Geometry