Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Can you access joined tables through a da.SearchCursor?

I've found documentation to do this with SearchCursor (arcpy), but nothing for the 10.1 data access module.

share|improve this question
add comment

2 Answers 2

The arcpy.da.*Cursor are functionally equivalent to their arcpy.*Cursor counterpart... some additional niceties (context, more sql), and lots more speed. see doc for full details: http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000011000000

When writing new code, always use arcpy.da.Cursors. If you have critical code that uses old cursors, you may want to switch that code to new cursors.

share|improve this answer
add comment
up vote 0 down vote accepted

I realized that the join in ArcMap does not persist in an arcpy session. So I needed to create the join in arcpy before accessing the table with a SearchCursor. A simple example:

import arcpy
from sys import exc_info
from traceback import format_tb

exoticPath = r"...\Exotic_Species"
protocolsPath=r"...\Treatment_Protocols"

try:
    arcpy.MakeFeatureLayer_management(exoticPath,"exotic")
    arcpy.MakeTableView_management(protocolsPath,"protocols")
    arcpy.AddJoin_management("exotic","Species","protocols","CommonName")

    with arcpy.da.SearchCursor("exotic", ["Exotic_Species.Species","Treatment_Protocols.Priority"]) as cursor:
        for row in cursor:
            print (row[0], row[1])

except:
        tb = exc_info()[2]
        tbinfo = format_tb(tb)[0]
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)
        print pymsg + "\n"
        print msgs


finally:
    if arcpy.Exists("exotic"):
        arcpy.Delete_management("exotic")
    if arcpy.Exists("protocols"):
        arcpy.Delete_management("protocols")
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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