How to transform a rectangle from page to map units


You can use this function to transform an envelope (rectangle) from page units to map units.

How to use

  1. Copy-paste this sample's code into a module in your Visual Basic Editor.
  2. Call this procedure by passing in an envelope in page units. This envelope is transformed into map units.
[VBA]
Private Sub TransformRectFromPageToMapUnits(pEnv As IEnvelope)
    
    'Get the active views
    Dim pLayoutView As IActiveView
    Dim pMapView As IActiveView
    Dim pMap As IMap
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    Set pLayoutView = pMxDoc.PageLayout
    Set pMapView = pMap
    
    'Get the display transformations
    Dim pPageTransformation As IDisplayTransformation
    Dim pMapTransformation As IDisplayTransformation
    Set pPageTransformation = pLayoutView.ScreenDisplay.DisplayTransformation
    Set pMapTransformation = pMapView.ScreenDisplay.DisplayTransformation
    
    'Transform envelope from page to map coordinates
    Dim Rect As tagRECT
    'Transform from Page units to Device units
    pPageTransformation.TransformRect pEnv, Rect, esriTransformToDevice + esriTransformPosition
    'Transform from Device units to Map units
    pMapTransformation.TransformRect pEnv, Rect, esriTransformToMap + esriTransformPosition
    
End Sub