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?
Try this:
<SPAN class="keyword token">import</SPAN> arcpy aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN> lyt <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listLayouts<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> mf <SPAN class="operator token">=</SPAN> lyt<SPAN class="punctuation token">.</SPAN>listElements<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> SR <SPAN class="operator token">=</SPAN> mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>getExtent<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>spatialReference pt <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">73.512864</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">45.59871</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN><SPAN class="number token">4326</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> pt <SPAN class="operator token">=</SPAN> pt<SPAN class="punctuation token">.</SPAN>projectAs<SPAN class="punctuation token">(</SPAN>SR<SPAN class="punctuation token">)</SPAN> mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>scale <SPAN class="operator token">=</SPAN> <SPAN class="number token">5000</SPAN> mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">,</SPAN> mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">=</SPAN> pt<SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">,</SPAN> pt<SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">.</SPAN>Y <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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 arcpyaprx = 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?
<SPAN class="keyword token">import</SPAN> arcpy aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN> m <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> lyr <SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> lyt <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listLayouts<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> mf <SPAN class="operator token">=</SPAN> lyt<SPAN class="punctuation token">.</SPAN>listElements<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">,</SPAN> mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">=</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">73</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">512864</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">45</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">659871</SPAN> <SPAN class="comment token"># assuming your localization uses commas for decimals</SPAN> mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>scale <SPAN class="operator token">=</SPAN> <SPAN class="number token">5000</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
<CODE><CODE><SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 14px;"> <EM># Perfection! This is the perfect wait to get at 1:5 000. </EM></SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">-------------------------------------------</SPAN><CODE><SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 14px;"> import</SPAN> arcpy aprx <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>mp<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>ArcGISProject<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 14px;">"CURRENT"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN> m <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> aprx<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>listMaps<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN> lyr <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> m<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>listLayers<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN> lyt <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> aprx<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>listLayouts<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN> mf <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> lyt<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>listElements<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN> mf<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>camera<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>scale <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">5000 </SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">------------------------------------------- </SPAN><CODE><SPAN style="border: 0px; color: #990000; font-weight: inherit; font-size: 14px;"><EM># But this doesn't work. It make's me go in the water near Africa. Its supose to bring me to Canada.</EM> <EM># Any idea anyone why it bring's me to wrong place? </EM></SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">-------------------------------------------</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;"><SPAN style="color: #990000;"> </SPAN><STRONG><SPAN style="color: #990000;">mf</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN><SPAN style="color: #990000;">camera</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN><SPAN style="color: #990000;">X</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN style="color: #990000;"> mf</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN><SPAN style="color: #990000;">camera</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN><SPAN style="color: #990000;">Y </SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit;">=</SPAN><SPAN style="color: #990000;"> </SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit;">-</SPAN><SPAN class="" style="border: 0px; font-weight: inherit;"><SPAN style="color: #990000;">73</SPAN><SPAN style="color: #999999;">.</SPAN></SPAN><SPAN class="" style="border: 0px; font-weight: inherit;">512864</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN style="color: #990000;"> </SPAN><SPAN class="" style="border: 0px; font-weight: inherit;">45</SPAN><SPAN style="border: 0px; color: #999999; font-weight: inherit;">.</SPAN><SPAN class="" style="border: 0px; font-weight: inherit;">659871 </SPAN><EM style="color: #990000;"> # True, I needed "."</EM></STRONG><SPAN style="color: #990000;"> ------------------------------------------- </SPAN></SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">-------------------------------------------</SPAN>
<CODE><CODE><SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 14px;"> <EM># Perfection! This is the perfect wait to get at 1:5 000. </EM></SPAN>
<SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">-------------------------------------------</SPAN>
<CODE><SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 14px;"> import</SPAN> arcpy aprx <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>mp<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>ArcGISProject<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 14px;">"CURRENT"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN> m <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> aprx<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>listMaps<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN> lyr <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> m<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>listLayers<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN> lyt <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> aprx<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>listLayouts<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN> mf <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> lyt<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>listElements<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">]</SPAN> mf<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>camera<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 14px;">.</SPAN>scale <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit; font-size: 14px;">=</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">5000 </SPAN>
<SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;">------------------------------------------- </SPAN>
<CODE><SPAN style="border: 0px; color: #990000; font-weight: inherit; font-size: 14px;"><EM># But this doesn't work. It make's me go in the water near Africa. Its supose to bring me to Canada.</EM> <EM># Any idea anyone why it bring's me to wrong place? </EM></SPAN>
<SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 14px;"><SPAN style="color: #990000;"> </SPAN><STRONG><SPAN style="color: #990000;">mf</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN><SPAN style="color: #990000;">camera</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN><SPAN style="color: #990000;">X</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN style="color: #990000;"> mf</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN><SPAN style="color: #990000;">camera</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN><SPAN style="color: #990000;">Y </SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit;">=</SPAN><SPAN style="color: #990000;"> </SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit;">-</SPAN><SPAN class="" style="border: 0px; font-weight: inherit;"><SPAN style="color: #990000;">73</SPAN><SPAN style="color: #999999;">.</SPAN></SPAN><SPAN class="" style="border: 0px; font-weight: inherit;">512864</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN style="color: #990000;"> </SPAN><SPAN class="" style="border: 0px; font-weight: inherit;">45</SPAN><SPAN style="border: 0px; color: #999999; font-weight: inherit;">.</SPAN><SPAN class="" style="border: 0px; font-weight: inherit;">659871 </SPAN><EM style="color: #990000;"> # True, I needed "."</EM></STRONG><SPAN style="color: #990000;"> ------------------------------------------- </SPAN></SPAN>
Are you using a 2d or 3d view... there is some discussion within the help topics on camera particularly the sections on 'extent'
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.