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
Solved! Go to Solution.
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.
from arcgis.gis import GIS
import getpass
password = getpass.getpass("Enter password: ")
gis = GIS('org', 'me', password)
print("Connected to: {}\nConnected as: {}".format(
gis.properties.urlKey + "." + gis.properties.customBaseUrl,
gis.users.me.username))
search_result = gis.content.search(query="title:Liikenneväylät Helsinki", item_type="Feature Layer")
search_result
#[<Item title:"Liikenneväylät Helsinki (Read-only)" type:Feature Layer Collection owner:xxx>,
# <Item title:"Liikenneväylät Helsinki" type:Feature Layer Collection owner:xxx>,
# <Item title:"Liikenneväylät Helsinki (Edit)" type:Feature Layer Collection owner:xxx>]
# Get item to be updated
copy_to_item = search_result[0]
print(copy_to_item.extent)
# [[24.831443582098018, 60.13653584942151], [25.253194793265198, 60.295780040404615]]
# Define which values are updated
item_properties = {
'extent' : '[[24.831, 60.136], [25.253, 60.295]]'
}
copy_to_item.update(item_properties=item_properties)
print(copy_to_item.extent)
# [[24.831, 60.136], [25.253, 60.295]]
Do you mean the extent on the items or inside of the feature service? The approach is a bit different based on the case.
Hi Antti,
Thanks for your response.
I want to set extent on the item.
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.
from arcgis.gis import GIS
import getpass
password = getpass.getpass("Enter password: ")
gis = GIS('org', 'me', password)
print("Connected to: {}\nConnected as: {}".format(
gis.properties.urlKey + "." + gis.properties.customBaseUrl,
gis.users.me.username))
search_result = gis.content.search(query="title:Liikenneväylät Helsinki", item_type="Feature Layer")
search_result
#[<Item title:"Liikenneväylät Helsinki (Read-only)" type:Feature Layer Collection owner:xxx>,
# <Item title:"Liikenneväylät Helsinki" type:Feature Layer Collection owner:xxx>,
# <Item title:"Liikenneväylät Helsinki (Edit)" type:Feature Layer Collection owner:xxx>]
# Get item to be updated
copy_to_item = search_result[0]
print(copy_to_item.extent)
# [[24.831443582098018, 60.13653584942151], [25.253194793265198, 60.295780040404615]]
# Define which values are updated
item_properties = {
'extent' : '[[24.831, 60.136], [25.253, 60.295]]'
}
copy_to_item.update(item_properties=item_properties)
print(copy_to_item.extent)
# [[24.831, 60.136], [25.253, 60.295]]
Thanks.. IT worked..