Python and related tables

918
3
06-28-2014 10:13 AM
WesKing
New Contributor
Hi Everyone,
I'm relatively new using Python and I can't seem to find any good information on what I'm attempting to do.  Thanks in advance if you have any tips.

Set up:
I have 3 tables; A (spatial) B (non-spatial) and C (non-spatial).  A is related to B and B is related to C.  All are in a file geodatabase and relationship classes have been built.  I would like to select features from A and traverse through B and ultimately work with the data in C.  In ArcMap I would select features in A, open related table B, then open related table C...and do what I need to do.  I would smile, pat myself on the back and go to sleep feeling satisfied 🙂  But I want to do this using Python and can't seem to figure out how, other than creating a list using a search cursor to store the unique values in A then using that list and another search cursor on B to create another list, and then do the same on C.  It seems there must be a more efficient way to do this in Python.

Thanks,
Wes
Tags (2)
0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus
It seems that your described workflow is working.  Why do you feel the need to code it?  Is it part of something larger?  There is little/no way to "select" a feature using python other than via a query.  Could you describe your end purpose in more detail
0 Kudos
WesKing
New Contributor
Hi Dan, thanks for the response.

Yes there is something larger.  We have an ongoing project where new vegetation data is collected on about 120 transects at regular intervals.  The end results will be statistical calculations such as Jaccard index, percent similarity, and others.  These will be calculated in so many combinations (over 3000 in one case) that a manual process would be too time consuming.  Also, my goal is to enable others that have an understanding of these statistics, but lack the software knowledge to run their own calculations, to be able to use a script to be self-sufficient.

I hope that gives a better understanding of my goal.

Wes
0 Kudos
ChrisSnyder
Regular Contributor III
Would this "auto-relate" take place via the ArcMap (like you would want a button or script tool to select the records in table C, per your selected features in Feature class A), or in a stand alone script?

Either way, this is very doable in Python using some search cursors... It might look something like:

fc = r"C:\temp\test.gdb\my_fc"
fieldValueListA = [r[0] for r in arcpy.da.SearchCursor(fc, ["FIELD_A"])]
tblB = r"C:\temp\test.gdb\tbl_b"
fieldValueListB = [r[0] for r in arcpy.da.SearchCursor(tblB, ["FIELD_B"], "FIELD_A in (" + str(fieldValueListA)[1:-1] + ")")]
#....and so on
0 Kudos