AnsweredAssumed Answered

How do I loop this to go through the every feature in the layer.

Question asked by jajoffre on May 21, 2018
Latest reply on May 21, 2018 by jajoffre

I'm trying to loop this to go through the every feature in a layer. New to python and learning on the go here. This is the first time writing something so if see anything else let me know.

 

 

Import arcpy

...

... # Local variables:

... GasUtilNode_Segment = "GasUtilNode_Segment"

... GasUtilNode_Segment__3_ = GasUtilNode_Segment

... GasUtilNode_gControlFitting = "GasUtilNode_gControlFitting"

... GasUtilNode_gControlFitting_ = "\\\\zpstg07.mcip.usmc.mil\\roaming_profile\\home$\\geofi\\JJoffre\\Documents\\ArcGIS\\Default.gdb\\GasUtilNode_gControlFitting_"

...

...

...

... # Process: Select

... arcpy.Select_analysis ("GasUtilNode_gControlFitting", r'P:\YU_Restricted\Yuma_Admin\Projects\FY18\WO18_100_199\18-190_Gas_Utilities_Update_(Plicka_Joffre)\Gas_Utilites.gdb\UTILITIES_GAS\Fitting2', "OBJECTID = 1")

...

... # Process: Make Feature Layer

... arcpy.MakeFeatureLayer_management( "Fitting2",r'P:\YU_Restricted\Yuma_Admin\Projects\FY18\WO18_100_199\18-190_Gas_Utilities_Update_(Plicka_Joffre)\Gas_Utilites.gdb\UTILITIES_GAS\Fitting2Layer', '#', '#', "OBJECTID OBJECTID VISIBLE NONE;gasUtilNodeIDPK gasUtilNodeIDPK VISIBLE NONE;gasNodeType gasNodeType VISIBLE NONE;mediaID mediaID VISIBLE NONE;operationalStatus operationalStatus VISIBLE NONE;realPropertyNetworkIdentifier realPropertyNetworkIdentifier VISIBLE NONE;realPropertySiteUniqueID realPropertySiteUniqueID VISIBLE NONE;realPropertyUniqueIdentifier realPropertyUniqueIdentifier VISIBLE NONE;sdsFeatureDescription sdsFeatureDescription VISIBLE NONE;sdsFeatureName sdsFeatureName VISIBLE NONE;sdsMetadataID sdsMetadataID VISIBLE NONE;facilityConditionIndex facilityConditionIndex VISIBLE NONE;facilityIDFK facilityIDFK VISIBLE NONE;facilityNumber facilityNumber VISIBLE NONE;contractNumber contractNumber VISIBLE NONE;dateInService dateInService VISIBLE NONE;diameter diameter VISIBLE NONE;diameterUOM diameterUOM VISIBLE NONE;fittingType fittingType VISIBLE NONE;installationCode installationCode VISIBLE NONE;isCUI isCUI VISIBLE NONE;maximoIDFK maximoIDFK VISIBLE NONE;projectID projectID VISIBLE NONE;utilityOwner utilityOwner VISIBLE NONE;createdDate createdDate VISIBLE NONE;createdBy createdBy VISIBLE NONE;lastEditedBy lastEditedBy VISIBLE NONE;lastEditedDate lastEditedDate VISIBLE NONE;sdsID sdsID VISIBLE NONE;Shape Shape VISIBLE NONE")

...

... # Process: Select Layer By Location

... arcpy.SelectLayerByLocation_management('GasUtilNode_Segment', 'BOUNDARY_TOUCHES', r'P:\YU_Restricted\Yuma_Admin\Projects\FY18\WO18_100_199\18-190_Gas_Utilities_Update_(Plicka_Joffre)\Gas_Utilites.gdb\UTILITIES_GAS\Fitting2Layer', '#', 'NEW_SELECTION', 'NOT_INVERT')

...

... # Process: Copy Features

... arcpy.CopyFeatures_management(GasUtilNode_Segment__3_, results_shp, '#', "0", "0", "0")

...

... # Process: Get Count

... arcpy.GetCount_management(results_shp)

...

... # Local variables:

... lyrfile = r"P:\\YU_Restricted\\Yuma_Admin\\Projects\\FY18\\WO18_100_199\\18-190_Gas_Utilities_Update_(Plicka_Joffre)\\results.shp"

... result = arcpy.GetCount_management(lyrfile)

... count = int(result.getOutput(0))

... calcuFld = count

...

...

...

... # Process: Calculate Field

... arcpy.CalculateField_management ("GasUtilNode_gControlFitting","mediaID",calcuFld)

...

... # Process: Delete

... arcpy.Delete_management(r'P:\YU_Restricted\Yuma_Admin\Projects\FY18\WO18_100_199\18-190_Gas_Utilities_Update_(Plicka_Joffre)\results.shp', 'ShapeFile')

... arcpy.Delete_management("Fitting2")

... arcpy.Delete_management(r'P:\YU_Restricted\Yuma_Admin\Projects\FY18\WO18_100_199\18-190_Gas_Utilities_Update_

Outcomes