I have been trying to use arcpy.da.seachcursor to rip through a datasets rows and use each in an intersect analysis like so:

with arcpy.da.SearchCursor(in_feature, ['SHAPE@', 'NAME']) as cursor:
    for f in cursor:
        data = []
        print '...Working on {}'.format(f[1])
        for path, subdirs, files in os.walk(in_folder):
            for i,x in enumerate(files):
                if x.endswith('.shp'):
                   arcpy.Intersect_analysis(os.path.join(path, x)+';' + f[0], 'in_memory\\r{}'.format(i))
        arcpy.Merge_management(data, out_folder + '\\out_dataset_{}.shp'.format(name))

it yields the following error code message:

TypeError: cannot concatenate 'str' and 'Polygon' objects

Upon reviewing how to fix this, I have stumbled upon code like:


that is used by da cursors (reference: https://arcpy.wordpress.com/2012/02/01/find-overlapping-features/). This has piqued my interest but I cannot find documentation on the implementation of this data structure. Where do I find it? Are there methods for doing other spatial processes like intersect?

Hopefully through this I find out the answer to my error code, but if anyone has a quick bit of knowledge outside of the data structure I am looking for info on, please drop it :)

  • arcpy.Intersect_analysis([os.path.join(path, name), f[0]], 'in_memory\\r{}'.format(i)) - RuntimeError: Object: Error in executing tool – D_C Feb 22 '18 at 20:01

Intersect wants a list of inputs so this wont work: arcpy.Intersect_analysis(os.path.join(path, name)+';' + f[0],...

Also try copying the polygon object to the in memory workspace and use this as input to the intersection:

arcpy.CopyFeatures_management(f[0], r'in_memory\temp')
arcpy.Intersect_analysis([os.path.join(path, name), r'in_memory\temp'],..

For this to work you probably need to set

arcpy.env.overwriteOutput = True

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.