I am a little bit confused with the "ADD_TO_SELECTION" possibility. I process a point layer. First, the idea was to process the points with the different GBAUPS attribute separately. And it worked like this:
periode_field = "GBAUPS"
valueList = []
rows = arcpy.SearchCursor(input_gws_layer)
for row in rows:
valueList.append(row.getValue(periode_field))
uniqueSet = set(valueList)
uniqueList = list(uniqueSet)
uniqueList.sort()
print uniqueList
for period in uniqueList:
period = int(period)
bauperiod = arcpy.Select_analysis(input_gws_layer, "input_gws_layer_%i" % period, "GBAUPS = %i" % period)
...... and the processing ......
But I would like now to add continuously the points from the previous layers to the next one (first just one value of the attribute GBAUPS, then this one and the second one etc.) I've tried like this, but the result is exactly the same as in the previous case.
for period in uniqueList:
period = int(period)
# selection
arcpy.MakeFeatureLayer_management(input_gws_layer, "input_gws_layer_lyr")
arcpy.SelectLayerByAttribute_management("input_gws_layer_lyr", "ADD_TO_SELECTION", "GBAUPS = %i" % period)
arcpy.CopyFeatures_management("input_gws_layer_lyr", "input_gws_layer_lyr_%i" % period)
...... and the processing ......
I am not sure if I do something wrong in the SelectLayerByAttribute_management or in the CopyFeatures_management.
1 Answer 1
In your current code, you are running the MakeFeatureLayer_management
command inside the for
loop. This is overwriting the layer referred to by "input_gws_layer_lyr"
each iteration. Here's some revised code that should fix the problem:
arcpy.MakeFeatureLayer_management(input_gws_layer, "input_gws_layer_lyr")
for period in uniqueList:
period = int(period)
# selection
arcpy.SelectLayerByAttribute_management("input_gws_layer_lyr", "ADD_TO_SELECTION", "GBAUPS = %i" % period)
arcpy.CopyFeatures_management("input_gws_layer_lyr", "input_gws_layer_lyr_%i" % period)
#...... and the processing ......