Zoom in at 1:5 000 at x : -73,512864 and y: 45,659871

2537
14
Jump to solution
02-20-2017 12:02 PM
Jean-SimonLevert
New Contributor II

I have

x :  -73,512864

and

y:  45,659871

What is the code i need to put in ArcGIS Pro Python to zoom in directly at that GPS place and to zoom it at 1:5 000?

Anyone can help?

Tags (2)
0 Kudos
14 Replies
DanPatterson_Retired
MVP Emeritus

Yes... It think the python access is probably designed with analysis in mind.  Navigating the whole properties object can be a bit much.  For example in the MapFrame topic there are vague references to the setting of local and global view.  I suspect you are in a global view since you are probably off the coast of Africa, south of Ghana as you seem to reference, which suggests that you are in some sort of web projection, like web Mercator and not in a coordinate system that is using decimal degrees.  Your coordinates are indeed just east of me and not in Kazakshtan as would an omission of the -ve in longitude.  I wouldn't expect python to perform your required task as simply as other interfaces since I suspect it is not designed for this.  Good luck

JoshuaBixby
MVP Esteemed Contributor

Try this:

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")
lyt = aprx.listLayouts()[0]
mf = lyt.listElements()[0]

SR = mf.camera.getExtent().spatialReference
pt = arcpy.PointGeometry(arcpy.Point(-73.512864, 45.59871),
                         arcpy.SpatialReference(4326))
pt = pt.projectAs(SR)

mf.camera.scale = 5000
mf.camera.X, mf.camera.Y = pt.firstPoint.X, pt.firstPoint.Y
Jean-SimonLevert
New Contributor II

This is the answer!

Thx alot! Work perfectly!

0 Kudos
Jean-SimonLevert
New Contributor II
Those code lines work perfectly when I want to zoom in my layout.
I try to work the same code lines to zoom in in the map instead of the layout.

I tried to replace
lyt = aprx.listLayouts()[0]

for

lyt = aprx.listMaps()[0]



But nothing works... anyone can help me?



0 Kudos
JoshuaBixby
MVP Esteemed Contributor

It isn't possible to do what you want.  You need to control the camera, and you can only access the camera from a map frame.  A Map let's you access the Default Camera, but it is the Default Camera and not the active camera. 

The explanation for this behavior/limitation lies in the Migrating from arcpy.mapping to ArcGIS Pro—ArcPy | ArcGIS Desktop documentation:

New Map, MapFrame, and Camera objects replace the role of the data frame

The ArcGIS Pro framework has introduced new capabilities that affect how you interact with map displays and therefore new objects are being introduced. These new Map, MapFrame, and Camera objects each serve a specific role and are tightly integrated with one another.

A Map in ArcGIS Pro represents a collection of tabular and symbolized geographic layers and also persists information such as coordinate system, default views of the data, and various other metadata. The only way to visualize the contents of a map is in a map view, as a tab in the application with its own table of contents, or in a mapframe on a page layout. The same map can be displayed in multiple map views or map frames. If a layer is added to a map, all map views and map frames that reference that map will display the added layer. If you want a different collection of layers or tables to be displayed in different views, you will need to build and use different maps.

The key line is, "The same map can be displayed in multiple map views or map frames."  I believe it is this reason that Esri has used to not allow access to the camera in the Map object.

0 Kudos