Why does ArcPy mapView.defaultCamera.getExtent not provide the real extents?

680
4
01-02-2019 12:38 AM
PaulKennedy1
New Contributor III

Hi,

I am using arcgispro 2.2.4, and have a python script which needs the actual extents of the current map view.  I use this code...

#get the map extents from the current map...
 aprx = arcpy.mp.ArcGISProject("current")
 aprxMap = aprx.listMaps("Map")[0]
 mapView = aprx.listMaps()[0]
 mapExtents=mapView.defaultCamera.getExtent()
 TL = mapExtents.upperLeft
 BR = mapExtents.lowerRight

which suggests the map upper latitude limit is -13.978...

however, if I roll my mouse to the top left of the map view, it is more like -13.933

The extents do change when I pan the map, but they are always a significant subset of the actual viewable area, which is really strange.

Can some one please let me know how I can get the actual extents of the map view?

many thanks

0 Kudos
4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Have you used this background?

Camera—ArcPy | ArcGIS Desktop 

it is a derived property so when you were scrolling is it at full extent? and is there any coordinate system set for the map?

PaulKennedy1
New Contributor III

Hi Dan,

I do have a spatial reference set for the map. It is GCS WGS 1984

Having debugged this further, the camera extents DO-NOT change when the map is panned/zoomed and the python script rerun. The numbers remain the same.

I guess I am doing something wrong, just not sure what!

0 Kudos
PaulKennedy1
New Contributor III

Evening Dan,

any more thoughts how I can use python to get hold of the extents of my map view?  I dont see any way forward right now, as the camera simply does not provide the correct extents to the map view

        #get the map extents from the current map...
        aprx = arcpy.mp.ArcGISProject("current")
        mapView = aprx.listMaps()[0]
        mapExtents=mapView.defaultCamera.getExtent()
        TL = mapExtents.upperLeft
        BR = mapExtents.lowerRight

        ptGeometry = arcpy.PointGeometry(TL, mapExtents.spatialReference)
        TLprojectedGeometry = ptGeometry.projectAs(spatialReference)

        ptGeometry = arcpy.PointGeometry(BR, mapExtents.spatialReference)
        BRprojectedGeometry = ptGeometry.projectAs(spatialReference)
0 Kudos
PeteCrosier
Occasional Contributor III

From what I can see, camera extents only work correctly with map frames within layouts.

This is with a project with one map, one layout and one map frame in the layout..

p = arcpy.mp.ArcGISProject("current")

l = p.listLayouts()[0]

f = l.listElements()[0]

f.camera.getExtent().upperLeft

<Point (436809.68803366175, 433075.2979928817, #, #)>

.. navigate in the layout's map frame..
f.camera.getExtent().upperLeft
<Point (437874.1306022081, 432917.17427798914, #, #)>