AnsweredAssumed Answered

ArcPy getExtent() on rotated Map are different for MapView versus MapFrame?

Question asked by VCEGIS500 on Apr 5, 2020
Latest reply on Apr 5, 2020 by VCEGIS500

My goal is to create a python script that generates a current view polygon in ArcGIS Pro (2.5). I am testing the code below by just running it in the Python Window. I'd like this to function much like all the "data frame to polygon" tools for ArcGIS Desktop.

 

When looking at a "Map" tab, I use the following code to get the extent of the view (not a specific layer, the whole view of the frame):

current_project = arcpy.mp.ArcGISProject("CURRENT")
active_object = current_project.activeView
extent = active_object.camera.getExtent()
print(extent)

As I understand it, activeView returns a MapView object, and camera.getExtent() gets an Extent. The printed extent results are the same for a map with a rotation of 0 and a rotation 45. This is what I want, as I'd like the output polygons to be the same size (if the map is at the same scale) regardless of rotation, and then I just rotate the final output polygon if I need to using the value from camera.heading. The end result of the larger script, ran once at "0 rotation" and once at "45 rotation," are two equal-sized polygons, just rotated accordingly.

 

Map at 0 rotation, Extent:   (675,978 728,153) (676,606 728,496)

Map at 45 rotation, Extent: (675,978 728,153) (676,606 728,496)

 

However, this does not seem to work with a MapFrame from a Layout. When looking at a "Layout" tab, here is the code:

current_project = arcpy.mp.ArcGISProject("CURRENT")
active_object = current_project.activeView
map = active_object.listElements("MAPFRAME_ELEMENT")[0]
extent = map.camera.getExtent()
print(extent)

In this case, there is the extra step of getting the MapFrame from the Layout, as activeView returns a Layout object. I can't tell if if is possible to get a MapView from a Layout. When printed, the results of a map at 0 and 45 rotation are as follows (doesn't matter that they are different from above, the area may have been different, I only care that they are different from one another):

 

Map at 0 rotation, Extent:   (676,162 728,233) (676,437 728,379)

Map at 45 rotation, Extent: (676,151 728,157) (676,448 728,455)

 

Since the initial size of the "Extents" are different, I get different sized polygons for the rotated and non-rotated versions. The images attached show what all this looks like in the first (map tab) and second (layout tab) cases.

 

getExtent() appears to do different things if it is called on a MapView versus a MapFrame. For a MapView, rotation does not appear to impact the extent; in a MapFrame, rotation does appear to impact the extent. Is there a better approach to getting the visible extent boundaries while looking at a layout? Or is there a method of obtaining a MapView from a MapFrame or Layout object when I'm working in a Layout tab so I avoid this issue?

Attachments

Outcomes