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?
Solved! Go to Solution.
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
Creating a point can be done easily, even by adding a gps point waypoint. If you want to do this using python, then the arcpy module is what you need but there is little there to enable zooming, so it sounds you will need to decide what root you want to go and whether the zooming bit is critical especially if you can set the map frame extent apriori
Is there anyone that could show me a code that I could use to achieve my task?
You need to work with the Camera class. When working with the Camera class, it is very important to read and remember:
The ArcGIS Pro application integrates 2D and 3D display and, therefore, the Camera object is used to control both the scale and extent for 2D maps and the camera position for 3D maps in a MapFrame.
Since MapFrames only exist as Layout elements, the majority of the Camera class properties and methods don't do anything when working in a Map.
So, you will need to have a MapFrame in a Layout, and then you can use the MapFrame camera to control center (X, Y), scale, etc...
-----------------------------------------------------
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyr = m.listLayers()[0]
lyt = aprx.listLayouts()[0]
mf = lyt.listElements()[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))
-----------------------------------------------------
I found that this will zoom out until i see everything.
Im still looking for a way to get to x : -73,512864 and y: 45,659871 and to zoom to 1:5 000.
Have you looked at the Camera object properties?
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyr = m.listLayers()[0]
lyt = aprx.listLayouts()[0]
mf = lyt.listElements()[0]
mf.camera.X, mf.camera.Y = -73,512864, 45,659871 # assuming your localization uses commas for decimals
mf.camera.scale = 5000
-------------------------------------------
# Perfection! This is the perfect wait to get at 1:5 000.
-------------------------------------------
import arcpy aprx = arcpy.mp.ArcGISProject("CURRENT") m = aprx.listMaps()[0] lyr = m.listLayers()[0] lyt = aprx.listLayouts()[0] mf = lyt.listElements()[0] mf.camera.scale = 5000
-------------------------------------------
# But this doesn't work. It make's me go in the water near Africa. Its supose to bring me to Canada. # Any idea anyone why it bring's me to wrong place?
-------------------------------------------
mf.camera.X, mf.camera.Y = -73.512864, 45.659871 # True, I needed "." -------------------------------------------
Are you using a 2d or 3d view... there is some discussion within the help topics on camera particularly the sections on 'extent'
I am using 2d view. Even with the topic on camera, i can't find the best way to make it possible with Python. Normaly i code with WinAutomation. Its so simple, it took me 10 min to set up an Automation that add the x,y on the search zone and scale zone in ArcGIS Pro without any click within 3sec and the zone is printed in pdf in that time... Im just looking to learn how to do things with Python.