0

I need this to loop through all the OBJECTID for the Fitting layer. Then it get the count for every line feature touching it. Now I'm at the point where I need the attribute table to be edited with that count. I have calculate field and I know arcpy.CalculateField_management is wrong and need to change I just don't know what it should change to.

Almost Finished

Fitting = r'P:\YU_Restricted\Yuma_Admin\Projects\FY18\WO18_100_199\18-190_Gas_Utilities_Update_(Plicka_Joffre)\Gas_Utilites.gdb\UTILITIES_GAS\GasUtilNode_gControlFitting'
Pipe = r'P:\YU_Restricted\Yuma_Admin\Projects\FY18\WO18_100_199\18-190_Gas_Utilities_Update_(Plicka_Joffre)\Service\Service_Pipe.gdb\GasUtilNode_Segment'

         # Process Selection Loop
 with arcpy.da.SearchCursor(Fitting, ["OID@"]) as cursor:
     for row in cursor:
         # Process: Make Feature Layer
         arcpy.MakeFeatureLayer_management(Fitting, "FittingLyr", "OBJECTID = " + str(row[0]))

         # Process: Select Layer By Location
         arcpy.SelectLayerByLocation_management('GasUtilNode_Segment', 'BOUNDARY_TOUCHES', "FittingLyr", '#', 'NEW_SELECTION', 'NOT_INVERT')

         # Process: Copy Features
         arcpy.CopyFeatures_management('GasUtilNode_Segment', r'P:\\YU_Restricted\\Yuma_Admin\\Projects\\FY18\\WO18_100_199\\18-190_Gas_Utilities_Update_(Plicka_Joffre)\\results', '#', "0", "0", "0")

         # Process: Get Count
         arcpy.GetCount_management("results")

         # Local variables:
         lyrfile = "results"
         result = arcpy.GetCount_management(lyrfile)
         count = int(result.getOutput(0))
         calcuFld = count 

         # Process: Delete 
         arcpy.CalculateField_management(Fitting,"mediaID",calcuFld)
         arcpy.DeleteFeatures_management(r'P:\\YU_Restricted\\Yuma_Admin\\Projects\\FY18\\WO18_100_199\\18-190_Gas_Utilities_Update_(Plicka_Joffre)\\results')         
         arcpy.DeleteFeatures_management("FittingLyr") 
  • 4
    Please paste code as text, not a screen shot. If that's from the arcpy window you've pasted it from somewhere, copy/paste the text into your question. – Michael Stimson May 23 '18 at 22:14
  • I messed that edit up about 4 times – Tony May 23 '18 at 22:26
  • You should also remove the "... " from the beginning of each code line, and then highlight all your code, and click the Format button ({ }) which inserts four spaces at the beginning of each line to indicate that it is code. That way potential answerers can copy/paste your code for testing. – PolyGeo May 23 '18 at 22:33
  • Your layer lyrfile = "resultsNUMBER" doesn't exist, you need arcpy.MakeFeatureLayer_management( "resultsNUMBER",r'P:\\YU_Restricted\\Yuma_Admin\\Projects\\FY18\\WO18_100_199\\18-190_Gas_Utilities_Update_(Plicka_Joffre)\\resultsNUMBER') but you don't need that really, you can getcount straight from the resultsNUMBER feature class. What is mediaID? (int, float, text?) Do you have any error messages? You also don't want to do DeleteFeatures_management("FittingLyr") as that will delete what you've just calculated, you want arcpy.Delete_management("FittingLyr") to get rid of the layer object. – Michael Stimson May 23 '18 at 23:00
  • 1
    You could also save yourself a lot of grief by performing a Spatial Join then Summary Statistics with a case field of input id (to count the number of joined features), attribute join to the statistics table and calculate the summary count. – Michael Stimson May 23 '18 at 23:05

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.