AnsweredAssumed Answered

Problem running arcpy.CopyFeatures using arcpy.da.SearchCursor

Question asked by rubinsty on Apr 22, 2014
Latest reply on Apr 28, 2014 by rubinsty
Hi, I'm trying to run the following script using python that uses the 10.1 introduced arcpy.da.SearchCursor (with a group by sql clause) to run over a feature layer, select two features with the same field value (hence the group by), export the current features to an outside feature layer, and then calculate a route (using network analyst) between the two point.

The PROBLEM(for now, at least):

when the script runs the arcpy.CopyFeatures, the script fails. I suspect that it is due to the the input features - that row is not a valid input feature. But there I'm stuck, what should I put instead? Am I right in the diagnosis? what can I do to solve it?


 import arcpy  # Check out any necessary licenses arcpy.CheckOutExtension("Network")   # Script arguments Field_To_Group_By = arcpy.GetParameterAsText(0) if Field_To_Group_By == '#' or not Field_To_Group_By:     Field_To_Group_By = "myID" #" # provide a default value if unspecified  Input_Point_Layer = arcpy.GetParameterAsText(1) if Input_Point_Layer == '#' or not Input_Point_Layer:     Input_Point_Layer = "D:\\Projects\\A\\MyDefaultGDB.gdb\\MyDefaultInput" # provide a default value if unspecified  # Local variables: FTGB = Field_To_Group_By Add_Locations_Output_Layer = FTGB  Solved_Layer = Add_Locations_Output_Layer Routes = Solved_Layer route__Value_ = Routes Route__Name___2 = route__Value_ Route__Name___3 = Route__Name___2 totals__2_ = Route__Name___3 Solve_Succeeded = Add_Locations_Output_Layer Value = Field_To_Group_By BasePointsResult = "D:\\Projects\\A\\BasePoints.gdb\\" net_ND = "D:\\Projects\\A\\MyRoute.gdb\\net\\net_ND" totals = "D:\\Projects\\A\\SumsOfRoutes.gdb\\totals" Make_Route_Result_Layer = "Route"  count = 0 field1 = "myID" sql = [None,"GROUP BY myID,  OBJECTID"] currObj =  arcpy.da.SearchCursor(Input_Point_Layer,field1,sql_clause=sql)  try:     for row in currObj:         rowBasePoint = BasePointsResult + "basePoints_" + str(int(row[0]))         print count         # Process: Make Route Layer         arcpy.MakeRouteLayer_na(net_ND, "Route", "Seconds")#, "USE_INPUT_ORDER", "PRESERVE_BOTH", "NO_TIMEWINDOWS", "", "ALLOW_UTURNS", "Oneway", "NO_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "")         print "MakeRouteLayer"          print row         # Process: Copy Features - create BasePoints         arcpy.CopyFeatures_management(row, rowBasePoint )#, "", "0", "0", "0")         print "basePoints_" + str(int(row[0]))         print "Copy Features -basepoints"          # Process: Add Locations         arcpy.AddLocations_na(Make_Route_Result_Layer, "Stops", row, "Name # #;Attr_Length # 0", "5000 Meters", "", "Roads SHAPE;net_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "SNAP", "30 Meters", "EXCLUDE", "Roads  #;net_ND_Junctions #")         print "Add Locations"          # Process: Solve         arcpy.Solve_na(Add_Locations_Output_Layer, "SKIP", "CONTINUE", "")          # Process: Select Data         arcpy.SelectData_management(Solved_Layer, "Routes")