How do I obtain the envelope of a data frame in Layout?

446
2
Jump to solution
07-06-2012 07:35 AM
Highlighted
Regular Contributor
How can I programatically obtain the corner coordinates (in page units) or the envelope of the data frame in layout view?

  I don't seem to be able to do this with iActiveView:Extent as it is  returning the extent of the data view in page units. The below screen  capture shows what I would like to get. The coordinates are roughly;  upper left 0.9,10 and lower right 8, 0.9. Even in page layout  iActive:extent returns: upper left -3.4, 12 and lower right 14,-3 which  is the extent of the entire application window not the data frame as it  appears in layout.
[ATTACH=CONFIG]15823[/ATTACH]
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Regular Contributor
Figured it out with the help of the good folks on GIS SE.  The finished tool can be downloaded here: http://www.arcgis.com/home/item.html?id=a9b032f739254ebeb6221c9294ebc886

View solution in original post

Reply
0 Kudos
2 Replies
Highlighted
New Contributor II
Jakub,

  I believe the general approach in the Page Layout is to obtain a reference to the page element of interest (such as the MapFrame), get its geometry, and then retrieve the Envelope for that particular geometry.

As an example, I have included a Visual C++ code fragment below extracted from one of the methods we use in our ArcGIS Engine application when interacting with the PageLayoutControl (with all error checking removed).


IMapFramePtr   pMapFrame = NULL;
IElementPtr    pElement = NULL;

IGeometryPtr   pMapFrameGeometry = NULL;
IEnvelopePtr   pMapFrameEnvelope = NULL;

HRESULT        hr = S_OK;

double         dXMin = 0.0;
double         dYMin = 0.0;
double         dXMax = 0.0;
double         dYMax = 0.0;

// QI to get the IElement interface
pElement = pMapFrame;

// Obtain the extent of the MapFrame geometry
hr = pElement->get_Geometry(&pMapFrameGeometry);
hr = pMapFrameGeometry->get_Envelope(&pMapFrameEnvelope);

// Note that the min/max X,Y values are in page units (such as inches, cm, etc.)
hr = pMapFrameEnvelope->QueryCoords(&dXMin, &dYMin, &dXMax, &dYMax);


  As another brief example, below is a Visual C++ code fragment that demonstrates one approach for obtaining a reference to the MapFrame element (within the overall Page Layout's graphics container).


IGraphicsContainerPtr     pGraphicsContainer = NULL;
IElementPtr               pElement = NULL;
IMapFramePtr              pMapFrame = NULL;

// Iterate across all the elements in the PageLayoutControl graphics container
pGraphicsContainer = m_pPageLayoutControl->GetGraphicsContainer();
ASSERT(pGraphicsContainer != NULL);

if (pGraphicsContainer != NULL)
{
  hr = pGraphicsContainer->Reset();
  hr = pGraphicsContainer->Next(&pElement);

  // Examine the next page element, only being interested in MapFrame elements for this method
  while (pElement != NULL)
  {
    // QI to determine if this graphic element is the MapFrame
    pMapFrame = pElement;

    if (pMapFrame != NULL)
    {
      // ... processing for the MapFrame element
    }

    hr = pGraphicsContainer->Next(&pElement);
  }


  I hope this helps.

Scott
Reply
0 Kudos
Highlighted
Regular Contributor
Figured it out with the help of the good folks on GIS SE.  The finished tool can be downloaded here: http://www.arcgis.com/home/item.html?id=a9b032f739254ebeb6221c9294ebc886

View solution in original post

Reply
0 Kudos