HOW TO

Edit read-only domains of a hosted feature layer using Python in ArcGIS Pro

Last Published: July 4, 2022

Summary

As of the June 2018 ArcGIS Online update, domains can be added and updated in ArcGIS Online through the Data tab on the hosted feature layer's item page. For more details, refer to ArcGIS Online: Define attribute lists and ranges.

Edits to read-only domains of a hosted feature layer can be made by running a Python script in ArcGIS Pro and this article provides the workflow.

Procedure

Note:
The workflow below changes the domain name, code, and code value as examples.
  1. Start ArcGIS Pro and open the project.
  2. To open the Python window, on the top ribbon, click Analysis, click the Python drop-down list arrow and select Python window.
The Python window icon in the Python drop-down box on the Analysis tab
  1. Specify the following script in the Python window.
    1. Import the necessary module.
import arcgis
  1. Specify the ArcGIS Online credentials to access the organization content.
gis = arcgis.gis.GIS('https://www.arcgis.com', 'Username', 'Password')
  1. Specify the URL of the hosted feature layer.
url = 'the hosted feature layer URL'
  1. Specify a variable Syntax for the feature layer module.
fs = arcgis.features.FeatureLayer(url, gis)
  1. Specify a variable Syntax to update the specified items in the dictionary.
update_dict ={'fields':[{'name':'field_name','domain':{'type':'codedValue','name':'domain_name','codedValues':[{'name':'code name','code':'code value'},{'name':'code name2','code':'code value2'},{'name':'code name3','code':'code value3'},{'name':'code name4','code':'code value4'},{'name':'code name5','code':'code value5'},{'name':'code name6','code':'code value6'},{'name':'code name7','code':'code value7'}]}}]}
  1. Specify the feature manager module.
fs.manager.update_definition(update_dict)

The following code block demonstrates the full working script.

import arcgis

gis = arcgis.gis.GIS('https://www.arcgis.com', 'Username', 'Password')
url = 'https://services.arcgis.com/Wl7Y1m92PbjtJs5n/arcgis/rest/services/Domain_Art_Test/FeatureServer/0'

fs = arcgis.features.FeatureLayer(url, gis)

update_dict ={'fields':[{'name':'Asia','domain':{'type':'codedValue','name':'Asia','codedValues':[{'name':'Tokyo, Japan','code':1},{'name':'Jakarta, Indonesia','code':2},{'name':'Kuala Lumpur, Malaysia','code':3},{'name':'Beijing, China','code':4},{'name':'Hanoi, Vietnam','code':5},{'name':'Manila, Philippines','code':6},{'name':'Seoul, South Korea','code':7}]}}]}

fs.manager.update_definition(update_dict)

The image below shows the updated read-only hosted feature layer domains using Python for ArcGIS Pro.

The Python script and the results of the updated hosted feature layer domains

Article ID:000027789

Software:
  • ArcGIS API for Python 1 x
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic