2

I've been playing around with 'Maintaining Attribute Integrity' functions found here:

http://resources.arcgis.com/en/help/...000000n000000/

I see how I can set domains and subtypes to control the values in the attribute table to maintain quality and how to validate features and relationships using the tools ArcGIS provides.

I don't know if I am missing something, but I have a situation where values in one field in an attribute table, depend on the value in another field in the same attribute table.

Let's have 3 fields (CITY, PROVINCE, COUNTRY)

Let's say I set a domain on the CITY field to populate a list of all the cities in the world. I want to be able to validate that the PROVINCE and COUNTRY fields are correct. So, for example, if I enter 'Toronto' in the CITY field, I want to validate that the PROVINCE field is 'Ontario' and the COUNTRY field is 'Canada'

I'm not sure how to set up the domains or subtypes to do this. I want to be able to run the validate functionality found here:

http://resources.arcgis.com/en/help/...000000v000000/

To throw an invalid error if these conditions aren't met. Can anyone suggest how I can accomplish this?

I can do this through python, but the validation in ArcGIS does a lot of things I was going to script, so I'm hoping it will do this for me too.

Thanks, Mike

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 10, 2013 at 19:28
2
  • 2
    Good question! ArcInfo Workstation had a command called CODEFIND which did exactly this but it may have been lost in translation to ArcGIS Desktop. DataReviewer is the most likely place to find it. Commented May 10, 2013 at 20:32
  • Thanks PolyGeo. I'm working with a Standard license, so I don't have ArcInfo. Unfortunately, the direction I got from my manager is that I am allowed to write a script, but he won't let me fork out 2500ドル for the Data Reviewer license :( Commented May 10, 2013 at 20:52

1 Answer 1

2

I have just submitted an ArcGIS Idea for Validation of Hierarchical Fields but since your comment says that your requirement is now for Python I thought I would put together some code showing how to do this using dictionaries.

  • The CityProvinceLookup table has two fields CITY and PROVINCE with a row for each valid combination.
  • The ProvinceCountryLookup table has two fields PROVINCE and COUNTRY with a row for each valid combination.
  • The test table has fields CITY, PROVINCE and COUNTRY.

The code is not as pythonic as it could be but I wanted to keep it fairly readable.

import arcpy
# Make dictionaries of lookup tables
dictCityProvince = {}
rows = arcpy.SearchCursor(r"C:\temp\test.gdb\CityProvinceLookup")
for row in rows:
 dictCityProvince[row.CITY] = row.PROVINCE
del row,rows
dictProvinceCountry = {}
rows = arcpy.SearchCursor(r"C:\temp\test.gdb\ProvinceCountryLookup")
for row in rows:
 dictProvinceCountry[row.PROVINCE] = row.COUNTRY
del row,rows
# Now test the data
rows = arcpy.SearchCursor(r"C:\temp\test.gdb\test")
for row in rows:
 if row.CITY == None or row.CITY == "" or row.CITY == " ":
 print "Row " + str(row.OBJECTID) + " has no value for CITY"
 hasCity = False
 else:
 hasCity = True
 if row.PROVINCE == None or row.PROVINCE == "" or row.PROVINCE == " ":
 print "Row " + str(row.OBJECTID) + " has no value for PROVINCE"
 hasProvince = False
 else:
 hasProvince = True
 if row.COUNTRY == None or row.COUNTRY == "" or row.COUNTRY == " ":
 print "Row " + str(row.OBJECTID) + " has no value for COUNTRY"
 hasCountry = False
 else:
 hasCountry = True
 if hasCity and hasProvince:
 if row.CITY in dictCityProvince:
 if row.PROVINCE == dictCityProvince[row.CITY]:
 pass
 else:
 print row.CITY + " is NOT in " + row.PROVINCE + " (Row " + str(row.OBJECTID) + ")"
 else:
 print row.CITY + " is NOT in CityProvinceLookup (Row " + str(row.OBJECTID) + ")"
 if hasProvince and hasCountry:
 if row.PROVINCE in dictProvinceCountry:
 if row.COUNTRY == dictProvinceCountry[row.PROVINCE]:
 pass
 else:
 print row.PROVINCE + " is NOT in " + row.COUNTRY + " (Row " + str(row.OBJECTID) + ")"
 else:
 print row.PROVINCE + " is NOT in ProvinceCountryLookup (Row " + str(row.OBJECTID) + ")"
del row,rows
answered May 11, 2013 at 22:06
1
  • Hey PolyGeo, I finally had a chance to look at this code. I made a couple adjustments to suit my needs, but it works well. I like the idea of using dictionaries this way. It's new to me. Thanks for taking the time creating and posting this code! Commented May 30, 2013 at 17:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.