Getting screen coordinates from map coordinates
Call IDisplayTransformation.FromMapPoint and pass in an IPoint that contains real-world (map) coordinates and x,y device (screen) coordinates that will be populated and returned by the method. See the following steps and code examples:
- Obtain an IScreenDisplay reference to the ScreenDisplay object from IActiveView.ScreenDisplay. See the following code example:
Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay=activeView.ScreenDisplay
[C#] ESRI.ArcGIS.Display.IScreenDisplay screenDisplay=activeView.ScreenDisplay;
- Obtain an IDisplayTransformation reference to the DisplayTransformation object from IScreenDisplay.DisplayTransformation. See the following code example:
Dim displayTransformation As ESRI.ArcGIS.Display.IDisplayTransformation=screenDisplay.DisplayTransformation
[C#] ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation =
screenDisplay.DisplayTransformation
- Call the IDisplayTransformation.FromMapPoint method to convert point's map coordinates to screen coordinates. An IPoint that contains real-world (map) coordinates is passed into the method and x,y that will return corresponding screen coordinates. See the following code example:
displayTransformation.FromMapPoint(mapPoint, x, y)
[C#] displayTransformation.FromMapPoint(mapPoint, out x, out y);
See the following code example that shows the GetScreenCoordinatesFromMapCoorindates function that takes point in map coordinates as the parameter and returns point in screen coordinates:
[VB.NET] 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
[C#] 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;
}
See Also:
How to get map coordinates from screen coordinatesSnippet: Get screen coordinates from map 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 |