2

I want to run the ArcGIS Data reviewer in Python code, to check domains.

My scenario is check the attribute values if its meet the domain value.

Is it possible to run ArcGIS Data Reviewer in Python code ?

  • 1
    What do you intend to do if the value isn't in the domain? – Fezter Aug 20 '14 at 3:18
  • 1
    A better question might be "how can I check attribute domains using Python?" – Stephen Lead Aug 20 '14 at 3:55
  • I agree with @StephenLead that checking attribute values against domains is straightforward ArcPy rather than requiring any Data Reviewer involvement (and licensing). – PolyGeo Aug 20 '14 at 4:08
3

Here is my part of the code :

#I have a dictionary field name and domain name

self.domainName = {'Inspection_Type' : 'VM_SourceType',
                          'Clearance_From_Conductor' : 'VM_Clearance' ,
                          'Clearance_Category' : 'VM_ClearanceClass' ,
                          'Outside_Clearance' : 'VM_OutClearance' ,
                          'Density' : 'VM_Density' ,
                          'Voltage' : 'VM_Voltage' ,
                          'Severity' : 'VM_SeverityCode'
                          }

# this method to populate domains in dictionary
def populateDomains(self):

    lstdomains = arcpy.da.ListDomains(self.inWorkSpace)

    for domain in lstdomains:

        tmp_domain = domain.codedValues

        if (domain.type == "Text" and domain.domainType == 'CodedValue'):
            # make the keys upper case to check domain
            tmp_domain = self.upper_kdict(tmp_domain)




        if (domain.name=='VM_SourceType' and domain.domainType == 'CodedValue'):
            self.VM_SourceType = tmp_domain

        if (domain.name=='VM_Clearance' and domain.domainType == 'CodedValue'):
            self.VM_Clearance = tmp_domain

        if (domain.name=='VM_ClearanceClass' and domain.domainType == 'CodedValue'):
            self.VM_ClearanceClass = tmp_domain

        if (domain.name=='VM_OutClearance' and domain.domainType == 'CodedValue'):
            self.VM_OutClearance = tmp_domain

        if (domain.name=='VM_Density' and domain.domainType == 'CodedValue'):
            self.VM_Density = tmp_domain

        if (domain.name=='VM_Voltage' and domain.domainType == 'CodedValue'):
            self.VM_Voltage = tmp_domain

        if (domain.name=='VM_SeverityCode' and domain.domainType == 'CodedValue'):
            self.VM_SeverityCode = tmp_domain



# this method validate records , I am using python namedtuple from row ; return error message from the function if records value not in domain.

def validateRecords(self,worktask):

    try:


        strValidtion = ""

        for fldname in worktask._fields:

            # Check the task name 
            if (fldname=='Task'):
                mValue = getattr(worktask , fldname)
                if not (mValue in self.task_name):
                    if (strValidtion ==""):
                        strValidtion= "Field: Task is not valid value"
                    else:
                        strValidtion= strValidtion +  ", Field: Task is not valid value"

            #check if it require check domains
            if self.domainName.has_key(fldname):
                mValue = getattr(worktask , fldname)

                if ((mValue is None) or (mValue == '') or mValue == ' '):
                    continue

                # make the value is upper case to check with domain value if it is string
                if isinstance(mValue,basestring):
                    mValue = mValue.upper()

                dname = self.domainName.get(fldname)

                if (dname=='VM_SourceType'):
                    aDomain = self.VM_SourceType

                if (dname=='VM_Clearance'):
                    aDomain = self.VM_Clearance

                if (dname=='VM_ClearanceClass'):
                    aDomain = self.VM_ClearanceClass

                if (dname=='VM_OutClearance'):
                    aDomain = self.VM_OutClearance

                if (dname=='VM_Density'):
                    aDomain = self.VM_Density

                if (dname=='VM_Voltage'):
                    aDomain = self.VM_Voltage

                if (dname=='VM_SeverityCode'):
                    aDomain = self.VM_SeverityCode

                # check the value exists in domain keys
                if not (mValue in aDomain.keys()):
                    if (strValidtion ==""):
                        strValidtion= "Field :" + fldname + " Value:" + mValue + " not in domain "
                    else:
                        strValidtion= strValidtion +  ", Field :" + fldname + " Value:" + mValue + " not in domain "






        return strValidtion
    except :
            raise
2

If you want to use the ArcGIS Data Reviewer with ArcPy then the GIS & Python blog seems to be a fan and offers some starting code:

Data Reviewer for ArcGIS Desktop is a pretty neat tool, especially when errors need to go through a system of correction and validation. A common workflow is to create standalone or batch checks and write the results to data reviewer in an ArcMap session. However, results created from a python script can be written to a data reviewer session as well. The following lines demonstrate how to check out the data reviewer extension, create a new session, retrieve that session’s ID, and write results to the data reviewer geodatabase.

However, if you only want to perform checks, and not write to a data reviewer session then the ArcPy pseudo code could be:

  1. Use arcpy.ListDomains to get values or range of your domain
  2. Use a arcpy.da.SearchCursor to read through your feature class values and compare them against the coded values or range
  3. Print result, write it to a table, etc
  • Thanks , I read the domain and make dictionaries based on code and descriptions and open a search cursor and check records against those dictionaries and write in a csv the records that not in domain. – shafey Aug 22 '14 at 2:59
  • If you are willing to share that code then do not be afraid to share it here as a second answer to your own question, which it is also permissible for you to accept. This could help you to accumulate some reputation points towards unlocking some more GIS SE privileges. – PolyGeo Aug 22 '14 at 3:11

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.