Update Feature Layer Extent

694
4
Jump to solution
01-27-2020 09:50 AM
KrishV
by
Occasional Contributor II

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

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AnttiKajanus
New Contributor III

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]]

View solution in original post

4 Replies
AnttiKajanus
New Contributor III

Do you mean the extent on the items or inside of the feature service? The approach is a bit different based on the case.

KrishV
by
Occasional Contributor II

Hi Antti,

Thanks for your response.

I want to set extent on the item.

Thanks,

Krish

0 Kudos
AnttiKajanus
New Contributor III

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]]
KrishV
by
Occasional Contributor II

Thanks.. IT worked..

0 Kudos