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


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

Get Screen Coordinates from Map Coordinates Snippet

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

[C#]
///<summary>Obtain the device (screen) coordinates from the real world (map) coordinates.</summary>
/// 
///<param name="mapPoint">An IPoint interface that contains the real world (map) coordinates</param>
///<param name="activeView">An IActiveView interface</param>
///  
///<returns>An IPoint interface that contains the X,Y device (screen) coordinated for your Windows application</returns>
///  
///<remarks></remarks>
public ESRI.ArcGIS.Geometry.IPoint GetScreenCoordinatesFromMapCoorindates(ESRI.ArcGIS.Geometry.IPoint mapPoint, ESRI.ArcGIS.Carto.IActiveView activeView)
{
  if (mapPoint == null || mapPoint.IsEmpty || activeView == null)
  {
    return null;
  }
  ESRI.ArcGIS.Display.IScreenDisplay screenDisplay=activeView.ScreenDisplay;
  ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation=screenDisplay.DisplayTransformation;

  System.Int32 x;
  System.Int32 y;
  displayTransformation.FromMapPoint(mapPoint, out x, out y);
  ESRI.ArcGIS.Geometry.IPoint returnPoint=new ESRI.ArcGIS.Geometry.PointClass();
  returnPoint.PutCoords(x, y);

  return returnPoint;
}
[Visual Basic .NET]
'''<summary>Obtain the device (screen) coordinates from the real world (map) coordinates.</summary>
''' 
'''<param name="mapPoint">An IPoint interface that contains the real world (map) coordinates</param>
'''<param name="activeView">An IActiveView interface</param>
'''  
'''<returns>An IPoint interface that contains the X,Y device (screen) coordinated for your Windows application</returns>
'''  
'''<remarks></remarks>
Public Function GetScreenCoordinatesFromMapCoorindates(ByVal mapPoint As ESRI.ArcGIS.Geometry.IPoint, ByVal activeView As ESRI.ArcGIS.Carto.IActiveView) As ESRI.ArcGIS.Geometry.IPoint

  If mapPoint Is Nothing OrElse mapPoint.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

  Dim x As System.Int32
  Dim y As System.Int32
  displayTransformation.FromMapPoint(mapPoint, x, y)
  Dim returnPoint As ESRI.ArcGIS.Geometry.IPoint=New ESRI.ArcGIS.Geometry.PointClass
  returnPoint.PutCoords(x, y)

  Return returnPoint

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
  • ESRI.ArcGIS.System