I am attempting to identify features in multiple feature layers by their attributes and perform a union on the geometry object. Essentially pull specific features from different layers and combine them into a new feature. A decomposed version of the function works in the console directly, but for some reason when I run it with a custom Python function imported into the Python Window (ArcMap 10.6.1) and run it there, it does not work. I've identified the culprit (in the post title) but don't know how to fix it.
def union_multiple(fp_feat, field_name, target_val, fname): arcpy.env.workspace = 'path/to/default.gdb' for i in range(len(fp_feat)): feat = fp_feat[i] field = field_name[i] target = target_val[i] with arcpy.da.SearchCursor(feat, [field, 'SHAPE@']) as cursor: for row in cursor: if target_val in row: if 'shp' not in locals(): shp = row else: shp = shp.union(row) arcpy.CopyFeatures_management(shp, fname_out)
Then in the console I import the function and run it:
from zachs_arc_scripts import union_multiple fp_feat = ['feat1', 'feat2', 'feat3'] field_name = ['util_type', 'util_type', 'util_type'] target_val = ['pline', 'pline', 'pline'] fname = 'plines_union' union_multiple(fp_feat, field_name, target_val, fname)
Herein lies the problem - it runs and
plines_union is created, but it's only containing one of the feats. BUT it's not a problem with my code - I've tried. It's this:
If I add a
print(row) to debug I get two different objects between directly running parts of this script decomposed in the Python Window and if I run using an imported function:
Directly in Python Window:
<Polyline object at xxx>
From Function in console
<geoprocessing describe geometry object object at xxx>
So it's NOT a syntax error, it's something with running via a function that returns the
geoprocessing describe geometry object object instead of the
Polyline object. FYI I am utilizing Table of Content feature layers, NOT full file paths.