1

I have a list to hold the iterated results of running arcpy.MakeFeatureLayer and 'arcpy.CopyFeatures` geoprocesses.

selectList = []
fip = '13245'
for fc in featureclasses:
     select = arcpy.MakeFeatureLayer_management(fc, "temp_lyr","FIPS_CODE = '{}'".format(fip))
     arcpy.env.workspace = "C:/Workspace/Sandbox/selects.gdb"
     selectFeatures = arcpy.CopyFeatures_management(select, "select_{}".format(fip))
     selectList.append(selectFeatures)

When I print(selectList) it gives me a weird list of results:

[<Result'C:\\Workspace\\Sandbox\\MapChangeProject\\selects.gdb\\select_13245'>, <Result 'C:\\Workspace\\Sandbox\\MapChangeProject\\selects.gdb\\select_06037'>]

What I want to do is merge all of these results together into one feature like this:

arcpy.Merge_management(selectList, "merge")

What am I doing wrong here and how do I get my results into a format that will work for my merge?

  • 3
    you have a result object so try this, result = arcpy.CopyFeatures_management(select, "select_{}".format(fip)) selectFeatures = result.getOutput(0) – klewis Sep 5 '18 at 23:03
  • 2
    @klewis is on the right path but I would like to point out that for each iteration of fc your selected features will be overwritten as the value for fip doesn't change in the loop so what you'll end up with is just the last feature class len(featureclasses) times. Try changing the output of copy features to "in_memory\\select_{}".format(fc) then selectList.append( "in_memory\\select_{}".format(fc)) then perform a loop after the merge for fc in selectList: del fc to clean up... assuming you have plenty of memory otherwise ensure your env.overwriteOutput == True or the script will fail. – Michael Stimson Sep 5 '18 at 23:23
2

All arcpy geoprocessing tools return a Result object. Result objects cannot be used as inputs into other geoprocessing tools. You'll need the path to the tool output to populate your list.

selectList = []
fip = '13245'
for fc in featureclasses:
     arcpy.MakeFeatureLayer_management(fc, "temp_lyr","FIPS_CODE = '{}'".format(fip))
     arcpy.env.workspace = "C:/Workspace/Sandbox/selects.gdb"
     selectFeatures = arcpy.CopyFeatures_management("temp_lyr", "select_{}".format(fip))
     selectList.append("select_{}".format(fip))
| improve this answer | |

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.