0

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[1]
          else:
            shp = shp.union(row[1])
  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[1]) 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:
row[1] = <Polyline object at xxx>
From Function in console
row[1] = <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.

ArcMap 10.6.1

2
  • In ArcMap (and ArcGIS Pro) I think it’s always referred to as the Python Window. I think your Python Console terminology may come from QGIS. – PolyGeo Mar 19 at 4:17
  • 1
    Thanks @PolyGeo! I noticed the edit and certainly appreciate any edits to standardize my technical terminology. – NW_Photo_Laureate Mar 19 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.