# Create a list of all the polygon feature classes zonePolys = arcpy.ListFeatureClasses("Zone*") for fc in zonePolys: arcpy.AddField_management(fc,"SumOfValues","LONG") arcpy.MakeFeatureLayer_management("OriginalLayer", "OriginalLayer_Lyr") arcpy.SelectLayerByLocation_management("OriginalLayer_Lyr","INTERSECT",fc) # Calculate the sum of the values in the selected features in OriginalLayer_Lyr SumValues = ?? # Take the sum value of the line features field and populate the polygon layer's new SumOfValues field with it arcpy.CalculateField_management(fc,"SumOfValues",SumValues)
Solved! Go to Solution.
zonePolys = arcpy.ListFeatureClasses("Zone*") for fc in zonePolys: arcpy.AddField_management(fc,"SumOfValues","DOUBLE") arcpy.MakeFeatureLayer_management("OriginalLayer", "OriginalLayer_Lyr") arcpy.SelectLayerByLocation_management("OriginalLayer_Lyr","INTERSECT",fc) # Calculate the sum of the values in the selected features in OriginalLayer_Lyr with arcpy.da.SearchCursor("OriginalLayer_Lyr", ["Length"]) as cursor: sumValues = 0 for row in cursor: sumValues += row[0] # Take the sum value of the line features field and populate the polygon layer's new SumOfValues field with it arcpy.CalculateField_management(fc,"SumOfValues",sumValues)
zonePolys = arcpy.ListFeatureClasses("Zone*") for fc in zonePolys: arcpy.AddField_management(fc,"SumOfValues","DOUBLE") arcpy.MakeFeatureLayer_management("OriginalLayer", "OriginalLayer_Lyr") arcpy.SelectLayerByLocation_management("OriginalLayer_Lyr","INTERSECT",fc) # Calculate the sum of the values in the selected features in OriginalLayer_Lyr with arcpy.da.SearchCursor("OriginalLayer_Lyr", ["Length"]) as cursor: sumValues = 0 for row in cursor: sumValues += row[0] # Take the sum value of the line features field and populate the polygon layer's new SumOfValues field with it arcpy.CalculateField_management(fc,"SumOfValues",sumValues)
zonePolys = arcpy.ListFeatureClasses("Zone*") for fc in zonePolys: arcpy.AddField_management(fc,"SumOfValues","LONG") arcpy.MakeFeatureLayer_management("OriginalLayer", "OriginalLayer_Lyr") arcpy.SelectLayerByLocation_management("OriginalLayer_Lyr","INTERSECT",fc) someValue = sum([r[0] for r in arcpy.da.SearchCursor("OriginalLayer_Lyr",["FIELD_NM"])]) arcpy.CalculateField_management(fc,"SumOfValues",someValue) #haha get it...