HOW TO
Unique values symbolize qualitative categories of values and can be based on one or more attribute fields in the dataset. When data are published to ArcGIS Online or Portal for ArcGIS, unique constraints can be added to a field to ensure no duplicate values are stored. This method is useful in identifying unique features, and improves labeling. It also helps stop operations such as appending or updating that add duplicate values into the fields. Constraints can be added by accessing the Data page of the hosted feature layer. It can also be added using ArcGIS API for Python and this article provides the workflow.
from arcgis.gis import GIS from arcgis.features import FeatureLayer, Table, FeatureLayerCollection #For ArcGIS Online gis = GIS("ORGANIZATION_URL", "username", "password") #For ArcGIS Notebook gis = GIS("Home") #For Portal for ArcGIS gis = GIS("https://<machine>.<domain>.com/<web_adaptor_name>", "username", "password", verify_cert=False)
featurel_url = "https://services.domain.com/<xxxxxxxxxxx>/arcgis/rest/services/<feature_layer>/FeatureServer/<sublayer_id>" fl = FeatureLayer(fl_url, gis)
definition_to_add = {"indexes":[ { "fields": "<field_name>", "isUnique": True, "description": "description" } ]} fl.manager.add_to_definition(definition_to_add)
The code block below shows the full working script for Portal for ArcGIS.
from arcgis.gis import GIS from arcgis.features import FeatureLayer, Table, FeatureLayerCollection gis = GIS("https://machine.esri.com/arcgis", "username123", "password123", verify_cert=False) featurel_url = "https://services.domain.com/xxxxxxxxxxx/arcgis/rest/services/testUnique/FeatureServer/0" fl = FeatureLayer(fl_url, gis) definition_to_add = {"indexes":[ { "fields": "<field>", "isUnique": True, "description": "description" } ]} fl.manager.add_to_definition(definition_to_add)
Get help from ArcGIS experts
Download the Esri Support App