I have two point feature layers. One represents cleaning and the other catch basins. The cleaning layer exists as a hosted feature service in ArcGIS Online. In ArcGIS Pro, I am trying to run the below code to snap cleaning points to catch basin points so they are coincident. It only runs through the main loop one time. It used to run fine but now I can't figure out why. I am not a programmer so I am hoping someone that is can help me figure out why my code won't loop more than once. Any ideas? Thanks!
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"E:\MDC\Catch Basin Cleaning\map_docs\Catch Basin Cleaning 2018\Inspection 2018 Review.gdb"</SPAN>
cleaning_fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Cleaning and Sediment Monitoring'</SPAN>
catchBasin_fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">'ssCatchbasin'</SPAN>
objId_field <SPAN class="operator token">=</SPAN> <SPAN class="string token">'OBJECTID'</SPAN>
name_field <SPAN class="operator token">=</SPAN> <SPAN class="string token">'SAPLINKID_FK'</SPAN>
name_field2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">'SAPLINKID'</SPAN>
<SPAN class="comment token">#Create a where clause based on the cleaning date</SPAN>
aCleanDateWhereClause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"CleanDate >= timestamp '2018-06-26 01:10:00'"</SPAN>
aTownWhereClause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"TOWNCODE = '01'"</SPAN>
<SPAN class="comment token">#Create layer files</SPAN>
cleaning_layer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>cleaning_fc<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"cleaning_lyr"</SPAN><SPAN class="punctuation token">,</SPAN> aCleanDateWhereClause<SPAN class="punctuation token">)</SPAN>
catchbasin_layer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>catchBasin_fc<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"catchbasin_lyr"</SPAN><SPAN class="punctuation token">,</SPAN> aTownWhereClause<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Clear any selections</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute<SPAN class="punctuation token">(</SPAN>cleaning_layer <SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CLEAR_SELECTION"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute<SPAN class="punctuation token">(</SPAN>catchbasin_layer <SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CLEAR_SELECTION"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Create a search cursor using an SQL expression to count</SPAN>
<SPAN class="comment token">#total number of cleaning records to be snapped</SPAN>
totalRec <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>cleaning_layer<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN>objId_field<SPAN class="punctuation token">,</SPAN> name_field<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
totalRec <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Total Cleaning Recs: "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>totalRec<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#I get 734 records here</SPAN>
<SPAN class="comment token">#Create a search cursor using an SQL expression to loop through only</SPAN>
<SPAN class="comment token">#those points that have been created since a specific date. Snap those</SPAN>
<SPAN class="comment token">#cleaning points to the ssCatchbasin so they are coincident</SPAN>
curRec <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="comment token">#counter for keep tracking of where we are in the loop</SPAN>
<SPAN class="comment token">#the same loop below only runs one time</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>cleaning_layer<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN>objId_field<SPAN class="punctuation token">,</SPAN> name_field<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
curRec <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN>
sapLinkId <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="string token">"GIS"</SPAN> <SPAN class="keyword token">in</SPAN> sapLinkId<SPAN class="punctuation token">:</SPAN>
layer1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute<SPAN class="punctuation token">(</SPAN>cleaning_layer <SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SAPLINKID_FK="</SPAN> <SPAN class="operator token">+</SPAN><SPAN class="string token">"'"</SPAN><SPAN class="operator token">+</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="operator token">+</SPAN><SPAN class="string token">"'"</SPAN><SPAN class="punctuation token">)</SPAN>
layer2 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute<SPAN class="punctuation token">(</SPAN>catchbasin_layer <SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SAPLINKID="</SPAN> <SPAN class="operator token">+</SPAN><SPAN class="string token">"'"</SPAN><SPAN class="operator token">+</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="operator token">+</SPAN><SPAN class="string token">"'"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Snap_edit<SPAN class="punctuation token">(</SPAN>layer1<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN>layer2<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"VERTEX"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"120000 feet"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
percentDone <SPAN class="operator token">=</SPAN> round<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>curRec<SPAN class="operator token">/</SPAN>totalRec<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN><SPAN class="number token">100</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Processing row "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" for SAPLINKID "</SPAN> <SPAN class="operator token">+</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" ("</SPAN><SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>percentDone<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"% percent complete)"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Done!"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>