Hi,
I am trying to update the extent of each layers in a feature layer after overwritting the data with new features (located elsewhere), but my script doesn't seem to have any effect. As anyone managed to update the extent of all layers using python?
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
# Connect to ArcGIS Online (replace 'username' and 'password' with your credentials)
gis = GIS("https://www.arcgis.com", "username", "password")
# Access the feature layer by item ID
item_id = 'item_id'
item = gis.content.get(item_id)
# Access the feature layer collection
feature_layer_collection = FeatureLayerCollection.fromitem(item)
# Get the layers within the feature layer collection
layers = feature_layer_collection.layers
# Iterate through each layer
for layer in layers:
# Update the extent of the layer (replace the values with the desired extent)
layer.manager.update_definition({
'extent': {
"xmin": new_min_x,
"ymin": new_min_y,
"xmax": new_max_x,
"ymax": new_max_y,
"spatialReference": {
"wkid": new_wkid
}
}
})
# Print the properties of the updated layer
print("Properties of Layer '{}' after updating extent:".format(layer.properties.name))
print(layer.properties)