0

I need to Replace the Domain on Field level on my Geodatabase.

My Geodatabase having multiple features and tables where at each on field one Domain is assigned, I need to replace that Domain and Delete old domain.

To better way understand. (example)

  1. Table1 having Field XYZ on which Domain A1 is assigned

now I like to replace A1 with A2 and once it change for all the tables I would like to delete A1 from my Domains.

I search on internet but I could not find any helping materials.

Do I do this with performing some query on database ?

select * from sde.GDB_ITEMS

Above query get me all the domains which exists for my Geodatabase but I could not to find relation how this domains is assigned to my tables (how's the relationship between them?)

I do believe that with that relationship I can replace the domain.

I am not python developer.. but I am trying to write this script..

>>> import arcpy 
... admin_workspace = "Database Connections/WGis01-SDE.sde" 
... arcpy.env.workspace = admin_workspace 
... domain_to_search = r"MM Work Function_1" #supply the CV domain name 
... datasets = arcpy.ListDatasets() 
... for dataset in datasets: 
... if dataset == N.Electric: 
... featureclasses = arcpy.ListFeatureClasses() 
... for featureclass in featureclasses: 
... print featureclass 
...

Parsing error IndentationError: expected an indented block (line 9)

1

You could write a script with arcpy to iterate through the feature classes and tables in your SDE workspace by setting the workspace environment to the sde instance and using the ListDatasets, ListFeatureClasses and ListTables functions. You would use the ListFields function with each feature class and table to get its field list, and then iterate the fields to read the domain property of each field object. Any field with the domain you want to replace would have the domain property of that field changed to the new domain. Once all feature classes and tables were processed you could delete the outdated domain.

Since you have begun to write a script the first thing you need to know about Python is that proper indentation of lines is required for the script to run. If clauses and For loops are normally followed by an indented line. So I would write the script as follows (fix the replacement domain name):

import arcpy 
admin_workspace = "Database Connections/WGis01-SDE.sde" 
arcpy.env.workspace = admin_workspace 
domain_to_search = r"MM Work Function_1" #supply the CV domain name 
domain_replacement = r"MM Work Function_2" #supply the new CV domain name
datasets = arcpy.ListDatasets() 
for dataset in datasets: 
    featureclasses = arcpy.ListFeatureClasses("", "All", dataset) 
    for featureclass in featureclasses: 
        fields = arcpy.ListFields(featureclass)
        for field in fields:
            if field.domain == domain_to_search:
                print field.name + " in " + featureclass + " has the old domain"
                field.domain = domain_replacement
featureclasses = arcpy.ListFeatureClasses() # outside any dataset
for featureclass in featureclasses: 
    fields = arcpy.ListFields(featureclass)
    for field in fields:
        if field.domain == domain_to_search:
            print field.name + " in " + featureclass + " has the old domain"
            field.domain = domain_replacement
tables = arcpy.ListTables() # tables are outside any dataset
for table in tables: 
    fields = arcpy.ListFields(table)
    for field in fields:
        if field.domain == domain_to_search:
            print field.name + " in " + table + " has the old domain"
            field.domain = domain_replacement
arcpy.DeleteDomain_management(admin_workspace, domain_to_search)
  • Thanks. I am not python developer.. but I am trying to write this script.. >>> import arcpy ... admin_workspace = "Database Connections/WGisDs01-SDE.sde" ... arcpy.env.workspace = admin_workspace ... domain_to_search = r"MM Work Function_1" #supply the CV domain name ... ... datasets = arcpy.ListDatasets() ... for dataset in datasets: ... if dataset == N.Electric: ... featureclasses = arcpy.ListFeatureClasses() ... for featureclass in featureclasses: ... print featureclass ... Parsing error IndentationError: expected an indented block (line 9) >>> – Hardik Nov 30 '14 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.