Select to view content in your preferred language

Is "Optimize Layer Drawing" Supported in API?

1133
4
11-08-2021 12:39 PM
PatrickMcKinney99
Regular Contributor

If you have a polyline or polygon hosted feature service in ArcGIS Online, there is an option under the Settings tab to Optimize Layer Drawing, which "increases the drawing speed of line and polygon layers with detailed geometry (e.g., many vertices) but also uses additional storage space to do so."

Does anyone know if there is a Python API way to run this process on feature services?  It would be a very beneficial thing to do via scripting.

4 Replies
ArcProOne
Occasional Contributor

See example eight on this page: https://developers.arcgis.com/rest/services-reference/online/update-definition-feature-layer-.htm

Not a full answer, but maybe will get you on the right track.

0 Kudos
DiegoMeira
Occasional Contributor

When I have Optimize Layer Drawing active I cannot use featureLayer.layers[0].edit_features(). 
Having a way to programmatically disable the optimization temporarily, to perform the edit_features, would be appreciated. 

0 Kudos
JosephRhodes2
Frequent Contributor

Old thread but thought I'd post this here in case Google brings anyone here. There is an update_definition method in the arcgis.features.managers module of the Python API, but it's been inconsistent for me. So I just make the call through the REST API. The code below enables layer optimization for the specified feature service item and layer index:

 

from arcgis.gis import GIS
import requests
import json

gis = (portal_url, username, password)
item_id = '' # item id of feature service wih layer to optimize

item = gis.content.get(item_id)
layer_index = 0 # layer index in feature service for layer to optimize
update_def_url = f"{item.layers[layer_index].url}/updateDefinition".replace(r'rest/services',r'rest/admin/services')

token = gis._con.token

data = {'token':token,
        'f': 'json',
        'async': 'true',
        'updateDefinition': r'{"multiScaleGeometryInfo":{"levels":[]}}'
        }

result = requests.post(update_def_url, data=data, timeout=10)
status_url = f"{result.json().get('statusURL')}?token={token}&f=json"

status = None

while not status == 'Completed' and not status == 'Failed':
    status = requests.get(status_url, timeout=10).json().get('status')
    print(f"Optimization status: {status}")
    time.sleep(10)
else:
    if status == 'Completed':
        logging.info(f"Layer drawing optimized successfully for {item.title} ({item.id})")
    if status == 'Failed':
        status = requests.get(status_url, timeout=10).json()
            logging.error(f"Layer optimization failed for {item.title} ({item.id}). Status: {status.json()}")

 

miro_aus
Emerging Contributor

Thank you, got brought here by Google exactly for this. I am having success setting it up through FeatureLayerCollection and layer.manager.update_definition with no problems so far. 

from arcgis.features import FeatureLayerCollection

flc = FeatureLayerCollection.fromitem(fs_item)
flc.layers[0].manager.update_definition({"multiScaleGeometryInfo":{"levels":[]}})

I am a bit worried about inconsistency you mentioned, might need to add scheduled monitoring of published layers later.

0 Kudos