Hi All,
I have 100's of layers in my portal. I want to set extent for all those layers to Features in each feature layer. Please let me know how to achieve this using arcgis python api.
Thanks,
Krish
You can do it something along this. Ofc, you need to build logic to go through your services and then on loop update their item properties but you get the idea.
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS <SPAN class="keyword token">import</SPAN> getpass password <SPAN class="operator token">=</SPAN> getpass<SPAN class="punctuation token">.</SPAN>getpass<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Enter password: "</SPAN><SPAN class="punctuation token">)</SPAN> gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'org'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'me'</SPAN><SPAN class="punctuation token">,</SPAN> password<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Connected to: {}\nConnected as: {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN> gis<SPAN class="punctuation token">.</SPAN>properties<SPAN class="punctuation token">.</SPAN>urlKey <SPAN class="operator token">+</SPAN> <SPAN class="string token">"."</SPAN> <SPAN class="operator token">+</SPAN> gis<SPAN class="punctuation token">.</SPAN>properties<SPAN class="punctuation token">.</SPAN>customBaseUrl<SPAN class="punctuation token">,</SPAN> gis<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>me<SPAN class="punctuation token">.</SPAN>username<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> search_result <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN>query<SPAN class="operator token">=</SPAN><SPAN class="string token">"title:Liikenneväylät Helsinki"</SPAN><SPAN class="punctuation token">,</SPAN> item_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"Feature Layer"</SPAN><SPAN class="punctuation token">)</SPAN> search_result <SPAN class="comment token">#[<Item title:"Liikenneväylät Helsinki (Read-only)" type:Feature Layer Collection owner:xyz>,</SPAN> <SPAN class="comment token"># <Item title:"Liikenneväylät Helsinki" type:Feature Layer Collection owner:xyz>,</SPAN> <SPAN class="comment token"># <Item title:"Liikenneväylät Helsinki (Edit)" type:Feature Layer Collection owner:xyz>]</SPAN> <SPAN class="comment token"># Get item to be updated</SPAN> copy_to_item <SPAN class="operator token">=</SPAN> search_result<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>copy_to_item<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># [[24.831443582098018, 60.13653584942151], [25.253194793265198, 60.295780040404615]]</SPAN> <SPAN class="comment token"># Define which values are updated</SPAN> item_properties <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="string token">'extent'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'[[24.831, 60.136], [25.253, 60.295]]'</SPAN> <SPAN class="punctuation token">}</SPAN> copy_to_item<SPAN class="punctuation token">.</SPAN>update<SPAN class="punctuation token">(</SPAN>item_properties<SPAN class="operator token">=</SPAN>item_properties<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>copy_to_item<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># [[24.831, 60.136], [25.253, 60.295]]</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></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><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks.. IT worked..
Hi Antti,
Thanks for your response.
I want to set extent on the item.
Do you mean the extent on the items or inside of the feature service? The approach is a bit different based on the case.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.